Misc change to support loading dynamic summary/icon in app
- Add ThreadUtils.postOnBackground helper method - Don't fallback to app.icon if tile's metadata contains icon uri - Deprecate TITLE_RES_ID in favor of TITLE metadata Bug: 63758074 Test: robotests Change-Id: Ie60fb4677cdb12c3ff313ffdfdb4a4f4960fac0f
This commit is contained in:
@@ -148,13 +148,6 @@ public class TileUtils {
|
||||
*/
|
||||
public static final String META_DATA_PREFERENCE_TITLE = "com.android.settings.title";
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #META_DATA_PREFERENCE_TITLE} with {@code android:resource}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String META_DATA_PREFERENCE_TITLE_RES_ID =
|
||||
"com.android.settings.title.resid";
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -176,7 +169,7 @@ public class TileUtils {
|
||||
* custom view which should be displayed for the preference. The custom view will be inflated
|
||||
* as a remote view.
|
||||
*
|
||||
* This also can be used with {@link META_DATA_PREFERENCE_SUMMARY_URI} above, by setting the id
|
||||
* This also can be used with {@link #META_DATA_PREFERENCE_SUMMARY_URI}, by setting the id
|
||||
* of the summary TextView to '@android:id/summary'.
|
||||
*/
|
||||
public static final String META_DATA_PREFERENCE_CUSTOM_VIEW =
|
||||
@@ -411,14 +404,7 @@ public class TileUtils {
|
||||
metaData.getBoolean(META_DATA_PREFERENCE_ICON_TINTABLE);
|
||||
}
|
||||
}
|
||||
int resId = 0;
|
||||
if (metaData.containsKey(META_DATA_PREFERENCE_TITLE_RES_ID)) {
|
||||
resId = metaData.getInt(META_DATA_PREFERENCE_TITLE_RES_ID);
|
||||
if (resId != 0) {
|
||||
title = res.getString(resId);
|
||||
}
|
||||
}
|
||||
if ((resId == 0) && metaData.containsKey(META_DATA_PREFERENCE_TITLE)) {
|
||||
if (metaData.containsKey(META_DATA_PREFERENCE_TITLE)) {
|
||||
if (metaData.get(META_DATA_PREFERENCE_TITLE) instanceof Integer) {
|
||||
title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE));
|
||||
} else {
|
||||
@@ -464,12 +450,14 @@ public class TileUtils {
|
||||
}
|
||||
|
||||
// Set the icon
|
||||
if (iconFromUri != null) {
|
||||
tile.icon = Icon.createWithResource(iconFromUri.first, iconFromUri.second);
|
||||
} else {
|
||||
if (icon == 0) {
|
||||
if (icon == 0) {
|
||||
// Only fallback to activityinfo.icon if metadata does not contain ICON_URI.
|
||||
// ICON_URI should be loaded in app UI when need the icon object.
|
||||
if (!tile.metaData.containsKey(META_DATA_PREFERENCE_ICON_URI)) {
|
||||
icon = activityInfo.icon;
|
||||
}
|
||||
}
|
||||
if (icon != 0) {
|
||||
tile.icon = Icon.createWithResource(activityInfo.packageName, icon);
|
||||
}
|
||||
|
||||
@@ -492,7 +480,7 @@ public class TileUtils {
|
||||
|
||||
/**
|
||||
* Gets the icon package name and resource id from content provider.
|
||||
* @param Context context
|
||||
* @param context context
|
||||
* @param packageName package name of the target activity
|
||||
* @param uriString URI for the content provider
|
||||
* @param providerMap Maps URI authorities to providers
|
||||
@@ -522,7 +510,7 @@ public class TileUtils {
|
||||
|
||||
/**
|
||||
* Gets text associated with the input key from the content provider.
|
||||
* @param Context context
|
||||
* @param context context
|
||||
* @param uriString URI for the content provider
|
||||
* @param providerMap Maps URI authorities to providers
|
||||
* @param key Key mapping to the text in bundle returned by the content provider
|
||||
|
||||
@@ -18,10 +18,14 @@ package com.android.settingslib.utils;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class ThreadUtils {
|
||||
|
||||
private static volatile Thread sMainThread;
|
||||
private static volatile Handler sMainThreadHandler;
|
||||
private static volatile ExecutorService sSingleThreadExecutor;
|
||||
|
||||
/**
|
||||
* Returns true if the current thread is the UI thread.
|
||||
@@ -53,6 +57,16 @@ public class ThreadUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts runnable in background using shared background thread pool.
|
||||
*/
|
||||
public static void postOnBackgroundThread(Runnable runnable) {
|
||||
if (sSingleThreadExecutor == null) {
|
||||
sSingleThreadExecutor = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
sSingleThreadExecutor.execute(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts the runnable on the main thread.
|
||||
*/
|
||||
|
||||
@@ -535,14 +535,10 @@ public class TileUtilsTest {
|
||||
info.activityInfo.metaData.putString("com.android.settings.summary_uri", summaryUri);
|
||||
}
|
||||
if (titleResId != 0) {
|
||||
info.activityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_TITLE, title);
|
||||
info.activityInfo.metaData.putInt(TileUtils.META_DATA_PREFERENCE_TITLE, titleResId);
|
||||
} else if (title != null) {
|
||||
info.activityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_TITLE, title);
|
||||
}
|
||||
if (titleResId != 0) {
|
||||
info.activityInfo.metaData.putInt(
|
||||
TileUtils.META_DATA_PREFERENCE_TITLE_RES_ID, titleResId);
|
||||
}
|
||||
info.activityInfo.applicationInfo = new ApplicationInfo();
|
||||
if (systemApp) {
|
||||
info.activityInfo.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM;
|
||||
|
||||
Reference in New Issue
Block a user