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

Commit 56b0b570 authored by Doris Liu's avatar Doris Liu
Browse files

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
parent b6e1dafe
Loading
Loading
Loading
Loading
+7 −3
Original line number Original line Diff line number Diff line
@@ -1200,13 +1200,17 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio
    boolean animateBasedOnTime(long currentTime) {
    boolean animateBasedOnTime(long currentTime) {
        boolean done = false;
        boolean done = false;
        if (mRunning) {
        if (mRunning) {
            final float fraction = getScaledDuration() > 0 ?
            final long scaledDuration = getScaledDuration();
                    (float)(currentTime - mStartTime) / getScaledDuration() : 1f;
            final float fraction = scaledDuration > 0 ?
                    (float)(currentTime - mStartTime) / scaledDuration : 1f;
            final float lastFraction = mOverallFraction;
            final float lastFraction = mOverallFraction;
            final boolean newIteration = (int) fraction > (int) lastFraction;
            final boolean newIteration = (int) fraction > (int) lastFraction;
            final boolean lastIterationFinished = (fraction >= mRepeatCount + 1) &&
            final boolean lastIterationFinished = (fraction >= mRepeatCount + 1) &&
                    (mRepeatCount != INFINITE);
                    (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
                // Time to repeat
                if (mListeners != null) {
                if (mListeners != null) {
                    int numListeners = mListeners.size();
                    int numListeners = mListeners.size();