diff options
author | Alan Viverette <alanv@google.com> | 2014-02-03 18:40:20 -0800 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2014-02-03 18:42:24 -0800 |
commit | 8eea3ea5591e59f55cbb4f6b2b7e9363a285ced3 (patch) | |
tree | a067807fe9c905fda3568db98cb654a520e694f8 /core | |
parent | 8cff1a370e8d89c0a977b82cd8730ab791866808 (diff) | |
download | frameworks_base-8eea3ea5591e59f55cbb4f6b2b7e9363a285ced3.zip frameworks_base-8eea3ea5591e59f55cbb4f6b2b7e9363a285ced3.tar.gz frameworks_base-8eea3ea5591e59f55cbb4f6b2b7e9363a285ced3.tar.bz2 |
Add APIs for obtaining themed Drawable from Theme, Context
BUG: 12611005
Change-Id: Ic0057be4e4c2d0c61ce02a019b3f7d0625e3a016
Diffstat (limited to 'core')
40 files changed, 178 insertions, 107 deletions
diff --git a/core/java/android/accounts/ChooseAccountActivity.java b/core/java/android/accounts/ChooseAccountActivity.java index bfbae24..242b3ea 100644 --- a/core/java/android/accounts/ChooseAccountActivity.java +++ b/core/java/android/accounts/ChooseAccountActivity.java @@ -100,7 +100,7 @@ public class ChooseAccountActivity extends Activity { try { AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType); Context authContext = createPackageContext(desc.packageName, 0); - icon = authContext.getResources().getDrawable(desc.iconId); + icon = authContext.getDrawable(desc.iconId); } catch (PackageManager.NameNotFoundException e) { // Nothing we can do much here, just log if (Log.isLoggable(TAG, Log.WARN)) { diff --git a/core/java/android/accounts/ChooseAccountTypeActivity.java b/core/java/android/accounts/ChooseAccountTypeActivity.java index acc8549..a3222d8 100644 --- a/core/java/android/accounts/ChooseAccountTypeActivity.java +++ b/core/java/android/accounts/ChooseAccountTypeActivity.java @@ -129,7 +129,7 @@ public class ChooseAccountTypeActivity extends Activity { Drawable icon = null; try { Context authContext = createPackageContext(desc.packageName, 0); - icon = authContext.getResources().getDrawable(desc.iconId); + icon = authContext.getDrawable(desc.iconId); final CharSequence sequence = authContext.getResources().getText(desc.labelId); if (sequence != null) { name = sequence.toString(); diff --git a/core/java/android/app/SearchDialog.java b/core/java/android/app/SearchDialog.java index d04e9db..af1810b 100644 --- a/core/java/android/app/SearchDialog.java +++ b/core/java/android/app/SearchDialog.java @@ -188,8 +188,7 @@ public class SearchDialog extends Dialog { mSearchView.findViewById(com.android.internal.R.id.search_src_text); mAppIcon = (ImageView) findViewById(com.android.internal.R.id.search_app_icon); mSearchPlate = mSearchView.findViewById(com.android.internal.R.id.search_plate); - mWorkingSpinner = getContext().getResources(). - getDrawable(com.android.internal.R.drawable.search_spinner); + mWorkingSpinner = getContext().getDrawable(com.android.internal.R.drawable.search_spinner); // TODO: Restore the spinner for slow suggestion lookups // mSearchAutoComplete.setCompoundDrawablesWithIntrinsicBounds( // null, null, mWorkingSpinner, null); @@ -458,7 +457,7 @@ public class SearchDialog extends Dialog { // optionally show one or the other. if (mSearchable.useBadgeIcon()) { - icon = mActivityContext.getResources().getDrawable(mSearchable.getIconId()); + icon = mActivityContext.getDrawable(mSearchable.getIconId()); visibility = View.VISIBLE; if (DBG) Log.d(LOG_TAG, "Using badge icon: " + mSearchable.getIconId()); } else if (mSearchable.useBadgeLabel()) { diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index ac08d9b..9f90de0 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -376,6 +376,19 @@ public abstract class Context { return getResources().getString(resId, formatArgs); } + /** + * Return a drawable object associated with a particular resource ID and + * styled for the current theme. + * + * @param id The desired resource identifier, as generated by the aapt + * tool. This integer encodes the package, type, and resource + * entry. The value 0 is an invalid identifier. + * @return Drawable An object that can be used to draw this resource. + */ + public final Drawable getDrawable(int id) { + return getResources().getDrawable(id, getTheme()); + } + /** * Set the base theme for this context. Note that this should be called * before any views are instantiated in the Context (for example before diff --git a/core/java/android/content/SyncActivityTooManyDeletes.java b/core/java/android/content/SyncActivityTooManyDeletes.java index 350f35e..093fb08 100644 --- a/core/java/android/content/SyncActivityTooManyDeletes.java +++ b/core/java/android/content/SyncActivityTooManyDeletes.java @@ -95,7 +95,7 @@ public class SyncActivityTooManyDeletes extends Activity // try { // final Context authContext = createPackageContext(desc.packageName, 0); // ImageView imageView = new ImageView(this); -// imageView.setImageDrawable(authContext.getResources().getDrawable(desc.iconId)); +// imageView.setImageDrawable(authContext.getDrawable(desc.iconId)); // ll.addView(imageView, lp); // } catch (PackageManager.NameNotFoundException e) { // } diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index 185bfd8..aa96f0e 100644 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -686,12 +686,27 @@ public class Resources { * @param id The desired resource identifier, as generated by the aapt * tool. This integer encodes the package, type, and resource * entry. The value 0 is an invalid identifier. - * - * @throws NotFoundException Throws NotFoundException if the given ID does not exist. - * * @return Drawable An object that can be used to draw this resource. + * @throws NotFoundException Throws NotFoundException if the given ID does + * not exist. */ public Drawable getDrawable(int id) throws NotFoundException { + return getDrawable(id, null); + } + + /** + * Return a drawable object associated with a particular resource ID and + * styled for the specified theme. + * + * @param id The desired resource identifier, as generated by the aapt + * tool. This integer encodes the package, type, and resource + * entry. The value 0 is an invalid identifier. + * @param theme The theme used to style the drawable attributes. + * @return Drawable An object that can be used to draw this resource. + * @throws NotFoundException Throws NotFoundException if the given ID does + * not exist. + */ + public Drawable getDrawable(int id, Theme theme) throws NotFoundException { TypedValue value; synchronized (mAccessLock) { value = mTmpValue; @@ -702,7 +717,7 @@ public class Resources { } getValue(id, value, true); } - Drawable res = loadDrawable(value, id); + final Drawable res = loadDrawable(value, id, theme); synchronized (mAccessLock) { if (mTmpValue == null) { mTmpValue = value; @@ -720,17 +735,36 @@ public class Resources { * depending on the underlying resource -- for example, a solid color, PNG * image, scalable image, etc. The Drawable API hides these implementation * details. - * + * * @param id The desired resource identifier, as generated by the aapt tool. * This integer encodes the package, type, and resource entry. * The value 0 is an invalid identifier. * @param density the desired screen density indicated by the resource as * found in {@link DisplayMetrics}. + * @return Drawable An object that can be used to draw this resource. * @throws NotFoundException Throws NotFoundException if the given ID does * not exist. - * @return Drawable An object that can be used to draw this resource. + * @see #getDrawableForDensity(int, int, Theme) */ public Drawable getDrawableForDensity(int id, int density) throws NotFoundException { + return getDrawableForDensity(id, density, null); + } + + /** + * Return a drawable object associated with a particular resource ID for the + * given screen density in DPI and styled for the specified theme. + * + * @param id The desired resource identifier, as generated by the aapt tool. + * This integer encodes the package, type, and resource entry. + * The value 0 is an invalid identifier. + * @param density The desired screen density indicated by the resource as + * found in {@link DisplayMetrics}. + * @param theme The theme used to style the drawable attributes. + * @return Drawable An object that can be used to draw this resource. + * @throws NotFoundException Throws NotFoundException if the given ID does + * not exist. + */ + public Drawable getDrawableForDensity(int id, int density, Theme theme) { TypedValue value; synchronized (mAccessLock) { value = mTmpValue; @@ -757,7 +791,7 @@ public class Resources { } } - Drawable res = loadDrawable(value, id); + final Drawable res = loadDrawable(value, id, theme); synchronized (mAccessLock) { if (mTmpValue == null) { mTmpValue = value; @@ -1251,8 +1285,9 @@ public class Resources { * @see #obtainStyledAttributes(AttributeSet, int[], int, int) */ public TypedArray obtainStyledAttributes(int[] attrs) { - int len = attrs.length; - TypedArray array = getCachedStyledAttributes(len); + final int len = attrs.length; + final TypedArray array = getCachedStyledAttributes(len); + array.mTheme = this; array.mRsrcs = attrs; AssetManager.applyStyle(mTheme, 0, 0, 0, attrs, array.mData, array.mIndices); @@ -1279,10 +1314,10 @@ public class Resources { * @see #obtainStyledAttributes(int[]) * @see #obtainStyledAttributes(AttributeSet, int[], int, int) */ - public TypedArray obtainStyledAttributes(int resid, int[] attrs) - throws NotFoundException { - int len = attrs.length; - TypedArray array = getCachedStyledAttributes(len); + public TypedArray obtainStyledAttributes(int resid, int[] attrs) throws NotFoundException { + final int len = attrs.length; + final TypedArray array = getCachedStyledAttributes(len); + array.mTheme = this; array.mRsrcs = attrs; AssetManager.applyStyle(mTheme, 0, resid, 0, attrs, @@ -1366,19 +1401,18 @@ public class Resources { */ public TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { - int len = attrs.length; - TypedArray array = getCachedStyledAttributes(len); + final int len = attrs.length; + final TypedArray array = getCachedStyledAttributes(len); // XXX note that for now we only work with compiled XML files. // To support generic XML files we will need to manually parse // out the attributes from the XML file (applying type information // contained in the resources and such). - XmlBlock.Parser parser = (XmlBlock.Parser)set; - AssetManager.applyStyle( - mTheme, defStyleAttr, defStyleRes, - parser != null ? parser.mParseState : 0, attrs, - array.mData, array.mIndices); + final XmlBlock.Parser parser = (XmlBlock.Parser)set; + AssetManager.applyStyle(mTheme, defStyleAttr, defStyleRes, + parser != null ? parser.mParseState : 0, attrs, array.mData, array.mIndices); + array.mTheme = this; array.mRsrcs = attrs; array.mXml = parser; @@ -1444,6 +1478,21 @@ public class Resources { } /** + * Return a drawable object associated with a particular resource ID + * and styled for the Theme. + * + * @param id The desired resource identifier, as generated by the aapt + * tool. This integer encodes the package, type, and resource + * entry. The value 0 is an invalid identifier. + * @return Drawable An object that can be used to draw this resource. + * @throws NotFoundException Throws NotFoundException if the given ID + * does not exist. + */ + public Drawable getDrawable(int id) throws NotFoundException { + return Resources.this.getDrawable(id, this); + } + + /** * Print contents of this theme out to the log. For debugging only. * * @param priority The log priority to use. @@ -1453,7 +1502,8 @@ public class Resources { public void dump(int priority, String tag, String prefix) { AssetManager.dumpTheme(mTheme, priority, tag, prefix); } - + + @Override protected void finalize() throws Throwable { super.finalize(); mAssets.releaseTheme(mTheme); @@ -1464,6 +1514,7 @@ public class Resources { mTheme = mAssets.createTheme(); } + @SuppressWarnings("hiding") private final AssetManager mAssets; private final long mTheme; } @@ -2028,14 +2079,14 @@ public class Resources { return true; } - /*package*/ Drawable loadDrawable(TypedValue value, int id) - throws NotFoundException { - + /*package*/ Drawable loadDrawable(TypedValue value, int id, Theme theme) throws NotFoundException { if (TRACE_FOR_PRELOAD) { // Log only framework resources if ((id >>> 24) == 0x1) { final String name = getResourceName(id); - if (name != null) android.util.Log.d("PreloadDrawable", name); + if (name != null) { + Log.d("PreloadDrawable", name); + } } } @@ -2240,12 +2291,12 @@ public class Resources { "Resource is not a ColorStateList (color or path): " + value); } - String file = value.string.toString(); + final String file = value.string.toString(); if (file.endsWith(".xml")) { Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, file); try { - XmlResourceParser rp = loadXmlResourceParser( + final XmlResourceParser rp = loadXmlResourceParser( file, id, value.assetCookie, "colorstatelist"); csl = ColorStateList.createFromXml(this, rp); rp.close(); @@ -2372,7 +2423,6 @@ public class Resources { synchronized (mAccessLock) { final TypedArray cached = mCachedStyledAttributes; if (cached == null || cached.mData.length < attrs.mData.length) { - attrs.mXml = null; mCachedStyledAttributes = attrs; } } diff --git a/core/java/android/content/res/TypedArray.java b/core/java/android/content/res/TypedArray.java index 87d65a5..4858d08 100644 --- a/core/java/android/content/res/TypedArray.java +++ b/core/java/android/content/res/TypedArray.java @@ -45,7 +45,8 @@ public class TypedArray { /*package*/ int[] mIndices; /*package*/ int mLength; /*package*/ TypedValue mValue = new TypedValue(); - + /*package*/ Resources.Theme mTheme; + /** * Return the number of values in this array. */ @@ -600,7 +601,7 @@ public class TypedArray { + " cookie=" + value.assetCookie); System.out.println("******************************************************************"); } - return mResources.loadDrawable(value, value.resourceId); + return mResources.loadDrawable(value, value.resourceId, mTheme); } return null; } @@ -690,6 +691,10 @@ public class TypedArray { */ public void recycle() { mResources.recycleCachedStyledAttributes(this); + + mXml = null; + mRsrcs = null; + mTheme = null; } private boolean getValueAt(int index, TypedValue outValue) { diff --git a/core/java/android/preference/DialogPreference.java b/core/java/android/preference/DialogPreference.java index 5275bc0..b65eac7 100644 --- a/core/java/android/preference/DialogPreference.java +++ b/core/java/android/preference/DialogPreference.java @@ -169,7 +169,7 @@ public abstract class DialogPreference extends Preference implements * @param dialogIconRes The icon, as a resource ID. */ public void setDialogIcon(int dialogIconRes) { - mDialogIcon = getContext().getResources().getDrawable(dialogIconRes); + mDialogIcon = getContext().getDrawable(dialogIconRes); } /** diff --git a/core/java/android/preference/Preference.java b/core/java/android/preference/Preference.java index 76fccc7..144c909 100644 --- a/core/java/android/preference/Preference.java +++ b/core/java/android/preference/Preference.java @@ -561,7 +561,7 @@ public class Preference implements Comparable<Preference> { if (imageView != null) { if (mIconResId != 0 || mIcon != null) { if (mIcon == null) { - mIcon = getContext().getResources().getDrawable(mIconResId); + mIcon = getContext().getDrawable(mIconResId); } if (mIcon != null) { imageView.setImageDrawable(mIcon); @@ -694,7 +694,7 @@ public class Preference implements Comparable<Preference> { */ public void setIcon(int iconResId) { mIconResId = iconResId; - setIcon(mContext.getResources().getDrawable(iconResId)); + setIcon(mContext.getDrawable(iconResId)); } /** diff --git a/core/java/android/text/style/ImageSpan.java b/core/java/android/text/style/ImageSpan.java index 74b9463..3d6f8e6 100644 --- a/core/java/android/text/style/ImageSpan.java +++ b/core/java/android/text/style/ImageSpan.java @@ -145,7 +145,7 @@ public class ImageSpan extends DynamicDrawableSpan { } } else { try { - drawable = mContext.getResources().getDrawable(mResourceId); + drawable = mContext.getDrawable(mResourceId); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); } catch (Exception e) { diff --git a/core/java/android/view/PointerIcon.java b/core/java/android/view/PointerIcon.java index bb7ed41..063a08d 100644 --- a/core/java/android/view/PointerIcon.java +++ b/core/java/android/view/PointerIcon.java @@ -140,7 +140,7 @@ public final class PointerIcon implements Parcelable { if ((resourceId & 0xff000000) == 0x01000000) { icon.mSystemIconResourceId = resourceId; } else { - icon.loadResource(context.getResources(), resourceId); + icon.loadResource(context, context.getResources(), resourceId); } return icon; } @@ -198,7 +198,7 @@ public final class PointerIcon implements Parcelable { } PointerIcon icon = new PointerIcon(STYLE_CUSTOM); - icon.loadResource(resources, resourceId); + icon.loadResource(null, resources, resourceId); return icon; } @@ -224,7 +224,7 @@ public final class PointerIcon implements Parcelable { PointerIcon result = new PointerIcon(mStyle); result.mSystemIconResourceId = mSystemIconResourceId; - result.loadResource(context.getResources(), mSystemIconResourceId); + result.loadResource(context, context.getResources(), mSystemIconResourceId); return result; } @@ -373,7 +373,7 @@ public final class PointerIcon implements Parcelable { return true; } - private void loadResource(Resources resources, int resourceId) { + private void loadResource(Context context, Resources resources, int resourceId) { XmlResourceParser parser = resources.getXml(resourceId); final int bitmapRes; final float hotSpotX; @@ -397,7 +397,12 @@ public final class PointerIcon implements Parcelable { throw new IllegalArgumentException("<pointer-icon> is missing bitmap attribute."); } - Drawable drawable = resources.getDrawable(bitmapRes); + Drawable drawable; + if (context == null) { + drawable = resources.getDrawable(bitmapRes); + } else { + drawable = context.getDrawable(bitmapRes); + } if (!(drawable instanceof BitmapDrawable)) { throw new IllegalArgumentException("<pointer-icon> bitmap attribute must " + "refer to a bitmap drawable."); diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 239eda4..15ede96 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -15584,7 +15584,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Drawable d= null; if (resid != 0) { - d = mResources.getDrawable(resid); + d = mContext.getDrawable(resid); } setBackground(d); diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 5aa46f3..ccb85a6 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -2592,7 +2592,7 @@ public final class ViewRootImpl implements ViewParent, R.attr.accessibilityFocusedDrawable, value, true); if (resolved) { mAttachInfo.mAccessibilityFocusDrawable = - mView.mContext.getResources().getDrawable(value.resourceId); + mView.mContext.getDrawable(value.resourceId); } } return mAttachInfo.mAccessibilityFocusDrawable; diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index 2f62431..1064a08 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -1039,7 +1039,7 @@ public abstract class Window { */ public void setBackgroundDrawableResource(int resid) { - setBackgroundDrawable(mContext.getResources().getDrawable(resid)); + setBackgroundDrawable(mContext.getDrawable(resid)); } /** diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index 4d8975c..13febe9 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -1604,7 +1604,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te } private void useDefaultSelector() { - setSelector(getResources().getDrawable( + setSelector(getContext().getDrawable( com.android.internal.R.drawable.list_selector_background)); } @@ -2616,7 +2616,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te * @attr ref android.R.styleable#AbsListView_listSelector */ public void setSelector(int resID) { - setSelector(getResources().getDrawable(resID)); + setSelector(getContext().getDrawable(resID)); } public void setSelector(Drawable sel) { diff --git a/core/java/android/widget/AnalogClock.java b/core/java/android/widget/AnalogClock.java index 3c88e94..5b80648 100644 --- a/core/java/android/widget/AnalogClock.java +++ b/core/java/android/widget/AnalogClock.java @@ -80,17 +80,17 @@ public class AnalogClock extends View { mDial = a.getDrawable(com.android.internal.R.styleable.AnalogClock_dial); if (mDial == null) { - mDial = r.getDrawable(com.android.internal.R.drawable.clock_dial); + mDial = context.getDrawable(com.android.internal.R.drawable.clock_dial); } mHourHand = a.getDrawable(com.android.internal.R.styleable.AnalogClock_hand_hour); if (mHourHand == null) { - mHourHand = r.getDrawable(com.android.internal.R.drawable.clock_hand_hour); + mHourHand = context.getDrawable(com.android.internal.R.drawable.clock_hand_hour); } mMinuteHand = a.getDrawable(com.android.internal.R.styleable.AnalogClock_hand_minute); if (mMinuteHand == null) { - mMinuteHand = r.getDrawable(com.android.internal.R.drawable.clock_hand_minute); + mMinuteHand = context.getDrawable(com.android.internal.R.drawable.clock_hand_minute); } mCalendar = new Time(); diff --git a/core/java/android/widget/AppSecurityPermissions.java b/core/java/android/widget/AppSecurityPermissions.java index 34cfea5..10e56c7 100644 --- a/core/java/android/widget/AppSecurityPermissions.java +++ b/core/java/android/widget/AppSecurityPermissions.java @@ -322,7 +322,7 @@ public class AppSecurityPermissions { CharSequence grpName, CharSequence description, boolean dangerous) { LayoutInflater inflater = (LayoutInflater)context.getSystemService( Context.LAYOUT_INFLATER_SERVICE); - Drawable icon = context.getResources().getDrawable(dangerous + Drawable icon = context.getDrawable(dangerous ? R.drawable.ic_bullet_key_permission : R.drawable.ic_text_dot); return getPermissionItemViewOld(context, inflater, grpName, description, dangerous, icon); diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java index 259c66b..eb232fd 100644 --- a/core/java/android/widget/AutoCompleteTextView.java +++ b/core/java/android/widget/AutoCompleteTextView.java @@ -366,7 +366,7 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe * @attr ref android.R.styleable#PopupWindow_popupBackground */ public void setDropDownBackgroundResource(int id) { - mPopup.setBackgroundDrawable(getResources().getDrawable(id)); + mPopup.setBackgroundDrawable(getContext().getDrawable(id)); } /** diff --git a/core/java/android/widget/CalendarView.java b/core/java/android/widget/CalendarView.java index c6be6dd..ea60abb 100644 --- a/core/java/android/widget/CalendarView.java +++ b/core/java/android/widget/CalendarView.java @@ -1029,7 +1029,7 @@ public class CalendarView extends FrameLayout { @Override public void setSelectedDateVerticalBar(int resourceId) { - Drawable drawable = mDelegator.getResources().getDrawable(resourceId); + Drawable drawable = mDelegator.getContext().getDrawable(resourceId); setSelectedDateVerticalBar(drawable); } diff --git a/core/java/android/widget/CheckedTextView.java b/core/java/android/widget/CheckedTextView.java index 78b1b75..1533510 100644 --- a/core/java/android/widget/CheckedTextView.java +++ b/core/java/android/widget/CheckedTextView.java @@ -123,7 +123,7 @@ public class CheckedTextView extends TextView implements Checkable { Drawable d = null; if (mCheckMarkResource != 0) { - d = getResources().getDrawable(mCheckMarkResource); + d = getContext().getDrawable(mCheckMarkResource); } setCheckMarkDrawable(d); } diff --git a/core/java/android/widget/CompoundButton.java b/core/java/android/widget/CompoundButton.java index b22088c..4298545 100644 --- a/core/java/android/widget/CompoundButton.java +++ b/core/java/android/widget/CompoundButton.java @@ -186,7 +186,7 @@ public abstract class CompoundButton extends Button implements Checkable { Drawable d = null; if (mButtonResource != 0) { - d = getResources().getDrawable(mButtonResource); + d = getContext().getDrawable(mButtonResource); } setButtonDrawable(d); } diff --git a/core/java/android/widget/EdgeEffect.java b/core/java/android/widget/EdgeEffect.java index 30752e0..fa37443 100644 --- a/core/java/android/widget/EdgeEffect.java +++ b/core/java/android/widget/EdgeEffect.java @@ -136,8 +136,8 @@ public class EdgeEffect { */ public EdgeEffect(Context context) { final Resources res = context.getResources(); - mEdge = res.getDrawable(R.drawable.overscroll_edge); - mGlow = res.getDrawable(R.drawable.overscroll_glow); + mEdge = context.getDrawable(R.drawable.overscroll_edge); + mGlow = context.getDrawable(R.drawable.overscroll_glow); mEdgeHeight = mEdge.getIntrinsicHeight(); mGlowHeight = mGlow.getIntrinsicHeight(); diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 11dbce8..ea62bbe 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -1679,7 +1679,7 @@ public class Editor { private void updateCursorPosition(int cursorIndex, int top, int bottom, float horizontal) { if (mCursorDrawable[cursorIndex] == null) - mCursorDrawable[cursorIndex] = mTextView.getResources().getDrawable( + mCursorDrawable[cursorIndex] = mTextView.getContext().getDrawable( mTextView.mCursorDrawableRes); if (mTempRect == null) mTempRect = new Rect(); @@ -2969,7 +2969,7 @@ public class Editor { positionY += mContentView.getMeasuredHeight(); // Assumes insertion and selection handles share the same height - final Drawable handle = mTextView.getResources().getDrawable( + final Drawable handle = mTextView.getContext().getDrawable( mTextView.mTextSelectHandleRes); positionY += handle.getIntrinsicHeight(); } @@ -3546,7 +3546,7 @@ public class Editor { private InsertionHandleView getHandle() { if (mSelectHandleCenter == null) { - mSelectHandleCenter = mTextView.getResources().getDrawable( + mSelectHandleCenter = mTextView.getContext().getDrawable( mTextView.mTextSelectHandleRes); } if (mHandle == null) { @@ -3592,11 +3592,11 @@ public class Editor { private void initDrawables() { if (mSelectHandleLeft == null) { - mSelectHandleLeft = mTextView.getContext().getResources().getDrawable( + mSelectHandleLeft = mTextView.getContext().getDrawable( mTextView.mTextSelectHandleLeftRes); } if (mSelectHandleRight == null) { - mSelectHandleRight = mTextView.getContext().getResources().getDrawable( + mSelectHandleRight = mTextView.getContext().getDrawable( mTextView.mTextSelectHandleRightRes); } } diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java index 58e4e86..572302a 100644 --- a/core/java/android/widget/ImageView.java +++ b/core/java/android/widget/ImageView.java @@ -642,7 +642,7 @@ public class ImageView extends View { if (mResource != 0) { try { - d = rsrc.getDrawable(mResource); + d = mContext.getDrawable(mResource); } catch (Exception e) { Log.w("ImageView", "Unable to find resource: " + mResource, e); // Don't try again. @@ -655,7 +655,7 @@ public class ImageView extends View { // Load drawable through Resources, to get the source density information ContentResolver.OpenResourceIdResult r = mContext.getContentResolver().getResourceId(mUri); - d = r.r.getDrawable(r.id); + d = r.r.getDrawable(r.id, mContext.getTheme()); } catch (Exception e) { Log.w("ImageView", "Unable to open content: " + mUri, e); } diff --git a/core/java/android/widget/QuickContactBadge.java b/core/java/android/widget/QuickContactBadge.java index a4f758c..74b41c9 100644 --- a/core/java/android/widget/QuickContactBadge.java +++ b/core/java/android/widget/QuickContactBadge.java @@ -155,7 +155,7 @@ public class QuickContactBadge extends ImageView implements OnClickListener { */ public void setImageToDefault() { if (mDefaultAvatar == null) { - mDefaultAvatar = getResources().getDrawable(R.drawable.ic_contact_picture); + mDefaultAvatar = mContext.getDrawable(R.drawable.ic_contact_picture); } setImageDrawable(mDefaultAvatar); } diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java index 3791258..1eedc5d 100644 --- a/core/java/android/widget/SearchView.java +++ b/core/java/android/widget/SearchView.java @@ -1059,7 +1059,7 @@ public class SearchView extends LinearLayout implements CollapsibleActionView { SpannableStringBuilder ssb = new SpannableStringBuilder(" "); // for the icon ssb.append(hintText); - Drawable searchIcon = getContext().getResources().getDrawable(getSearchIconId()); + Drawable searchIcon = getContext().getDrawable(getSearchIconId()); int textSize = (int) (mQueryTextView.getTextSize() * 1.25); searchIcon.setBounds(0, 0, textSize, textSize); ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); diff --git a/core/java/android/widget/ShareActionProvider.java b/core/java/android/widget/ShareActionProvider.java index bdaaa01..64a1574 100644 --- a/core/java/android/widget/ShareActionProvider.java +++ b/core/java/android/widget/ShareActionProvider.java @@ -168,7 +168,7 @@ public class ShareActionProvider extends ActionProvider { // Lookup and set the expand action icon. TypedValue outTypedValue = new TypedValue(); mContext.getTheme().resolveAttribute(R.attr.actionModeShareDrawable, outTypedValue, true); - Drawable drawable = mContext.getResources().getDrawable(outTypedValue.resourceId); + Drawable drawable = mContext.getDrawable(outTypedValue.resourceId); activityChooserView.setExpandActivityOverflowButtonDrawable(drawable); activityChooserView.setProvider(this); diff --git a/core/java/android/widget/Spinner.java b/core/java/android/widget/Spinner.java index eabe1a3..9601d4a 100644 --- a/core/java/android/widget/Spinner.java +++ b/core/java/android/widget/Spinner.java @@ -281,7 +281,7 @@ public class Spinner extends AbsSpinner implements OnClickListener { * @attr ref android.R.styleable#Spinner_popupBackground */ public void setPopupBackgroundResource(int resId) { - setPopupBackgroundDrawable(getContext().getResources().getDrawable(resId)); + setPopupBackgroundDrawable(getContext().getDrawable(resId)); } /** diff --git a/core/java/android/widget/SuggestionsAdapter.java b/core/java/android/widget/SuggestionsAdapter.java index c44d431..c8917e0 100644 --- a/core/java/android/widget/SuggestionsAdapter.java +++ b/core/java/android/widget/SuggestionsAdapter.java @@ -529,7 +529,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter implements OnClickListene return drawable; } // Not cached, find it by resource ID - drawable = mProviderContext.getResources().getDrawable(resourceId); + drawable = mProviderContext.getDrawable(resourceId); // Stick it in the cache, using the URI as key storeInIconCache(drawableUri, drawable); return drawable; @@ -563,7 +563,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter implements OnClickListene OpenResourceIdResult r = mProviderContext.getContentResolver().getResourceId(uri); try { - return r.r.getDrawable(r.id); + return r.r.getDrawable(r.id, mContext.getTheme()); } catch (Resources.NotFoundException ex) { throw new FileNotFoundException("Resource does not exist: " + uri); } diff --git a/core/java/android/widget/Switch.java b/core/java/android/widget/Switch.java index c9a1ca4..2a5fb15 100644 --- a/core/java/android/widget/Switch.java +++ b/core/java/android/widget/Switch.java @@ -417,7 +417,7 @@ public class Switch extends CompoundButton { * @attr ref android.R.styleable#Switch_track */ public void setTrackResource(int resId) { - setTrackDrawable(getContext().getResources().getDrawable(resId)); + setTrackDrawable(getContext().getDrawable(resId)); } /** @@ -453,7 +453,7 @@ public class Switch extends CompoundButton { * @attr ref android.R.styleable#Switch_thumb */ public void setThumbResource(int resId) { - setThumbDrawable(getContext().getResources().getDrawable(resId)); + setThumbDrawable(getContext().getDrawable(resId)); } /** diff --git a/core/java/android/widget/TabWidget.java b/core/java/android/widget/TabWidget.java index 568b3e6..47a5449 100644 --- a/core/java/android/widget/TabWidget.java +++ b/core/java/android/widget/TabWidget.java @@ -120,28 +120,27 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { setChildrenDrawingOrderEnabled(true); final Context context = mContext; - final Resources resources = context.getResources(); // Tests the target Sdk version, as set in the Manifest. Could not be set using styles.xml // in a values-v? directory which targets the current platform Sdk version instead. if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.DONUT) { // Donut apps get old color scheme if (mLeftStrip == null) { - mLeftStrip = resources.getDrawable( + mLeftStrip = context.getDrawable( com.android.internal.R.drawable.tab_bottom_left_v4); } if (mRightStrip == null) { - mRightStrip = resources.getDrawable( + mRightStrip = context.getDrawable( com.android.internal.R.drawable.tab_bottom_right_v4); } } else { // Use modern color scheme for Eclair and beyond if (mLeftStrip == null) { - mLeftStrip = resources.getDrawable( + mLeftStrip = context.getDrawable( com.android.internal.R.drawable.tab_bottom_left); } if (mRightStrip == null) { - mRightStrip = resources.getDrawable( + mRightStrip = context.getDrawable( com.android.internal.R.drawable.tab_bottom_right); } } @@ -246,7 +245,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { * divider. */ public void setDividerDrawable(int resId) { - setDividerDrawable(getResources().getDrawable(resId)); + setDividerDrawable(mContext.getDrawable(resId)); } /** @@ -267,7 +266,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { * left strip drawable */ public void setLeftStripDrawable(int resId) { - setLeftStripDrawable(getResources().getDrawable(resId)); + setLeftStripDrawable(mContext.getDrawable(resId)); } /** @@ -288,7 +287,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { * right strip drawable */ public void setRightStripDrawable(int resId) { - setRightStripDrawable(getResources().getDrawable(resId)); + setRightStripDrawable(mContext.getDrawable(resId)); } /** diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 15606a4..3be23b7 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -2073,11 +2073,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener */ @android.view.RemotableViewMethod public void setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom) { - final Resources resources = getContext().getResources(); - setCompoundDrawablesWithIntrinsicBounds(left != 0 ? resources.getDrawable(left) : null, - top != 0 ? resources.getDrawable(top) : null, - right != 0 ? resources.getDrawable(right) : null, - bottom != 0 ? resources.getDrawable(bottom) : null); + final Context context = getContext(); + setCompoundDrawablesWithIntrinsicBounds(left != 0 ? context.getDrawable(left) : null, + top != 0 ? context.getDrawable(top) : null, + right != 0 ? context.getDrawable(right) : null, + bottom != 0 ? context.getDrawable(bottom) : null); } /** @@ -2247,12 +2247,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @android.view.RemotableViewMethod public void setCompoundDrawablesRelativeWithIntrinsicBounds(int start, int top, int end, int bottom) { - final Resources resources = getContext().getResources(); + final Context context = getContext(); setCompoundDrawablesRelativeWithIntrinsicBounds( - start != 0 ? resources.getDrawable(start) : null, - top != 0 ? resources.getDrawable(top) : null, - end != 0 ? resources.getDrawable(end) : null, - bottom != 0 ? resources.getDrawable(bottom) : null); + start != 0 ? context.getDrawable(start) : null, + top != 0 ? context.getDrawable(top) : null, + end != 0 ? context.getDrawable(end) : null, + bottom != 0 ? context.getDrawable(bottom) : null); } /** @@ -4385,8 +4385,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (error == null) { setError(null, null); } else { - Drawable dr = getContext().getResources(). - getDrawable(com.android.internal.R.drawable.indicator_input_error); + Drawable dr = getContext().getDrawable( + com.android.internal.R.drawable.indicator_input_error); dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight()); setError(error, dr); diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java index 347f957..0a80495 100644 --- a/core/java/com/android/internal/app/ActionBarImpl.java +++ b/core/java/com/android/internal/app/ActionBarImpl.java @@ -1081,7 +1081,7 @@ public class ActionBarImpl extends ActionBar { @Override public Tab setIcon(int resId) { - return setIcon(mContext.getResources().getDrawable(resId)); + return setIcon(mContext.getDrawable(resId)); } @Override diff --git a/core/java/com/android/internal/app/MediaRouteControllerDialog.java b/core/java/com/android/internal/app/MediaRouteControllerDialog.java index 8fc99c7..b0e0373 100644 --- a/core/java/com/android/internal/app/MediaRouteControllerDialog.java +++ b/core/java/com/android/internal/app/MediaRouteControllerDialog.java @@ -256,13 +256,13 @@ public class MediaRouteControllerDialog extends Dialog { private Drawable getIconDrawable() { if (mRoute.isConnecting()) { if (mMediaRouteConnectingDrawable == null) { - mMediaRouteConnectingDrawable = getContext().getResources().getDrawable( + mMediaRouteConnectingDrawable = getContext().getDrawable( R.drawable.ic_media_route_connecting_holo_dark); } return mMediaRouteConnectingDrawable; } else { if (mMediaRouteOnDrawable == null) { - mMediaRouteOnDrawable = getContext().getResources().getDrawable( + mMediaRouteOnDrawable = getContext().getDrawable( R.drawable.ic_media_route_on_holo_dark); } return mMediaRouteOnDrawable; diff --git a/core/java/com/android/internal/view/menu/ActionMenuItem.java b/core/java/com/android/internal/view/menu/ActionMenuItem.java index 7ca6c1b..ed676bb 100644 --- a/core/java/com/android/internal/view/menu/ActionMenuItem.java +++ b/core/java/com/android/internal/view/menu/ActionMenuItem.java @@ -163,7 +163,7 @@ public class ActionMenuItem implements MenuItem { public MenuItem setIcon(int iconRes) { mIconResId = iconRes; - mIconDrawable = mContext.getResources().getDrawable(iconRes); + mIconDrawable = mContext.getDrawable(iconRes); return this; } diff --git a/core/java/com/android/internal/view/menu/MenuBuilder.java b/core/java/com/android/internal/view/menu/MenuBuilder.java index b7cb0de..b776226 100644 --- a/core/java/com/android/internal/view/menu/MenuBuilder.java +++ b/core/java/com/android/internal/view/menu/MenuBuilder.java @@ -1121,7 +1121,7 @@ public class MenuBuilder implements Menu { } if (iconRes > 0) { - mHeaderIcon = r.getDrawable(iconRes); + mHeaderIcon = getContext().getDrawable(iconRes); } else if (icon != null) { mHeaderIcon = icon; } diff --git a/core/java/com/android/internal/view/menu/MenuItemImpl.java b/core/java/com/android/internal/view/menu/MenuItemImpl.java index 4d0a326..61dcaca 100644 --- a/core/java/com/android/internal/view/menu/MenuItemImpl.java +++ b/core/java/com/android/internal/view/menu/MenuItemImpl.java @@ -385,7 +385,7 @@ public final class MenuItemImpl implements MenuItem { } if (mIconResId != NO_ICON) { - Drawable icon = mMenu.getResources().getDrawable(mIconResId); + Drawable icon = mMenu.getContext().getDrawable(mIconResId); mIconResId = NO_ICON; mIconDrawable = icon; return icon; diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java index ff2c625..1273c4d 100644 --- a/core/java/com/android/internal/widget/ActionBarView.java +++ b/core/java/com/android/internal/widget/ActionBarView.java @@ -697,7 +697,7 @@ public class ActionBarView extends AbsActionBarView { } public void setIcon(int resId) { - setIcon(resId != 0 ? mContext.getResources().getDrawable(resId) : null); + setIcon(resId != 0 ? mContext.getDrawable(resId) : null); } public boolean hasIcon() { @@ -712,7 +712,7 @@ public class ActionBarView extends AbsActionBarView { } public void setLogo(int resId) { - setLogo(resId != 0 ? mContext.getResources().getDrawable(resId) : null); + setLogo(resId != 0 ? mContext.getDrawable(resId) : null); } public boolean hasLogo() { @@ -1417,7 +1417,7 @@ public class ActionBarView extends AbsActionBarView { public void setUpIndicator(int resId) { mUpIndicatorRes = resId; - mUpView.setImageDrawable(resId != 0 ? getResources().getDrawable(resId) : null); + mUpView.setImageDrawable(resId != 0 ? getContext().getDrawable(resId) : null); } @Override diff --git a/core/java/com/android/internal/widget/PasswordEntryKeyboard.java b/core/java/com/android/internal/widget/PasswordEntryKeyboard.java index 8368136..7483e75 100644 --- a/core/java/com/android/internal/widget/PasswordEntryKeyboard.java +++ b/core/java/com/android/internal/widget/PasswordEntryKeyboard.java @@ -72,8 +72,8 @@ public class PasswordEntryKeyboard extends Keyboard { private void init(Context context) { final Resources res = context.getResources(); - mShiftIcon = res.getDrawable(R.drawable.sym_keyboard_shift); - mShiftLockIcon = res.getDrawable(R.drawable.sym_keyboard_shift_locked); + mShiftIcon = context.getDrawable(R.drawable.sym_keyboard_shift); + mShiftLockIcon = context.getDrawable(R.drawable.sym_keyboard_shift_locked); sSpacebarVerticalCorrection = res.getDimensionPixelOffset( R.dimen.password_keyboard_spacebar_vertical_correction); } diff --git a/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java b/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java index cd1ccd3..93ea5b3 100644 --- a/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java +++ b/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java @@ -234,7 +234,7 @@ public class GlowPadView extends View { mMagneticTargets = a.getBoolean(R.styleable.GlowPadView_magneticTargets, mMagneticTargets); int pointId = getResourceId(a, R.styleable.GlowPadView_pointDrawable); - Drawable pointDrawable = pointId != 0 ? res.getDrawable(pointId) : null; + Drawable pointDrawable = pointId != 0 ? context.getDrawable(pointId) : null; mGlowRadius = a.getDimension(R.styleable.GlowPadView_glowRadius, 0.0f); TypedValue outValue = new TypedValue(); |