Loading packages/SettingsLib/Tile/src/com/android/settingslib/drawer/Tile.java +56 −99 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.settingslib.drawer; import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_ORDER; import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE; import static com.android.settingslib.drawer.TileUtils.META_DATA_NEW_TASK; import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_GROUP_KEY; import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON; import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT; import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SEARCHABLE; Loading Loading @@ -52,16 +51,12 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; /** * Description of a single dashboard tile that the user can select. */ /** Description of a single dashboard tile that the user can select. */ public abstract class Tile implements Parcelable { private static final String TAG = "Tile"; /** * Optional list of user handles which the intent should be launched on. */ /** Optional list of user handles which the intent should be launched on. */ public ArrayList<UserHandle> userHandle = new ArrayList<>(); public HashMap<UserHandle, PendingIntent> pendingIntentMap = new HashMap<>(); Loading @@ -76,6 +71,7 @@ public abstract class Tile implements Parcelable { private CharSequence mSummaryOverride; private Bundle mMetaData; private String mCategory; private String mGroupKey; public Tile(ComponentInfo info, String category, Bundle metaData) { mComponentInfo = info; Loading @@ -102,6 +98,7 @@ public abstract class Tile implements Parcelable { if (isNewTask()) { mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } mGroupKey = in.readString(); } @Override Loading @@ -121,16 +118,13 @@ public abstract class Tile implements Parcelable { } dest.writeString(mCategory); dest.writeBundle(mMetaData); dest.writeString(mGroupKey); } /** * Unique ID of the tile */ /** Unique ID of the tile */ public abstract int getId(); /** * Human-readable description of the tile */ /** Human-readable description of the tile */ public abstract String getDescription(); protected abstract ComponentInfo getComponentInfo(Context context); Loading @@ -147,16 +141,12 @@ public abstract class Tile implements Parcelable { return mComponentName; } /** * Intent to launch when the preference is selected. */ /** Intent to launch when the preference is selected. */ public Intent getIntent() { return mIntent; } /** * Category in which the tile should be placed. */ /** Category in which the tile should be placed. */ public String getCategory() { return mCategory; } Loading @@ -165,9 +155,7 @@ public abstract class Tile implements Parcelable { mCategory = newCategoryKey; } /** * Priority of this tile, used for display ordering. */ /** Priority of this tile, used for display ordering. */ public int getOrder() { if (hasOrder()) { return mMetaData.getInt(META_DATA_KEY_ORDER); Loading @@ -176,32 +164,24 @@ public abstract class Tile implements Parcelable { } } /** * Check whether tile has order. */ /** Check whether tile has order. */ public boolean hasOrder() { return mMetaData != null && mMetaData.containsKey(META_DATA_KEY_ORDER) && mMetaData.get(META_DATA_KEY_ORDER) instanceof Integer; } /** * Check whether tile has a switch. */ /** Check whether tile has a switch. */ public boolean hasSwitch() { return mMetaData != null && mMetaData.containsKey(META_DATA_PREFERENCE_SWITCH_URI); } /** * Check whether tile has a pending intent. */ /** Check whether tile has a pending intent. */ public boolean hasPendingIntent() { return !pendingIntentMap.isEmpty(); } /** * Title of the tile that is shown to the user. */ /** Title of the tile that is shown to the user. */ public CharSequence getTitle(Context context) { CharSequence title = null; ensureMetadataNotStale(context); Loading Loading @@ -238,9 +218,7 @@ public abstract class Tile implements Parcelable { mSummaryOverride = summaryOverride; } /** * Optional summary describing what this tile controls. */ /** Optional summary describing what this tile controls. */ public CharSequence getSummary(Context context) { if (mSummaryOverride != null) { return mSummaryOverride; Loading Loading @@ -275,16 +253,12 @@ public abstract class Tile implements Parcelable { mMetaData = metaData; } /** * The metaData from the activity that defines this tile. */ /** The metaData from the activity that defines this tile. */ public Bundle getMetaData() { return mMetaData; } /** * Optional key to use for this tile. */ /** Optional key to use for this tile. */ public String getKey(Context context) { ensureMetadataNotStale(context); if (!hasKey()) { Loading @@ -297,9 +271,7 @@ public abstract class Tile implements Parcelable { } } /** * Check whether title has key. */ /** Check whether title has key. */ public boolean hasKey() { return mMetaData != null && mMetaData.containsKey(META_DATA_PREFERENCE_KEYHINT); } Loading @@ -325,8 +297,9 @@ public abstract class Tile implements Parcelable { if (iconResId != 0 && iconResId != android.R.color.transparent) { final Icon icon = Icon.createWithResource(componentInfo.packageName, iconResId); if (isIconTintable(context)) { final TypedArray a = context.obtainStyledAttributes(new int[]{ android.R.attr.colorControlNormal}); final TypedArray a = context.obtainStyledAttributes( new int[] {android.R.attr.colorControlNormal}); final int tintColor = a.getColor(0, 0); a.recycle(); icon.setTint(tintColor); Loading @@ -349,26 +322,22 @@ public abstract class Tile implements Parcelable { return false; } /** * Whether the {@link Activity} should be launched in a separate task. */ /** Whether the {@link Activity} should be launched in a separate task. */ public boolean isNewTask() { if (mMetaData != null && mMetaData.containsKey(META_DATA_NEW_TASK)) { if (mMetaData != null && mMetaData.containsKey(META_DATA_NEW_TASK)) { return mMetaData.getBoolean(META_DATA_NEW_TASK); } return false; } /** * Ensures metadata is not stale for this tile. */ /** Ensures metadata is not stale for this tile. */ private void ensureMetadataNotStale(Context context) { final PackageManager pm = context.getApplicationContext().getPackageManager(); try { final long lastUpdateTime = pm.getPackageInfo(mComponentPackage, PackageManager.GET_META_DATA).lastUpdateTime; final long lastUpdateTime = pm.getPackageInfo(mComponentPackage, PackageManager.GET_META_DATA) .lastUpdateTime; if (lastUpdateTime == mLastUpdateTime) { // All good. Do nothing return; Loading @@ -382,7 +351,8 @@ public abstract class Tile implements Parcelable { } } public static final Creator<Tile> CREATOR = new Creator<Tile>() { public static final Creator<Tile> CREATOR = new Creator<Tile>() { public Tile createFromParcel(Parcel source) { final boolean isProviderTile = source.readBoolean(); // reset the Parcel pointer before delegating to the real constructor. Loading @@ -395,59 +365,46 @@ public abstract class Tile implements Parcelable { } }; /** * Check whether tile only has primary profile. */ /** Check whether tile only has primary profile. */ public boolean isPrimaryProfileOnly() { return isPrimaryProfileOnly(mMetaData); } static boolean isPrimaryProfileOnly(Bundle metaData) { String profile = metaData != null ? metaData.getString(META_DATA_KEY_PROFILE) : PROFILE_ALL; String profile = metaData != null ? metaData.getString(META_DATA_KEY_PROFILE) : PROFILE_ALL; profile = (profile != null ? profile : PROFILE_ALL); return TextUtils.equals(profile, PROFILE_PRIMARY); } /** * Returns whether the tile belongs to another group / category. */ /** Returns whether the tile belongs to another group / category. */ public boolean hasGroupKey() { return mMetaData != null && !TextUtils.isEmpty(mMetaData.getString(META_DATA_PREFERENCE_GROUP_KEY)); return !TextUtils.isEmpty(mGroupKey); } /** * Returns the group / category key this tile belongs to. */ /** Set the group / PreferenceCategory key this tile belongs to. */ public void setGroupKey(String groupKey) { mGroupKey = groupKey; } /** Returns the group / category key this tile belongs to. */ public String getGroupKey() { return (mMetaData == null) ? null : mMetaData.getString(META_DATA_PREFERENCE_GROUP_KEY); return mGroupKey; } /** * Returns if this is searchable. */ /** Returns if this is searchable. */ public boolean isSearchable() { return mMetaData == null || mMetaData.getBoolean(META_DATA_PREFERENCE_SEARCHABLE, true); } /** * The type of the tile. */ /** The type of the tile. */ public enum Type { /** * A preference that can be tapped on to open a new page. */ /** A preference that can be tapped on to open a new page. */ ACTION, /** * A preference that can be tapped on to open an external app. */ /** A preference that can be tapped on to open an external app. */ EXTERNAL_ACTION, /** * A preference that shows an on / off switch that can be toggled by the user. */ /** A preference that shows an on / off switch that can be toggled by the user. */ SWITCH, /** Loading @@ -460,7 +417,7 @@ public abstract class Tile implements Parcelable { * A preference category with a title that can be used to group multiple preferences * together. */ GROUP; GROUP } /** Loading packages/SettingsLib/Tile/src/com/android/settingslib/drawer/TileUtils.java +55 −67 Original line number Diff line number Diff line Loading @@ -77,9 +77,7 @@ public class TileUtils { */ public static final String IA_SETTINGS_ACTION = "com.android.settings.action.IA_SETTINGS"; /** * Same as #EXTRA_SETTINGS_ACTION but used for the platform Settings activities. */ /** Same as #EXTRA_SETTINGS_ACTION but used for the platform Settings activities. */ private static final String SETTINGS_ACTION = "com.android.settings.action.SETTINGS"; private static final String OPERATOR_SETTINGS = Loading @@ -101,9 +99,7 @@ public class TileUtils { */ static final String EXTRA_CATEGORY_KEY = "com.android.settings.category"; /** * The key used to get the package name of the icon resource for the preference. */ /** The key used to get the package name of the icon resource for the preference. */ static final String EXTRA_PREFERENCE_ICON_PACKAGE = "com.android.settings.icon_package"; /** Loading Loading @@ -145,18 +141,17 @@ public class TileUtils { "com.android.settings.bg.argb"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the content provider providing the icon that should be displayed for * the preference. * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * content provider providing the icon that should be displayed for the preference. * * Icon provided by the content provider overrides any static icon. * <p>Icon provided by the content provider overrides any static icon. */ public static final String META_DATA_PREFERENCE_ICON_URI = "com.android.settings.icon_uri"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify whether the icon is tintable. This should be a boolean value {@code true} or * {@code false}, set using {@code android:value} * Name of the meta-data item that should be set in the AndroidManifest.xml to specify whether * the icon is tintable. This should be a boolean value {@code true} or {@code false}, set using * {@code android:value} */ public static final String META_DATA_PREFERENCE_ICON_TINTABLE = "com.android.settings.icon_tintable"; Loading @@ -171,41 +166,36 @@ public class TileUtils { public static final String META_DATA_PREFERENCE_TITLE = "com.android.settings.title"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the content provider providing the title text that should be displayed for the * preference. * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * content provider providing the title text that should be displayed for the preference. * * Title provided by the content provider overrides any static title. * <p>Title provided by the content provider overrides any static title. */ public static final String META_DATA_PREFERENCE_TITLE_URI = "com.android.settings.title_uri"; public static final String META_DATA_PREFERENCE_TITLE_URI = "com.android.settings.title_uri"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the summary text that should be displayed for the preference. * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * summary text that should be displayed for the preference. */ public static final String META_DATA_PREFERENCE_SUMMARY = "com.android.settings.summary"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the content provider providing the summary text that should be displayed for the * preference. * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * content provider providing the summary text that should be displayed for the preference. * * Summary provided by the content provider overrides any static summary. * <p>Summary provided by the content provider overrides any static summary. */ public static final String META_DATA_PREFERENCE_SUMMARY_URI = "com.android.settings.summary_uri"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the content provider providing the switch that should be displayed for the * preference. * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * content provider providing the switch that should be displayed for the preference. * * This works with {@link #META_DATA_PREFERENCE_KEYHINT} which should also be set in the * <p>This works with {@link #META_DATA_PREFERENCE_KEYHINT} which should also be set in the * AndroidManifest.xml */ public static final String META_DATA_PREFERENCE_SWITCH_URI = "com.android.settings.switch_uri"; public static final String META_DATA_PREFERENCE_SWITCH_URI = "com.android.settings.switch_uri"; /** * Name of the meta-data item that can be set from the content provider providing the intent Loading @@ -215,8 +205,8 @@ public class TileUtils { "com.android.settings.pending_intent"; /** * Value for {@link #META_DATA_KEY_PROFILE}. When the device has a managed profile, * the app will always be run in the primary profile. * Value for {@link #META_DATA_KEY_PROFILE}. When the device has a managed profile, the app will * always be run in the primary profile. * * @see #META_DATA_KEY_PROFILE */ Loading @@ -231,11 +221,11 @@ public class TileUtils { public static final String PROFILE_ALL = "all_profiles"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the profile in which the app should be run when the device has a managed profile. * The default value is {@link #PROFILE_ALL} which means the user will be presented with a * dialog to choose the profile. If set to {@link #PROFILE_PRIMARY} the app will always be * run in the primary profile. * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * profile in which the app should be run when the device has a managed profile. The default * value is {@link #PROFILE_ALL} which means the user will be presented with a dialog to choose * the profile. If set to {@link #PROFILE_PRIMARY} the app will always be run in the primary * profile. * * @see #PROFILE_PRIMARY * @see #PROFILE_ALL Loading @@ -243,20 +233,16 @@ public class TileUtils { public static final String META_DATA_KEY_PROFILE = "com.android.settings.profile"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify whether the {@link android.app.Activity} should be launched in a separate task. * This should be a boolean value {@code true} or {@code false}, set using {@code android:value} * Name of the meta-data item that should be set in the AndroidManifest.xml to specify whether * the {@link android.app.Activity} should be launched in a separate task. This should be a * boolean value {@code true} or {@code false}, set using {@code android:value} */ public static final String META_DATA_NEW_TASK = "com.android.settings.new_task"; /** * If the entry should be shown in settings search results. Defaults to true. */ /** If the entry should be shown in settings search results. Defaults to true. */ public static final String META_DATA_PREFERENCE_SEARCHABLE = "com.android.settings.searchable"; /** * Build a list of DashboardCategory. */ /** Build a list of DashboardCategory. */ public static List<DashboardCategory> getCategories(Context context, Map<Pair<String, String>, Tile> cache) { final long startTime = System.currentTimeMillis(); Loading Loading @@ -341,8 +327,8 @@ public class TileUtils { UserHandle user, Map<Pair<String, String>, Tile> addedCache, String defaultCategory, List<Tile> outTiles, Intent intent) { final PackageManager pm = context.getPackageManager(); final List<ResolveInfo> results = pm.queryIntentContentProvidersAsUser(intent, 0 /* flags */, user.getIdentifier()); final List<ResolveInfo> results = pm.queryIntentContentProvidersAsUser(intent, 0 /* flags */, user.getIdentifier()); for (ResolveInfo resolved : results) { if (!resolved.system) { // Do not allow any app to add to settings, only system ones. Loading Loading @@ -403,6 +389,8 @@ public class TileUtils { tile.setMetaData(metaData); } tile.setGroupKey(metaData.getString(META_DATA_PREFERENCE_GROUP_KEY)); if (!tile.userHandle.contains(user)) { tile.userHandle.add(user); } Loading Loading @@ -448,11 +436,11 @@ public class TileUtils { /** * Returns the complete uri from the meta data key of the tile. * * A complete uri should contain at least one path segment and be one of the following types: * content://authority/method * content://authority/method/key * <p>A complete uri should contain at least one path segment and be one of the following types: * <br>content://authority/method * <br>content://authority/method/key * * If the uri from the tile is not complete, build a uri by the default method and the * <p>If the uri from the tile is not complete, build a uri by the default method and the * preference key. * * @param tile Tile which contains meta data Loading Loading
packages/SettingsLib/Tile/src/com/android/settingslib/drawer/Tile.java +56 −99 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.settingslib.drawer; import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_ORDER; import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE; import static com.android.settingslib.drawer.TileUtils.META_DATA_NEW_TASK; import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_GROUP_KEY; import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON; import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT; import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SEARCHABLE; Loading Loading @@ -52,16 +51,12 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; /** * Description of a single dashboard tile that the user can select. */ /** Description of a single dashboard tile that the user can select. */ public abstract class Tile implements Parcelable { private static final String TAG = "Tile"; /** * Optional list of user handles which the intent should be launched on. */ /** Optional list of user handles which the intent should be launched on. */ public ArrayList<UserHandle> userHandle = new ArrayList<>(); public HashMap<UserHandle, PendingIntent> pendingIntentMap = new HashMap<>(); Loading @@ -76,6 +71,7 @@ public abstract class Tile implements Parcelable { private CharSequence mSummaryOverride; private Bundle mMetaData; private String mCategory; private String mGroupKey; public Tile(ComponentInfo info, String category, Bundle metaData) { mComponentInfo = info; Loading @@ -102,6 +98,7 @@ public abstract class Tile implements Parcelable { if (isNewTask()) { mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } mGroupKey = in.readString(); } @Override Loading @@ -121,16 +118,13 @@ public abstract class Tile implements Parcelable { } dest.writeString(mCategory); dest.writeBundle(mMetaData); dest.writeString(mGroupKey); } /** * Unique ID of the tile */ /** Unique ID of the tile */ public abstract int getId(); /** * Human-readable description of the tile */ /** Human-readable description of the tile */ public abstract String getDescription(); protected abstract ComponentInfo getComponentInfo(Context context); Loading @@ -147,16 +141,12 @@ public abstract class Tile implements Parcelable { return mComponentName; } /** * Intent to launch when the preference is selected. */ /** Intent to launch when the preference is selected. */ public Intent getIntent() { return mIntent; } /** * Category in which the tile should be placed. */ /** Category in which the tile should be placed. */ public String getCategory() { return mCategory; } Loading @@ -165,9 +155,7 @@ public abstract class Tile implements Parcelable { mCategory = newCategoryKey; } /** * Priority of this tile, used for display ordering. */ /** Priority of this tile, used for display ordering. */ public int getOrder() { if (hasOrder()) { return mMetaData.getInt(META_DATA_KEY_ORDER); Loading @@ -176,32 +164,24 @@ public abstract class Tile implements Parcelable { } } /** * Check whether tile has order. */ /** Check whether tile has order. */ public boolean hasOrder() { return mMetaData != null && mMetaData.containsKey(META_DATA_KEY_ORDER) && mMetaData.get(META_DATA_KEY_ORDER) instanceof Integer; } /** * Check whether tile has a switch. */ /** Check whether tile has a switch. */ public boolean hasSwitch() { return mMetaData != null && mMetaData.containsKey(META_DATA_PREFERENCE_SWITCH_URI); } /** * Check whether tile has a pending intent. */ /** Check whether tile has a pending intent. */ public boolean hasPendingIntent() { return !pendingIntentMap.isEmpty(); } /** * Title of the tile that is shown to the user. */ /** Title of the tile that is shown to the user. */ public CharSequence getTitle(Context context) { CharSequence title = null; ensureMetadataNotStale(context); Loading Loading @@ -238,9 +218,7 @@ public abstract class Tile implements Parcelable { mSummaryOverride = summaryOverride; } /** * Optional summary describing what this tile controls. */ /** Optional summary describing what this tile controls. */ public CharSequence getSummary(Context context) { if (mSummaryOverride != null) { return mSummaryOverride; Loading Loading @@ -275,16 +253,12 @@ public abstract class Tile implements Parcelable { mMetaData = metaData; } /** * The metaData from the activity that defines this tile. */ /** The metaData from the activity that defines this tile. */ public Bundle getMetaData() { return mMetaData; } /** * Optional key to use for this tile. */ /** Optional key to use for this tile. */ public String getKey(Context context) { ensureMetadataNotStale(context); if (!hasKey()) { Loading @@ -297,9 +271,7 @@ public abstract class Tile implements Parcelable { } } /** * Check whether title has key. */ /** Check whether title has key. */ public boolean hasKey() { return mMetaData != null && mMetaData.containsKey(META_DATA_PREFERENCE_KEYHINT); } Loading @@ -325,8 +297,9 @@ public abstract class Tile implements Parcelable { if (iconResId != 0 && iconResId != android.R.color.transparent) { final Icon icon = Icon.createWithResource(componentInfo.packageName, iconResId); if (isIconTintable(context)) { final TypedArray a = context.obtainStyledAttributes(new int[]{ android.R.attr.colorControlNormal}); final TypedArray a = context.obtainStyledAttributes( new int[] {android.R.attr.colorControlNormal}); final int tintColor = a.getColor(0, 0); a.recycle(); icon.setTint(tintColor); Loading @@ -349,26 +322,22 @@ public abstract class Tile implements Parcelable { return false; } /** * Whether the {@link Activity} should be launched in a separate task. */ /** Whether the {@link Activity} should be launched in a separate task. */ public boolean isNewTask() { if (mMetaData != null && mMetaData.containsKey(META_DATA_NEW_TASK)) { if (mMetaData != null && mMetaData.containsKey(META_DATA_NEW_TASK)) { return mMetaData.getBoolean(META_DATA_NEW_TASK); } return false; } /** * Ensures metadata is not stale for this tile. */ /** Ensures metadata is not stale for this tile. */ private void ensureMetadataNotStale(Context context) { final PackageManager pm = context.getApplicationContext().getPackageManager(); try { final long lastUpdateTime = pm.getPackageInfo(mComponentPackage, PackageManager.GET_META_DATA).lastUpdateTime; final long lastUpdateTime = pm.getPackageInfo(mComponentPackage, PackageManager.GET_META_DATA) .lastUpdateTime; if (lastUpdateTime == mLastUpdateTime) { // All good. Do nothing return; Loading @@ -382,7 +351,8 @@ public abstract class Tile implements Parcelable { } } public static final Creator<Tile> CREATOR = new Creator<Tile>() { public static final Creator<Tile> CREATOR = new Creator<Tile>() { public Tile createFromParcel(Parcel source) { final boolean isProviderTile = source.readBoolean(); // reset the Parcel pointer before delegating to the real constructor. Loading @@ -395,59 +365,46 @@ public abstract class Tile implements Parcelable { } }; /** * Check whether tile only has primary profile. */ /** Check whether tile only has primary profile. */ public boolean isPrimaryProfileOnly() { return isPrimaryProfileOnly(mMetaData); } static boolean isPrimaryProfileOnly(Bundle metaData) { String profile = metaData != null ? metaData.getString(META_DATA_KEY_PROFILE) : PROFILE_ALL; String profile = metaData != null ? metaData.getString(META_DATA_KEY_PROFILE) : PROFILE_ALL; profile = (profile != null ? profile : PROFILE_ALL); return TextUtils.equals(profile, PROFILE_PRIMARY); } /** * Returns whether the tile belongs to another group / category. */ /** Returns whether the tile belongs to another group / category. */ public boolean hasGroupKey() { return mMetaData != null && !TextUtils.isEmpty(mMetaData.getString(META_DATA_PREFERENCE_GROUP_KEY)); return !TextUtils.isEmpty(mGroupKey); } /** * Returns the group / category key this tile belongs to. */ /** Set the group / PreferenceCategory key this tile belongs to. */ public void setGroupKey(String groupKey) { mGroupKey = groupKey; } /** Returns the group / category key this tile belongs to. */ public String getGroupKey() { return (mMetaData == null) ? null : mMetaData.getString(META_DATA_PREFERENCE_GROUP_KEY); return mGroupKey; } /** * Returns if this is searchable. */ /** Returns if this is searchable. */ public boolean isSearchable() { return mMetaData == null || mMetaData.getBoolean(META_DATA_PREFERENCE_SEARCHABLE, true); } /** * The type of the tile. */ /** The type of the tile. */ public enum Type { /** * A preference that can be tapped on to open a new page. */ /** A preference that can be tapped on to open a new page. */ ACTION, /** * A preference that can be tapped on to open an external app. */ /** A preference that can be tapped on to open an external app. */ EXTERNAL_ACTION, /** * A preference that shows an on / off switch that can be toggled by the user. */ /** A preference that shows an on / off switch that can be toggled by the user. */ SWITCH, /** Loading @@ -460,7 +417,7 @@ public abstract class Tile implements Parcelable { * A preference category with a title that can be used to group multiple preferences * together. */ GROUP; GROUP } /** Loading
packages/SettingsLib/Tile/src/com/android/settingslib/drawer/TileUtils.java +55 −67 Original line number Diff line number Diff line Loading @@ -77,9 +77,7 @@ public class TileUtils { */ public static final String IA_SETTINGS_ACTION = "com.android.settings.action.IA_SETTINGS"; /** * Same as #EXTRA_SETTINGS_ACTION but used for the platform Settings activities. */ /** Same as #EXTRA_SETTINGS_ACTION but used for the platform Settings activities. */ private static final String SETTINGS_ACTION = "com.android.settings.action.SETTINGS"; private static final String OPERATOR_SETTINGS = Loading @@ -101,9 +99,7 @@ public class TileUtils { */ static final String EXTRA_CATEGORY_KEY = "com.android.settings.category"; /** * The key used to get the package name of the icon resource for the preference. */ /** The key used to get the package name of the icon resource for the preference. */ static final String EXTRA_PREFERENCE_ICON_PACKAGE = "com.android.settings.icon_package"; /** Loading Loading @@ -145,18 +141,17 @@ public class TileUtils { "com.android.settings.bg.argb"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the content provider providing the icon that should be displayed for * the preference. * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * content provider providing the icon that should be displayed for the preference. * * Icon provided by the content provider overrides any static icon. * <p>Icon provided by the content provider overrides any static icon. */ public static final String META_DATA_PREFERENCE_ICON_URI = "com.android.settings.icon_uri"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify whether the icon is tintable. This should be a boolean value {@code true} or * {@code false}, set using {@code android:value} * Name of the meta-data item that should be set in the AndroidManifest.xml to specify whether * the icon is tintable. This should be a boolean value {@code true} or {@code false}, set using * {@code android:value} */ public static final String META_DATA_PREFERENCE_ICON_TINTABLE = "com.android.settings.icon_tintable"; Loading @@ -171,41 +166,36 @@ public class TileUtils { public static final String META_DATA_PREFERENCE_TITLE = "com.android.settings.title"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the content provider providing the title text that should be displayed for the * preference. * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * content provider providing the title text that should be displayed for the preference. * * Title provided by the content provider overrides any static title. * <p>Title provided by the content provider overrides any static title. */ public static final String META_DATA_PREFERENCE_TITLE_URI = "com.android.settings.title_uri"; public static final String META_DATA_PREFERENCE_TITLE_URI = "com.android.settings.title_uri"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the summary text that should be displayed for the preference. * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * summary text that should be displayed for the preference. */ public static final String META_DATA_PREFERENCE_SUMMARY = "com.android.settings.summary"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the content provider providing the summary text that should be displayed for the * preference. * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * content provider providing the summary text that should be displayed for the preference. * * Summary provided by the content provider overrides any static summary. * <p>Summary provided by the content provider overrides any static summary. */ public static final String META_DATA_PREFERENCE_SUMMARY_URI = "com.android.settings.summary_uri"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the content provider providing the switch that should be displayed for the * preference. * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * content provider providing the switch that should be displayed for the preference. * * This works with {@link #META_DATA_PREFERENCE_KEYHINT} which should also be set in the * <p>This works with {@link #META_DATA_PREFERENCE_KEYHINT} which should also be set in the * AndroidManifest.xml */ public static final String META_DATA_PREFERENCE_SWITCH_URI = "com.android.settings.switch_uri"; public static final String META_DATA_PREFERENCE_SWITCH_URI = "com.android.settings.switch_uri"; /** * Name of the meta-data item that can be set from the content provider providing the intent Loading @@ -215,8 +205,8 @@ public class TileUtils { "com.android.settings.pending_intent"; /** * Value for {@link #META_DATA_KEY_PROFILE}. When the device has a managed profile, * the app will always be run in the primary profile. * Value for {@link #META_DATA_KEY_PROFILE}. When the device has a managed profile, the app will * always be run in the primary profile. * * @see #META_DATA_KEY_PROFILE */ Loading @@ -231,11 +221,11 @@ public class TileUtils { public static final String PROFILE_ALL = "all_profiles"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the profile in which the app should be run when the device has a managed profile. * The default value is {@link #PROFILE_ALL} which means the user will be presented with a * dialog to choose the profile. If set to {@link #PROFILE_PRIMARY} the app will always be * run in the primary profile. * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * profile in which the app should be run when the device has a managed profile. The default * value is {@link #PROFILE_ALL} which means the user will be presented with a dialog to choose * the profile. If set to {@link #PROFILE_PRIMARY} the app will always be run in the primary * profile. * * @see #PROFILE_PRIMARY * @see #PROFILE_ALL Loading @@ -243,20 +233,16 @@ public class TileUtils { public static final String META_DATA_KEY_PROFILE = "com.android.settings.profile"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify whether the {@link android.app.Activity} should be launched in a separate task. * This should be a boolean value {@code true} or {@code false}, set using {@code android:value} * Name of the meta-data item that should be set in the AndroidManifest.xml to specify whether * the {@link android.app.Activity} should be launched in a separate task. This should be a * boolean value {@code true} or {@code false}, set using {@code android:value} */ public static final String META_DATA_NEW_TASK = "com.android.settings.new_task"; /** * If the entry should be shown in settings search results. Defaults to true. */ /** If the entry should be shown in settings search results. Defaults to true. */ public static final String META_DATA_PREFERENCE_SEARCHABLE = "com.android.settings.searchable"; /** * Build a list of DashboardCategory. */ /** Build a list of DashboardCategory. */ public static List<DashboardCategory> getCategories(Context context, Map<Pair<String, String>, Tile> cache) { final long startTime = System.currentTimeMillis(); Loading Loading @@ -341,8 +327,8 @@ public class TileUtils { UserHandle user, Map<Pair<String, String>, Tile> addedCache, String defaultCategory, List<Tile> outTiles, Intent intent) { final PackageManager pm = context.getPackageManager(); final List<ResolveInfo> results = pm.queryIntentContentProvidersAsUser(intent, 0 /* flags */, user.getIdentifier()); final List<ResolveInfo> results = pm.queryIntentContentProvidersAsUser(intent, 0 /* flags */, user.getIdentifier()); for (ResolveInfo resolved : results) { if (!resolved.system) { // Do not allow any app to add to settings, only system ones. Loading Loading @@ -403,6 +389,8 @@ public class TileUtils { tile.setMetaData(metaData); } tile.setGroupKey(metaData.getString(META_DATA_PREFERENCE_GROUP_KEY)); if (!tile.userHandle.contains(user)) { tile.userHandle.add(user); } Loading Loading @@ -448,11 +436,11 @@ public class TileUtils { /** * Returns the complete uri from the meta data key of the tile. * * A complete uri should contain at least one path segment and be one of the following types: * content://authority/method * content://authority/method/key * <p>A complete uri should contain at least one path segment and be one of the following types: * <br>content://authority/method * <br>content://authority/method/key * * If the uri from the tile is not complete, build a uri by the default method and the * <p>If the uri from the tile is not complete, build a uri by the default method and the * preference key. * * @param tile Tile which contains meta data Loading