From: Daniel Sandler Date: Wed, 16 Nov 2011 23:31:23 +0000 (-0800) Subject: Show desk dock apps as screen savers. X-Git-Tag: android-x86-4.4-r1~1627^2~69^2 X-Git-Url: http://git.osdn.net/view?p=android-x86%2Fpackages-apps-Settings.git;a=commitdiff_plain;h=f630808093ee9a85e24956cff1f0e532391d6bf8 Show desk dock apps as screen savers. Now that docking launches the screen saver instead of a dock app, we offer those apps as screen savers to allow them to continue functioning as they did before. As a bonus, users without docks can now use dock apps! Bug: 5591015 Change-Id: Ifc138ab4c0bdffa1bbd7afe8b3ad730ec971aa34 --- diff --git a/src/com/android/settings/DreamComponentPreference.java b/src/com/android/settings/DreamComponentPreference.java index 3bc0eb4994..662c82fa0b 100644 --- a/src/com/android/settings/DreamComponentPreference.java +++ b/src/com/android/settings/DreamComponentPreference.java @@ -44,10 +44,14 @@ import android.widget.ListAdapter; import android.widget.TextView; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; public class DreamComponentPreference extends Preference { private static final String TAG = "DreamComponentPreference"; + + private static final boolean SHOW_DOCK_APPS_TOO = true; private final PackageManager pm; private final ContentResolver resolver; @@ -62,6 +66,10 @@ public class DreamComponentPreference extends Preference { private void refreshFromSettings() { String component = Settings.Secure.getString(resolver, DREAM_COMPONENT); + if (component == null) { + component = getContext().getResources().getString( + com.android.internal.R.string.config_defaultDreamComponent); + } if (component != null) { ComponentName cn = ComponentName.unflattenFromString(component); try { @@ -72,6 +80,18 @@ public class DreamComponentPreference extends Preference { } } + final static Comparator sResolveInfoComparator = new Comparator() { + @Override + public int compare(ResolveInfo a, ResolveInfo b) { + int cmp = a.activityInfo.applicationInfo.packageName.compareTo( + b.activityInfo.applicationInfo.packageName); + if (cmp == 0) { + cmp = a.activityInfo.name.compareTo(b.activityInfo.name); + } + return cmp; + } + }; + public class DreamListAdapter extends BaseAdapter implements ListAdapter { private ArrayList results; private final LayoutInflater inflater; @@ -81,7 +101,25 @@ public class DreamComponentPreference extends Preference { .addCategory("android.intent.category.DREAM"); inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + results = new ArrayList(pm.queryIntentActivities(choosy, 0)); + + // Group by package + Collections.sort(results, sResolveInfoComparator); + + if (SHOW_DOCK_APPS_TOO) { + choosy = new Intent(Intent.ACTION_MAIN) + .addCategory(Intent.CATEGORY_DESK_DOCK); + + List dockApps = pm.queryIntentActivities(choosy, 0); + for (ResolveInfo app : dockApps) { + // do not insert duplicate packages + int pos = Collections.binarySearch(results, app, sResolveInfoComparator); + if (pos < 0) { + results.add(-1-pos, app); + } + } + } } @Override