Fix LayerDrawable#mutate

Change-Id: I985b80141ffc96db969eaf36538df938cb093661
This commit is contained in:
Adam Powell
2012-03-21 14:53:15 -07:00
parent 8dc8a435a1
commit 26e35fca60

View File

@@ -575,6 +575,11 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
@Override
public Drawable mutate() {
if (!mMutated && super.mutate() == this) {
if (!mLayerState.canConstantState()) {
throw new IllegalStateException("One or more children of this LayerDrawable does " +
"not have constant state; this drawable cannot be mutated.");
}
mLayerState = new LayerState(mLayerState, this, null);
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
@@ -694,7 +699,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
return stateful;
}
public synchronized boolean canConstantState() {
public boolean canConstantState() {
if (!mCheckedConstantState && mChildren != null) {
mCanConstantState = true;
final int N = mNum;