diff options
author | Alan Viverette <alanv@google.com> | 2014-11-26 17:16:08 -0800 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2014-11-26 17:16:08 -0800 |
commit | 5ed8f27858dbdf85203068eca46eef0a65f3344e (patch) | |
tree | 18d3ae680c05999405b63b06b5c70d86aafc2f5d /graphics | |
parent | bc3226e21dfe881bf1ccae62e10b660d97b2b232 (diff) | |
download | frameworks_base-5ed8f27858dbdf85203068eca46eef0a65f3344e.zip frameworks_base-5ed8f27858dbdf85203068eca46eef0a65f3344e.tar.gz frameworks_base-5ed8f27858dbdf85203068eca46eef0a65f3344e.tar.bz2 |
Update drawable container constant state following clone
DrawableContainer's internal state was getting out of sync with the
internal state of child classes because we failed to call set state.
BUG: 18542282
Change-Id: Iacaa12042e99c1b9e9eaf08f0ab879d82260e7ee
Diffstat (limited to 'graphics')
4 files changed, 28 insertions, 8 deletions
diff --git a/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java b/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java index 5fc40f2..4af5946 100644 --- a/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java @@ -651,6 +651,7 @@ public class AnimatedStateListDrawable extends StateListDrawable { } } + @Override protected void setConstantState(@NonNull DrawableContainerState state) { super.setConstantState(state); diff --git a/graphics/java/android/graphics/drawable/AnimationDrawable.java b/graphics/java/android/graphics/drawable/AnimationDrawable.java index 28ada82..9eb0251 100644 --- a/graphics/java/android/graphics/drawable/AnimationDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimationDrawable.java @@ -23,6 +23,7 @@ import java.io.IOException; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import android.annotation.NonNull; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.Resources.Theme; @@ -81,7 +82,7 @@ import android.util.AttributeSet; * @attr ref android.R.styleable#AnimationDrawableItem_drawable */ public class AnimationDrawable extends DrawableContainer implements Runnable, Animatable { - private final AnimationState mAnimationState; + private AnimationState mAnimationState; /** The current frame, may be -1 when not animating. */ private int mCurFrame = -1; @@ -408,9 +409,17 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An } } + @Override + protected void setConstantState(@NonNull DrawableContainerState state) { + super.setConstantState(state); + + if (state instanceof AnimationState) { + mAnimationState = (AnimationState) state; + } + } + private AnimationDrawable(AnimationState state, Resources res) { - AnimationState as = new AnimationState(state, this, res); - mAnimationState = as; + final AnimationState as = new AnimationState(state, this, res); setConstantState(as); if (state != null) { setFrame(0, true, false); diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java index 6d43a0c..68fd296 100644 --- a/graphics/java/android/graphics/drawable/DrawableContainer.java +++ b/graphics/java/android/graphics/drawable/DrawableContainer.java @@ -567,8 +567,9 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { @Override public Drawable mutate() { if (!mMutated && super.mutate() == this) { - mDrawableContainerState = cloneConstantState(); - mDrawableContainerState.mutate(); + final DrawableContainerState clone = cloneConstantState(); + clone.mutate(); + setConstantState(clone); mMutated = true; } return this; diff --git a/graphics/java/android/graphics/drawable/LevelListDrawable.java b/graphics/java/android/graphics/drawable/LevelListDrawable.java index dc41216..b01c643 100644 --- a/graphics/java/android/graphics/drawable/LevelListDrawable.java +++ b/graphics/java/android/graphics/drawable/LevelListDrawable.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import android.annotation.NonNull; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.Resources.Theme; @@ -57,7 +58,7 @@ import android.util.AttributeSet; * @attr ref android.R.styleable#LevelListDrawableItem_drawable */ public class LevelListDrawable extends DrawableContainer { - private final LevelListState mLevelListState; + private LevelListState mLevelListState; private boolean mMutated; public LevelListDrawable() { @@ -227,9 +228,17 @@ public class LevelListDrawable extends DrawableContainer { } } + @Override + protected void setConstantState(@NonNull DrawableContainerState state) { + super.setConstantState(state); + + if (state instanceof LevelListState) { + mLevelListState = (LevelListState) state; + } + } + private LevelListDrawable(LevelListState state, Resources res) { - LevelListState as = new LevelListState(state, this, res); - mLevelListState = as; + final LevelListState as = new LevelListState(state, this, res); setConstantState(as); onLevelChange(getLevel()); } |