Merge "Fix wrong target launches in Chooser." into rvc-qpr-dev

This commit is contained in:
TreeHugger Robot
2020-12-10 15:50:08 +00:00
committed by Android (Google) Code Review
3 changed files with 27 additions and 29 deletions

View File

@@ -162,6 +162,9 @@ public class ChooserActivity extends ResolverActivity implements
private AppPredictor mWorkAppPredictor; private AppPredictor mWorkAppPredictor;
private boolean mShouldDisplayLandscape; private boolean mShouldDisplayLandscape;
private static final int MAX_TARGETS_PER_ROW_PORTRAIT = 4;
private static final int MAX_TARGETS_PER_ROW_LANDSCAPE = 8;
@UnsupportedAppUsage @UnsupportedAppUsage
public ChooserActivity() { public ChooserActivity() {
} }
@@ -904,7 +907,7 @@ public class ChooserActivity extends ResolverActivity implements
adapter, adapter,
getPersonalProfileUserHandle(), getPersonalProfileUserHandle(),
/* workProfileUserHandle= */ null, /* workProfileUserHandle= */ null,
isSendAction(getTargetIntent())); isSendAction(getTargetIntent()), getMaxTargetsPerRow());
} }
private ChooserMultiProfilePagerAdapter createChooserMultiProfilePagerAdapterForTwoProfiles( private ChooserMultiProfilePagerAdapter createChooserMultiProfilePagerAdapterForTwoProfiles(
@@ -933,7 +936,7 @@ public class ChooserActivity extends ResolverActivity implements
selectedProfile, selectedProfile,
getPersonalProfileUserHandle(), getPersonalProfileUserHandle(),
getWorkProfileUserHandle(), getWorkProfileUserHandle(),
isSendAction(getTargetIntent())); isSendAction(getTargetIntent()), getMaxTargetsPerRow());
} }
private int findSelectedProfile() { private int findSelectedProfile() {
@@ -2660,7 +2663,7 @@ public class ChooserActivity extends ResolverActivity implements
// and b/150936654 // and b/150936654
recyclerView.setAdapter(gridAdapter); recyclerView.setAdapter(gridAdapter);
((GridLayoutManager) recyclerView.getLayoutManager()).setSpanCount( ((GridLayoutManager) recyclerView.getLayoutManager()).setSpanCount(
gridAdapter.getMaxTargetsPerRow()); getMaxTargetsPerRow());
} }
UserHandle currentUserHandle = mChooserMultiProfilePagerAdapter.getCurrentUserHandle(); UserHandle currentUserHandle = mChooserMultiProfilePagerAdapter.getCurrentUserHandle();
@@ -2825,9 +2828,7 @@ public class ChooserActivity extends ResolverActivity implements
@Override // ChooserListCommunicator @Override // ChooserListCommunicator
public int getMaxRankedTargets() { public int getMaxRankedTargets() {
return mChooserMultiProfilePagerAdapter.getCurrentRootAdapter() == null return getMaxTargetsPerRow();
? ChooserGridAdapter.MAX_TARGETS_PER_ROW_PORTRAIT
: mChooserMultiProfilePagerAdapter.getCurrentRootAdapter().getMaxTargetsPerRow();
} }
@Override // ChooserListCommunicator @Override // ChooserListCommunicator
@@ -3176,6 +3177,13 @@ 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. * 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 * Note that ranked sections like Direct Share - while appearing grid-like - are handled on the
@@ -3204,9 +3212,6 @@ public class ChooserActivity extends ResolverActivity implements
private static final int VIEW_TYPE_CALLER_AND_RANK = 5; private static final int VIEW_TYPE_CALLER_AND_RANK = 5;
private static final int VIEW_TYPE_FOOTER = 6; private static final int VIEW_TYPE_FOOTER = 6;
private static final int MAX_TARGETS_PER_ROW_PORTRAIT = 4;
private static final int MAX_TARGETS_PER_ROW_LANDSCAPE = 8;
private static final int NUM_EXPANSIONS_TO_HIDE_AZ_LABEL = 20; private static final int NUM_EXPANSIONS_TO_HIDE_AZ_LABEL = 20;
ChooserGridAdapter(ChooserListAdapter wrappedAdapter) { ChooserGridAdapter(ChooserListAdapter wrappedAdapter) {
@@ -3255,14 +3260,6 @@ public class ChooserActivity extends ResolverActivity implements
return false; return false;
} }
int getMaxTargetsPerRow() {
int maxTargets = MAX_TARGETS_PER_ROW_PORTRAIT;
if (mShouldDisplayLandscape) {
maxTargets = MAX_TARGETS_PER_ROW_LANDSCAPE;
}
return maxTargets;
}
/** /**
* Hides the list item content preview. * Hides the list item content preview.
* <p>Not to be confused with the sticky content preview which is above the * <p>Not to be confused with the sticky content preview which is above the
@@ -3632,8 +3629,7 @@ public class ChooserActivity extends ResolverActivity implements
position -= getSystemRowCount() + getProfileRowCount(); position -= getSystemRowCount() + getProfileRowCount();
final int serviceCount = mChooserListAdapter.getServiceTargetCount(); final int serviceCount = mChooserListAdapter.getServiceTargetCount();
final int serviceRows = (int) Math.ceil((float) serviceCount final int serviceRows = (int) Math.ceil((float) serviceCount / getMaxRankedTargets());
/ ChooserListAdapter.MAX_SERVICE_TARGETS);
if (position < serviceRows) { if (position < serviceRows) {
return position * getMaxTargetsPerRow(); return position * getMaxTargetsPerRow();
} }

View File

@@ -82,8 +82,6 @@ public class ChooserListAdapter extends ResolverListAdapter {
private static final int MAX_SERVICE_TARGET_APP = 8; private static final int MAX_SERVICE_TARGET_APP = 8;
private static final int DEFAULT_DIRECT_SHARE_RANKING_SCORE = 1000; private static final int DEFAULT_DIRECT_SHARE_RANKING_SCORE = 1000;
static final int MAX_SERVICE_TARGETS = 8;
/** {@link #getBaseScore} */ /** {@link #getBaseScore} */
public static final float CALLER_TARGET_SCORE_BOOST = 900.f; public static final float CALLER_TARGET_SCORE_BOOST = 900.f;
/** {@link #getBaseScore} */ /** {@link #getBaseScore} */
@@ -130,10 +128,10 @@ public class ChooserListAdapter extends ResolverListAdapter {
super(context, payloadIntents, null, rList, filterLastUsed, super(context, payloadIntents, null, rList, filterLastUsed,
resolverListController, chooserListCommunicator, false); resolverListController, chooserListCommunicator, false);
createPlaceHolders();
mMaxShortcutTargetsPerApp = mMaxShortcutTargetsPerApp =
context.getResources().getInteger(R.integer.config_maxShortcutTargetsPerApp); context.getResources().getInteger(R.integer.config_maxShortcutTargetsPerApp);
mChooserListCommunicator = chooserListCommunicator; mChooserListCommunicator = chooserListCommunicator;
createPlaceHolders();
mSelectableTargetInfoCommunicator = selectableTargetInfoCommunicator; mSelectableTargetInfoCommunicator = selectableTargetInfoCommunicator;
if (initialIntents != null) { if (initialIntents != null) {
@@ -227,7 +225,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
mParkingDirectShareTargets.clear(); mParkingDirectShareTargets.clear();
mPendingChooserTargetService.clear(); mPendingChooserTargetService.clear();
mShortcutComponents.clear(); mShortcutComponents.clear();
for (int i = 0; i < MAX_SERVICE_TARGETS; i++) { for (int i = 0; i < mChooserListCommunicator.getMaxRankedTargets(); i++) {
mServiceTargets.add(mPlaceHolderTargetInfo); mServiceTargets.add(mPlaceHolderTargetInfo);
} }
} }
@@ -382,7 +380,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
public int getServiceTargetCount() { public int getServiceTargetCount() {
if (mChooserListCommunicator.isSendAction(mChooserListCommunicator.getTargetIntent()) if (mChooserListCommunicator.isSendAction(mChooserListCommunicator.getTargetIntent())
&& !ActivityManager.isLowRamDeviceStatic()) { && !ActivityManager.isLowRamDeviceStatic()) {
return Math.min(mServiceTargets.size(), MAX_SERVICE_TARGETS); return Math.min(mServiceTargets.size(), mChooserListCommunicator.getMaxRankedTargets());
} }
return 0; return 0;
@@ -847,7 +845,8 @@ public class ChooserListAdapter extends ResolverListAdapter {
int currentSize = mServiceTargets.size(); int currentSize = mServiceTargets.size();
final float newScore = chooserTargetInfo.getModifiedScore(); final float newScore = chooserTargetInfo.getModifiedScore();
for (int i = 0; i < Math.min(currentSize, MAX_SERVICE_TARGETS); i++) { for (int i = 0; i < Math.min(currentSize, mChooserListCommunicator.getMaxRankedTargets());
i++) {
final ChooserTargetInfo serviceTarget = mServiceTargets.get(i); final ChooserTargetInfo serviceTarget = mServiceTargets.get(i);
if (serviceTarget == null) { if (serviceTarget == null) {
mServiceTargets.set(i, chooserTargetInfo); mServiceTargets.set(i, chooserTargetInfo);
@@ -858,7 +857,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
} }
} }
if (currentSize < MAX_SERVICE_TARGETS) { if (currentSize < mChooserListCommunicator.getMaxRankedTargets()) {
mServiceTargets.add(chooserTargetInfo); mServiceTargets.add(chooserTargetInfo);
return true; return true;
} }

View File

@@ -39,17 +39,19 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd
private final ChooserProfileDescriptor[] mItems; private final ChooserProfileDescriptor[] mItems;
private final boolean mIsSendAction; private final boolean mIsSendAction;
private int mBottomOffset; private int mBottomOffset;
private int mMaxTargetsPerRow;
ChooserMultiProfilePagerAdapter(Context context, ChooserMultiProfilePagerAdapter(Context context,
ChooserActivity.ChooserGridAdapter adapter, ChooserActivity.ChooserGridAdapter adapter,
UserHandle personalProfileUserHandle, UserHandle personalProfileUserHandle,
UserHandle workProfileUserHandle, UserHandle workProfileUserHandle,
boolean isSendAction) { boolean isSendAction, int maxTargetsPerRow) {
super(context, /* currentPage */ 0, personalProfileUserHandle, workProfileUserHandle); super(context, /* currentPage */ 0, personalProfileUserHandle, workProfileUserHandle);
mItems = new ChooserProfileDescriptor[] { mItems = new ChooserProfileDescriptor[] {
createProfileDescriptor(adapter) createProfileDescriptor(adapter)
}; };
mIsSendAction = isSendAction; mIsSendAction = isSendAction;
mMaxTargetsPerRow = maxTargetsPerRow;
} }
ChooserMultiProfilePagerAdapter(Context context, ChooserMultiProfilePagerAdapter(Context context,
@@ -58,7 +60,7 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd
@Profile int defaultProfile, @Profile int defaultProfile,
UserHandle personalProfileUserHandle, UserHandle personalProfileUserHandle,
UserHandle workProfileUserHandle, UserHandle workProfileUserHandle,
boolean isSendAction) { boolean isSendAction, int maxTargetsPerRow) {
super(context, /* currentPage */ defaultProfile, personalProfileUserHandle, super(context, /* currentPage */ defaultProfile, personalProfileUserHandle,
workProfileUserHandle); workProfileUserHandle);
mItems = new ChooserProfileDescriptor[] { mItems = new ChooserProfileDescriptor[] {
@@ -66,6 +68,7 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd
createProfileDescriptor(workAdapter) createProfileDescriptor(workAdapter)
}; };
mIsSendAction = isSendAction; mIsSendAction = isSendAction;
mMaxTargetsPerRow = maxTargetsPerRow;
} }
private ChooserProfileDescriptor createProfileDescriptor( private ChooserProfileDescriptor createProfileDescriptor(
@@ -114,7 +117,7 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd
ChooserActivity.ChooserGridAdapter chooserGridAdapter = ChooserActivity.ChooserGridAdapter chooserGridAdapter =
getItem(pageIndex).chooserGridAdapter; getItem(pageIndex).chooserGridAdapter;
GridLayoutManager glm = (GridLayoutManager) recyclerView.getLayoutManager(); GridLayoutManager glm = (GridLayoutManager) recyclerView.getLayoutManager();
glm.setSpanCount(chooserGridAdapter.getMaxTargetsPerRow()); glm.setSpanCount(mMaxTargetsPerRow);
glm.setSpanSizeLookup( glm.setSpanSizeLookup(
new GridLayoutManager.SpanSizeLookup() { new GridLayoutManager.SpanSizeLookup() {
@Override @Override