diff options
author | Alan Viverette <alanv@google.com> | 2015-05-19 00:37:02 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-19 00:37:03 +0000 |
commit | 0c4729a1e468e2b0783a4234e39677d8078473b3 (patch) | |
tree | 561ddec48cb25bb37f98c5c93f0ebe8ca6573445 /graphics | |
parent | f8575f667b88d87207053cca06101bbc1c36f68c (diff) | |
parent | 344ad7126f1e598e4259f128eaeac8a7ef904dd3 (diff) | |
download | frameworks_base-0c4729a1e468e2b0783a4234e39677d8078473b3.zip frameworks_base-0c4729a1e468e2b0783a4234e39677d8078473b3.tar.gz frameworks_base-0c4729a1e468e2b0783a4234e39677d8078473b3.tar.bz2 |
Merge "Revert "Postpone AnimatedVectorDrawable animator inflation until applyTheme()"" into mnc-dev
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java | 119 |
1 files changed, 13 insertions, 106 deletions
diff --git a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java index ea60040..28c26ff 100644 --- a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java @@ -19,7 +19,6 @@ import android.animation.AnimatorInflater; import android.animation.AnimatorSet; import android.animation.Animator.AnimatorListener; import android.annotation.NonNull; -import android.annotation.Nullable; import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.Resources.Theme; @@ -128,19 +127,13 @@ import java.util.List; * @attr ref android.R.styleable#AnimatedVectorDrawableTarget_animation */ public class AnimatedVectorDrawable extends Drawable implements Animatable { - private static final String LOGTAG = "AnimatedVectorDrawable"; + private static final String LOGTAG = AnimatedVectorDrawable.class.getSimpleName(); private static final String ANIMATED_VECTOR = "animated-vector"; private static final String TARGET = "target"; private static final boolean DBG_ANIMATION_VECTOR_DRAWABLE = false; - /** - * The resources against which this drawable was created. Used to attempt - * to inflate animators if applyTheme() doesn't get called. - */ - private Resources mRes; - private AnimatedVectorDrawableState mAnimatedVectorState; private boolean mMutated; @@ -151,7 +144,6 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { private AnimatedVectorDrawable(AnimatedVectorDrawableState state, Resources res) { mAnimatedVectorState = new AnimatedVectorDrawableState(state, mCallback, res); - mRes = res; } @Override @@ -281,7 +273,6 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { @Override public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException { - final AnimatedVectorDrawableState state = mAnimatedVectorState; int eventType = parser.getEventType(); float pathErrorScale = 1; @@ -299,10 +290,10 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { vectorDrawable.setAllowCaching(false); vectorDrawable.setCallback(mCallback); pathErrorScale = vectorDrawable.getPixelSize(); - if (state.mVectorDrawable != null) { - state.mVectorDrawable.setCallback(null); + if (mAnimatedVectorState.mVectorDrawable != null) { + mAnimatedVectorState.mVectorDrawable.setCallback(null); } - state.mVectorDrawable = vectorDrawable; + mAnimatedVectorState.mVectorDrawable = vectorDrawable; } a.recycle(); } else if (TARGET.equals(tagName)) { @@ -311,25 +302,12 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { final String target = a.getString( R.styleable.AnimatedVectorDrawableTarget_name); - final int animResId = a.getResourceId( + int id = a.getResourceId( R.styleable.AnimatedVectorDrawableTarget_animation, 0); - if (animResId != 0) { - if (theme != null) { - final Animator objectAnimator = AnimatorInflater.loadAnimator( - res, theme, animResId, pathErrorScale); - setupAnimatorsForTarget(target, objectAnimator); - } else { - // The animation may be theme-dependent. As a - // workaround until Animator has full support for - // applyTheme(), postpone loading the animator - // until we have a theme in applyTheme(). - if (state.mPendingAnims == null) { - state.mPendingAnims = new ArrayList<>(1); - } - state.mPendingAnims.add( - new PendingAnimator(animResId, pathErrorScale, target)); - - } + if (id != 0) { + Animator objectAnimator = AnimatorInflater.loadAnimator(res, theme, id, + pathErrorScale); + setupAnimatorsForTarget(target, objectAnimator); } a.recycle(); } @@ -337,13 +315,6 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { eventType = parser.next(); } - - // If we don't have any pending animations, we don't need to hold a - // reference to the resources. - if (state.mPendingAnims == null) { - mRes = null; - } - setupAnimatorSet(); } @@ -369,29 +340,6 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { if (vectorDrawable != null && vectorDrawable.canApplyTheme()) { vectorDrawable.applyTheme(t); } - - if (t != null) { - inflatePendingAnimators(t.getResources(), t); - } - } - - /** - * Inflates pending animators, if any, against a theme. Clears the list of - * pending animators. - * - * @param t the theme against which to inflate the animators - */ - private void inflatePendingAnimators(@NonNull Resources res, @Nullable Theme t) { - final ArrayList<PendingAnimator> pendingAnims = mAnimatedVectorState.mPendingAnims; - if (pendingAnims != null) { - mAnimatedVectorState.mPendingAnims = null; - - for (int i = 0, count = pendingAnims.size(); i < count; i++) { - final PendingAnimator pendingAnimator = pendingAnims.get(i); - final Animator objectAnimator = pendingAnimator.newInstance(res, t); - setupAnimatorsForTarget(pendingAnimator.target, objectAnimator); - } - } } /** @@ -433,7 +381,6 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { // we add this array into the mAnimatorSet. private ArrayList<Animator> mTempAnimators; ArrayMap<Animator, String> mTargetNameMap; - ArrayList<PendingAnimator> mPendingAnims; public AnimatedVectorDrawableState(AnimatedVectorDrawableState copy, Callback owner, Resources res) { @@ -456,7 +403,7 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { final int numAnimators = copy.mTargetNameMap.size(); // Deep copy a animator set, and then setup the target map again. mAnimatorSet = copy.mAnimatorSet.clone(); - mTargetNameMap = new ArrayMap<>(numAnimators); + mTargetNameMap = new ArrayMap<Animator, String>(numAnimators); // Since the new AnimatorSet is cloned from the old one, the order must be the // same inside the array. ArrayList<Animator> oldAnim = copy.mAnimatorSet.getChildAnimations(); @@ -471,9 +418,6 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { mTargetNameMap.put(newAnim.get(i), targetName); } } - - // Shallow copy since the array is immutable after inflate(). - mPendingAnims = copy.mPendingAnims; } else { mVectorDrawable = new VectorDrawable(); } @@ -482,7 +426,7 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { @Override public boolean canApplyTheme() { return (mVectorDrawable != null && mVectorDrawable.canApplyTheme()) - || mPendingAnims != null || super.canApplyTheme(); + || super.canApplyTheme(); } @Override @@ -501,32 +445,12 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { } } - /** - * Basically a constant state for Animators until we actually implement - * constant states for Animators. - */ - private static class PendingAnimator { - public final int animResId; - public final float pathErrorScale; - public final String target; - - public PendingAnimator(int animResId, float pathErrorScale, String target) { - this.animResId = animResId; - this.pathErrorScale = pathErrorScale; - this.target = target; - } - - public Animator newInstance(Resources res, Theme theme) { - return AnimatorInflater.loadAnimator(res, theme, animResId, pathErrorScale); - } - } - private void setupAnimatorsForTarget(String name, Animator animator) { Object target = mAnimatedVectorState.mVectorDrawable.getTargetByName(name); animator.setTarget(target); if (mAnimatedVectorState.mTempAnimators == null) { - mAnimatedVectorState.mTempAnimators = new ArrayList<>(); - mAnimatedVectorState.mTargetNameMap = new ArrayMap<>(); + mAnimatedVectorState.mTempAnimators = new ArrayList<Animator>(); + mAnimatedVectorState.mTargetNameMap = new ArrayMap<Animator, String>(); } mAnimatedVectorState.mTempAnimators.add(animator); mAnimatedVectorState.mTargetNameMap.put(animator, name); @@ -550,23 +474,6 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { if (isStarted()) { return; } - - // Check for uninflated animators. We can remove this after we add - // support for Animator.applyTheme(). See comments in inflate(). - if (mAnimatedVectorState.mPendingAnims != null) { - // Attempt to load animators without applying a theme. - if (mRes != null) { - inflatePendingAnimators(mRes, null); - mRes = null; - } else { - Log.e(LOGTAG, "Failed to load animators. Either the AnimatedVectorDrawable must be" - + " created using a Resources object or applyTheme() must be called with" - + " a non-null Theme object."); - } - - mAnimatedVectorState.mPendingAnims = null; - } - mAnimatedVectorState.mAnimatorSet.start(); invalidateSelf(); } |