From 56b0b570890dbb7baa00da95f5be2eb3e0122f0a Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Wed, 13 Apr 2016 14:13:49 -0700 Subject: [PATCH] Skip to end for 0-duration animation Repeating a 0-duration animation makes no sense. In the case of battery saver mode, all animators are set to 0 duration, and repeating the 0 duration animations not only waste battery power but also potentially produce flickers on screen. In this CL, 0-duration animations are skipped to the end, regardless their repeat count. Bug: 25451472 Change-Id: I20f9dc2f0ff9c027782a8363ff4cf4a4d390736c --- core/java/android/animation/ValueAnimator.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java index c6a51523cfe58..31035a746d5f8 100644 --- a/core/java/android/animation/ValueAnimator.java +++ b/core/java/android/animation/ValueAnimator.java @@ -1200,13 +1200,17 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio boolean animateBasedOnTime(long currentTime) { boolean done = false; if (mRunning) { - final float fraction = getScaledDuration() > 0 ? - (float)(currentTime - mStartTime) / getScaledDuration() : 1f; + final long scaledDuration = getScaledDuration(); + final float fraction = scaledDuration > 0 ? + (float)(currentTime - mStartTime) / scaledDuration : 1f; final float lastFraction = mOverallFraction; final boolean newIteration = (int) fraction > (int) lastFraction; final boolean lastIterationFinished = (fraction >= mRepeatCount + 1) && (mRepeatCount != INFINITE); - if (newIteration && !lastIterationFinished) { + if (scaledDuration == 0) { + // 0 duration animator, ignore the repeat count and skip to the end + done = true; + } else if (newIteration && !lastIterationFinished) { // Time to repeat if (mListeners != null) { int numListeners = mListeners.size();