am 940abed2: am 6f3f660c: am 24bf1226: am e9cbf415: Merge "Sort and limit ChooserActivity targets from ChooserTargetServices" into mnc-dev
* commit '940abed246f37454426f56c9cbb37e12ec4cdfb5': Sort and limit ChooserActivity targets from ChooserTargetServices
This commit is contained in:
@@ -59,6 +59,8 @@ import com.android.internal.R;
|
|||||||
import com.android.internal.logging.MetricsLogger;
|
import com.android.internal.logging.MetricsLogger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ChooserActivity extends ResolverActivity {
|
public class ChooserActivity extends ResolverActivity {
|
||||||
@@ -97,7 +99,10 @@ public class ChooserActivity extends ResolverActivity {
|
|||||||
+ " Have you considered returning results faster?");
|
+ " Have you considered returning results faster?");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mChooserListAdapter.addServiceResults(sri.originalTarget, sri.resultTargets);
|
if (sri.resultTargets != null) {
|
||||||
|
mChooserListAdapter.addServiceResults(sri.originalTarget,
|
||||||
|
sri.resultTargets);
|
||||||
|
}
|
||||||
unbindService(sri.connection);
|
unbindService(sri.connection);
|
||||||
mServiceConnections.remove(sri.connection);
|
mServiceConnections.remove(sri.connection);
|
||||||
if (mServiceConnections.isEmpty()) {
|
if (mServiceConnections.isEmpty()) {
|
||||||
@@ -485,10 +490,13 @@ public class ChooserActivity extends ResolverActivity {
|
|||||||
private Drawable mDisplayIcon;
|
private Drawable mDisplayIcon;
|
||||||
private final Intent mFillInIntent;
|
private final Intent mFillInIntent;
|
||||||
private final int mFillInFlags;
|
private final int mFillInFlags;
|
||||||
|
private final float mModifiedScore;
|
||||||
|
|
||||||
public ChooserTargetInfo(DisplayResolveInfo sourceInfo, ChooserTarget chooserTarget) {
|
public ChooserTargetInfo(DisplayResolveInfo sourceInfo, ChooserTarget chooserTarget,
|
||||||
|
float modifiedScore) {
|
||||||
mSourceInfo = sourceInfo;
|
mSourceInfo = sourceInfo;
|
||||||
mChooserTarget = chooserTarget;
|
mChooserTarget = chooserTarget;
|
||||||
|
mModifiedScore = modifiedScore;
|
||||||
if (sourceInfo != null) {
|
if (sourceInfo != null) {
|
||||||
final ResolveInfo ri = sourceInfo.getResolveInfo();
|
final ResolveInfo ri = sourceInfo.getResolveInfo();
|
||||||
if (ri != null) {
|
if (ri != null) {
|
||||||
@@ -520,6 +528,11 @@ public class ChooserActivity extends ResolverActivity {
|
|||||||
mDisplayIcon = other.mDisplayIcon;
|
mDisplayIcon = other.mDisplayIcon;
|
||||||
mFillInIntent = fillInIntent;
|
mFillInIntent = fillInIntent;
|
||||||
mFillInFlags = flags;
|
mFillInFlags = flags;
|
||||||
|
mModifiedScore = other.mModifiedScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getModifiedScore() {
|
||||||
|
return mModifiedScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -632,9 +645,16 @@ public class ChooserActivity extends ResolverActivity {
|
|||||||
public static final int TARGET_SERVICE = 1;
|
public static final int TARGET_SERVICE = 1;
|
||||||
public static final int TARGET_STANDARD = 2;
|
public static final int TARGET_STANDARD = 2;
|
||||||
|
|
||||||
|
private static final int MAX_SERVICE_TARGETS = 8;
|
||||||
|
|
||||||
private final List<ChooserTargetInfo> mServiceTargets = new ArrayList<>();
|
private final List<ChooserTargetInfo> mServiceTargets = new ArrayList<>();
|
||||||
private final List<TargetInfo> mCallerTargets = new ArrayList<>();
|
private final List<TargetInfo> mCallerTargets = new ArrayList<>();
|
||||||
|
|
||||||
|
private float mLateFee = 1.f;
|
||||||
|
|
||||||
|
private final BaseChooserTargetComparator mBaseTargetComparator
|
||||||
|
= new BaseChooserTargetComparator();
|
||||||
|
|
||||||
public ChooserListAdapter(Context context, List<Intent> payloadIntents,
|
public ChooserListAdapter(Context context, List<Intent> payloadIntents,
|
||||||
Intent[] initialIntents, List<ResolveInfo> rList, int launchedFromUid,
|
Intent[] initialIntents, List<ResolveInfo> rList, int launchedFromUid,
|
||||||
boolean filterLastUsed) {
|
boolean filterLastUsed) {
|
||||||
@@ -703,12 +723,12 @@ public class ChooserActivity extends ResolverActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return super.getCount() + mServiceTargets.size() + mCallerTargets.size();
|
return super.getCount() + getServiceTargetCount() + getCallerTargetCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getUnfilteredCount() {
|
public int getUnfilteredCount() {
|
||||||
return super.getUnfilteredCount() + mServiceTargets.size() + mCallerTargets.size();
|
return super.getUnfilteredCount() + getServiceTargetCount() + getCallerTargetCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCallerTargetCount() {
|
public int getCallerTargetCount() {
|
||||||
@@ -716,7 +736,7 @@ public class ChooserActivity extends ResolverActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getServiceTargetCount() {
|
public int getServiceTargetCount() {
|
||||||
return mServiceTargets.size();
|
return Math.min(mServiceTargets.size(), MAX_SERVICE_TARGETS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStandardTargetCount() {
|
public int getStandardTargetCount() {
|
||||||
@@ -726,13 +746,13 @@ public class ChooserActivity extends ResolverActivity {
|
|||||||
public int getPositionTargetType(int position) {
|
public int getPositionTargetType(int position) {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
final int callerTargetCount = mCallerTargets.size();
|
final int callerTargetCount = getCallerTargetCount();
|
||||||
if (position < callerTargetCount) {
|
if (position < callerTargetCount) {
|
||||||
return TARGET_CALLER;
|
return TARGET_CALLER;
|
||||||
}
|
}
|
||||||
offset += callerTargetCount;
|
offset += callerTargetCount;
|
||||||
|
|
||||||
final int serviceTargetCount = mServiceTargets.size();
|
final int serviceTargetCount = getServiceTargetCount();
|
||||||
if (position - offset < serviceTargetCount) {
|
if (position - offset < serviceTargetCount) {
|
||||||
return TARGET_SERVICE;
|
return TARGET_SERVICE;
|
||||||
}
|
}
|
||||||
@@ -755,13 +775,13 @@ public class ChooserActivity extends ResolverActivity {
|
|||||||
public TargetInfo targetInfoForPosition(int position, boolean filtered) {
|
public TargetInfo targetInfoForPosition(int position, boolean filtered) {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
final int callerTargetCount = mCallerTargets.size();
|
final int callerTargetCount = getCallerTargetCount();
|
||||||
if (position < callerTargetCount) {
|
if (position < callerTargetCount) {
|
||||||
return mCallerTargets.get(position);
|
return mCallerTargets.get(position);
|
||||||
}
|
}
|
||||||
offset += callerTargetCount;
|
offset += callerTargetCount;
|
||||||
|
|
||||||
final int serviceTargetCount = mServiceTargets.size();
|
final int serviceTargetCount = getServiceTargetCount();
|
||||||
if (position - offset < serviceTargetCount) {
|
if (position - offset < serviceTargetCount) {
|
||||||
return mServiceTargets.get(position - offset);
|
return mServiceTargets.get(position - offset);
|
||||||
}
|
}
|
||||||
@@ -774,15 +794,49 @@ public class ChooserActivity extends ResolverActivity {
|
|||||||
public void addServiceResults(DisplayResolveInfo origTarget, List<ChooserTarget> targets) {
|
public void addServiceResults(DisplayResolveInfo origTarget, List<ChooserTarget> targets) {
|
||||||
if (DEBUG) Log.d(TAG, "addServiceResults " + origTarget + ", " + targets.size()
|
if (DEBUG) Log.d(TAG, "addServiceResults " + origTarget + ", " + targets.size()
|
||||||
+ " targets");
|
+ " targets");
|
||||||
|
final float parentScore = getScore(origTarget);
|
||||||
|
Collections.sort(targets, mBaseTargetComparator);
|
||||||
|
float lastScore = 0;
|
||||||
for (int i = 0, N = targets.size(); i < N; i++) {
|
for (int i = 0, N = targets.size(); i < N; i++) {
|
||||||
mServiceTargets.add(new ChooserTargetInfo(origTarget, targets.get(i)));
|
final ChooserTarget target = targets.get(i);
|
||||||
|
float targetScore = target.getScore();
|
||||||
|
targetScore *= parentScore;
|
||||||
|
targetScore *= mLateFee;
|
||||||
|
if (i > 0 && targetScore >= lastScore) {
|
||||||
|
// Apply a decay so that the top app can't crowd out everything else.
|
||||||
|
// This incents ChooserTargetServices to define what's truly better.
|
||||||
|
targetScore = lastScore * 0.95f;
|
||||||
|
}
|
||||||
|
insertServiceTarget(new ChooserTargetInfo(origTarget, target, targetScore));
|
||||||
|
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, " => " + target.toString() + " score=" + targetScore
|
||||||
|
+ " base=" + target.getScore()
|
||||||
|
+ " lastScore=" + lastScore
|
||||||
|
+ " parentScore=" + parentScore
|
||||||
|
+ " lateFee=" + mLateFee);
|
||||||
|
}
|
||||||
|
|
||||||
|
lastScore = targetScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Maintain sort by ranking scores.
|
mLateFee *= 0.95f;
|
||||||
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void insertServiceTarget(ChooserTargetInfo chooserTargetInfo) {
|
||||||
|
final float newScore = chooserTargetInfo.getModifiedScore();
|
||||||
|
for (int i = 0, N = mServiceTargets.size(); i < N; i++) {
|
||||||
|
final ChooserTargetInfo serviceTarget = mServiceTargets.get(i);
|
||||||
|
if (newScore > serviceTarget.getModifiedScore()) {
|
||||||
|
mServiceTargets.add(i, chooserTargetInfo);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mServiceTargets.add(chooserTargetInfo);
|
||||||
|
}
|
||||||
|
|
||||||
private void pruneServiceTargets() {
|
private void pruneServiceTargets() {
|
||||||
if (DEBUG) Log.d(TAG, "pruneServiceTargets");
|
if (DEBUG) Log.d(TAG, "pruneServiceTargets");
|
||||||
for (int i = mServiceTargets.size() - 1; i >= 0; i--) {
|
for (int i = mServiceTargets.size() - 1; i >= 0; i--) {
|
||||||
@@ -795,6 +849,14 @@ public class ChooserActivity extends ResolverActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class BaseChooserTargetComparator implements Comparator<ChooserTarget> {
|
||||||
|
@Override
|
||||||
|
public int compare(ChooserTarget lhs, ChooserTarget rhs) {
|
||||||
|
// Descending order
|
||||||
|
return (int) Math.signum(lhs.getScore() - rhs.getScore());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ChooserRowAdapter extends BaseAdapter {
|
class ChooserRowAdapter extends BaseAdapter {
|
||||||
private ChooserListAdapter mChooserListAdapter;
|
private ChooserListAdapter mChooserListAdapter;
|
||||||
private final LayoutInflater mLayoutInflater;
|
private final LayoutInflater mLayoutInflater;
|
||||||
|
|||||||
@@ -1142,6 +1142,10 @@ public class ResolverActivity extends Activity {
|
|||||||
return mFilterLastUsed && mLastChosenPosition >= 0;
|
return mFilterLastUsed && mLastChosenPosition >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getScore(DisplayResolveInfo target) {
|
||||||
|
return mResolverComparator.getScore(target.getResolvedComponentName());
|
||||||
|
}
|
||||||
|
|
||||||
private void rebuildList() {
|
private void rebuildList() {
|
||||||
List<ResolvedComponentInfo> currentResolveList = null;
|
List<ResolvedComponentInfo> currentResolveList = null;
|
||||||
|
|
||||||
|
|||||||
@@ -191,6 +191,14 @@ class ResolverComparator implements Comparator<ResolvedComponentInfo> {
|
|||||||
return mCollator.compare(sa.toString().trim(), sb.toString().trim());
|
return mCollator.compare(sa.toString().trim(), sb.toString().trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getScore(ComponentName name) {
|
||||||
|
final ScoredTarget target = mScoredTargets.get(name);
|
||||||
|
if (target != null) {
|
||||||
|
return target.score;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static class ScoredTarget {
|
static class ScoredTarget {
|
||||||
public final ComponentInfo componentInfo;
|
public final ComponentInfo componentInfo;
|
||||||
public float score;
|
public float score;
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ public class ResolverDrawerLayout extends ViewGroup {
|
|||||||
mInitialTouchY = mLastTouchY = y;
|
mInitialTouchY = mLastTouchY = y;
|
||||||
mActivePointerId = ev.getPointerId(0);
|
mActivePointerId = ev.getPointerId(0);
|
||||||
final boolean hitView = findChildUnder(mInitialTouchX, mInitialTouchY) != null;
|
final boolean hitView = findChildUnder(mInitialTouchX, mInitialTouchY) != null;
|
||||||
handled = (!hitView && mOnDismissedListener != null) || mCollapsibleHeight > 0;
|
handled = mOnDismissedListener != null || mCollapsibleHeight > 0;
|
||||||
mIsDragging = hitView && handled;
|
mIsDragging = hitView && handled;
|
||||||
abortAnimation();
|
abortAnimation();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user