diff options
author | Danesh M <daneshm90@gmail.com> | 2013-11-08 17:58:44 -0800 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2015-10-29 17:36:27 -0700 |
commit | e116de1c0318e50200c7d82f3a31e08eaa3a189a (patch) | |
tree | eb3b095d005550b00c9f7d348de4f5210c418903 /src/com/android/settings/Utils.java | |
parent | 2ea9a80502df3cd28c4255b7250cd257755e9e2f (diff) | |
download | packages_apps_Settings-e116de1c0318e50200c7d82f3a31e08eaa3a189a.zip packages_apps_Settings-e116de1c0318e50200c7d82f3a31e08eaa3a189a.tar.gz packages_apps_Settings-e116de1c0318e50200c7d82f3a31e08eaa3a189a.tar.bz2 |
Settings : Add hooks for device specific features
Add support for :
Devices with bluetooth input peripherals
Devices with screen gesture support
Devices with a back touchpad
Change-Id: Ia4835c69a8ba8fb76597e0ab0540f8ef1ed6e322
Diffstat (limited to 'src/com/android/settings/Utils.java')
-rw-r--r-- | src/com/android/settings/Utils.java | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java index 075194a..b1170c8 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -223,6 +223,98 @@ public final class Utils { return false; } + /** + * Finds a matching activity for a preference's intent. If a matching + * activity is not found, it will remove the preference. The icon, title and + * summary of the preference will also be updated with the values retrieved + * from the activity's meta-data elements. If no meta-data elements are + * specified then the preference title will be set to match the label of the + * activity, an icon and summary text will not be displayed. + * + * @param context The context. + * @param parentPreferenceGroup The preference group that contains the + * preference whose intent is being resolved. + * @param preferenceKey The key of the preference whose intent is being + * resolved. + * + * @return Whether an activity was found. If false, the preference was + * removed. + * + * @see {@link #META_DATA_PREFERENCE_ICON} + * {@link #META_DATA_PREFERENCE_TITLE} + * {@link #META_DATA_PREFERENCE_SUMMARY} + */ + public static boolean updatePreferenceToSpecificActivityFromMetaDataOrRemove(Context context, + PreferenceGroup parentPreferenceGroup, String preferenceKey) { + + Preference preference = parentPreferenceGroup.findPreference(preferenceKey); + if (preference == null) { + return false; + } + + Intent intent = preference.getIntent(); + if (intent != null) { + // Find the activity that is in the system image + PackageManager pm = context.getPackageManager(); + List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.GET_META_DATA); + int listSize = list.size(); + for (int i = 0; i < listSize; i++) { + ResolveInfo resolveInfo = list.get(i); + if ((resolveInfo.activityInfo.applicationInfo.flags + & ApplicationInfo.FLAG_SYSTEM) != 0) { + Drawable icon = null; + String title = null; + String summary = null; + + // Get the activity's meta-data + try { + Resources res = pm + .getResourcesForApplication(resolveInfo.activityInfo.packageName); + Bundle metaData = resolveInfo.activityInfo.metaData; + + if (res != null && metaData != null) { + if (preference instanceof IconPreferenceScreen) { + icon = res.getDrawable(metaData.getInt(META_DATA_PREFERENCE_ICON)); + } + title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE)); + summary = res.getString(metaData.getInt(META_DATA_PREFERENCE_SUMMARY)); + } + } catch (NameNotFoundException e) { + // Ignore + } catch (NotFoundException e) { + // Ignore + } + + // Set the preference title to the activity's label if no + // meta-data is found + if (TextUtils.isEmpty(title)) { + title = resolveInfo.loadLabel(pm).toString(); + } + + // Set icon, title and summary for the preference + preference.setTitle(title); + preference.setSummary(summary); + if (preference instanceof IconPreferenceScreen) { + IconPreferenceScreen iconPreference = (IconPreferenceScreen) preference; + iconPreference.setIcon(icon); + } + + // Replace the intent with this specific activity + preference.setIntent(new Intent().setClassName( + resolveInfo.activityInfo.packageName, + resolveInfo.activityInfo.name)); + + return true; + } + } + } + + // Did not find a matching activity, so remove the preference + parentPreferenceGroup.removePreference(preference); + + return false; + } + public static boolean updateTileToSpecificActivityFromMetaDataOrRemove(Context context, DashboardTile tile) { |