Improved intent sorting

(default app listed first again, sorting broke this)
This commit is contained in:
fkloft 2013-12-06 00:16:22 +01:00 committed by Philipp Schaefer
parent 1e4b56dd22
commit 18afab9952
2 changed files with 23 additions and 10 deletions

View File

@ -124,6 +124,13 @@ public class IntentComparator implements Comparator<ResolveInfo> {
public int compare(ResolveInfo lhs, ResolveInfo rhs) {
int order;
// we might be merging multiple intents, so there could be more than one default
if (lhs.isDefault && !rhs.isDefault)
return -1;
if (rhs.isDefault && !lhs.isDefault)
return 1;
// Show more frequently used items in top
Integer lCount = mIntentMap.get(new Component(lhs));
Integer rCount = mIntentMap.get(new Component(rhs));
@ -133,8 +140,15 @@ public class IntentComparator implements Comparator<ResolveInfo> {
if (lCount > rCount) return -1;
if (lCount < rCount) return 1;
order = lhs.loadLabel(mPackageManager).toString()
.compareTo(rhs.loadLabel(mPackageManager).toString());
// don't known how these are set (or if they can be set at all), but it sounds promising...
if (lhs.preferredOrder != rhs.preferredOrder)
return rhs.preferredOrder - lhs.preferredOrder;
if (lhs.priority != rhs.priority)
return rhs.priority - lhs.priority;
// still no order. fall back to alphabetical order
order = lhs.loadLabel(mPackageManager).toString().compareTo(
rhs.loadLabel(mPackageManager).toString());
if (order != 0) return order;
if (lhs.nonLocalizedLabel != null && rhs.nonLocalizedLabel != null) {

View File

@ -187,17 +187,16 @@ public class IntentListView extends ListView {
ActivityInfo activity = resolveInfo.activityInfo;
ComponentName activityId = new ComponentName(activity.packageName, activity.name);
// ResolveInfo.isDefault usually means "The target would like to be considered a default action that the
// user can perform on this data." It is set by the package manager, but we overwrite it to store
// whether this app is the default for the given intent
resolveInfo.isDefault = resolveInfo.activityInfo.name.equals(defaultTarget.activityInfo.name)
&& resolveInfo.activityInfo.packageName.equals(defaultTarget.activityInfo.packageName);
if (!mActivities.containsKey(activityId)) {
mActivities.put(activityId, intent);
// move default Intent to top
if (resolveInfo.activityInfo.packageName.equals(defaultTarget.activityInfo.packageName)
&& resolveInfo.activityInfo.name.equals(defaultTarget.activityInfo.name)) {
allActivities.add(0, resolveInfo);
} else {
allActivities.add(resolveInfo);
}
allActivities.add(resolveInfo);
}
}
}