Fix problem with zero-duration AnimatedVectorDrawables
There was an issue with some vector drawables, particularly those with more
than one underlying, sequential animators, where the final frame would not be
drawn when battery saver mode was enabled (or animators were set to have durations
of 0). This resulted in an incorrect fingerprint graphic on the lockscreen, because
the animation effectively didn't run at all.
The fix is to always invalidate whenever the AnimatedVectorDrawble draws itself. This
causes us to constantly invalidate() the view while the animation is running.
Issue #26591987 Fingerprint icon displayed as dots when batter saver mode is on
Change-Id: I13cbd71fd229db09418c6dcacfec5a13bbb44b2e
diff --git a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java
index 84ca546..1857345 100644
--- a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java
+++ b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java
@@ -19,7 +19,6 @@
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 @@
/** 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 @@
@Override
public void draw(Canvas canvas) {
mAnimatedVectorState.mVectorDrawable.draw(canvas);
+ if (isStarted()) {
+ invalidateSelf();
+ }
}
@Override
@@ -493,7 +486,6 @@
* 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 @@
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 @@
@NonNull
private void ensureAnimatorSet() {
if (!mHasAnimatorSet) {
- mAnimatedVectorState.prepareLocalAnimators(mAnimatorSet, mUpdateListener, mRes);
+ mAnimatedVectorState.prepareLocalAnimators(mAnimatorSet, mRes);
mHasAnimatorSet = true;
mRes = null;
}