diff --git a/api/current.xml b/api/current.xml index 04823e577ff64..ee82e008a0911 100644 --- a/api/current.xml +++ b/api/current.xml @@ -63352,7 +63352,7 @@ type="android.graphics.drawable.BitmapDrawable" static="false" final="false" - deprecated="not deprecated" + deprecated="deprecated" visibility="public" > @@ -63365,6 +63365,30 @@ deprecated="not deprecated" visibility="public" > + + + + + + + + + + + + @@ -64543,6 +64567,19 @@ visibility="public" > + + + + = TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) { @@ -1743,7 +1743,7 @@ public class Resources { //Log.i(TAG, "Returning cached drawable @ #" + // Integer.toHexString(((Integer)key).intValue()) // + " in " + this + ": " + entry); - return entry.newDrawable(); + return entry.newDrawable(this); } else { // our entry has been purged mDrawableCache.delete(key); diff --git a/core/java/com/android/internal/view/menu/IconMenuView.java b/core/java/com/android/internal/view/menu/IconMenuView.java index b81c2b3527d65..bba2ee2755621 100644 --- a/core/java/com/android/internal/view/menu/IconMenuView.java +++ b/core/java/com/android/internal/view/menu/IconMenuView.java @@ -282,7 +282,9 @@ public final class IconMenuView extends ViewGroup implements ItemInvoker, MenuVi itemView.setIconMenuView(this); // Apply the background to the item view - itemView.setBackgroundDrawable(mItemBackground.getConstantState().newDrawable()); + itemView.setBackgroundDrawable( + mItemBackground.getConstantState().newDrawable( + getContext().getResources())); // This class is the invoker for all its item views itemView.setItemInvoker(this); diff --git a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java index ac96f20bc5274..58206d484fb6e 100644 --- a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java @@ -45,11 +45,11 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac private boolean mRunning; public AnimatedRotateDrawable() { - this(null); + this(null, null); } - private AnimatedRotateDrawable(AnimatedRotateState rotateState) { - mState = new AnimatedRotateState(rotateState, this); + private AnimatedRotateDrawable(AnimatedRotateState rotateState, Resources res) { + mState = new AnimatedRotateState(rotateState, this, res); init(); } @@ -296,9 +296,14 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac private boolean mCanConstantState; private boolean mCheckedConstantState; - public AnimatedRotateState(AnimatedRotateState source, AnimatedRotateDrawable owner) { + public AnimatedRotateState(AnimatedRotateState source, AnimatedRotateDrawable owner, + Resources res) { if (source != null) { - mDrawable = source.mDrawable.getConstantState().newDrawable(); + if (res != null) { + mDrawable = source.mDrawable.getConstantState().newDrawable(res); + } else { + mDrawable = source.mDrawable.getConstantState().newDrawable(); + } mDrawable.setCallback(owner); mPivotXRel = source.mPivotXRel; mPivotX = source.mPivotX; @@ -312,7 +317,12 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac @Override public Drawable newDrawable() { - return new AnimatedRotateDrawable(this); + return new AnimatedRotateDrawable(this, null); + } + + @Override + public Drawable newDrawable(Resources res) { + return new AnimatedRotateDrawable(this, res); } @Override diff --git a/graphics/java/android/graphics/drawable/AnimationDrawable.java b/graphics/java/android/graphics/drawable/AnimationDrawable.java index 68718c9763eb6..fdc4c92e178d9 100644 --- a/graphics/java/android/graphics/drawable/AnimationDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimationDrawable.java @@ -77,7 +77,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An private boolean mMutated; public AnimationDrawable() { - this(null); + this(null, null); } @Override @@ -297,8 +297,9 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An private int[] mDurations; private boolean mOneShot; - AnimationState(AnimationState orig, AnimationDrawable owner) { - super(orig, owner); + AnimationState(AnimationState orig, AnimationDrawable owner, + Resources res) { + super(orig, owner, res); if (orig != null) { mDurations = orig.mDurations; @@ -311,7 +312,12 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An @Override public Drawable newDrawable() { - return new AnimationDrawable(this); + return new AnimationDrawable(this, null); + } + + @Override + public Drawable newDrawable(Resources res) { + return new AnimationDrawable(this, res); } public void addFrame(Drawable dr, int dur) { @@ -330,8 +336,8 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An } } - private AnimationDrawable(AnimationState state) { - AnimationState as = new AnimationState(state, this); + private AnimationDrawable(AnimationState state, Resources res) { + AnimationState as = new AnimationState(state, this, res); mAnimationState = as; setConstantState(as); if (state != null) { diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java index 30cef670d90a7..e82f297dfff2e 100644 --- a/graphics/java/android/graphics/drawable/BitmapDrawable.java +++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java @@ -60,15 +60,15 @@ public class BitmapDrawable extends Drawable { Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG; private BitmapState mBitmapState; private Bitmap mBitmap; + private int mTargetDensity; + private final Rect mDstRect = new Rect(); // Gravity.apply() sets this private boolean mApplyGravity; private boolean mRebuildShader; private boolean mMutated; - private int mTargetDensity = DisplayMetrics.DENSITY_DEFAULT; - - // These are scaled to match the target density. + // These are scaled to match the target density. private int mBitmapWidth; private int mBitmapHeight; @@ -88,10 +88,7 @@ public class BitmapDrawable extends Drawable { */ public BitmapDrawable(Resources res) { mBitmapState = new BitmapState((Bitmap) null); - if (res != null) { - setTargetDensity(res.getDisplayMetrics()); - mBitmapState.mTargetDensity = mTargetDensity; - } + mBitmapState.mTargetDensity = mTargetDensity; } /** @@ -101,7 +98,7 @@ public class BitmapDrawable extends Drawable { */ @Deprecated public BitmapDrawable(Bitmap bitmap) { - this(new BitmapState(bitmap)); + this(new BitmapState(bitmap), null); } /** @@ -109,22 +106,51 @@ public class BitmapDrawable extends Drawable { * the display metrics of the resources. */ public BitmapDrawable(Resources res, Bitmap bitmap) { - this(new BitmapState(bitmap)); - if (res != null) { - setTargetDensity(res.getDisplayMetrics()); - mBitmapState.mTargetDensity = mTargetDensity; - } + this(new BitmapState(bitmap), res); + mBitmapState.mTargetDensity = mTargetDensity; } + /** + * Create a drawable by opening a given file path and decoding the bitmap. + * @deprecated Use {@link #BitmapDrawable(Resources, String)} to ensure + * that the drawable has correctly set its target density. + */ public BitmapDrawable(String filepath) { - this(new BitmapState(BitmapFactory.decodeFile(filepath))); + this(new BitmapState(BitmapFactory.decodeFile(filepath)), null); if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + filepath); } } + /** + * Create a drawable by opening a given file path and decoding the bitmap. + */ + public BitmapDrawable(Resources res, String filepath) { + this(new BitmapState(BitmapFactory.decodeFile(filepath)), null); + mBitmapState.mTargetDensity = mTargetDensity; + if (mBitmap == null) { + android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + filepath); + } + } + + /** + * Create a drawable by decoding a bitmap from the given input stream. + * @deprecated Use {@link #BitmapDrawable(Resources, java.io.InputStream)} to ensure + * that the drawable has correctly set its target density. + */ public BitmapDrawable(java.io.InputStream is) { - this(new BitmapState(BitmapFactory.decodeStream(is))); + this(new BitmapState(BitmapFactory.decodeStream(is)), null); + if (mBitmap == null) { + android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + is); + } + } + + /** + * Create a drawable by decoding a bitmap from the given input stream. + */ + public BitmapDrawable(Resources res, java.io.InputStream is) { + this(new BitmapState(BitmapFactory.decodeStream(is)), null); + mBitmapState.mTargetDensity = mTargetDensity; if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + is); } @@ -425,7 +451,12 @@ public class BitmapDrawable extends Drawable { @Override public Drawable newDrawable() { - return new BitmapDrawable(this); + return new BitmapDrawable(this, null); + } + + @Override + public Drawable newDrawable(Resources res) { + return new BitmapDrawable(this, res); } @Override @@ -434,9 +465,15 @@ public class BitmapDrawable extends Drawable { } } - private BitmapDrawable(BitmapState state) { + private BitmapDrawable(BitmapState state, Resources res) { mBitmapState = state; - mTargetDensity = state.mTargetDensity; + if (res != null) { + mTargetDensity = res.getDisplayMetrics().densityDpi; + } else if (state != null) { + mTargetDensity = state.mTargetDensity; + } else { + mTargetDensity = DisplayMetrics.DENSITY_DEFAULT; + } setBitmap(state.mBitmap); } } diff --git a/graphics/java/android/graphics/drawable/ClipDrawable.java b/graphics/java/android/graphics/drawable/ClipDrawable.java index 95d4dd096b9cf..c387a9ba7d5f8 100644 --- a/graphics/java/android/graphics/drawable/ClipDrawable.java +++ b/graphics/java/android/graphics/drawable/ClipDrawable.java @@ -48,14 +48,14 @@ public class ClipDrawable extends Drawable implements Drawable.Callback { public static final int VERTICAL = 2; ClipDrawable() { - this(null); + this(null, null); } /** * @param orientation Bitwise-or of {@link #HORIZONTAL} and/or {@link #VERTICAL} */ public ClipDrawable(Drawable drawable, int gravity, int orientation) { - this(null); + this(null, null); mClipState.mDrawable = drawable; mClipState.mGravity = gravity; @@ -241,9 +241,13 @@ public class ClipDrawable extends Drawable implements Drawable.Callback { private boolean mCheckedConstantState; private boolean mCanConstantState; - ClipState(ClipState orig, ClipDrawable owner) { + ClipState(ClipState orig, ClipDrawable owner, Resources res) { if (orig != null) { - mDrawable = orig.mDrawable.getConstantState().newDrawable(); + if (res != null) { + mDrawable = orig.mDrawable.getConstantState().newDrawable(res); + } else { + mDrawable = orig.mDrawable.getConstantState().newDrawable(); + } mDrawable.setCallback(owner); mOrientation = orig.mOrientation; mGravity = orig.mGravity; @@ -253,7 +257,12 @@ public class ClipDrawable extends Drawable implements Drawable.Callback { @Override public Drawable newDrawable() { - return new ClipDrawable(this); + return new ClipDrawable(this, null); + } + + @Override + public Drawable newDrawable(Resources res) { + return new ClipDrawable(this, res); } @Override @@ -271,8 +280,8 @@ public class ClipDrawable extends Drawable implements Drawable.Callback { } } - private ClipDrawable(ClipState state) { - mClipState = new ClipState(state, this); + private ClipDrawable(ClipState state, Resources res) { + mClipState = new ClipState(state, this, res); } } diff --git a/graphics/java/android/graphics/drawable/ColorDrawable.java b/graphics/java/android/graphics/drawable/ColorDrawable.java index 226cc04129fba..604c602207bf7 100644 --- a/graphics/java/android/graphics/drawable/ColorDrawable.java +++ b/graphics/java/android/graphics/drawable/ColorDrawable.java @@ -145,6 +145,11 @@ public class ColorDrawable extends Drawable { return new ColorDrawable(this); } + @Override + public Drawable newDrawable(Resources res) { + return new ColorDrawable(this); + } + @Override public int getChangingConfigurations() { return mChangingConfigurations; diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 21b5e39552094..6a7b2d1ae9227 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -822,7 +822,26 @@ public abstract class Drawable { } public static abstract class ConstantState { + /** + * Create a new drawable without supplying resources the caller + * is running in. Note that using this means the density-dependent + * drawables (like bitmaps) will not be able to update their target + * density correctly. + */ public abstract Drawable newDrawable(); + /** + * Create a new Drawable instance from its constant state. This + * must be implemented for drawables that change based on the target + * density of their caller (that is depending on whether it is + * in compatibility mode). + */ + public Drawable newDrawable(Resources res) { + return newDrawable(); + } + /** + * Return a bit mask of configuration changes that will impact + * this drawable (and thus require completely reloading it). + */ public abstract int getChangingConfigurations(); } diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java index af1a2892a8a5f..3266f1e211026 100644 --- a/graphics/java/android/graphics/drawable/DrawableContainer.java +++ b/graphics/java/android/graphics/drawable/DrawableContainer.java @@ -16,6 +16,7 @@ package android.graphics.drawable; +import android.content.res.Resources; import android.graphics.*; public class DrawableContainer extends Drawable implements Drawable.Callback { @@ -285,7 +286,8 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { boolean mPaddingChecked = false; - DrawableContainerState(DrawableContainerState orig, DrawableContainer owner) { + DrawableContainerState(DrawableContainerState orig, DrawableContainer owner, + Resources res) { mOwner = owner; if (orig != null) { @@ -299,7 +301,11 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { final int N = mNumChildren; for (int i=0; i 0) { ensurePadding(); } } - LayerState createConstantState(LayerState state) { - return new LayerState(state, this); + LayerState createConstantState(LayerState state, Resources res) { + return new LayerState(state, this, res); } @Override @@ -563,7 +563,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { private boolean mCheckedConstantState; private boolean mCanConstantState; - LayerState(LayerState orig, LayerDrawable owner) { + LayerState(LayerState orig, LayerDrawable owner, Resources res) { if (orig != null) { final ChildDrawable[] origChildDrawable = orig.mChildren; final int N = orig.mNum; @@ -577,7 +577,11 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { for (int i = 0; i < N; i++) { final ChildDrawable r = mChildren[i] = new ChildDrawable(); final ChildDrawable or = origChildDrawable[i]; - r.mDrawable = or.mDrawable.getConstantState().newDrawable(); + if (res != null) { + r.mDrawable = or.mDrawable.getConstantState().newDrawable(res); + } else { + r.mDrawable = or.mDrawable.getConstantState().newDrawable(); + } r.mDrawable.setCallback(owner); r.mInsetL = or.mInsetL; r.mInsetT = or.mInsetT; @@ -599,7 +603,12 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { @Override public Drawable newDrawable() { - return new LayerDrawable(this); + return new LayerDrawable(this, null); + } + + @Override + public Drawable newDrawable(Resources res) { + return new LayerDrawable(this, res); } @Override diff --git a/graphics/java/android/graphics/drawable/LevelListDrawable.java b/graphics/java/android/graphics/drawable/LevelListDrawable.java index 7ae649f91cad2..ae8f224c80df3 100644 --- a/graphics/java/android/graphics/drawable/LevelListDrawable.java +++ b/graphics/java/android/graphics/drawable/LevelListDrawable.java @@ -57,7 +57,7 @@ public class LevelListDrawable extends DrawableContainer { private boolean mMutated; public LevelListDrawable() { - this(null); + this(null, null); } public void addLevel(int low, int high, Drawable drawable) { @@ -154,8 +154,8 @@ public class LevelListDrawable extends DrawableContainer { private int[] mLows; private int[] mHighs; - LevelListState(LevelListState orig, LevelListDrawable owner) { - super(orig, owner); + LevelListState(LevelListState orig, LevelListDrawable owner, Resources res) { + super(orig, owner, res); if (orig != null) { mLows = orig.mLows; @@ -186,7 +186,12 @@ public class LevelListDrawable extends DrawableContainer { @Override public Drawable newDrawable() { - return new LevelListDrawable(this); + return new LevelListDrawable(this, null); + } + + @Override + public Drawable newDrawable(Resources res) { + return new LevelListDrawable(this, res); } @Override @@ -201,8 +206,8 @@ public class LevelListDrawable extends DrawableContainer { } } - private LevelListDrawable(LevelListState state) { - LevelListState as = new LevelListState(state, this); + private LevelListDrawable(LevelListState state, Resources res) { + LevelListState as = new LevelListState(state, this, res); mLevelListState = as; setConstantState(as); onLevelChange(getLevel()); diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java index 997efb813a6da..803e7b113ba47 100644 --- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java +++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java @@ -61,7 +61,7 @@ public class NinePatchDrawable extends Drawable { */ @Deprecated public NinePatchDrawable(Bitmap bitmap, byte[] chunk, Rect padding, String srcName) { - this(new NinePatchState(new NinePatch(bitmap, chunk, srcName), padding)); + this(new NinePatchState(new NinePatch(bitmap, chunk, srcName), padding), null); } /** @@ -70,11 +70,8 @@ public class NinePatchDrawable extends Drawable { */ public NinePatchDrawable(Resources res, Bitmap bitmap, byte[] chunk, Rect padding, String srcName) { - this(new NinePatchState(new NinePatch(bitmap, chunk, srcName), padding)); - if (res != null) { - setTargetDensity(res.getDisplayMetrics()); - mNinePatchState.mTargetDensity = mTargetDensity; - } + this(new NinePatchState(new NinePatch(bitmap, chunk, srcName), padding), res); + mNinePatchState.mTargetDensity = mTargetDensity; } /** @@ -84,7 +81,7 @@ public class NinePatchDrawable extends Drawable { */ @Deprecated public NinePatchDrawable(NinePatch patch) { - this(new NinePatchState(patch, null)); + this(new NinePatchState(patch, null), null); } /** @@ -92,18 +89,16 @@ public class NinePatchDrawable extends Drawable { * based on the display metrics of the resources. */ public NinePatchDrawable(Resources res, NinePatch patch) { - this(new NinePatchState(patch, null)); - if (res != null) { - setTargetDensity(res.getDisplayMetrics()); - mNinePatchState.mTargetDensity = mTargetDensity; - } + this(new NinePatchState(patch, null), res); + mNinePatchState.mTargetDensity = mTargetDensity; } - private void setNinePatchState(NinePatchState state) { + private void setNinePatchState(NinePatchState state, Resources res) { mNinePatchState = state; mNinePatch = state.mNinePatch; mPadding = state.mPadding; - mTargetDensity = state.mTargetDensity; + mTargetDensity = res != null ? res.getDisplayMetrics().densityDpi + : state.mTargetDensity; if (DEFAULT_DITHER != state.mDither) { // avoid calling the setter unless we need to, since it does a // lazy allocation of a paint @@ -258,7 +253,8 @@ public class NinePatchDrawable extends Drawable { } setNinePatchState(new NinePatchState( - new NinePatch(bitmap, bitmap.getNinePatchChunk(), "XML 9-patch"), padding, dither)); + new NinePatch(bitmap, bitmap.getNinePatchChunk(), "XML 9-patch"), + padding, dither), r); mNinePatchState.mTargetDensity = mTargetDensity; a.recycle(); @@ -357,7 +353,12 @@ public class NinePatchDrawable extends Drawable { @Override public Drawable newDrawable() { - return new NinePatchDrawable(this); + return new NinePatchDrawable(this, null); + } + + @Override + public Drawable newDrawable(Resources res) { + return new NinePatchDrawable(this, res); } @Override @@ -366,8 +367,7 @@ public class NinePatchDrawable extends Drawable { } } - private NinePatchDrawable(NinePatchState state) { - setNinePatchState(state); + private NinePatchDrawable(NinePatchState state, Resources res) { + setNinePatchState(state, res); } } - diff --git a/graphics/java/android/graphics/drawable/RotateDrawable.java b/graphics/java/android/graphics/drawable/RotateDrawable.java index cb16cb711b427..c4a78223c98ce 100644 --- a/graphics/java/android/graphics/drawable/RotateDrawable.java +++ b/graphics/java/android/graphics/drawable/RotateDrawable.java @@ -54,7 +54,7 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { *

Create a new rotating drawable with an empty state.

*/ public RotateDrawable() { - this(null); + this(null, null); } /** @@ -64,8 +64,8 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { * * @param rotateState the state for this drawable */ - private RotateDrawable(RotateState rotateState) { - mState = new RotateState(rotateState, this); + private RotateDrawable(RotateState rotateState, Resources res) { + mState = new RotateState(rotateState, this, res); } public void draw(Canvas canvas) { @@ -291,9 +291,13 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { private boolean mCanConstantState; private boolean mCheckedConstantState; - public RotateState(RotateState source, RotateDrawable owner) { + public RotateState(RotateState source, RotateDrawable owner, Resources res) { if (source != null) { - mDrawable = source.mDrawable.getConstantState().newDrawable(); + if (res != null) { + mDrawable = source.mDrawable.getConstantState().newDrawable(res); + } else { + mDrawable = source.mDrawable.getConstantState().newDrawable(); + } mDrawable.setCallback(owner); mPivotXRel = source.mPivotXRel; mPivotX = source.mPivotX; @@ -307,7 +311,12 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { @Override public Drawable newDrawable() { - return new RotateDrawable(this); + return new RotateDrawable(this, null); + } + + @Override + public Drawable newDrawable(Resources res) { + return new RotateDrawable(this, res); } @Override diff --git a/graphics/java/android/graphics/drawable/ScaleDrawable.java b/graphics/java/android/graphics/drawable/ScaleDrawable.java index 7125ab1e689e8..275e36f4730f3 100644 --- a/graphics/java/android/graphics/drawable/ScaleDrawable.java +++ b/graphics/java/android/graphics/drawable/ScaleDrawable.java @@ -47,11 +47,11 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { private final Rect mTmpRect = new Rect(); ScaleDrawable() { - this(null); + this(null, null); } public ScaleDrawable(Drawable drawable, int gravity, float scaleWidth, float scaleHeight) { - this(null); + this(null, null); mScaleState.mDrawable = drawable; mScaleState.mGravity = gravity; @@ -260,9 +260,13 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { private boolean mCheckedConstantState; private boolean mCanConstantState; - ScaleState(ScaleState orig, ScaleDrawable owner) { + ScaleState(ScaleState orig, ScaleDrawable owner, Resources res) { if (orig != null) { - mDrawable = orig.mDrawable.getConstantState().newDrawable(); + if (res != null) { + mDrawable = orig.mDrawable.getConstantState().newDrawable(res); + } else { + mDrawable = orig.mDrawable.getConstantState().newDrawable(); + } mDrawable.setCallback(owner); mScaleWidth = orig.mScaleWidth; mScaleHeight = orig.mScaleHeight; @@ -273,7 +277,12 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { @Override public Drawable newDrawable() { - return new ScaleDrawable(this); + return new ScaleDrawable(this, null); + } + + @Override + public Drawable newDrawable(Resources res) { + return new ScaleDrawable(this, res); } @Override @@ -291,8 +300,8 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { } } - private ScaleDrawable(ScaleState state) { - mScaleState = new ScaleState(state, this); + private ScaleDrawable(ScaleState state, Resources res) { + mScaleState = new ScaleState(state, this, res); } } diff --git a/graphics/java/android/graphics/drawable/ShapeDrawable.java b/graphics/java/android/graphics/drawable/ShapeDrawable.java index 6677a3560de38..c699a82f0ccd8 100644 --- a/graphics/java/android/graphics/drawable/ShapeDrawable.java +++ b/graphics/java/android/graphics/drawable/ShapeDrawable.java @@ -395,6 +395,11 @@ public class ShapeDrawable extends Drawable { return new ShapeDrawable(this); } + @Override + public Drawable newDrawable(Resources res) { + return new ShapeDrawable(this); + } + @Override public int getChangingConfigurations() { return mChangingConfigurations; diff --git a/graphics/java/android/graphics/drawable/StateListDrawable.java b/graphics/java/android/graphics/drawable/StateListDrawable.java index 59cb2268431fa..b1d588e8e606a 100644 --- a/graphics/java/android/graphics/drawable/StateListDrawable.java +++ b/graphics/java/android/graphics/drawable/StateListDrawable.java @@ -65,7 +65,7 @@ public class StateListDrawable extends DrawableContainer { private boolean mMutated; public StateListDrawable() { - this(null); + this(null, null); } /** @@ -248,8 +248,8 @@ public class StateListDrawable extends DrawableContainer { static final class StateListState extends DrawableContainerState { private int[][] mStateSets; - StateListState(StateListState orig, StateListDrawable owner) { - super(orig, owner); + StateListState(StateListState orig, StateListDrawable owner, Resources res) { + super(orig, owner, res); if (orig != null) { mStateSets = orig.mStateSets; @@ -277,7 +277,12 @@ public class StateListDrawable extends DrawableContainer { @Override public Drawable newDrawable() { - return new StateListDrawable(this); + return new StateListDrawable(this, null); + } + + @Override + public Drawable newDrawable(Resources res) { + return new StateListDrawable(this, res); } @Override @@ -289,8 +294,8 @@ public class StateListDrawable extends DrawableContainer { } } - private StateListDrawable(StateListState state) { - StateListState as = new StateListState(state, this); + private StateListDrawable(StateListState state, Resources res) { + StateListState as = new StateListState(state, this, res); mStateListState = as; setConstantState(as); onStateChange(getState()); diff --git a/graphics/java/android/graphics/drawable/TransitionDrawable.java b/graphics/java/android/graphics/drawable/TransitionDrawable.java index 358f889bc08f1..97b45d8edae98 100644 --- a/graphics/java/android/graphics/drawable/TransitionDrawable.java +++ b/graphics/java/android/graphics/drawable/TransitionDrawable.java @@ -16,6 +16,7 @@ package android.graphics.drawable; +import android.content.res.Resources; import android.graphics.Canvas; import android.os.SystemClock; @@ -72,7 +73,7 @@ public class TransitionDrawable extends LayerDrawable implements Drawable.Callba * 2 layers are required for this drawable to work properly. */ public TransitionDrawable(Drawable[] layers) { - this(new TransitionState(null, null), layers); + this(new TransitionState(null, null, null), layers); } /** @@ -82,11 +83,11 @@ public class TransitionDrawable extends LayerDrawable implements Drawable.Callba * @see #TransitionDrawable(Drawable[]) */ TransitionDrawable() { - this(new TransitionState(null, null)); + this(new TransitionState(null, null, null), (Resources)null); } - private TransitionDrawable(TransitionState state) { - super(state); + private TransitionDrawable(TransitionState state, Resources res) { + super(state, res); } private TransitionDrawable(TransitionState state, Drawable[] layers) { @@ -94,8 +95,8 @@ public class TransitionDrawable extends LayerDrawable implements Drawable.Callba } @Override - LayerState createConstantState(LayerState state) { - return new TransitionState((TransitionState) state, this); + LayerState createConstantState(LayerState state, Resources res) { + return new TransitionState((TransitionState) state, this, res); } /** @@ -229,13 +230,19 @@ public class TransitionDrawable extends LayerDrawable implements Drawable.Callba } static class TransitionState extends LayerState { - TransitionState(TransitionState orig, TransitionDrawable owner) { - super(orig, owner); + TransitionState(TransitionState orig, TransitionDrawable owner, + Resources res) { + super(orig, owner, res); } @Override public Drawable newDrawable() { - return new TransitionDrawable(this); + return new TransitionDrawable(this, (Resources)null); + } + + @Override + public Drawable newDrawable(Resources res) { + return new TransitionDrawable(this, res); } @Override