From 800136a56ed7294e1e1f0a7972ebcb860943f3ab Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Wed, 8 May 2019 07:46:39 -0400 Subject: [PATCH] Sharesheet - Edge to edge support Support edge-to-edge sharesheet to align with support for new gesture navigation. Use top inset to prevent sharesheet from scrolling under. Use bottom inset to give the listview space for scrolling all items into view. Bug: 132114008 Test: Visual inspection Change-Id: Ie96d19f187d32d477eaf0515463d1adf335f80ce --- .../android/internal/app/ChooserActivity.java | 13 +++--- .../internal/app/ResolverActivity.java | 44 +++++++++++++++++++ .../internal/widget/ResolverDrawerLayout.java | 11 +++-- .../values-night/themes_device_defaults.xml | 1 - .../res/res/values/themes_device_defaults.xml | 11 +++-- 5 files changed, 62 insertions(+), 18 deletions(-) diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index 5924fb15d8aff..16ab36655fb4d 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -235,7 +235,6 @@ public class ChooserActivity extends ResolverActivity { private boolean mListViewDataChanged = false; - @Retention(SOURCE) @IntDef({CONTENT_PREVIEW_FILE, CONTENT_PREVIEW_IMAGE, CONTENT_PREVIEW_TEXT}) private @interface ContentPreviewType { @@ -2035,7 +2034,8 @@ public class ChooserActivity extends ResolverActivity { return; } - if (mChooserRowAdapter.calculateChooserTargetWidth(right - left) + int availableWidth = right - left - v.getPaddingLeft() - v.getPaddingRight(); + if (mChooserRowAdapter.calculateChooserTargetWidth(availableWidth) || mAdapterView.getAdapter() == null) { mAdapterView.setAdapter(mChooserRowAdapter); @@ -2044,7 +2044,9 @@ public class ChooserActivity extends ResolverActivity { return; } - int offset = 0; + final int bottomInset = mSystemWindowInsets != null + ? mSystemWindowInsets.bottom : 0; + int offset = bottomInset; int rowsToShow = mChooserRowAdapter.getContentPreviewRowCount() + mChooserRowAdapter.getProfileRowCount() + mChooserRowAdapter.getServiceTargetRowCount() @@ -2059,7 +2061,7 @@ public class ChooserActivity extends ResolverActivity { // still zero? then use a default height and leave, which // can happen when there are no targets to show if (rowsToShow == 0) { - offset = getResources().getDimensionPixelSize( + offset += getResources().getDimensionPixelSize( R.dimen.chooser_max_collapsed_height); mResolverDrawerLayout.setCollapsibleHeightReserved(offset); return; @@ -2084,8 +2086,9 @@ public class ChooserActivity extends ResolverActivity { // make sure to leave room for direct share 4->8 expansion int requiredExpansionHeight = (int) (directShareHeight / DIRECT_SHARE_EXPANSION_RATE); + int topInset = mSystemWindowInsets != null ? mSystemWindowInsets.top : 0; int minHeight = bottom - top - mResolverDrawerLayout.getAlwaysShowHeight() - - requiredExpansionHeight; + - requiredExpansionHeight - topInset - bottomInset; offset = Math.min(offset, minHeight); } diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index 3ea746d5f4174..a5daa0ae81e6e 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -46,6 +46,7 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; +import android.graphics.Insets; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; @@ -67,12 +68,15 @@ import android.util.Slog; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; +import android.view.WindowInsets; import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageView; import android.widget.ListView; +import android.widget.Space; import android.widget.TextView; import android.widget.Toast; @@ -136,6 +140,9 @@ public class ResolverActivity extends Activity { private ColorMatrixColorFilter mSuspendedMatrixColorFilter; + protected Insets mSystemWindowInsets = null; + private Space mFooterSpacer = null; + /** See {@link #setRetainInOnStop}. */ private boolean mRetainInOnStop; @@ -329,6 +336,11 @@ public class ResolverActivity extends Activity { if (isVoiceInteraction()) { rdl.setCollapsed(false); } + + rdl.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); + rdl.setOnApplyWindowInsetsListener(this::onApplyWindowInsets); + mResolverDrawerLayout = rdl; } @@ -364,10 +376,38 @@ public class ResolverActivity extends Activity { finish(); } + protected WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { + mSystemWindowInsets = insets.getSystemWindowInsets(); + + mResolverDrawerLayout.setPadding(mSystemWindowInsets.left, mSystemWindowInsets.top, + mSystemWindowInsets.right, 0); + + View emptyView = findViewById(R.id.empty); + emptyView.setPadding(0, 0, 0, mSystemWindowInsets.bottom + + getResources().getDimensionPixelSize( + R.dimen.chooser_edge_margin_normal) * 2); + + if (mFooterSpacer == null) { + mFooterSpacer = new Space(getApplicationContext()); + } else { + ((ListView) mAdapterView).removeFooterView(mFooterSpacer); + } + mFooterSpacer.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, + mSystemWindowInsets.bottom)); + ((ListView) mAdapterView).addFooterView(mFooterSpacer); + + return insets.consumeSystemWindowInsets(); + } + @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mAdapter.handlePackagesChanged(); + + if (mSystemWindowInsets != null) { + mResolverDrawerLayout.setPadding(mSystemWindowInsets.left, mSystemWindowInsets.top, + mSystemWindowInsets.right, 0); + } } private void initSuspendedColorMatrix() { @@ -1277,6 +1317,10 @@ public class ResolverActivity extends Activity { final ViewGroup buttonLayout = findViewById(R.id.button_bar); if (buttonLayout != null) { buttonLayout.setVisibility(View.VISIBLE); + int inset = mSystemWindowInsets != null ? mSystemWindowInsets.bottom : 0; + buttonLayout.setPadding(buttonLayout.getPaddingLeft(), buttonLayout.getPaddingTop(), + buttonLayout.getPaddingRight(), buttonLayout.getPaddingBottom() + inset); + mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once); mSettingsButton = (Button) buttonLayout.findViewById(R.id.button_app_settings); mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always); diff --git a/core/java/com/android/internal/widget/ResolverDrawerLayout.java b/core/java/com/android/internal/widget/ResolverDrawerLayout.java index 3adb36f5e54bf..c73de8fad5b2c 100644 --- a/core/java/com/android/internal/widget/ResolverDrawerLayout.java +++ b/core/java/com/android/internal/widget/ResolverDrawerLayout.java @@ -854,12 +854,11 @@ public class ResolverDrawerLayout extends ViewGroup { final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY); final int heightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY); - final int widthPadding = getPaddingLeft() + getPaddingRight(); // Currently we allot more height than is really needed so that the entirety of the // sheet may be pulled up. // TODO: Restrict the height here to be the right value. - int heightUsed = getPaddingTop() + getPaddingBottom(); + int heightUsed = 0; // Measure always-show children first. final int childCount = getChildCount(); @@ -869,11 +868,11 @@ public class ResolverDrawerLayout extends ViewGroup { if (lp.alwaysShow && child.getVisibility() != GONE) { if (lp.maxHeight != -1) { final int remainingHeight = heightSize - heightUsed; - measureChildWithMargins(child, widthSpec, widthPadding, + measureChildWithMargins(child, widthSpec, 0, MeasureSpec.makeMeasureSpec(lp.maxHeight, MeasureSpec.AT_MOST), lp.maxHeight > remainingHeight ? lp.maxHeight - remainingHeight : 0); } else { - measureChildWithMargins(child, widthSpec, widthPadding, heightSpec, heightUsed); + measureChildWithMargins(child, widthSpec, 0, heightSpec, heightUsed); } heightUsed += child.getMeasuredHeight(); } @@ -889,11 +888,11 @@ public class ResolverDrawerLayout extends ViewGroup { if (!lp.alwaysShow && child.getVisibility() != GONE) { if (lp.maxHeight != -1) { final int remainingHeight = heightSize - heightUsed; - measureChildWithMargins(child, widthSpec, widthPadding, + measureChildWithMargins(child, widthSpec, 0, MeasureSpec.makeMeasureSpec(lp.maxHeight, MeasureSpec.AT_MOST), lp.maxHeight > remainingHeight ? lp.maxHeight - remainingHeight : 0); } else { - measureChildWithMargins(child, widthSpec, widthPadding, heightSpec, heightUsed); + measureChildWithMargins(child, widthSpec, 0, heightSpec, heightUsed); } heightUsed += child.getMeasuredHeight(); } diff --git a/core/res/res/values-night/themes_device_defaults.xml b/core/res/res/values-night/themes_device_defaults.xml index b8bc17f2a2322..bba2bb8d4a46b 100644 --- a/core/res/res/values-night/themes_device_defaults.xml +++ b/core/res/res/values-night/themes_device_defaults.xml @@ -86,5 +86,4 @@ easier. - diff --git a/core/res/res/values/themes_device_defaults.xml b/core/res/res/values/themes_device_defaults.xml index 8015a5d5fbdd8..39948fe379513 100644 --- a/core/res/res/values/themes_device_defaults.xml +++ b/core/res/res/values/themes_device_defaults.xml @@ -1677,8 +1677,11 @@ easier. ?attr/colorControlHighlight ?attr/dialogPreferredPadding ?attr/dialogPreferredPadding - ?attr/colorBackgroundFloating - @color/chooser_row_divider + @android:color/transparent + + + - -