diff --git a/library/src/main/java/xyz/klinker/android/drag_dismiss/activity/AbstractDragDismissActivity.java b/library/src/main/java/xyz/klinker/android/drag_dismiss/activity/AbstractDragDismissActivity.java index 93e43c7..2dfa9c3 100644 --- a/library/src/main/java/xyz/klinker/android/drag_dismiss/activity/AbstractDragDismissActivity.java +++ b/library/src/main/java/xyz/klinker/android/drag_dismiss/activity/AbstractDragDismissActivity.java @@ -18,9 +18,12 @@ import android.os.Bundle; import android.view.MenuItem; +import android.view.View; import android.widget.ProgressBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.view.ViewCompat; + import xyz.klinker.android.drag_dismiss.delegate.AbstractDragDismissDelegate; /** 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 20427a3..dafb4b7 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 @@ -30,11 +30,15 @@ import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.core.view.ViewCompat; + import xyz.klinker.android.drag_dismiss.DragDismissIntentBuilder; import xyz.klinker.android.drag_dismiss.R; +import xyz.klinker.android.drag_dismiss.util.AndroidVersionUtils; import xyz.klinker.android.drag_dismiss.util.ColorUtils; import xyz.klinker.android.drag_dismiss.util.StatusBarHelper; import xyz.klinker.android.drag_dismiss.view.ElasticDragDismissFrameLayout; +import xyz.klinker.android.drag_dismiss.view.TransparentStatusBarInsetLayout; public abstract class AbstractDragDismissDelegate { @@ -46,6 +50,7 @@ public abstract class AbstractDragDismissDelegate { private Toolbar toolbar; private AppBarLayout appBarLayout; private View statusBar; + protected TransparentStatusBarInsetLayout transparentStatusBarLayout; private String dragElasticity; private String theme; @@ -69,10 +74,16 @@ public void onCreate(Bundle savedInstanceState) { 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); + transparentStatusBarLayout = activity.findViewById(R.id.dragdismiss_transparentStatusBarLayout); setupToolbar(); setupDragDismiss(); changeColors(); + + if (AndroidVersionUtils.isAndroidQ()) { + int newSystemUiFlags = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + statusBar.setSystemUiVisibility(newSystemUiFlags); + } } /** 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 1fee08e..b41209b 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 @@ -16,18 +16,25 @@ package xyz.klinker.android.drag_dismiss.delegate; +import android.annotation.SuppressLint; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.WindowInsets; import android.widget.FrameLayout; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.view.OnApplyWindowInsetsListener; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; import androidx.core.widget.NestedScrollView; import xyz.klinker.android.drag_dismiss.R; +import xyz.klinker.android.drag_dismiss.util.AndroidVersionUtils; import xyz.klinker.android.drag_dismiss.util.StatusBarHelper; import xyz.klinker.android.drag_dismiss.view.ElasticDragDismissFrameLayout; import xyz.klinker.android.drag_dismiss.view.ToolbarScrollListener; +import xyz.klinker.android.drag_dismiss.view.TransparentStatusBarInsetLayout; public class DragDismissDelegate extends AbstractDragDismissDelegate { @@ -61,6 +68,14 @@ public void onDrag(float elasticOffset, float elasticOffsetPixels, float rawOffs } } }); + if (AndroidVersionUtils.isAndroidQ()) { + transparentStatusBarLayout.setOnApplyInsetsListener(new TransparentStatusBarInsetLayout.AppliedInsets() { + @Override @SuppressLint("NewApi") + public void onApplyInsets(WindowInsets insets) { + scrollView.setPadding(0, 0, 0, insets.getSystemWindowInsetBottom()); + } + }); + } } else { getToolbar().setBackgroundColor(getPrimaryColor()); getStatusBar().setBackgroundColor(getPrimaryColor()); diff --git a/library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/DragDismissRecyclerViewDelegate.java b/library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/DragDismissRecyclerViewDelegate.java index bfb9467..8310335 100644 --- a/library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/DragDismissRecyclerViewDelegate.java +++ b/library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/DragDismissRecyclerViewDelegate.java @@ -16,13 +16,17 @@ package xyz.klinker.android.drag_dismiss.delegate; +import android.annotation.SuppressLint; import android.os.Bundle; +import android.view.WindowInsets; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.RecyclerView; import xyz.klinker.android.drag_dismiss.R; +import xyz.klinker.android.drag_dismiss.util.AndroidVersionUtils; import xyz.klinker.android.drag_dismiss.util.ColorUtils; import xyz.klinker.android.drag_dismiss.view.ToolbarScrollListener; +import xyz.klinker.android.drag_dismiss.view.TransparentStatusBarInsetLayout; public class DragDismissRecyclerViewDelegate extends AbstractDragDismissDelegate { @@ -41,7 +45,7 @@ public DragDismissRecyclerViewDelegate(AppCompatActivity activity, Callback call public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.dragdismiss_recycler); + final RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.dragdismiss_recycler); if (shouldScrollToolbar() && shouldShowToolbar()) { recyclerView.addOnScrollListener(new ToolbarScrollListener(getToolbar(), getStatusBar(), getPrimaryColor())); @@ -50,6 +54,15 @@ public void onCreate(Bundle savedInstanceState) { getStatusBar().setBackgroundColor(getPrimaryColor()); } + if (AndroidVersionUtils.isAndroidQ()) { + transparentStatusBarLayout.setOnApplyInsetsListener(new TransparentStatusBarInsetLayout.AppliedInsets() { + @Override @SuppressLint("NewApi") + public void onApplyInsets(WindowInsets insets) { + recyclerView.setPadding(0, 0, 0, insets.getSystemWindowInsetBottom()); + } + }); + } + ColorUtils.changeRecyclerOverscrollColors(recyclerView, getPrimaryColor()); callback.setupRecyclerView(recyclerView); } diff --git a/library/src/main/java/xyz/klinker/android/drag_dismiss/util/AndroidVersionUtils.java b/library/src/main/java/xyz/klinker/android/drag_dismiss/util/AndroidVersionUtils.java new file mode 100644 index 0000000..18f744f --- /dev/null +++ b/library/src/main/java/xyz/klinker/android/drag_dismiss/util/AndroidVersionUtils.java @@ -0,0 +1,11 @@ +package xyz.klinker.android.drag_dismiss.util; + +import android.os.Build; + +public class AndroidVersionUtils { + + public static boolean isAndroidQ() { + return Build.VERSION.SDK_INT > Build.VERSION_CODES.P || Build.VERSION.CODENAME.equals("Q"); + } + +} diff --git a/library/src/main/java/xyz/klinker/android/drag_dismiss/view/TransparentStatusBarInsetLayout.java b/library/src/main/java/xyz/klinker/android/drag_dismiss/view/TransparentStatusBarInsetLayout.java index b587b2f..05d6ef0 100644 --- a/library/src/main/java/xyz/klinker/android/drag_dismiss/view/TransparentStatusBarInsetLayout.java +++ b/library/src/main/java/xyz/klinker/android/drag_dismiss/view/TransparentStatusBarInsetLayout.java @@ -24,8 +24,11 @@ import androidx.annotation.Nullable; +import xyz.klinker.android.drag_dismiss.util.AndroidVersionUtils; + public class TransparentStatusBarInsetLayout extends LinearLayout { private int[] mInsets = new int[4]; + private AppliedInsets appliedInsetsListener = null; public TransparentStatusBarInsetLayout(Context context) { super(context); @@ -39,16 +42,31 @@ public TransparentStatusBarInsetLayout(Context context, @Nullable AttributeSet a super(context, attrs, defStyleAttr); } + public void setOnApplyInsetsListener(AppliedInsets listener) { + this.appliedInsetsListener = listener; + } + @Override public final WindowInsets onApplyWindowInsets(WindowInsets insets) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { mInsets[0] = insets.getSystemWindowInsetLeft(); mInsets[1] = insets.getSystemWindowInsetTop(); mInsets[2] = insets.getSystemWindowInsetRight(); - return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0, - insets.getSystemWindowInsetBottom())); + if (AndroidVersionUtils.isAndroidQ()) { + if (appliedInsetsListener != null) { + appliedInsetsListener.onApplyInsets(insets); + } + return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0, 0)); + } else { + return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0, + insets.getSystemWindowInsetBottom())); + } } else { return insets; } } + + public interface AppliedInsets { + void onApplyInsets(WindowInsets insets); + } } diff --git a/library/src/main/res/layout/dragdismiss_activity.xml b/library/src/main/res/layout/dragdismiss_activity.xml index e0c172e..b8953ec 100644 --- a/library/src/main/res/layout/dragdismiss_activity.xml +++ b/library/src/main/res/layout/dragdismiss_activity.xml @@ -17,6 +17,7 @@ + android:overScrollMode="never" + android:clipToPadding="false"> + + + + + \ No newline at end of file