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"/> <android.support.design.widget.AppBarLayout + android:id="@+id/dragdismiss_app_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" diff --git a/sample/src/main/java/xyz/klinker/drag_dismiss/DismissableActivityNormalContent.java b/sample/src/main/java/xyz/klinker/drag_dismiss/DismissableActivityNormalContent.java index f996f65..4542a67 100644 --- a/sample/src/main/java/xyz/klinker/drag_dismiss/DismissableActivityNormalContent.java +++ b/sample/src/main/java/xyz/klinker/drag_dismiss/DismissableActivityNormalContent.java @@ -24,6 +24,7 @@ import xyz.klinker.android.drag_dismiss.DragDismissIntentBuilder; import xyz.klinker.android.drag_dismiss.activity.DragDismissActivity; +import xyz.klinker.android.drag_dismiss.util.StatusBarHelper; public class DismissableActivityNormalContent extends DragDismissActivity { @@ -36,7 +37,7 @@ public View onCreateContent(LayoutInflater inflater, ViewGroup parent, Bundle sa if (!getDragDismissDelegate().shouldShowToolbar()) { // don't need the padding that pushes it below the toolbar - tv.setPadding(0,0,0,0); + tv.setPadding(0, 0,0,0); } if (getIntent().getBooleanExtra(EXTRA_SHOW_PROGRESS, false)) { diff --git a/sample/src/main/res/layout/activity_scrollable.xml b/sample/src/main/res/layout/activity_scrollable.xml index 06b17b5..297b0ff 100644 --- a/sample/src/main/res/layout/activity_scrollable.xml +++ b/sample/src/main/res/layout/activity_scrollable.xml @@ -20,7 +20,6 @@ android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="24dp" android:padding="16dp" > <TextView