Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit af8859fc authored by Chet Haase's avatar Chet Haase Committed by Android (Google) Code Review
Browse files

Merge "Fix problem with zero-duration AnimatedVectorDrawables"

parents 67269fe0 f0a7b3b6
Loading
Loading
Loading
Loading
+4 −23
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.Animator.AnimatorListener;
import android.animation.ValueAnimator;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.res.ColorStateList;
@@ -141,15 +140,6 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 {
    /** Local, mutable animator set. */
    private final AnimatorSet mAnimatorSet = new AnimatorSet();


    private final ValueAnimator.AnimatorUpdateListener mUpdateListener =
            new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    invalidateSelf();
                }
            };

    /**
     * The resources against which this drawable was created. Used to attempt
     * to inflate animators if applyTheme() doesn't get called.
@@ -211,6 +201,9 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 {
    @Override
    public void draw(Canvas canvas) {
        mAnimatedVectorState.mVectorDrawable.draw(canvas);
        if (isStarted()) {
            invalidateSelf();
        }
    }

    @Override
@@ -493,7 +486,6 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 {
         *            animators, or {@code null} if not available
         */
        public void prepareLocalAnimators(@NonNull AnimatorSet animatorSet,
                @NonNull ValueAnimator.AnimatorUpdateListener updateListener,
                @Nullable Resources res) {
            // Check for uninflated animators. We can remove this after we add
            // support for Animator.applyTheme(). See comments in inflate().
@@ -519,17 +511,6 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 {
                    final Animator nextAnim = prepareLocalAnimator(i);
                    builder.with(nextAnim);
                }

                // Setup a value animator to get animation update callbacks.
                long totalDuration = animatorSet.getTotalDuration();
                ValueAnimator updateAnim = ValueAnimator.ofFloat(0f, 1f);
                if (totalDuration == ValueAnimator.DURATION_INFINITE) {
                    updateAnim.setRepeatCount(ValueAnimator.INFINITE);
                } else {
                    updateAnim.setDuration(totalDuration);
                }
                updateAnim.addUpdateListener(updateListener);
                builder.with(updateAnim);
            }
        }

@@ -622,7 +603,7 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 {
    @NonNull
    private void ensureAnimatorSet() {
        if (!mHasAnimatorSet) {
            mAnimatedVectorState.prepareLocalAnimators(mAnimatorSet, mUpdateListener, mRes);
            mAnimatedVectorState.prepareLocalAnimators(mAnimatorSet, mRes);
            mHasAnimatorSet = true;
            mRes = null;
        }