Update Settings to use themed Context.getDrawable()

Explicit null theme is passed when using Resources.getDrawable() and
no theme is available, e.g. when using getResourcesForApplication().
This fixes an issue with ic_text_dot theming and helps avoid similar
issues in the future.

BUG: 17648301
Change-Id: I3e97c3490b6f2a55744f567b21284f2935ae9af7
This commit is contained in:
Alan Viverette
2014-10-10 10:58:58 -07:00
parent 9062532960
commit 0ba89bd54c
16 changed files with 19 additions and 18 deletions

View File

@@ -159,7 +159,7 @@ public class ActivityPicker extends AlertActivity implements
Resources res = packageManager.getResourcesForApplication( Resources res = packageManager.getResourcesForApplication(
iconResource.packageName); iconResource.packageName);
icon = res.getDrawable(res.getIdentifier( icon = res.getDrawable(res.getIdentifier(
iconResource.resourceName, null, null)); iconResource.resourceName, null, null), null);
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
// Ignore // Ignore
} }

View File

@@ -212,7 +212,7 @@ public class MasterClear extends Fragment {
try { try {
if (desc.iconId != 0) { if (desc.iconId != 0) {
Context authContext = context.createPackageContext(desc.packageName, 0); Context authContext = context.createPackageContext(desc.packageName, 0);
icon = authContext.getResources().getDrawable(desc.iconId); icon = authContext.getDrawable(desc.iconId);
} }
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "No icon for account type " + desc.type); Log.w(TAG, "No icon for account type " + desc.type);

View File

@@ -63,7 +63,7 @@ public class RegulatoryInfoDisplayActivity extends Activity implements
int resId = getResourceId(); int resId = getResourceId();
if (resId != 0) { if (resId != 0) {
try { try {
Drawable d = resources.getDrawable(resId); Drawable d = getDrawable(resId);
// set to false if the width or height is <= 2 // set to false if the width or height is <= 2
// (missing PNG can return an empty 2x2 pixel Drawable) // (missing PNG can return an empty 2x2 pixel Drawable)
regulatoryInfoDrawableExists = (d.getIntrinsicWidth() > 2 regulatoryInfoDrawableExists = (d.getIntrinsicWidth() > 2

View File

@@ -51,7 +51,7 @@ public class UserSpinnerAdapter implements SpinnerAdapter {
UserInfo userInfo = um.getUserInfo(mUserHandle.getIdentifier()); UserInfo userInfo = um.getUserInfo(mUserHandle.getIdentifier());
if (userInfo.isManagedProfile()) { if (userInfo.isManagedProfile()) {
name = context.getString(R.string.managed_user_title); name = context.getString(R.string.managed_user_title);
icon = Resources.getSystem().getDrawable( icon = context.getDrawable(
com.android.internal.R.drawable.ic_corp_icon); com.android.internal.R.drawable.ic_corp_icon);
} else { } else {
name = userInfo.name; name = userInfo.name;

View File

@@ -211,7 +211,8 @@ public final class Utils {
Bundle metaData = resolveInfo.activityInfo.metaData; Bundle metaData = resolveInfo.activityInfo.metaData;
if (res != null && metaData != null) { if (res != null && metaData != null) {
icon = res.getDrawable(metaData.getInt(META_DATA_PREFERENCE_ICON)); icon = res.getDrawable(
metaData.getInt(META_DATA_PREFERENCE_ICON), null);
title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE)); title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE));
summary = res.getString(metaData.getInt(META_DATA_PREFERENCE_SUMMARY)); summary = res.getString(metaData.getInt(META_DATA_PREFERENCE_SUMMARY));
} }

View File

@@ -231,7 +231,7 @@ public class ToggleAccessibilityServicePreferenceFragment
ImageView imageView = (ImageView) capabilityView.findViewById( ImageView imageView = (ImageView) capabilityView.findViewById(
com.android.internal.R.id.perm_icon); com.android.internal.R.id.perm_icon);
imageView.setImageDrawable(getResources().getDrawable( imageView.setImageDrawable(getActivity().getDrawable(
com.android.internal.R.drawable.ic_text_dot)); com.android.internal.R.drawable.ic_text_dot));
TextView labelView = (TextView) capabilityView.findViewById( TextView labelView = (TextView) capabilityView.findViewById(
@@ -257,7 +257,7 @@ public class ToggleAccessibilityServicePreferenceFragment
imageView = (ImageView) capabilityView.findViewById( imageView = (ImageView) capabilityView.findViewById(
com.android.internal.R.id.perm_icon); com.android.internal.R.id.perm_icon);
imageView.setImageDrawable(getResources().getDrawable( imageView.setImageDrawable(getActivity().getDrawable(
com.android.internal.R.drawable.ic_text_dot)); com.android.internal.R.drawable.ic_text_dot));
labelView = (TextView) capabilityView.findViewById( labelView = (TextView) capabilityView.findViewById(

View File

@@ -111,7 +111,7 @@ final public class AuthenticatorHelper extends BroadcastReceiver {
Context authContext = context.createPackageContextAsUser(desc.packageName, 0, Context authContext = context.createPackageContextAsUser(desc.packageName, 0,
mUserHandle); mUserHandle);
icon = mContext.getPackageManager().getUserBadgedIcon( icon = mContext.getPackageManager().getUserBadgedIcon(
authContext.getResources().getDrawable(desc.iconId), mUserHandle); authContext.getDrawable(desc.iconId), mUserHandle);
synchronized (mAccTypeIconCache) { synchronized (mAccTypeIconCache) {
mAccTypeIconCache.put(accountType, icon); mAccTypeIconCache.put(accountType, icon);
} }

View File

@@ -216,7 +216,7 @@ public class ChooseAccountActivity extends PreferenceActivity {
AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType); AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType);
Context authContext = createPackageContextAsUser(desc.packageName, 0, mUserHandle); Context authContext = createPackageContextAsUser(desc.packageName, 0, mUserHandle);
icon = getPackageManager().getUserBadgedIcon( icon = getPackageManager().getUserBadgedIcon(
authContext.getResources().getDrawable(desc.iconId), mUserHandle); authContext.getDrawable(desc.iconId), mUserHandle);
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
// TODO: place holder icon for missing account icons? // TODO: place holder icon for missing account icons?
Log.w(TAG, "No icon name for account type " + accountType); Log.w(TAG, "No icon name for account type " + accountType);

View File

@@ -269,7 +269,7 @@ public class AppOpsState {
return mIcon; return mIcon;
} }
return mState.mContext.getResources().getDrawable( return mState.mContext.getDrawable(
android.R.drawable.sym_def_app_icon); android.R.drawable.sym_def_app_icon);
} }

View File

@@ -144,7 +144,7 @@ public class ApplicationsState {
return true; return true;
} else { } else {
this.mounted = false; this.mounted = false;
this.icon = context.getResources().getDrawable( this.icon = context.getDrawable(
com.android.internal.R.drawable.sym_app_on_sd_unavailable_icon); com.android.internal.R.drawable.sym_app_on_sd_unavailable_icon);
} }
} else if (!this.mounted) { } else if (!this.mounted) {

View File

@@ -679,7 +679,7 @@ public class RunningState {
return constState.newDrawable(); return constState.newDrawable();
} }
} }
return context.getResources().getDrawable( return context.getDrawable(
com.android.internal.R.drawable.ic_menu_cc); com.android.internal.R.drawable.ic_menu_cc);
} }
} }

View File

@@ -194,7 +194,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
int iconResource = profile.getDrawableResource(mCachedDevice.getBtClass()); int iconResource = profile.getDrawableResource(mCachedDevice.getBtClass());
if (iconResource != 0) { if (iconResource != 0) {
pref.setIcon(getResources().getDrawable(iconResource)); pref.setIcon(getActivity().getDrawable(iconResource));
} }
refreshProfilePreference(pref, profile); refreshProfilePreference(pref, profile);

View File

@@ -189,7 +189,7 @@ public class BatteryEntry {
break; break;
} }
if (iconId > 0) { if (iconId > 0) {
icon = context.getResources().getDrawable(iconId); icon = context.getDrawable(iconId);
} }
if ((name == null || iconId == 0) && this.sipper.uidObj != null) { if ((name == null || iconId == 0) && this.sipper.uidObj != null) {
getQuickNameIconForUid(this.sipper.uidObj); getQuickNameIconForUid(this.sipper.uidObj);
@@ -228,7 +228,7 @@ public class BatteryEntry {
name = context.getResources().getString(R.string.process_mediaserver_label); name = context.getResources().getString(R.string.process_mediaserver_label);
} }
iconId = R.drawable.ic_power_system; iconId = R.drawable.ic_power_system;
icon = context.getResources().getDrawable(iconId); icon = context.getDrawable(iconId);
return; return;
} else { } else {
//name = packages[0]; //name = packages[0];

View File

@@ -379,7 +379,7 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener
// Use default icon // Use default icon
} }
} else if (iconId != 0) { } else if (iconId != 0) {
mAppIcon = getActivity().getResources().getDrawable(iconId); mAppIcon = getActivity().getDrawable(iconId);
} }
if (mAppIcon == null) { if (mAppIcon == null) {
mAppIcon = getActivity().getPackageManager().getDefaultActivityIcon(); mAppIcon = getActivity().getPackageManager().getDefaultActivityIcon();

View File

@@ -138,7 +138,7 @@ public class UidDetailProvider {
if (info != null) { if (info != null) {
if (info.isManagedProfile()) { if (info.isManagedProfile()) {
detail.label = res.getString(R.string.managed_user_title); detail.label = res.getString(R.string.managed_user_title);
detail.icon = Resources.getSystem().getDrawable( detail.icon = mContext.getDrawable(
com.android.internal.R.drawable.ic_corp_icon); com.android.internal.R.drawable.ic_corp_icon);
} else { } else {
detail.label = res.getString(R.string.running_process_item_user_label, detail.label = res.getString(R.string.running_process_item_user_label,

View File

@@ -275,7 +275,7 @@ public class NotificationStation extends SettingsPreferenceFragment {
} }
try { try {
return r.getDrawable(resId); return r.getDrawable(resId, null);
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.w(TAG, "Icon not found in " Log.w(TAG, "Icon not found in "
+ (pkg != null ? resId : "<system>") + (pkg != null ? resId : "<system>")