From a30787b8fa76bd81600c8ff3a18fa2090d660e58 Mon Sep 17 00:00:00 2001 From: arangelov Date: Wed, 11 Mar 2020 18:33:26 +0000 Subject: [PATCH] When calculating share sheet height, account for empty state screens. As we calculate the share sheet height only for the current profile, there is a rare case when the current profile may have no results. For that case, we need to adjust the share sheet offset so that it includes the empty state screen height. In addition, this CL also does an early return if we are in the non-main profile (e.g. personal tab in work profile) to prevent the height from being recalculated upon tab switch. Fixes: 150939637 Test: manual Change-Id: Ia465f53d7a2006e1b7c67ad1e95729ed79e2c3a0 --- .../app/AbstractMultiProfilePagerAdapter.java | 2 +- .../android/internal/app/ChooserActivity.java | 74 +++++++++++-------- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/core/java/com/android/internal/app/AbstractMultiProfilePagerAdapter.java b/core/java/com/android/internal/app/AbstractMultiProfilePagerAdapter.java index d50826f815a0b..fa567f235c945 100644 --- a/core/java/com/android/internal/app/AbstractMultiProfilePagerAdapter.java +++ b/core/java/com/android/internal/app/AbstractMultiProfilePagerAdapter.java @@ -452,7 +452,7 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter { mEmptyStateView = rootView.findViewById(R.id.resolver_empty_state); } - private ViewGroup getEmptyStateView() { + protected ViewGroup getEmptyStateView() { return mEmptyStateView; } } diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index c099301d20432..5620bff5142bc 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -2411,6 +2411,8 @@ public class ChooserActivity extends ResolverActivity implements mChooserMultiProfilePagerAdapter.getActiveAdapterView() .setAdapter(mChooserMultiProfilePagerAdapter.getCurrentRootAdapter()); return; + } else if (mChooserMultiProfilePagerAdapter.getCurrentUserHandle() != getUser()) { + return; } getMainThreadHandler().post(() -> { @@ -2455,39 +2457,46 @@ public class ChooserActivity extends ResolverActivity implements offset += tabDivider.getHeight(); } - int directShareHeight = 0; - rowsToShow = Math.min(4, rowsToShow); - mLastNumberOfChildren = recyclerView.getChildCount(); - for (int i = 0, childCount = recyclerView.getChildCount(); - i < childCount && rowsToShow > 0; i++) { - View child = recyclerView.getChildAt(i); - if (((GridLayoutManager.LayoutParams) - child.getLayoutParams()).getSpanIndex() != 0) { - continue; + if (recyclerView.getVisibility() == View.VISIBLE) { + int directShareHeight = 0; + rowsToShow = Math.min(4, rowsToShow); + mLastNumberOfChildren = recyclerView.getChildCount(); + for (int i = 0, childCount = recyclerView.getChildCount(); + i < childCount && rowsToShow > 0; i++) { + View child = recyclerView.getChildAt(i); + if (((GridLayoutManager.LayoutParams) + child.getLayoutParams()).getSpanIndex() != 0) { + continue; + } + int height = child.getHeight(); + offset += height; + + if (gridAdapter.getTargetType( + recyclerView.getChildAdapterPosition(child)) + == ChooserListAdapter.TARGET_SERVICE) { + directShareHeight = height; + } + rowsToShow--; } - int height = child.getHeight(); - offset += height; - if (gridAdapter.getTargetType( - recyclerView.getChildAdapterPosition(child)) - == ChooserListAdapter.TARGET_SERVICE) { - directShareHeight = height; + boolean isExpandable = getResources().getConfiguration().orientation + == Configuration.ORIENTATION_PORTRAIT && !isInMultiWindowMode(); + if (directShareHeight != 0 && isSendAction(getTargetIntent()) + && isExpandable) { + // 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 - topInset - bottomInset; + + offset = Math.min(offset, minHeight); + } + } else { + ViewGroup currentEmptyStateView = getCurrentEmptyStateView(); + if (currentEmptyStateView.getVisibility() == View.VISIBLE) { + offset += currentEmptyStateView.getHeight(); } - rowsToShow--; - } - - boolean isExpandable = getResources().getConfiguration().orientation - == Configuration.ORIENTATION_PORTRAIT && !isInMultiWindowMode(); - if (directShareHeight != 0 && isSendAction(getTargetIntent()) - && isExpandable) { - // 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 - topInset - bottomInset; - - offset = Math.min(offset, minHeight); } mResolverDrawerLayout.setCollapsibleHeightReserved(Math.min(offset, bottom - top)); @@ -2495,6 +2504,11 @@ public class ChooserActivity extends ResolverActivity implements } } + private ViewGroup getCurrentEmptyStateView() { + int currentPage = mChooserMultiProfilePagerAdapter.getCurrentPage(); + return mChooserMultiProfilePagerAdapter.getItem(currentPage).getEmptyStateView(); + } + static class BaseChooserTargetComparator implements Comparator { @Override public int compare(ChooserTarget lhs, ChooserTarget rhs) {