pageIndex, and other list view-related initialization procedures.
+ * Performs view-related initialization procedures for the adapter specified
+ * by pageIndex.
*/
abstract void setupListAdapter(int pageIndex);
diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java
index 250b1ea5a4e96..38fd560eae46c 100644
--- a/core/java/com/android/internal/app/ChooserActivity.java
+++ b/core/java/com/android/internal/app/ChooserActivity.java
@@ -241,6 +241,7 @@ public class ChooserActivity extends ResolverActivity implements
private int mChooserRowServiceSpacing;
private int mCurrAvailableWidth = 0;
+ private int mLastNumberOfChildren = -1;
private static final String TARGET_DETAILS_FRAGMENT_TAG = "targetDetailsFragment";
// TODO: Update to handle landscape instead of using static value
@@ -967,6 +968,7 @@ public class ChooserActivity extends ResolverActivity implements
super.onConfigurationChanged(newConfig);
adjustPreviewWidth(newConfig.orientation, null);
+ updateStickyContentPreview();
}
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_title_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) {
@@ -2398,14 +2398,17 @@ public class ChooserActivity extends ResolverActivity implements
}
final int availableWidth = right - left - v.getPaddingLeft() - v.getPaddingRight();
+ if (mChooserMultiProfilePagerAdapter.getCurrentUserHandle() != getUser()) {
+ gridAdapter.calculateChooserTargetWidth(availableWidth);
+ return;
+ }
+
if (gridAdapter.consumeLayoutRequest()
|| gridAdapter.calculateChooserTargetWidth(availableWidth)
|| recyclerView.getAdapter() == null
+ || mLastNumberOfChildren != recyclerView.getChildCount()
|| availableWidth != mCurrAvailableWidth) {
mCurrAvailableWidth = availableWidth;
- recyclerView.setAdapter(gridAdapter);
- ((GridLayoutManager) recyclerView.getLayoutManager())
- .setSpanCount(gridAdapter.getMaxTargetsPerRow());
getMainThreadHandler().post(() -> {
if (mResolverDrawerLayout == null || gridAdapter == null) {
@@ -2415,7 +2418,8 @@ public class ChooserActivity extends ResolverActivity implements
final int bottomInset = mSystemWindowInsets != null
? mSystemWindowInsets.bottom : 0;
int offset = bottomInset;
- int rowsToShow = gridAdapter.getProfileRowCount()
+ int rowsToShow = gridAdapter.getContentPreviewRowCount()
+ + gridAdapter.getProfileRowCount()
+ gridAdapter.getServiceTargetRowCount()
+ gridAdapter.getCallerAndRankedTargetRowCount();
@@ -2434,8 +2438,9 @@ public class ChooserActivity extends ResolverActivity implements
return;
}
- if (shouldShowStickyContentPreview()) {
- offset += findViewById(R.id.content_preview_container).getHeight();
+ View stickyContentPreview = findViewById(R.id.content_preview_container);
+ if (shouldShowStickyContentPreview() && isStickyContentPreviewShowing()) {
+ offset += stickyContentPreview.getHeight();
}
if (shouldShowTabs()) {
@@ -2444,6 +2449,7 @@ public class ChooserActivity extends ResolverActivity implements
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);
@@ -2526,6 +2532,14 @@ public class ChooserActivity extends ResolverActivity implements
setupScrollListener();
ChooserListAdapter chooserListAdapter = (ChooserListAdapter) listAdapter;
+ if (chooserListAdapter.getUserHandle()
+ == mChooserMultiProfilePagerAdapter.getCurrentUserHandle()) {
+ mChooserMultiProfilePagerAdapter.getActiveAdapterView()
+ .setAdapter(mChooserMultiProfilePagerAdapter.getCurrentRootAdapter());
+ mChooserMultiProfilePagerAdapter
+ .setupListAdapter(mChooserMultiProfilePagerAdapter.getCurrentPage());
+ }
+
if (chooserListAdapter.mDisplayList == null
|| chooserListAdapter.mDisplayList.isEmpty()) {
chooserListAdapter.notifyDataSetChanged();
@@ -2617,14 +2631,29 @@ public class ChooserActivity extends ResolverActivity implements
* we instead show the content preview as a regular list item.
*/
private boolean shouldShowStickyContentPreview() {
- return shouldShowTabs()
- && mMultiProfilePagerAdapter.getListAdapterForUserHandle(
- UserHandle.of(UserHandle.myUserId())).getCount() > 0
- && isSendAction(getTargetIntent())
+ return shouldShowStickyContentPreviewNoOrientationCheck()
&& 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() {
+ 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()) {
showStickyContentPreview();
} else {
@@ -2633,15 +2662,23 @@ public class ChooserActivity extends ResolverActivity implements
}
private void showStickyContentPreview() {
+ if (isStickyContentPreviewShowing()) {
+ return;
+ }
ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container);
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() {
+ if (!isStickyContentPreviewShowing()) {
+ return;
+ }
ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container);
- contentPreviewContainer.removeAllViews();
contentPreviewContainer.setVisibility(View.GONE);
}
diff --git a/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java b/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java
index d4404023c4f43..b39d42ec1e96e 100644
--- a/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java
+++ b/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java
@@ -106,7 +106,6 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd
final RecyclerView recyclerView = getItem(pageIndex).recyclerView;
ChooserActivity.ChooserGridAdapter chooserGridAdapter =
getItem(pageIndex).chooserGridAdapter;
- recyclerView.setAdapter(chooserGridAdapter);
GridLayoutManager glm = (GridLayoutManager) recyclerView.getLayoutManager();
glm.setSpanCount(chooserGridAdapter.getMaxTargetsPerRow());
glm.setSpanSizeLookup(
diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java
index 0790f21f30e12..2ea63b347cffe 100644
--- a/core/java/com/android/internal/app/ResolverActivity.java
+++ b/core/java/com/android/internal/app/ResolverActivity.java
@@ -396,6 +396,11 @@ public class ResolverActivity extends Activity implements
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
rdl.setOnApplyWindowInsetsListener(this::onApplyWindowInsets);
+ if (shouldShowTabs() && isIntentPicker()) {
+ rdl.setMaxCollapsedHeight(getResources()
+ .getDimensionPixelSize(R.dimen.resolver_max_collapsed_height_with_tabs));
+ }
+
mResolverDrawerLayout = rdl;
}
@@ -413,6 +418,10 @@ public class ResolverActivity extends Activity implements
+ (categories != null ? Arrays.toString(categories.toArray()) : ""));
}
+ private boolean isIntentPicker() {
+ return getClass().equals(ResolverActivity.class);
+ }
+
protected AbstractMultiProfilePagerAdapter createMultiProfilePagerAdapter(
Intent[] initialIntents,
ListNormally {@link ViewPager} instances expand their height to cover all remaining space in * the layout. - *
This class is used for the intent resolver's tabbed view. + *
This class is used for the intent resolver and share sheet's tabbed view.
*/
public class ResolverViewPager extends ViewPager {
diff --git a/core/res/res/layout/chooser_grid.xml b/core/res/res/layout/chooser_grid.xml
index 5676049fb940f..c0de6936dd128 100644
--- a/core/res/res/layout/chooser_grid.xml
+++ b/core/res/res/layout/chooser_grid.xml
@@ -90,7 +90,7 @@
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
-