Merge "Mutate and apply theme if needed before caching themed drawables" into lmp-mr1-dev

This commit is contained in:
Alan Viverette
2014-10-07 22:09:48 +00:00
committed by Android (Google) Code Review
20 changed files with 201 additions and 1 deletions

View File

@@ -2323,7 +2323,14 @@ public class Resources {
final Drawable dr;
if (cs != null) {
dr = cs.newDrawable(this, theme);
final Drawable clonedDr = cs.newDrawable(this);
if (theme != null) {
dr = clonedDr.mutate();
dr.applyTheme(theme);
dr.clearMutated();
} else {
dr = clonedDr;
}
} else if (isColorDrawable) {
dr = new ColorDrawable(value.data);
} else {

View File

@@ -331,6 +331,15 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mState.mDrawable.clearMutated();
mMutated = false;
}
final static class AnimatedRotateState extends Drawable.ConstantState {
Drawable mDrawable;

View File

@@ -507,6 +507,14 @@ public class AnimatedStateListDrawable extends StateListDrawable {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mMutated = false;
}
static class AnimatedStateListState extends StateListState {
private static final int REVERSE_SHIFT = 32;
private static final int REVERSE_MASK = 0x1;

View File

@@ -157,6 +157,15 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mAnimatedVectorState.mVectorDrawable.clearMutated();
mMutated = false;
}
@Override
public ConstantState getConstantState() {
mAnimatedVectorState.mChangingConfigurations = getChangingConfigurations();

View File

@@ -347,6 +347,14 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mMutated = false;
}
private final static class AnimationState extends DrawableContainerState {
private int[] mDurations;
private boolean mOneShot;

View File

@@ -684,6 +684,14 @@ public class BitmapDrawable extends Drawable {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mMutated = false;
}
@Override
protected boolean onStateChange(int[] stateSet) {
final BitmapState state = mBitmapState;

View File

@@ -55,6 +55,8 @@ public class ClipDrawable extends Drawable implements Drawable.Callback {
public static final int HORIZONTAL = 1;
public static final int VERTICAL = 2;
private boolean mMutated;
ClipDrawable() {
this(null, null);
}
@@ -268,6 +270,24 @@ public class ClipDrawable extends Drawable implements Drawable.Callback {
super.setLayoutDirection(layoutDirection);
}
@Override
public Drawable mutate() {
if (!mMutated && super.mutate() == this) {
mClipState.mDrawable.mutate();
mMutated = true;
}
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mClipState.mDrawable.clearMutated();
mMutated = false;
}
final static class ClipState extends ConstantState {
Drawable mDrawable;
int mChangingConfigurations;

View File

@@ -88,6 +88,14 @@ public class ColorDrawable extends Drawable {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mMutated = false;
}
@Override
public void draw(Canvas canvas) {
final ColorFilter colorFilter = mPaint.getColorFilter();

View File

@@ -916,6 +916,20 @@ public abstract class Drawable {
return this;
}
/**
* Clears the mutated state, allowing this drawable to be cached and
* mutated again.
* <p>
* This is hidden because only framework drawables can be cached, so
* custom drawables don't need to support constant state, mutate(), or
* clearMutated().
*
* @hide
*/
public void clearMutated() {
// Default implementation is no-op.
}
/**
* Create a drawable from an inputstream
*/

View File

@@ -573,6 +573,15 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mDrawableContainerState.clearMutated();
mMutated = false;
}
/**
* A ConstantState that can contain several {@link Drawable}s.
*
@@ -840,6 +849,18 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
mMutated = true;
}
final void clearMutated() {
final int N = mNumChildren;
final Drawable[] drawables = mDrawables;
for (int i = 0; i < N; i++) {
if (drawables[i] != null) {
drawables[i].clearMutated();
}
}
mMutated = false;
}
/**
* A boolean value indicating whether to use the maximum padding value
* of all frames in the set (false), or to use the padding value of the

View File

@@ -1479,6 +1479,14 @@ public class GradientDrawable extends Drawable {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mMutated = false;
}
final static class GradientState extends ConstantState {
public int mChangingConfigurations;
public int mShape = RECTANGLE;

View File

@@ -370,6 +370,15 @@ public class InsetDrawable extends Drawable implements Drawable.Callback {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mInsetState.mDrawable.clearMutated();
mMutated = false;
}
/**
* Returns the drawable wrapped by this InsetDrawable. May be null.
*/

View File

@@ -940,6 +940,19 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
array[i].mDrawable.clearMutated();
}
mMutated = false;
}
/** @hide */
@Override
public void setLayoutDirection(int layoutDirection) {

View File

@@ -153,6 +153,14 @@ public class LevelListDrawable extends DrawableContainer {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mMutated = false;
}
private final static class LevelListState extends DrawableContainerState {
private int[] mLows;
private int[] mHighs;

View File

@@ -563,6 +563,14 @@ public class NinePatchDrawable extends Drawable {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mMutated = false;
}
@Override
protected boolean onStateChange(int[] stateSet) {
final NinePatchState state = mNinePatchState;

View File

@@ -484,6 +484,15 @@ public class RotateDrawable extends Drawable implements Drawable.Callback {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mState.mDrawable.clearMutated();
mMutated = false;
}
/**
* Represents the state of a rotation for a given drawable. The same
* rotate drawable can be invoked with different states to drive several

View File

@@ -276,6 +276,15 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mScaleState.mDrawable.clearMutated();
mMutated = false;
}
final static class ScaleState extends ConstantState {
Drawable mDrawable;
int mChangingConfigurations;

View File

@@ -507,6 +507,14 @@ public class ShapeDrawable extends Drawable {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mMutated = false;
}
/**
* Defines the intrinsic properties of this ShapeDrawable's Shape.
*/

View File

@@ -263,6 +263,14 @@ public class StateListDrawable extends DrawableContainer {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mMutated = false;
}
/** @hide */
@Override
public void setLayoutDirection(int layoutDirection) {

View File

@@ -233,6 +233,14 @@ public class VectorDrawable extends Drawable {
return this;
}
/**
* @hide
*/
public void clearMutated() {
super.clearMutated();
mMutated = false;
}
Object getTargetByName(String name) {
return mVectorState.mVPathRenderer.mVGTargetsMap.get(name);
}