Fix issue #2116977: buttons are huge and bent
Now that we are using preloaded drawables in compatibilty mode, when constructing them from their constant state we need to set the new drawable's target density appropriately. Change-Id: I3665cbea09d38b9ac5f45f8c380dc8641f86b266
This commit is contained in:
@@ -63352,7 +63352,7 @@
|
|||||||
type="android.graphics.drawable.BitmapDrawable"
|
type="android.graphics.drawable.BitmapDrawable"
|
||||||
static="false"
|
static="false"
|
||||||
final="false"
|
final="false"
|
||||||
deprecated="not deprecated"
|
deprecated="deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="filepath" type="java.lang.String">
|
<parameter name="filepath" type="java.lang.String">
|
||||||
@@ -63365,6 +63365,30 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
|
<parameter name="res" type="android.content.res.Resources">
|
||||||
|
</parameter>
|
||||||
|
<parameter name="filepath" type="java.lang.String">
|
||||||
|
</parameter>
|
||||||
|
</constructor>
|
||||||
|
<constructor name="BitmapDrawable"
|
||||||
|
type="android.graphics.drawable.BitmapDrawable"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="is" type="java.io.InputStream">
|
||||||
|
</parameter>
|
||||||
|
</constructor>
|
||||||
|
<constructor name="BitmapDrawable"
|
||||||
|
type="android.graphics.drawable.BitmapDrawable"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="res" type="android.content.res.Resources">
|
||||||
|
</parameter>
|
||||||
<parameter name="is" type="java.io.InputStream">
|
<parameter name="is" type="java.io.InputStream">
|
||||||
</parameter>
|
</parameter>
|
||||||
</constructor>
|
</constructor>
|
||||||
@@ -64543,6 +64567,19 @@
|
|||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="newDrawable"
|
||||||
|
return="android.graphics.drawable.Drawable"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="res" type="android.content.res.Resources">
|
||||||
|
</parameter>
|
||||||
|
</method>
|
||||||
</class>
|
</class>
|
||||||
<class name="DrawableContainer"
|
<class name="DrawableContainer"
|
||||||
extends="android.graphics.drawable.Drawable"
|
extends="android.graphics.drawable.Drawable"
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
|
|||||||
Drawable.ConstantState cachedBg = mBackgroundsCache.get(backgroundColor);
|
Drawable.ConstantState cachedBg = mBackgroundsCache.get(backgroundColor);
|
||||||
if (cachedBg != null) {
|
if (cachedBg != null) {
|
||||||
if (DBG) Log.d(LOG_TAG, "Background cache hit for color " + backgroundColor);
|
if (DBG) Log.d(LOG_TAG, "Background cache hit for color " + backgroundColor);
|
||||||
return cachedBg.newDrawable();
|
return cachedBg.newDrawable(mProviderContext.getResources());
|
||||||
}
|
}
|
||||||
if (DBG) Log.d(LOG_TAG, "Creating new background for color " + backgroundColor);
|
if (DBG) Log.d(LOG_TAG, "Creating new background for color " + backgroundColor);
|
||||||
ColorDrawable transparent = new ColorDrawable(0);
|
ColorDrawable transparent = new ColorDrawable(0);
|
||||||
@@ -572,7 +572,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
|
|||||||
Drawable.ConstantState cached = mOutsideDrawablesCache.get(drawableId);
|
Drawable.ConstantState cached = mOutsideDrawablesCache.get(drawableId);
|
||||||
if (cached != null) {
|
if (cached != null) {
|
||||||
if (DBG) Log.d(LOG_TAG, "Found icon in cache: " + drawableId);
|
if (DBG) Log.d(LOG_TAG, "Found icon in cache: " + drawableId);
|
||||||
return cached.newDrawable();
|
return cached.newDrawable(mProviderContext.getResources());
|
||||||
}
|
}
|
||||||
|
|
||||||
Drawable drawable = null;
|
Drawable drawable = null;
|
||||||
@@ -663,7 +663,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
|
|||||||
// Using containsKey() since we also store null values.
|
// Using containsKey() since we also store null values.
|
||||||
if (mOutsideDrawablesCache.containsKey(componentIconKey)) {
|
if (mOutsideDrawablesCache.containsKey(componentIconKey)) {
|
||||||
Drawable.ConstantState cached = mOutsideDrawablesCache.get(componentIconKey);
|
Drawable.ConstantState cached = mOutsideDrawablesCache.get(componentIconKey);
|
||||||
return cached == null ? null : cached.newDrawable();
|
return cached == null ? null : cached.newDrawable(mProviderContext.getResources());
|
||||||
}
|
}
|
||||||
// Then try the activity or application icon
|
// Then try the activity or application icon
|
||||||
Drawable drawable = getActivityIcon(component);
|
Drawable drawable = getActivityIcon(component);
|
||||||
|
|||||||
@@ -1662,7 +1662,7 @@ public class Resources {
|
|||||||
|
|
||||||
Drawable.ConstantState cs = sPreloadedDrawables.get(key);
|
Drawable.ConstantState cs = sPreloadedDrawables.get(key);
|
||||||
if (cs != null) {
|
if (cs != null) {
|
||||||
dr = cs.newDrawable();
|
dr = cs.newDrawable(this);
|
||||||
} else {
|
} else {
|
||||||
if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
|
if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
|
||||||
value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
|
value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
|
||||||
@@ -1743,7 +1743,7 @@ public class Resources {
|
|||||||
//Log.i(TAG, "Returning cached drawable @ #" +
|
//Log.i(TAG, "Returning cached drawable @ #" +
|
||||||
// Integer.toHexString(((Integer)key).intValue())
|
// Integer.toHexString(((Integer)key).intValue())
|
||||||
// + " in " + this + ": " + entry);
|
// + " in " + this + ": " + entry);
|
||||||
return entry.newDrawable();
|
return entry.newDrawable(this);
|
||||||
}
|
}
|
||||||
else { // our entry has been purged
|
else { // our entry has been purged
|
||||||
mDrawableCache.delete(key);
|
mDrawableCache.delete(key);
|
||||||
|
|||||||
@@ -282,7 +282,9 @@ public final class IconMenuView extends ViewGroup implements ItemInvoker, MenuVi
|
|||||||
itemView.setIconMenuView(this);
|
itemView.setIconMenuView(this);
|
||||||
|
|
||||||
// Apply the background to the item view
|
// 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
|
// This class is the invoker for all its item views
|
||||||
itemView.setItemInvoker(this);
|
itemView.setItemInvoker(this);
|
||||||
|
|||||||
@@ -45,11 +45,11 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac
|
|||||||
private boolean mRunning;
|
private boolean mRunning;
|
||||||
|
|
||||||
public AnimatedRotateDrawable() {
|
public AnimatedRotateDrawable() {
|
||||||
this(null);
|
this(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AnimatedRotateDrawable(AnimatedRotateState rotateState) {
|
private AnimatedRotateDrawable(AnimatedRotateState rotateState, Resources res) {
|
||||||
mState = new AnimatedRotateState(rotateState, this);
|
mState = new AnimatedRotateState(rotateState, this, res);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,9 +296,14 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac
|
|||||||
private boolean mCanConstantState;
|
private boolean mCanConstantState;
|
||||||
private boolean mCheckedConstantState;
|
private boolean mCheckedConstantState;
|
||||||
|
|
||||||
public AnimatedRotateState(AnimatedRotateState source, AnimatedRotateDrawable owner) {
|
public AnimatedRotateState(AnimatedRotateState source, AnimatedRotateDrawable owner,
|
||||||
|
Resources res) {
|
||||||
if (source != null) {
|
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);
|
mDrawable.setCallback(owner);
|
||||||
mPivotXRel = source.mPivotXRel;
|
mPivotXRel = source.mPivotXRel;
|
||||||
mPivotX = source.mPivotX;
|
mPivotX = source.mPivotX;
|
||||||
@@ -312,7 +317,12 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable newDrawable() {
|
public Drawable newDrawable() {
|
||||||
return new AnimatedRotateDrawable(this);
|
return new AnimatedRotateDrawable(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(Resources res) {
|
||||||
|
return new AnimatedRotateDrawable(this, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
|
|||||||
private boolean mMutated;
|
private boolean mMutated;
|
||||||
|
|
||||||
public AnimationDrawable() {
|
public AnimationDrawable() {
|
||||||
this(null);
|
this(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -297,8 +297,9 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
|
|||||||
private int[] mDurations;
|
private int[] mDurations;
|
||||||
private boolean mOneShot;
|
private boolean mOneShot;
|
||||||
|
|
||||||
AnimationState(AnimationState orig, AnimationDrawable owner) {
|
AnimationState(AnimationState orig, AnimationDrawable owner,
|
||||||
super(orig, owner);
|
Resources res) {
|
||||||
|
super(orig, owner, res);
|
||||||
|
|
||||||
if (orig != null) {
|
if (orig != null) {
|
||||||
mDurations = orig.mDurations;
|
mDurations = orig.mDurations;
|
||||||
@@ -311,7 +312,12 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable newDrawable() {
|
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) {
|
public void addFrame(Drawable dr, int dur) {
|
||||||
@@ -330,8 +336,8 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private AnimationDrawable(AnimationState state) {
|
private AnimationDrawable(AnimationState state, Resources res) {
|
||||||
AnimationState as = new AnimationState(state, this);
|
AnimationState as = new AnimationState(state, this, res);
|
||||||
mAnimationState = as;
|
mAnimationState = as;
|
||||||
setConstantState(as);
|
setConstantState(as);
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
|
|||||||
@@ -60,15 +60,15 @@ public class BitmapDrawable extends Drawable {
|
|||||||
Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG;
|
Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG;
|
||||||
private BitmapState mBitmapState;
|
private BitmapState mBitmapState;
|
||||||
private Bitmap mBitmap;
|
private Bitmap mBitmap;
|
||||||
|
private int mTargetDensity;
|
||||||
|
|
||||||
private final Rect mDstRect = new Rect(); // Gravity.apply() sets this
|
private final Rect mDstRect = new Rect(); // Gravity.apply() sets this
|
||||||
|
|
||||||
private boolean mApplyGravity;
|
private boolean mApplyGravity;
|
||||||
private boolean mRebuildShader;
|
private boolean mRebuildShader;
|
||||||
private boolean mMutated;
|
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 mBitmapWidth;
|
||||||
private int mBitmapHeight;
|
private int mBitmapHeight;
|
||||||
|
|
||||||
@@ -88,10 +88,7 @@ public class BitmapDrawable extends Drawable {
|
|||||||
*/
|
*/
|
||||||
public BitmapDrawable(Resources res) {
|
public BitmapDrawable(Resources res) {
|
||||||
mBitmapState = new BitmapState((Bitmap) null);
|
mBitmapState = new BitmapState((Bitmap) null);
|
||||||
if (res != null) {
|
mBitmapState.mTargetDensity = mTargetDensity;
|
||||||
setTargetDensity(res.getDisplayMetrics());
|
|
||||||
mBitmapState.mTargetDensity = mTargetDensity;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,7 +98,7 @@ public class BitmapDrawable extends Drawable {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public BitmapDrawable(Bitmap bitmap) {
|
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.
|
* the display metrics of the resources.
|
||||||
*/
|
*/
|
||||||
public BitmapDrawable(Resources res, Bitmap bitmap) {
|
public BitmapDrawable(Resources res, Bitmap bitmap) {
|
||||||
this(new BitmapState(bitmap));
|
this(new BitmapState(bitmap), res);
|
||||||
if (res != null) {
|
mBitmapState.mTargetDensity = mTargetDensity;
|
||||||
setTargetDensity(res.getDisplayMetrics());
|
|
||||||
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) {
|
public BitmapDrawable(String filepath) {
|
||||||
this(new BitmapState(BitmapFactory.decodeFile(filepath)));
|
this(new BitmapState(BitmapFactory.decodeFile(filepath)), null);
|
||||||
if (mBitmap == null) {
|
if (mBitmap == null) {
|
||||||
android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + filepath);
|
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) {
|
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) {
|
if (mBitmap == null) {
|
||||||
android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + is);
|
android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + is);
|
||||||
}
|
}
|
||||||
@@ -425,7 +451,12 @@ public class BitmapDrawable extends Drawable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable newDrawable() {
|
public Drawable newDrawable() {
|
||||||
return new BitmapDrawable(this);
|
return new BitmapDrawable(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(Resources res) {
|
||||||
|
return new BitmapDrawable(this, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -434,9 +465,15 @@ public class BitmapDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BitmapDrawable(BitmapState state) {
|
private BitmapDrawable(BitmapState state, Resources res) {
|
||||||
mBitmapState = state;
|
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);
|
setBitmap(state.mBitmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,14 +48,14 @@ public class ClipDrawable extends Drawable implements Drawable.Callback {
|
|||||||
public static final int VERTICAL = 2;
|
public static final int VERTICAL = 2;
|
||||||
|
|
||||||
ClipDrawable() {
|
ClipDrawable() {
|
||||||
this(null);
|
this(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param orientation Bitwise-or of {@link #HORIZONTAL} and/or {@link #VERTICAL}
|
* @param orientation Bitwise-or of {@link #HORIZONTAL} and/or {@link #VERTICAL}
|
||||||
*/
|
*/
|
||||||
public ClipDrawable(Drawable drawable, int gravity, int orientation) {
|
public ClipDrawable(Drawable drawable, int gravity, int orientation) {
|
||||||
this(null);
|
this(null, null);
|
||||||
|
|
||||||
mClipState.mDrawable = drawable;
|
mClipState.mDrawable = drawable;
|
||||||
mClipState.mGravity = gravity;
|
mClipState.mGravity = gravity;
|
||||||
@@ -241,9 +241,13 @@ public class ClipDrawable extends Drawable implements Drawable.Callback {
|
|||||||
private boolean mCheckedConstantState;
|
private boolean mCheckedConstantState;
|
||||||
private boolean mCanConstantState;
|
private boolean mCanConstantState;
|
||||||
|
|
||||||
ClipState(ClipState orig, ClipDrawable owner) {
|
ClipState(ClipState orig, ClipDrawable owner, Resources res) {
|
||||||
if (orig != null) {
|
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);
|
mDrawable.setCallback(owner);
|
||||||
mOrientation = orig.mOrientation;
|
mOrientation = orig.mOrientation;
|
||||||
mGravity = orig.mGravity;
|
mGravity = orig.mGravity;
|
||||||
@@ -253,7 +257,12 @@ public class ClipDrawable extends Drawable implements Drawable.Callback {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable newDrawable() {
|
public Drawable newDrawable() {
|
||||||
return new ClipDrawable(this);
|
return new ClipDrawable(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(Resources res) {
|
||||||
|
return new ClipDrawable(this, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -271,8 +280,8 @@ public class ClipDrawable extends Drawable implements Drawable.Callback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClipDrawable(ClipState state) {
|
private ClipDrawable(ClipState state, Resources res) {
|
||||||
mClipState = new ClipState(state, this);
|
mClipState = new ClipState(state, this, res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,6 +145,11 @@ public class ColorDrawable extends Drawable {
|
|||||||
return new ColorDrawable(this);
|
return new ColorDrawable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(Resources res) {
|
||||||
|
return new ColorDrawable(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getChangingConfigurations() {
|
public int getChangingConfigurations() {
|
||||||
return mChangingConfigurations;
|
return mChangingConfigurations;
|
||||||
|
|||||||
@@ -822,7 +822,26 @@ public abstract class Drawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static abstract class ConstantState {
|
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();
|
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();
|
public abstract int getChangingConfigurations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package android.graphics.drawable;
|
package android.graphics.drawable;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
|
|
||||||
public class DrawableContainer extends Drawable implements Drawable.Callback {
|
public class DrawableContainer extends Drawable implements Drawable.Callback {
|
||||||
@@ -285,7 +286,8 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
|||||||
|
|
||||||
boolean mPaddingChecked = false;
|
boolean mPaddingChecked = false;
|
||||||
|
|
||||||
DrawableContainerState(DrawableContainerState orig, DrawableContainer owner) {
|
DrawableContainerState(DrawableContainerState orig, DrawableContainer owner,
|
||||||
|
Resources res) {
|
||||||
mOwner = owner;
|
mOwner = owner;
|
||||||
|
|
||||||
if (orig != null) {
|
if (orig != null) {
|
||||||
@@ -299,7 +301,11 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
|||||||
|
|
||||||
final int N = mNumChildren;
|
final int N = mNumChildren;
|
||||||
for (int i=0; i<N; i++) {
|
for (int i=0; i<N; i++) {
|
||||||
mDrawables[i] = origDr[i].getConstantState().newDrawable();
|
if (res != null) {
|
||||||
|
mDrawables[i] = origDr[i].getConstantState().newDrawable(res);
|
||||||
|
} else {
|
||||||
|
mDrawables[i] = origDr[i].getConstantState().newDrawable();
|
||||||
|
}
|
||||||
mDrawables[i].setCallback(owner);
|
mDrawables[i].setCallback(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -916,6 +916,11 @@ public class GradientDrawable extends Drawable {
|
|||||||
return new GradientDrawable(this);
|
return new GradientDrawable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(Resources res) {
|
||||||
|
return new GradientDrawable(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getChangingConfigurations() {
|
public int getChangingConfigurations() {
|
||||||
return mChangingConfigurations;
|
return mChangingConfigurations;
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class InsetDrawable extends Drawable implements Drawable.Callback
|
|||||||
private boolean mMutated;
|
private boolean mMutated;
|
||||||
|
|
||||||
/*package*/ InsetDrawable() {
|
/*package*/ InsetDrawable() {
|
||||||
this(null);
|
this(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InsetDrawable(Drawable drawable, int inset) {
|
public InsetDrawable(Drawable drawable, int inset) {
|
||||||
@@ -58,7 +58,7 @@ public class InsetDrawable extends Drawable implements Drawable.Callback
|
|||||||
|
|
||||||
public InsetDrawable(Drawable drawable, int insetLeft, int insetTop,
|
public InsetDrawable(Drawable drawable, int insetLeft, int insetTop,
|
||||||
int insetRight, int insetBottom) {
|
int insetRight, int insetBottom) {
|
||||||
this(null);
|
this(null, null);
|
||||||
|
|
||||||
mInsetState.mDrawable = drawable;
|
mInsetState.mDrawable = drawable;
|
||||||
mInsetState.mInsetLeft = insetLeft;
|
mInsetState.mInsetLeft = insetLeft;
|
||||||
@@ -263,9 +263,13 @@ public class InsetDrawable extends Drawable implements Drawable.Callback
|
|||||||
boolean mCheckedConstantState;
|
boolean mCheckedConstantState;
|
||||||
boolean mCanConstantState;
|
boolean mCanConstantState;
|
||||||
|
|
||||||
InsetState(InsetState orig, InsetDrawable owner) {
|
InsetState(InsetState orig, InsetDrawable owner, Resources res) {
|
||||||
if (orig != null) {
|
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);
|
mDrawable.setCallback(owner);
|
||||||
mInsetLeft = orig.mInsetLeft;
|
mInsetLeft = orig.mInsetLeft;
|
||||||
mInsetTop = orig.mInsetTop;
|
mInsetTop = orig.mInsetTop;
|
||||||
@@ -277,7 +281,12 @@ public class InsetDrawable extends Drawable implements Drawable.Callback
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable newDrawable() {
|
public Drawable newDrawable() {
|
||||||
return new InsetDrawable(this);
|
return new InsetDrawable(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(Resources res) {
|
||||||
|
return new InsetDrawable(this, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -295,8 +304,8 @@ public class InsetDrawable extends Drawable implements Drawable.Callback
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private InsetDrawable(InsetState state) {
|
private InsetDrawable(InsetState state, Resources res) {
|
||||||
mInsetState = new InsetState(state, this);
|
mInsetState = new InsetState(state, this, res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
|
|||||||
* @param state The constant drawable state.
|
* @param state The constant drawable state.
|
||||||
*/
|
*/
|
||||||
LayerDrawable(Drawable[] layers, LayerState state) {
|
LayerDrawable(Drawable[] layers, LayerState state) {
|
||||||
this(state);
|
this(state, null);
|
||||||
int length = layers.length;
|
int length = layers.length;
|
||||||
ChildDrawable[] r = new ChildDrawable[length];
|
ChildDrawable[] r = new ChildDrawable[length];
|
||||||
|
|
||||||
@@ -87,19 +87,19 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LayerDrawable() {
|
LayerDrawable() {
|
||||||
this((LayerState) null);
|
this((LayerState) null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
LayerDrawable(LayerState state) {
|
LayerDrawable(LayerState state, Resources res) {
|
||||||
LayerState as = createConstantState(state);
|
LayerState as = createConstantState(state, res);
|
||||||
mLayerState = as;
|
mLayerState = as;
|
||||||
if (as.mNum > 0) {
|
if (as.mNum > 0) {
|
||||||
ensurePadding();
|
ensurePadding();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LayerState createConstantState(LayerState state) {
|
LayerState createConstantState(LayerState state, Resources res) {
|
||||||
return new LayerState(state, this);
|
return new LayerState(state, this, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -563,7 +563,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
|
|||||||
private boolean mCheckedConstantState;
|
private boolean mCheckedConstantState;
|
||||||
private boolean mCanConstantState;
|
private boolean mCanConstantState;
|
||||||
|
|
||||||
LayerState(LayerState orig, LayerDrawable owner) {
|
LayerState(LayerState orig, LayerDrawable owner, Resources res) {
|
||||||
if (orig != null) {
|
if (orig != null) {
|
||||||
final ChildDrawable[] origChildDrawable = orig.mChildren;
|
final ChildDrawable[] origChildDrawable = orig.mChildren;
|
||||||
final int N = orig.mNum;
|
final int N = orig.mNum;
|
||||||
@@ -577,7 +577,11 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
|
|||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
final ChildDrawable r = mChildren[i] = new ChildDrawable();
|
final ChildDrawable r = mChildren[i] = new ChildDrawable();
|
||||||
final ChildDrawable or = origChildDrawable[i];
|
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.mDrawable.setCallback(owner);
|
||||||
r.mInsetL = or.mInsetL;
|
r.mInsetL = or.mInsetL;
|
||||||
r.mInsetT = or.mInsetT;
|
r.mInsetT = or.mInsetT;
|
||||||
@@ -599,7 +603,12 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable newDrawable() {
|
public Drawable newDrawable() {
|
||||||
return new LayerDrawable(this);
|
return new LayerDrawable(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(Resources res) {
|
||||||
|
return new LayerDrawable(this, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class LevelListDrawable extends DrawableContainer {
|
|||||||
private boolean mMutated;
|
private boolean mMutated;
|
||||||
|
|
||||||
public LevelListDrawable() {
|
public LevelListDrawable() {
|
||||||
this(null);
|
this(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLevel(int low, int high, Drawable drawable) {
|
public void addLevel(int low, int high, Drawable drawable) {
|
||||||
@@ -154,8 +154,8 @@ public class LevelListDrawable extends DrawableContainer {
|
|||||||
private int[] mLows;
|
private int[] mLows;
|
||||||
private int[] mHighs;
|
private int[] mHighs;
|
||||||
|
|
||||||
LevelListState(LevelListState orig, LevelListDrawable owner) {
|
LevelListState(LevelListState orig, LevelListDrawable owner, Resources res) {
|
||||||
super(orig, owner);
|
super(orig, owner, res);
|
||||||
|
|
||||||
if (orig != null) {
|
if (orig != null) {
|
||||||
mLows = orig.mLows;
|
mLows = orig.mLows;
|
||||||
@@ -186,7 +186,12 @@ public class LevelListDrawable extends DrawableContainer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable newDrawable() {
|
public Drawable newDrawable() {
|
||||||
return new LevelListDrawable(this);
|
return new LevelListDrawable(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(Resources res) {
|
||||||
|
return new LevelListDrawable(this, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -201,8 +206,8 @@ public class LevelListDrawable extends DrawableContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private LevelListDrawable(LevelListState state) {
|
private LevelListDrawable(LevelListState state, Resources res) {
|
||||||
LevelListState as = new LevelListState(state, this);
|
LevelListState as = new LevelListState(state, this, res);
|
||||||
mLevelListState = as;
|
mLevelListState = as;
|
||||||
setConstantState(as);
|
setConstantState(as);
|
||||||
onLevelChange(getLevel());
|
onLevelChange(getLevel());
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class NinePatchDrawable extends Drawable {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public NinePatchDrawable(Bitmap bitmap, byte[] chunk, Rect padding, String srcName) {
|
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,
|
public NinePatchDrawable(Resources res, Bitmap bitmap, byte[] chunk,
|
||||||
Rect padding, String srcName) {
|
Rect padding, String srcName) {
|
||||||
this(new NinePatchState(new NinePatch(bitmap, chunk, srcName), padding));
|
this(new NinePatchState(new NinePatch(bitmap, chunk, srcName), padding), res);
|
||||||
if (res != null) {
|
mNinePatchState.mTargetDensity = mTargetDensity;
|
||||||
setTargetDensity(res.getDisplayMetrics());
|
|
||||||
mNinePatchState.mTargetDensity = mTargetDensity;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +81,7 @@ public class NinePatchDrawable extends Drawable {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public NinePatchDrawable(NinePatch patch) {
|
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.
|
* based on the display metrics of the resources.
|
||||||
*/
|
*/
|
||||||
public NinePatchDrawable(Resources res, NinePatch patch) {
|
public NinePatchDrawable(Resources res, NinePatch patch) {
|
||||||
this(new NinePatchState(patch, null));
|
this(new NinePatchState(patch, null), res);
|
||||||
if (res != null) {
|
mNinePatchState.mTargetDensity = mTargetDensity;
|
||||||
setTargetDensity(res.getDisplayMetrics());
|
|
||||||
mNinePatchState.mTargetDensity = mTargetDensity;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNinePatchState(NinePatchState state) {
|
private void setNinePatchState(NinePatchState state, Resources res) {
|
||||||
mNinePatchState = state;
|
mNinePatchState = state;
|
||||||
mNinePatch = state.mNinePatch;
|
mNinePatch = state.mNinePatch;
|
||||||
mPadding = state.mPadding;
|
mPadding = state.mPadding;
|
||||||
mTargetDensity = state.mTargetDensity;
|
mTargetDensity = res != null ? res.getDisplayMetrics().densityDpi
|
||||||
|
: state.mTargetDensity;
|
||||||
if (DEFAULT_DITHER != state.mDither) {
|
if (DEFAULT_DITHER != state.mDither) {
|
||||||
// avoid calling the setter unless we need to, since it does a
|
// avoid calling the setter unless we need to, since it does a
|
||||||
// lazy allocation of a paint
|
// lazy allocation of a paint
|
||||||
@@ -258,7 +253,8 @@ public class NinePatchDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setNinePatchState(new NinePatchState(
|
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;
|
mNinePatchState.mTargetDensity = mTargetDensity;
|
||||||
|
|
||||||
a.recycle();
|
a.recycle();
|
||||||
@@ -357,7 +353,12 @@ public class NinePatchDrawable extends Drawable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable newDrawable() {
|
public Drawable newDrawable() {
|
||||||
return new NinePatchDrawable(this);
|
return new NinePatchDrawable(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(Resources res) {
|
||||||
|
return new NinePatchDrawable(this, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -366,8 +367,7 @@ public class NinePatchDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private NinePatchDrawable(NinePatchState state) {
|
private NinePatchDrawable(NinePatchState state, Resources res) {
|
||||||
setNinePatchState(state);
|
setNinePatchState(state, res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class RotateDrawable extends Drawable implements Drawable.Callback {
|
|||||||
* <p>Create a new rotating drawable with an empty state.</p>
|
* <p>Create a new rotating drawable with an empty state.</p>
|
||||||
*/
|
*/
|
||||||
public RotateDrawable() {
|
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
|
* @param rotateState the state for this drawable
|
||||||
*/
|
*/
|
||||||
private RotateDrawable(RotateState rotateState) {
|
private RotateDrawable(RotateState rotateState, Resources res) {
|
||||||
mState = new RotateState(rotateState, this);
|
mState = new RotateState(rotateState, this, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
@@ -291,9 +291,13 @@ public class RotateDrawable extends Drawable implements Drawable.Callback {
|
|||||||
private boolean mCanConstantState;
|
private boolean mCanConstantState;
|
||||||
private boolean mCheckedConstantState;
|
private boolean mCheckedConstantState;
|
||||||
|
|
||||||
public RotateState(RotateState source, RotateDrawable owner) {
|
public RotateState(RotateState source, RotateDrawable owner, Resources res) {
|
||||||
if (source != null) {
|
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);
|
mDrawable.setCallback(owner);
|
||||||
mPivotXRel = source.mPivotXRel;
|
mPivotXRel = source.mPivotXRel;
|
||||||
mPivotX = source.mPivotX;
|
mPivotX = source.mPivotX;
|
||||||
@@ -307,7 +311,12 @@ public class RotateDrawable extends Drawable implements Drawable.Callback {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable newDrawable() {
|
public Drawable newDrawable() {
|
||||||
return new RotateDrawable(this);
|
return new RotateDrawable(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(Resources res) {
|
||||||
|
return new RotateDrawable(this, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -47,11 +47,11 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback {
|
|||||||
private final Rect mTmpRect = new Rect();
|
private final Rect mTmpRect = new Rect();
|
||||||
|
|
||||||
ScaleDrawable() {
|
ScaleDrawable() {
|
||||||
this(null);
|
this(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScaleDrawable(Drawable drawable, int gravity, float scaleWidth, float scaleHeight) {
|
public ScaleDrawable(Drawable drawable, int gravity, float scaleWidth, float scaleHeight) {
|
||||||
this(null);
|
this(null, null);
|
||||||
|
|
||||||
mScaleState.mDrawable = drawable;
|
mScaleState.mDrawable = drawable;
|
||||||
mScaleState.mGravity = gravity;
|
mScaleState.mGravity = gravity;
|
||||||
@@ -260,9 +260,13 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback {
|
|||||||
private boolean mCheckedConstantState;
|
private boolean mCheckedConstantState;
|
||||||
private boolean mCanConstantState;
|
private boolean mCanConstantState;
|
||||||
|
|
||||||
ScaleState(ScaleState orig, ScaleDrawable owner) {
|
ScaleState(ScaleState orig, ScaleDrawable owner, Resources res) {
|
||||||
if (orig != null) {
|
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);
|
mDrawable.setCallback(owner);
|
||||||
mScaleWidth = orig.mScaleWidth;
|
mScaleWidth = orig.mScaleWidth;
|
||||||
mScaleHeight = orig.mScaleHeight;
|
mScaleHeight = orig.mScaleHeight;
|
||||||
@@ -273,7 +277,12 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable newDrawable() {
|
public Drawable newDrawable() {
|
||||||
return new ScaleDrawable(this);
|
return new ScaleDrawable(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(Resources res) {
|
||||||
|
return new ScaleDrawable(this, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -291,8 +300,8 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScaleDrawable(ScaleState state) {
|
private ScaleDrawable(ScaleState state, Resources res) {
|
||||||
mScaleState = new ScaleState(state, this);
|
mScaleState = new ScaleState(state, this, res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -395,6 +395,11 @@ public class ShapeDrawable extends Drawable {
|
|||||||
return new ShapeDrawable(this);
|
return new ShapeDrawable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(Resources res) {
|
||||||
|
return new ShapeDrawable(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getChangingConfigurations() {
|
public int getChangingConfigurations() {
|
||||||
return mChangingConfigurations;
|
return mChangingConfigurations;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class StateListDrawable extends DrawableContainer {
|
|||||||
private boolean mMutated;
|
private boolean mMutated;
|
||||||
|
|
||||||
public StateListDrawable() {
|
public StateListDrawable() {
|
||||||
this(null);
|
this(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -248,8 +248,8 @@ public class StateListDrawable extends DrawableContainer {
|
|||||||
static final class StateListState extends DrawableContainerState {
|
static final class StateListState extends DrawableContainerState {
|
||||||
private int[][] mStateSets;
|
private int[][] mStateSets;
|
||||||
|
|
||||||
StateListState(StateListState orig, StateListDrawable owner) {
|
StateListState(StateListState orig, StateListDrawable owner, Resources res) {
|
||||||
super(orig, owner);
|
super(orig, owner, res);
|
||||||
|
|
||||||
if (orig != null) {
|
if (orig != null) {
|
||||||
mStateSets = orig.mStateSets;
|
mStateSets = orig.mStateSets;
|
||||||
@@ -277,7 +277,12 @@ public class StateListDrawable extends DrawableContainer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable newDrawable() {
|
public Drawable newDrawable() {
|
||||||
return new StateListDrawable(this);
|
return new StateListDrawable(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(Resources res) {
|
||||||
|
return new StateListDrawable(this, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -289,8 +294,8 @@ public class StateListDrawable extends DrawableContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private StateListDrawable(StateListState state) {
|
private StateListDrawable(StateListState state, Resources res) {
|
||||||
StateListState as = new StateListState(state, this);
|
StateListState as = new StateListState(state, this, res);
|
||||||
mStateListState = as;
|
mStateListState = as;
|
||||||
setConstantState(as);
|
setConstantState(as);
|
||||||
onStateChange(getState());
|
onStateChange(getState());
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package android.graphics.drawable;
|
package android.graphics.drawable;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.os.SystemClock;
|
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.
|
* 2 layers are required for this drawable to work properly.
|
||||||
*/
|
*/
|
||||||
public TransitionDrawable(Drawable[] layers) {
|
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[])
|
* @see #TransitionDrawable(Drawable[])
|
||||||
*/
|
*/
|
||||||
TransitionDrawable() {
|
TransitionDrawable() {
|
||||||
this(new TransitionState(null, null));
|
this(new TransitionState(null, null, null), (Resources)null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TransitionDrawable(TransitionState state) {
|
private TransitionDrawable(TransitionState state, Resources res) {
|
||||||
super(state);
|
super(state, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TransitionDrawable(TransitionState state, Drawable[] layers) {
|
private TransitionDrawable(TransitionState state, Drawable[] layers) {
|
||||||
@@ -94,8 +95,8 @@ public class TransitionDrawable extends LayerDrawable implements Drawable.Callba
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
LayerState createConstantState(LayerState state) {
|
LayerState createConstantState(LayerState state, Resources res) {
|
||||||
return new TransitionState((TransitionState) state, this);
|
return new TransitionState((TransitionState) state, this, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -229,13 +230,19 @@ public class TransitionDrawable extends LayerDrawable implements Drawable.Callba
|
|||||||
}
|
}
|
||||||
|
|
||||||
static class TransitionState extends LayerState {
|
static class TransitionState extends LayerState {
|
||||||
TransitionState(TransitionState orig, TransitionDrawable owner) {
|
TransitionState(TransitionState orig, TransitionDrawable owner,
|
||||||
super(orig, owner);
|
Resources res) {
|
||||||
|
super(orig, owner, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable newDrawable() {
|
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
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user