Skip to content

Commit

Permalink
for android q: go edge to edge, draw under the content
Browse files Browse the repository at this point in the history
  • Loading branch information
klinker24 committed May 10, 2019
1 parent 2572ed0 commit 9cd46d1
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
Expand All @@ -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);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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()));
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
4 changes: 3 additions & 1 deletion library/src/main/res/layout/dragdismiss_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<xyz.klinker.android.drag_dismiss.view.TransparentStatusBarInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dragdismiss_transparentStatusBarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
Expand Down Expand Up @@ -46,7 +47,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never" >
android:overScrollMode="never"
android:clipToPadding="false">

<FrameLayout
android:id="@+id/dragdismiss_content"
Expand Down
2 changes: 2 additions & 0 deletions library/src/main/res/layout/dragdismiss_activity_recycler.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<xyz.klinker.android.drag_dismiss.view.TransparentStatusBarInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dragdismiss_transparentStatusBarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
Expand Down Expand Up @@ -46,6 +47,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:clipToPadding="false"
app:behavior_overlapTop="?attr/actionBarSize" />

<ProgressBar
Expand Down
9 changes: 9 additions & 0 deletions library/src/main/res/values-v29/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="DragDismissTheme" parent="DragDismissTheme.Base">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>

</resources>

0 comments on commit 9cd46d1

Please sign in to comment.