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
This commit is contained in:
Doris Liu
2016-04-13 14:13:49 -07:00
parent b6e1dafe78
commit 56b0b57089

View File

@@ -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();