Merge "Fix sharesheet height expansion." into rvc-dev

This commit is contained in:
Antoan Angelov
2020-03-04 13:49:47 +00:00
committed by Android (Google) Code Review
10 changed files with 75 additions and 22 deletions

View File

@@ -154,7 +154,6 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
@Override @Override
public ViewGroup instantiateItem(ViewGroup container, int position) { public ViewGroup instantiateItem(ViewGroup container, int position) {
final ProfileDescriptor profileDescriptor = getItem(position); final ProfileDescriptor profileDescriptor = getItem(position);
setupListAdapter(position);
container.addView(profileDescriptor.rootView); container.addView(profileDescriptor.rootView);
return profileDescriptor.rootView; return profileDescriptor.rootView;
} }
@@ -208,8 +207,8 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
abstract int getItemCount(); abstract int getItemCount();
/** /**
* Responsible for assigning an adapter to the list view for the relevant page, specified by * Performs view-related initialization procedures for the adapter specified
* <code>pageIndex</code>, and other list view-related initialization procedures. * by <code>pageIndex</code>.
*/ */
abstract void setupListAdapter(int pageIndex); abstract void setupListAdapter(int pageIndex);

View File

@@ -241,6 +241,7 @@ public class ChooserActivity extends ResolverActivity implements
private int mChooserRowServiceSpacing; private int mChooserRowServiceSpacing;
private int mCurrAvailableWidth = 0; private int mCurrAvailableWidth = 0;
private int mLastNumberOfChildren = -1;
private static final String TARGET_DETAILS_FRAGMENT_TAG = "targetDetailsFragment"; private static final String TARGET_DETAILS_FRAGMENT_TAG = "targetDetailsFragment";
// TODO: Update to handle landscape instead of using static value // TODO: Update to handle landscape instead of using static value
@@ -967,6 +968,7 @@ public class ChooserActivity extends ResolverActivity implements
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
adjustPreviewWidth(newConfig.orientation, null); adjustPreviewWidth(newConfig.orientation, null);
updateStickyContentPreview();
} }
private boolean shouldDisplayLandscape(int orientation) { private boolean shouldDisplayLandscape(int orientation) {
@@ -987,8 +989,6 @@ public class ChooserActivity extends ResolverActivity implements
updateLayoutWidth(R.id.content_preview_text_layout, width, parent); updateLayoutWidth(R.id.content_preview_text_layout, width, parent);
updateLayoutWidth(R.id.content_preview_title_layout, width, parent); updateLayoutWidth(R.id.content_preview_title_layout, width, parent);
updateLayoutWidth(R.id.content_preview_file_layout, width, parent); updateLayoutWidth(R.id.content_preview_file_layout, width, parent);
findViewById(R.id.content_preview_container)
.setVisibility(shouldShowStickyContentPreview() ? View.VISIBLE : View.GONE);
} }
private void updateLayoutWidth(int layoutResourceId, int width, View parent) { private void updateLayoutWidth(int layoutResourceId, int width, View parent) {
@@ -2398,14 +2398,17 @@ public class ChooserActivity extends ResolverActivity implements
} }
final int availableWidth = right - left - v.getPaddingLeft() - v.getPaddingRight(); final int availableWidth = right - left - v.getPaddingLeft() - v.getPaddingRight();
if (mChooserMultiProfilePagerAdapter.getCurrentUserHandle() != getUser()) {
gridAdapter.calculateChooserTargetWidth(availableWidth);
return;
}
if (gridAdapter.consumeLayoutRequest() if (gridAdapter.consumeLayoutRequest()
|| gridAdapter.calculateChooserTargetWidth(availableWidth) || gridAdapter.calculateChooserTargetWidth(availableWidth)
|| recyclerView.getAdapter() == null || recyclerView.getAdapter() == null
|| mLastNumberOfChildren != recyclerView.getChildCount()
|| availableWidth != mCurrAvailableWidth) { || availableWidth != mCurrAvailableWidth) {
mCurrAvailableWidth = availableWidth; mCurrAvailableWidth = availableWidth;
recyclerView.setAdapter(gridAdapter);
((GridLayoutManager) recyclerView.getLayoutManager())
.setSpanCount(gridAdapter.getMaxTargetsPerRow());
getMainThreadHandler().post(() -> { getMainThreadHandler().post(() -> {
if (mResolverDrawerLayout == null || gridAdapter == null) { if (mResolverDrawerLayout == null || gridAdapter == null) {
@@ -2415,7 +2418,8 @@ public class ChooserActivity extends ResolverActivity implements
final int bottomInset = mSystemWindowInsets != null final int bottomInset = mSystemWindowInsets != null
? mSystemWindowInsets.bottom : 0; ? mSystemWindowInsets.bottom : 0;
int offset = bottomInset; int offset = bottomInset;
int rowsToShow = gridAdapter.getProfileRowCount() int rowsToShow = gridAdapter.getContentPreviewRowCount()
+ gridAdapter.getProfileRowCount()
+ gridAdapter.getServiceTargetRowCount() + gridAdapter.getServiceTargetRowCount()
+ gridAdapter.getCallerAndRankedTargetRowCount(); + gridAdapter.getCallerAndRankedTargetRowCount();
@@ -2434,8 +2438,9 @@ public class ChooserActivity extends ResolverActivity implements
return; return;
} }
if (shouldShowStickyContentPreview()) { View stickyContentPreview = findViewById(R.id.content_preview_container);
offset += findViewById(R.id.content_preview_container).getHeight(); if (shouldShowStickyContentPreview() && isStickyContentPreviewShowing()) {
offset += stickyContentPreview.getHeight();
} }
if (shouldShowTabs()) { if (shouldShowTabs()) {
@@ -2444,6 +2449,7 @@ public class ChooserActivity extends ResolverActivity implements
int directShareHeight = 0; int directShareHeight = 0;
rowsToShow = Math.min(4, rowsToShow); rowsToShow = Math.min(4, rowsToShow);
mLastNumberOfChildren = recyclerView.getChildCount();
for (int i = 0, childCount = recyclerView.getChildCount(); for (int i = 0, childCount = recyclerView.getChildCount();
i < childCount && rowsToShow > 0; i++) { i < childCount && rowsToShow > 0; i++) {
View child = recyclerView.getChildAt(i); View child = recyclerView.getChildAt(i);
@@ -2526,6 +2532,14 @@ public class ChooserActivity extends ResolverActivity implements
setupScrollListener(); setupScrollListener();
ChooserListAdapter chooserListAdapter = (ChooserListAdapter) listAdapter; ChooserListAdapter chooserListAdapter = (ChooserListAdapter) listAdapter;
if (chooserListAdapter.getUserHandle()
== mChooserMultiProfilePagerAdapter.getCurrentUserHandle()) {
mChooserMultiProfilePagerAdapter.getActiveAdapterView()
.setAdapter(mChooserMultiProfilePagerAdapter.getCurrentRootAdapter());
mChooserMultiProfilePagerAdapter
.setupListAdapter(mChooserMultiProfilePagerAdapter.getCurrentPage());
}
if (chooserListAdapter.mDisplayList == null if (chooserListAdapter.mDisplayList == null
|| chooserListAdapter.mDisplayList.isEmpty()) { || chooserListAdapter.mDisplayList.isEmpty()) {
chooserListAdapter.notifyDataSetChanged(); chooserListAdapter.notifyDataSetChanged();
@@ -2617,14 +2631,29 @@ public class ChooserActivity extends ResolverActivity implements
* we instead show the content preview as a regular list item. * we instead show the content preview as a regular list item.
*/ */
private boolean shouldShowStickyContentPreview() { private boolean shouldShowStickyContentPreview() {
return shouldShowTabs() return shouldShowStickyContentPreviewNoOrientationCheck()
&& mMultiProfilePagerAdapter.getListAdapterForUserHandle(
UserHandle.of(UserHandle.myUserId())).getCount() > 0
&& isSendAction(getTargetIntent())
&& getResources().getBoolean(R.bool.sharesheet_show_content_preview); && getResources().getBoolean(R.bool.sharesheet_show_content_preview);
} }
private boolean shouldShowStickyContentPreviewNoOrientationCheck() {
return shouldShowTabs()
&& mMultiProfilePagerAdapter.getListAdapterForUserHandle(
UserHandle.of(UserHandle.myUserId())).getCount() > 0
&& isSendAction(getTargetIntent());
}
private void updateStickyContentPreview() { private void updateStickyContentPreview() {
if (shouldShowStickyContentPreviewNoOrientationCheck()) {
// The sticky content preview is only shown when we show the work and personal tabs.
// We don't show it in landscape as otherwise there is no room for scrolling.
// If the sticky content preview will be shown at some point with orientation change,
// then always preload it to avoid subsequent resizing of the share sheet.
ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container);
if (contentPreviewContainer.getChildCount() == 0) {
ViewGroup contentPreviewView = createContentPreviewView(contentPreviewContainer);
contentPreviewContainer.addView(contentPreviewView);
}
}
if (shouldShowStickyContentPreview()) { if (shouldShowStickyContentPreview()) {
showStickyContentPreview(); showStickyContentPreview();
} else { } else {
@@ -2633,15 +2662,23 @@ public class ChooserActivity extends ResolverActivity implements
} }
private void showStickyContentPreview() { private void showStickyContentPreview() {
if (isStickyContentPreviewShowing()) {
return;
}
ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container); ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container);
contentPreviewContainer.setVisibility(View.VISIBLE); contentPreviewContainer.setVisibility(View.VISIBLE);
ViewGroup contentPreviewView = createContentPreviewView(contentPreviewContainer); }
contentPreviewContainer.addView(contentPreviewView);
private boolean isStickyContentPreviewShowing() {
ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container);
return contentPreviewContainer.getVisibility() == View.VISIBLE;
} }
private void hideStickyContentPreview() { private void hideStickyContentPreview() {
if (!isStickyContentPreviewShowing()) {
return;
}
ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container); ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container);
contentPreviewContainer.removeAllViews();
contentPreviewContainer.setVisibility(View.GONE); contentPreviewContainer.setVisibility(View.GONE);
} }

View File

@@ -106,7 +106,6 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd
final RecyclerView recyclerView = getItem(pageIndex).recyclerView; final RecyclerView recyclerView = getItem(pageIndex).recyclerView;
ChooserActivity.ChooserGridAdapter chooserGridAdapter = ChooserActivity.ChooserGridAdapter chooserGridAdapter =
getItem(pageIndex).chooserGridAdapter; getItem(pageIndex).chooserGridAdapter;
recyclerView.setAdapter(chooserGridAdapter);
GridLayoutManager glm = (GridLayoutManager) recyclerView.getLayoutManager(); GridLayoutManager glm = (GridLayoutManager) recyclerView.getLayoutManager();
glm.setSpanCount(chooserGridAdapter.getMaxTargetsPerRow()); glm.setSpanCount(chooserGridAdapter.getMaxTargetsPerRow());
glm.setSpanSizeLookup( glm.setSpanSizeLookup(

View File

@@ -396,6 +396,11 @@ public class ResolverActivity extends Activity implements
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE); | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
rdl.setOnApplyWindowInsetsListener(this::onApplyWindowInsets); rdl.setOnApplyWindowInsetsListener(this::onApplyWindowInsets);
if (shouldShowTabs() && isIntentPicker()) {
rdl.setMaxCollapsedHeight(getResources()
.getDimensionPixelSize(R.dimen.resolver_max_collapsed_height_with_tabs));
}
mResolverDrawerLayout = rdl; mResolverDrawerLayout = rdl;
} }
@@ -413,6 +418,10 @@ public class ResolverActivity extends Activity implements
+ (categories != null ? Arrays.toString(categories.toArray()) : "")); + (categories != null ? Arrays.toString(categories.toArray()) : ""));
} }
private boolean isIntentPicker() {
return getClass().equals(ResolverActivity.class);
}
protected AbstractMultiProfilePagerAdapter createMultiProfilePagerAdapter( protected AbstractMultiProfilePagerAdapter createMultiProfilePagerAdapter(
Intent[] initialIntents, Intent[] initialIntents,
List<ResolveInfo> rList, List<ResolveInfo> rList,

View File

@@ -93,6 +93,12 @@ public class ResolverMultiProfilePagerAdapter extends AbstractMultiProfilePagerA
return mItems[pageIndex].resolverListAdapter; return mItems[pageIndex].resolverListAdapter;
} }
@Override
public ViewGroup instantiateItem(ViewGroup container, int position) {
setupListAdapter(position);
return super.instantiateItem(container, position);
}
@Override @Override
@Nullable @Nullable
ResolverListAdapter getListAdapterForUserHandle(UserHandle userHandle) { ResolverListAdapter getListAdapterForUserHandle(UserHandle userHandle) {

View File

@@ -26,7 +26,7 @@ import com.android.internal.widget.ViewPager;
* A {@link ViewPager} which wraps around its tallest child's height. * A {@link ViewPager} which wraps around its tallest child's height.
* <p>Normally {@link ViewPager} instances expand their height to cover all remaining space in * <p>Normally {@link ViewPager} instances expand their height to cover all remaining space in
* the layout. * the layout.
* <p>This class is used for the intent resolver's tabbed view. * <p>This class is used for the intent resolver and share sheet's tabbed view.
*/ */
public class ResolverViewPager extends ViewPager { public class ResolverViewPager extends ViewPager {

View File

@@ -90,7 +90,7 @@
android:id="@android:id/tabcontent" android:id="@android:id/tabcontent"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<com.android.internal.widget.ViewPager <com.android.internal.app.ResolverViewPager
android:id="@+id/profile_pager" android:id="@+id/profile_pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>

View File

@@ -21,7 +21,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:maxWidth="@dimen/resolver_max_width" android:maxWidth="@dimen/resolver_max_width"
android:maxCollapsedHeight="192dp" android:maxCollapsedHeight="@dimen/resolver_max_collapsed_height"
android:maxCollapsedHeightSmall="56dp" android:maxCollapsedHeightSmall="56dp"
android:id="@id/contentPanel"> android:id="@id/contentPanel">

View File

@@ -777,6 +777,8 @@
<dimen name="resolver_elevation">1dp</dimen> <dimen name="resolver_elevation">1dp</dimen>
<dimen name="resolver_empty_state_height">212dp</dimen> <dimen name="resolver_empty_state_height">212dp</dimen>
<dimen name="resolver_empty_state_height_with_tabs">268dp</dimen> <dimen name="resolver_empty_state_height_with_tabs">268dp</dimen>
<dimen name="resolver_max_collapsed_height">192dp</dimen>
<dimen name="resolver_max_collapsed_height_with_tabs">248dp</dimen>
<dimen name="chooser_action_button_icon_size">18dp</dimen> <dimen name="chooser_action_button_icon_size">18dp</dimen>

View File

@@ -3895,6 +3895,7 @@
<java-symbol type="drawable" name="ic_no_apps" /> <java-symbol type="drawable" name="ic_no_apps" />
<java-symbol type="dimen" name="resolver_empty_state_height" /> <java-symbol type="dimen" name="resolver_empty_state_height" />
<java-symbol type="dimen" name="resolver_empty_state_height_with_tabs" /> <java-symbol type="dimen" name="resolver_empty_state_height_with_tabs" />
<java-symbol type="dimen" name="resolver_max_collapsed_height_with_tabs" />
<java-symbol type="bool" name="sharesheet_show_content_preview" /> <java-symbol type="bool" name="sharesheet_show_content_preview" />
<!-- Toast message for background started foreground service while-in-use permission restriction feature --> <!-- Toast message for background started foreground service while-in-use permission restriction feature -->