summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alan Viverette <alanv@google.com> 2015-11-06 19:09:31 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2015-11-06 19:09:31 +0000
commitd5010c7df51d08280421cc89af2856333f907fa0 (patch)
tree51a98e2974567271dc6fa58defc6f3899db4adf7
parentc69a11fb7ae2b2fa12f9125aaf1567c4786612ac (diff)
parent1259f616c26f89dd5000745d7c364fae41b23682 (diff)
Merge "Use ConstantState directly instead of ConstantStateFuture"
-rw-r--r--graphics/java/android/graphics/drawable/DrawableContainer.java71
1 files changed, 20 insertions, 51 deletions
diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java
index b2044e1dcb4b..10d862e37514 100644
--- a/graphics/java/android/graphics/drawable/DrawableContainer.java
+++ b/graphics/java/android/graphics/drawable/DrawableContainer.java
@@ -656,7 +656,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
int mChangingConfigurations;
int mChildrenChangingConfigurations;
- SparseArray<ConstantStateFuture> mDrawableFutures;
+ SparseArray<ConstantState> mDrawableFutures;
Drawable[] mDrawables;
int mNumChildren;
@@ -757,7 +757,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
mDrawables = new Drawable[origDr.length];
mNumChildren = orig.mNumChildren;
- final SparseArray<ConstantStateFuture> origDf = orig.mDrawableFutures;
+ final SparseArray<ConstantState> origDf = orig.mDrawableFutures;
if (origDf != null) {
mDrawableFutures = origDf.clone();
} else {
@@ -770,8 +770,9 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
final int N = mNumChildren;
for (int i = 0; i < N; i++) {
if (origDr[i] != null) {
- if (origDr[i].getConstantState() != null) {
- mDrawableFutures.put(i, new ConstantStateFuture(origDr[i]));
+ final ConstantState cs = origDr[i].getConstantState();
+ if (cs != null) {
+ mDrawableFutures.put(i, cs);
} else {
mDrawables[i] = origDr[i];
}
@@ -815,18 +816,28 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
return mDrawables.length;
}
- private final void createAllFutures() {
+ private void createAllFutures() {
if (mDrawableFutures != null) {
final int futureCount = mDrawableFutures.size();
for (int keyIndex = 0; keyIndex < futureCount; keyIndex++) {
final int index = mDrawableFutures.keyAt(keyIndex);
- mDrawables[index] = mDrawableFutures.valueAt(keyIndex).get(this);
+ final ConstantState cs = mDrawableFutures.valueAt(keyIndex);
+ mDrawables[index] = prepareDrawable(cs.newDrawable(mSourceRes));
}
mDrawableFutures = null;
}
}
+ private Drawable prepareDrawable(Drawable child) {
+ child.setLayoutDirection(mLayoutDirection);
+ child.setCallback(mOwner);
+ if (mMutated) {
+ child = child.mutate();
+ }
+ return child;
+ }
+
public final int getChildCount() {
return mNumChildren;
}
@@ -851,7 +862,8 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
if (mDrawableFutures != null) {
final int keyIndex = mDrawableFutures.indexOfKey(index);
if (keyIndex >= 0) {
- final Drawable prepared = mDrawableFutures.valueAt(keyIndex).get(this);
+ final ConstantState cs = mDrawableFutures.valueAt(keyIndex);
+ final Drawable prepared = prepareDrawable(cs.newDrawable(mSourceRes));
mDrawables[index] = prepared;
mDrawableFutures.removeAt(keyIndex);
if (mDrawableFutures.size() == 0) {
@@ -938,7 +950,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
return true;
}
} else {
- final ConstantStateFuture future = mDrawableFutures.get(i);
+ final ConstantState future = mDrawableFutures.get(i);
if (future != null && future.canApplyTheme()) {
return true;
}
@@ -1173,49 +1185,6 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
}
return pixelCount;
}
-
- /**
- * Class capable of cloning a Drawable from another Drawable's
- * ConstantState.
- */
- private static class ConstantStateFuture {
- private final ConstantState mConstantState;
-
- private ConstantStateFuture(Drawable source) {
- mConstantState = source.getConstantState();
- }
-
- /**
- * Obtains and prepares the Drawable represented by this future.
- *
- * @param state the container into which this future will be placed
- * @return a prepared Drawable
- */
- public Drawable get(DrawableContainerState state) {
- final Drawable result;
- if (state.mSourceRes == null) {
- result = mConstantState.newDrawable();
- } else {
- result = mConstantState.newDrawable(state.mSourceRes);
- }
- result.setLayoutDirection(state.mLayoutDirection);
- result.setCallback(state.mOwner);
-
- if (state.mMutated) {
- result.mutate();
- }
-
- return result;
- }
-
- /**
- * Whether the constant state wrapped by this future can apply a
- * theme.
- */
- public boolean canApplyTheme() {
- return mConstantState.canApplyTheme();
- }
- }
}
protected void setConstantState(DrawableContainerState state) {