From db153e1f0eaf199d4d69df6efb7241f883583fa9 Mon Sep 17 00:00:00 2001 From: Luke Klinker Date: Fri, 22 Sep 2017 16:21:43 -0500 Subject: [PATCH] don't assume 24dp for the status bar size --- gradle.properties | 2 +- .../delegate/AbstractDragDismissDelegate.java | 15 ++++++++ .../delegate/DragDismissDelegate.java | 3 ++ .../android/drag_dismiss/util/ColorUtils.java | 16 +++++++++ .../drag_dismiss/util/StatusBarHelper.java | 36 +++++++++++++++++++ .../layout/dragdismiss_activity_recycler.xml | 1 + .../DismissableActivityNormalContent.java | 3 +- .../main/res/layout/activity_scrollable.xml | 1 - 8 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 library/src/main/java/xyz/klinker/android/drag_dismiss/util/StatusBarHelper.java diff --git a/gradle.properties b/gradle.properties index ba01525..e72c44b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ # limitations under the License. # -GRADLE_PLUGIN_VERSION=3.0.0-beta5 +GRADLE_PLUGIN_VERSION=3.0.0-beta6 BUILD_TOOLS_VERSION=26.0.1 ANDROID_SUPPORT_VERSION=26.0.1 diff --git a/library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/AbstractDragDismissDelegate.java b/library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/AbstractDragDismissDelegate.java index 9932028..1c6f1f7 100644 --- a/library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/AbstractDragDismissDelegate.java +++ b/library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/AbstractDragDismissDelegate.java @@ -20,16 +20,20 @@ import android.graphics.Color; import android.os.Bundle; import android.support.annotation.CallSuper; +import android.support.design.widget.AppBarLayout; +import android.support.design.widget.CoordinatorLayout; import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatDelegate; import android.support.v7.widget.Toolbar; import android.view.View; import android.view.ViewGroup; +import android.widget.FrameLayout; import android.widget.ProgressBar; import xyz.klinker.android.drag_dismiss.DragDismissIntentBuilder; import xyz.klinker.android.drag_dismiss.R; import xyz.klinker.android.drag_dismiss.util.ColorUtils; +import xyz.klinker.android.drag_dismiss.util.StatusBarHelper; import xyz.klinker.android.drag_dismiss.view.ElasticDragDismissFrameLayout; public abstract class AbstractDragDismissDelegate { @@ -40,6 +44,7 @@ public abstract class AbstractDragDismissDelegate { private ProgressBar progressBar; private Toolbar toolbar; + private AppBarLayout appBarLayout; private View statusBar; private String dragElasticity; @@ -61,6 +66,7 @@ public void onCreate(Bundle savedInstanceState) { progressBar = (ProgressBar) activity.findViewById(R.id.dragdismiss_loading); toolbar = (Toolbar) activity.findViewById(R.id.dragdismiss_toolbar); + appBarLayout = (AppBarLayout) activity.findViewById(R.id.dragdismiss_app_bar); statusBar = activity.findViewById(R.id.dragdismiss_status_bar); setupToolbar(); @@ -114,6 +120,15 @@ private void setupToolbar() { if (!shouldShowToolbar) { toolbar.setVisibility(View.GONE); } + + int statusBarHeight = StatusBarHelper.getStatusBarHeight(activity); + statusBar.getLayoutParams().height = statusBarHeight; + + if (appBarLayout == null) { + ((CoordinatorLayout.LayoutParams) toolbar.getLayoutParams()).topMargin = statusBarHeight; + } else { + ((CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams()).topMargin = statusBarHeight; + } } private void setupDragDismiss() { diff --git a/library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/DragDismissDelegate.java b/library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/DragDismissDelegate.java index 5da7401..f95668f 100644 --- a/library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/DragDismissDelegate.java +++ b/library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/DragDismissDelegate.java @@ -25,6 +25,7 @@ import android.widget.FrameLayout; import xyz.klinker.android.drag_dismiss.R; +import xyz.klinker.android.drag_dismiss.util.StatusBarHelper; import xyz.klinker.android.drag_dismiss.view.ElasticDragDismissFrameLayout; import xyz.klinker.android.drag_dismiss.view.ToolbarScrollListener; @@ -67,6 +68,8 @@ public void onDrag(float elasticOffset, float elasticOffsetPixels, float rawOffs FrameLayout elasticContent = (FrameLayout) activity.findViewById(R.id.dragdismiss_content); elasticContent.addView(callback.onCreateContent(activity.getLayoutInflater(), elasticContent, savedInstanceState)); + + ((NestedScrollView.LayoutParams) elasticContent.getLayoutParams()).topMargin = StatusBarHelper.getStatusBarHeight(activity); } @Override diff --git a/library/src/main/java/xyz/klinker/android/drag_dismiss/util/ColorUtils.java b/library/src/main/java/xyz/klinker/android/drag_dismiss/util/ColorUtils.java index d1fb839..95487d0 100644 --- a/library/src/main/java/xyz/klinker/android/drag_dismiss/util/ColorUtils.java +++ b/library/src/main/java/xyz/klinker/android/drag_dismiss/util/ColorUtils.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2017 Luke Klinker + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package xyz.klinker.android.drag_dismiss.util; import android.annotation.TargetApi; diff --git a/library/src/main/java/xyz/klinker/android/drag_dismiss/util/StatusBarHelper.java b/library/src/main/java/xyz/klinker/android/drag_dismiss/util/StatusBarHelper.java new file mode 100644 index 0000000..fdb0a19 --- /dev/null +++ b/library/src/main/java/xyz/klinker/android/drag_dismiss/util/StatusBarHelper.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2017 Luke Klinker + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package xyz.klinker.android.drag_dismiss.util; + +import android.content.Context; +import android.util.TypedValue; + +public class StatusBarHelper { + + public static int getStatusBarHeight(Context context) { + int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); + if (resourceId > 0) { + return context.getResources().getDimensionPixelSize(resourceId); + } else { + return toDp(24, context); + } + } + + private static int toDp(int px, Context context) { + return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, px, context.getResources().getDisplayMetrics()); + } +} diff --git a/library/src/main/res/layout/dragdismiss_activity_recycler.xml b/library/src/main/res/layout/dragdismiss_activity_recycler.xml index 847817e..b3e1e0e 100644 --- a/library/src/main/res/layout/dragdismiss_activity_recycler.xml +++ b/library/src/main/res/layout/dragdismiss_activity_recycler.xml @@ -64,6 +64,7 @@ android:background="@color/dragdismiss_toolbarBackground"/>