Avoid creating futures for drawables with no constant state

We don't need to create futures for drawables without constant state,
since we only copy on mutate and we don't need to do any work on mutate()
for drawables without shared constant state. Also we would crash in that
case, so avoiding the NPE is nice too.

Rider: Also fixes elevations again.

BUG: 18696100
Change-Id: I4d7737f39ce3efc5830704e5ce412c540603e6ac
This commit is contained in:
Alan Viverette
2014-12-10 13:52:28 -08:00
parent c780187745
commit 62b780e85f
3 changed files with 12 additions and 4 deletions

View File

@@ -714,10 +714,17 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
mDrawableFutures = new SparseArray<ConstantStateFuture>(mNumChildren);
}
// Create futures for drawables with constant states. If a
// drawable doesn't have a constant state, then we can't clone
// it and we'll have to reference the original.
final int N = mNumChildren;
for (int i = 0; i < N; i++) {
if (origDr[i] != null) {
mDrawableFutures.put(i, new ConstantStateFuture(origDr[i]));
if (origDr[i].getConstantState() != null) {
mDrawableFutures.put(i, new ConstantStateFuture(origDr[i]));
} else {
mDrawables[i] = origDr[i];
}
}
}
} else {