diff options
| author | Miranda Kephart <mkephart@google.com> | 2021-12-10 03:17:41 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-12-10 03:17:41 +0000 |
| commit | e3c03312e4e9a63006e63df13bfa07e02a050f45 (patch) | |
| tree | 56db1971d22145fd1b58ea5693de85cf25b81dfd /core/java | |
| parent | 1994b44a4c8f68f988dc8364a5fd0844328d6dc9 (diff) | |
| parent | 140166fd733491e742a7e53718207c4439b174a2 (diff) | |
Merge "Update sharesheet for large devices"
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/com/android/internal/app/ChooserActivity.java | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index 52122eeb3f3e..bc3c2f5872fc 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -171,9 +171,6 @@ public class ChooserActivity extends ResolverActivity implements private AppPredictor mWorkAppPredictor; private boolean mShouldDisplayLandscape; - private static final int MAX_TARGETS_PER_ROW_PORTRAIT = 4; - private static final int MAX_TARGETS_PER_ROW_LANDSCAPE = 8; - @UnsupportedAppUsage public ChooserActivity() { } @@ -294,6 +291,7 @@ public class ChooserActivity extends ResolverActivity implements private int mCurrAvailableWidth = 0; private int mLastNumberOfChildren = -1; + private int mMaxTargetsPerRow = 1; private static final String TARGET_DETAILS_FRAGMENT_TAG = "targetDetailsFragment"; @@ -681,8 +679,9 @@ public class ChooserActivity extends ResolverActivity implements mCallerChooserTargets = targets; } - mShouldDisplayLandscape = shouldDisplayLandscape( - getResources().getConfiguration().orientation); + mMaxTargetsPerRow = getResources().getInteger(R.integer.config_chooser_max_targets_per_row); + mShouldDisplayLandscape = + shouldDisplayLandscape(getResources().getConfiguration().orientation); setRetainInOnStop(intent.getBooleanExtra(EXTRA_PRIVATE_RETAIN_IN_ON_STOP, false)); super.onCreate(savedInstanceState, target, title, defaultTitleRes, initialIntents, null, false); @@ -915,7 +914,7 @@ public class ChooserActivity extends ResolverActivity implements adapter, getPersonalProfileUserHandle(), /* workProfileUserHandle= */ null, - isSendAction(getTargetIntent()), getMaxTargetsPerRow()); + isSendAction(getTargetIntent()), mMaxTargetsPerRow); } private ChooserMultiProfilePagerAdapter createChooserMultiProfilePagerAdapterForTwoProfiles( @@ -944,7 +943,7 @@ public class ChooserActivity extends ResolverActivity implements selectedProfile, getPersonalProfileUserHandle(), getWorkProfileUserHandle(), - isSendAction(getTargetIntent()), getMaxTargetsPerRow()); + isSendAction(getTargetIntent()), mMaxTargetsPerRow); } private int findSelectedProfile() { @@ -1112,6 +1111,7 @@ public class ChooserActivity extends ResolverActivity implements } mShouldDisplayLandscape = shouldDisplayLandscape(newConfig.orientation); + mMaxTargetsPerRow = getResources().getInteger(R.integer.config_chooser_max_targets_per_row); adjustPreviewWidth(newConfig.orientation, null); updateStickyContentPreview(); } @@ -2560,7 +2560,7 @@ public class ChooserActivity extends ResolverActivity implements // and b/150936654 recyclerView.setAdapter(gridAdapter); ((GridLayoutManager) recyclerView.getLayoutManager()).setSpanCount( - getMaxTargetsPerRow()); + mMaxTargetsPerRow); } UserHandle currentUserHandle = mChooserMultiProfilePagerAdapter.getCurrentUserHandle(); @@ -2724,7 +2724,7 @@ public class ChooserActivity extends ResolverActivity implements @Override // ChooserListCommunicator public int getMaxRankedTargets() { - return getMaxTargetsPerRow(); + return mMaxTargetsPerRow; } @Override // ChooserListCommunicator @@ -3075,13 +3075,6 @@ public class ChooserActivity extends ResolverActivity implements } } - int getMaxTargetsPerRow() { - int maxTargets = MAX_TARGETS_PER_ROW_PORTRAIT; - if (mShouldDisplayLandscape) { - maxTargets = MAX_TARGETS_PER_ROW_LANDSCAPE; - } - return maxTargets; - } /** * Adapter for all types of items and targets in ShareSheet. * Note that ranked sections like Direct Share - while appearing grid-like - are handled on the @@ -3149,7 +3142,11 @@ public class ChooserActivity extends ResolverActivity implements return false; } - int newWidth = width / getMaxTargetsPerRow(); + // Limit width to the maximum width of the chooser activity + int maxWidth = getResources().getDimensionPixelSize(R.dimen.chooser_width); + width = Math.min(maxWidth, width); + + int newWidth = width / mMaxTargetsPerRow; if (newWidth != mChooserTargetWidth) { mChooserTargetWidth = newWidth; return true; @@ -3184,7 +3181,7 @@ public class ChooserActivity extends ResolverActivity implements + getAzLabelRowCount() + Math.ceil( (float) mChooserListAdapter.getAlphaTargetCount() - / getMaxTargetsPerRow()) + / mMaxTargetsPerRow) ); } @@ -3224,7 +3221,7 @@ public class ChooserActivity extends ResolverActivity implements public int getCallerAndRankedTargetRowCount() { return (int) Math.ceil( ((float) mChooserListAdapter.getCallerTargetCount() - + mChooserListAdapter.getRankedTargetCount()) / getMaxTargetsPerRow()); + + mChooserListAdapter.getRankedTargetCount()) / mMaxTargetsPerRow); } // There can be at most one row in the listview, that is internally @@ -3423,7 +3420,7 @@ public class ChooserActivity extends ResolverActivity implements parentGroup.addView(row2); mDirectShareViewHolder = new DirectShareViewHolder(parentGroup, - Lists.newArrayList(row1, row2), getMaxTargetsPerRow(), viewType, + Lists.newArrayList(row1, row2), mMaxTargetsPerRow, viewType, mChooserMultiProfilePagerAdapter::getActiveListAdapter); loadViewsIntoGroup(mDirectShareViewHolder); @@ -3432,7 +3429,7 @@ public class ChooserActivity extends ResolverActivity implements ViewGroup row = (ViewGroup) mLayoutInflater.inflate(R.layout.chooser_row, parent, false); ItemGroupViewHolder holder = - new SingleRowViewHolder(row, getMaxTargetsPerRow(), viewType); + new SingleRowViewHolder(row, mMaxTargetsPerRow, viewType); loadViewsIntoGroup(holder); return holder; @@ -3524,7 +3521,7 @@ public class ChooserActivity extends ResolverActivity implements final int serviceCount = mChooserListAdapter.getServiceTargetCount(); final int serviceRows = (int) Math.ceil((float) serviceCount / getMaxRankedTargets()); if (position < serviceRows) { - return position * getMaxTargetsPerRow(); + return position * mMaxTargetsPerRow; } position -= serviceRows; @@ -3533,7 +3530,7 @@ public class ChooserActivity extends ResolverActivity implements + mChooserListAdapter.getRankedTargetCount(); final int callerAndRankedRows = getCallerAndRankedTargetRowCount(); if (position < callerAndRankedRows) { - return serviceCount + position * getMaxTargetsPerRow(); + return serviceCount + position * mMaxTargetsPerRow; } position -= getAzLabelRowCount() + callerAndRankedRows; @@ -3546,7 +3543,7 @@ public class ChooserActivity extends ResolverActivity implements if (mDirectShareViewHolder != null && canExpandDirectShare) { mDirectShareViewHolder.handleScroll( mChooserMultiProfilePagerAdapter.getActiveAdapterView(), y, oldy, - getMaxTargetsPerRow()); + mMaxTargetsPerRow); } } |
