Improved intent sorting
(default app listed first again, sorting broke this)
This commit is contained in:
		| @@ -124,6 +124,13 @@ public class IntentComparator implements Comparator<ResolveInfo> { | |||||||
|     public int compare(ResolveInfo lhs, ResolveInfo rhs) { |     public int compare(ResolveInfo lhs, ResolveInfo rhs) { | ||||||
|         int order; |         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 lCount = mIntentMap.get(new Component(lhs)); | ||||||
|         Integer rCount = mIntentMap.get(new Component(rhs)); |         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; | ||||||
|         if (lCount < rCount) return 1; |         if (lCount < rCount) return 1; | ||||||
|  |  | ||||||
|         order = lhs.loadLabel(mPackageManager).toString() |         // don't known how these are set (or if they can be set at all), but it sounds promising... | ||||||
|                 .compareTo(rhs.loadLabel(mPackageManager).toString()); |         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 (order != 0) return order; | ||||||
|  |  | ||||||
|         if (lhs.nonLocalizedLabel != null && rhs.nonLocalizedLabel != null) { |         if (lhs.nonLocalizedLabel != null && rhs.nonLocalizedLabel != null) { | ||||||
|   | |||||||
| @@ -187,18 +187,17 @@ public class IntentListView extends ListView { | |||||||
|                 ActivityInfo activity = resolveInfo.activityInfo; |                 ActivityInfo activity = resolveInfo.activityInfo; | ||||||
|                 ComponentName activityId = new ComponentName(activity.packageName, activity.name); |                 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)) { |                 if (!mActivities.containsKey(activityId)) { | ||||||
|                     mActivities.put(activityId, intent); |                     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); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         Collections.sort(allActivities, ((ShareActivity) getContext()).getIntentComparator()); |         Collections.sort(allActivities, ((ShareActivity) getContext()).getIntentComparator()); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user