diff --git a/mobile/src/com/cradle/iitc_mobile/share/IntentComparator.java b/mobile/src/com/cradle/iitc_mobile/share/IntentComparator.java index 436488e4..b01ab72d 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/IntentComparator.java +++ b/mobile/src/com/cradle/iitc_mobile/share/IntentComparator.java @@ -124,6 +124,13 @@ public class IntentComparator implements Comparator { 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 { 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) { diff --git a/mobile/src/com/cradle/iitc_mobile/share/IntentListView.java b/mobile/src/com/cradle/iitc_mobile/share/IntentListView.java index 785c1edb..a0af6dcc 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/IntentListView.java +++ b/mobile/src/com/cradle/iitc_mobile/share/IntentListView.java @@ -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); } - } }