summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Song Hu <songhu@google.com> 2020-05-16 08:42:54 -0700
committer Song Hu <songhu@google.com> 2020-05-18 06:13:34 -0700
commitb548df99a7a7fb42edccf8cb3955736b5e90f054 (patch)
tree2917e585becaf91665c509640cfb51d70718d64d
parent276e384e4c677ff6cb6c5f08edacc3e47a51e9b5 (diff)
In new direct share ranking, expand DS row as long as there are enough
targets parking in memory, even if targets are still loading on UI. Backfill targets of top 8 apps into DS row instead of top 4, if the row is not full. Bug: 156470651 Test: atest CtsSharesheetTestCases:android.sharesheet.cts.CtsSharesheetDeviceTest Test: atest com.android.internal.app.ChooserActivityTest Change-Id: Idefd6c225fca723d6d266b78ef41a4201483c634
-rw-r--r--core/java/com/android/internal/app/ChooserActivity.java14
-rw-r--r--core/java/com/android/internal/app/ChooserListAdapter.java43
2 files changed, 33 insertions, 24 deletions
diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java
index 3fc3f3e65d37..1b2df6047f5d 100644
--- a/core/java/com/android/internal/app/ChooserActivity.java
+++ b/core/java/com/android/internal/app/ChooserActivity.java
@@ -3501,13 +3501,11 @@ public class ChooserActivity extends ResolverActivity implements
}
/**
- * Only expand direct share area if there is a minimum number of shortcuts,
- * which will help reduce the amount of visible shuffling due to older-style
- * direct share targets.
+ * Only expand direct share area if there is a minimum number of targets.
*/
private boolean canExpandDirectShare() {
int orientation = getResources().getConfiguration().orientation;
- return mChooserListAdapter.getNumShortcutResults() > getMaxTargetsPerRow()
+ return mChooserListAdapter.getNumServiceTargetsForExpand() > getMaxTargetsPerRow()
&& orientation == Configuration.ORIENTATION_PORTRAIT
&& !isInMultiWindowMode();
}
@@ -3716,8 +3714,12 @@ public class ChooserActivity extends ResolverActivity implements
// only expand if we have more than maxTargetsPerRow, and delay that decision
// until they start to scroll
- if (mChooserMultiProfilePagerAdapter.getActiveListAdapter()
- .getSelectableServiceTargetCount() <= maxTargetsPerRow) {
+ ChooserListAdapter adapter =
+ mChooserMultiProfilePagerAdapter.getActiveListAdapter();
+ int validTargets =
+ mAppendDirectShareEnabled ? adapter.getNumServiceTargetsForExpand()
+ : adapter.getSelectableServiceTargetCount();
+ if (validTargets <= maxTargetsPerRow) {
mHideDirectShareExpansion = true;
return;
}
diff --git a/core/java/com/android/internal/app/ChooserListAdapter.java b/core/java/com/android/internal/app/ChooserListAdapter.java
index f9462a8f3bfc..c3c59f52090f 100644
--- a/core/java/com/android/internal/app/ChooserListAdapter.java
+++ b/core/java/com/android/internal/app/ChooserListAdapter.java
@@ -78,6 +78,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
private static final int MAX_SUGGESTED_APP_TARGETS = 4;
private static final int MAX_CHOOSER_TARGETS_PER_APP = 2;
+ private static final int MAX_SERVICE_TARGET_APP = 8;
static final int MAX_SERVICE_TARGETS = 8;
@@ -97,6 +98,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
private ChooserTargetInfo
mPlaceHolderTargetInfo = new ChooserActivity.PlaceHolderTargetInfo();
private int mValidServiceTargetsNum = 0;
+ private int mAvailableServiceTargetsNum = 0;
private final Map<ComponentName, Pair<List<ChooserTargetInfo>, Integer>>
mParkingDirectShareTargets = new HashMap<>();
private final Map<ComponentName, Map<String, Integer>> mChooserTargetScores = new HashMap<>();
@@ -589,7 +591,13 @@ public class ChooserListAdapter extends ResolverListAdapter {
Pair<List<ChooserTargetInfo>, Integer> parkingTargetInfoPair =
mParkingDirectShareTargets.getOrDefault(origComponentName,
new Pair<>(new ArrayList<>(), 0));
- parkingTargetInfoPair.first.addAll(parkingTargetInfos);
+ for (ChooserTargetInfo target : parkingTargetInfos) {
+ if (!checkDuplicateTarget(target, parkingTargetInfoPair.first)
+ && !checkDuplicateTarget(target, mServiceTargets)) {
+ parkingTargetInfoPair.first.add(target);
+ mAvailableServiceTargetsNum++;
+ }
+ }
mParkingDirectShareTargets.put(origComponentName, parkingTargetInfoPair);
rankTargetsWithinComponent(origComponentName);
if (isShortcutResult) {
@@ -634,7 +642,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
List<ChooserTargetInfo> parkingTargets = parkingTargetsItem.first;
int insertedNum = parkingTargetsItem.second;
while (insertedNum < quota && !parkingTargets.isEmpty()) {
- if (!checkDuplicateTarget(parkingTargets.get(0))) {
+ if (!checkDuplicateTarget(parkingTargets.get(0), mServiceTargets)) {
mServiceTargets.add(mValidServiceTargetsNum, parkingTargets.get(0));
mValidServiceTargetsNum++;
insertedNum++;
@@ -649,9 +657,6 @@ public class ChooserListAdapter extends ResolverListAdapter {
+ " totalScore=" + totalScore
+ " quota=" + quota);
}
- if (mShortcutComponents.contains(component)) {
- mNumShortcutResults += insertedNum - parkingTargetsItem.second;
- }
mParkingDirectShareTargets.put(component, new Pair<>(parkingTargets, insertedNum));
}
if (!shouldWaitPendingService) {
@@ -667,19 +672,15 @@ public class ChooserListAdapter extends ResolverListAdapter {
return;
}
Log.i(TAG, " fillAllServiceTargets");
- int maxRankedTargets = mChooserListCommunicator.getMaxRankedTargets();
- List<ComponentName> topComponentNames = getTopComponentNames(maxRankedTargets);
+ List<ComponentName> topComponentNames = getTopComponentNames(MAX_SERVICE_TARGET_APP);
// Append all remaining targets of top recommended components into direct share row.
for (ComponentName component : topComponentNames) {
if (!mParkingDirectShareTargets.containsKey(component)) {
continue;
}
mParkingDirectShareTargets.get(component).first.stream()
- .filter(target -> !checkDuplicateTarget(target))
+ .filter(target -> !checkDuplicateTarget(target, mServiceTargets))
.forEach(target -> {
- if (mShortcutComponents.contains(component)) {
- mNumShortcutResults++;
- }
mServiceTargets.add(mValidServiceTargetsNum, target);
mValidServiceTargetsNum++;
});
@@ -692,28 +693,34 @@ public class ChooserListAdapter extends ResolverListAdapter {
.map(pair -> pair.first)
.forEach(targets -> {
for (ChooserTargetInfo target : targets) {
- if (!checkDuplicateTarget(target)) {
+ if (!checkDuplicateTarget(target, mServiceTargets)) {
mServiceTargets.add(mValidServiceTargetsNum, target);
mValidServiceTargetsNum++;
- mNumShortcutResults++;
}
}
});
mParkingDirectShareTargets.clear();
}
- private boolean checkDuplicateTarget(ChooserTargetInfo chooserTargetInfo) {
+ private boolean checkDuplicateTarget(ChooserTargetInfo target,
+ List<ChooserTargetInfo> destination) {
// Check for duplicates and abort if found
- for (ChooserTargetInfo otherTargetInfo : mServiceTargets) {
- if (chooserTargetInfo.isSimilar(otherTargetInfo)) {
+ for (ChooserTargetInfo otherTargetInfo : destination) {
+ if (target.isSimilar(otherTargetInfo)) {
return true;
}
}
return false;
}
- int getNumShortcutResults() {
- return mNumShortcutResults;
+ /**
+ * The return number have to exceed a minimum limit to make direct share area expandable. When
+ * append direct share targets is enabled, return count of all available targets parking in the
+ * memory; otherwise, it is shortcuts count which will help reduce the amount of visible
+ * shuffling due to older-style direct share targets.
+ */
+ int getNumServiceTargetsForExpand() {
+ return mAppendDirectShareEnabled ? mAvailableServiceTargetsNum : mNumShortcutResults;
}
/**