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

Commit 5c71b8cc authored by Doris Liu's avatar Doris Liu
Browse files

Make sure start() is called for custom animators

BUG: 34758281
Test: ag/1848837

Change-Id: Iae5d2fb41c4556ee201b9c4dfbc356996dc475a5
parent fda076a1
Loading
Loading
Loading
Loading
+3 −13
Original line number Original line Diff line number Diff line
@@ -26,7 +26,7 @@ import java.util.ArrayList;
 * This is the superclass for classes which provide basic support for animations which can be
 * This is the superclass for classes which provide basic support for animations which can be
 * started, ended, and have <code>AnimatorListeners</code> added to them.
 * started, ended, and have <code>AnimatorListeners</code> added to them.
 */
 */
public abstract class Animator implements Cloneable, AnimationHandler.AnimationFrameCallback {
public abstract class Animator implements Cloneable {


    /**
    /**
     * The value used to indicate infinite duration (e.g. when Animators repeat infinitely).
     * The value used to indicate infinite duration (e.g. when Animators repeat infinitely).
@@ -464,23 +464,13 @@ public abstract class Animator implements Cloneable, AnimationHandler.AnimationF
        throw new IllegalStateException("Reverse is not supported");
        throw new IllegalStateException("Reverse is not supported");
    }
    }


    /**
    // Pulse an animation frame into the animation.
     * @hide
    boolean pulseAnimationFrame(long frameTime) {
     */
    @Override
    public boolean doAnimationFrame(long frameTime) {
        // TODO: Need to find a better signal than this. There's a bug in SystemUI that's preventing
        // TODO: Need to find a better signal than this. There's a bug in SystemUI that's preventing
        // returning !isStarted() from working.
        // returning !isStarted() from working.
        return false;
        return false;
    }
    }


    /**
     * @hide
     */
    @Override
    public void commitAnimationFrame(long frameTime) {}


    /**
    /**
     * Internal use only.
     * Internal use only.
     * This call starts the animation in regular or reverse direction without requiring them to
     * This call starts the animation in regular or reverse direction without requiring them to
+25 −7
Original line number Original line Diff line number Diff line
@@ -948,7 +948,8 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
        for (int i = 0; i < mPlayingSet.size(); i++) {
        for (int i = 0; i < mPlayingSet.size(); i++) {
            Node node = mPlayingSet.get(i);
            Node node = mPlayingSet.get(i);
            if (!node.mEnded) {
            if (!node.mEnded) {
                node.mEnded = node.mAnimation.doAnimationFrame(getPlayTimeForNode(playTime, node));
                node.mEnded = node.mAnimation.pulseAnimationFrame(
                    getPlayTimeForNode(playTime, node));
            }
            }
        }
        }


@@ -977,6 +978,19 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
        return false;
        return false;
    }
    }


    /**
     * @hide
     */
    @Override
    public void commitAnimationFrame(long frameTime) {
        // No op.
    }

    @Override
    boolean pulseAnimationFrame(long frameTime) {
        return doAnimationFrame(frameTime);
    }

    /**
    /**
     * When playing forward, we call start() at the animation's scheduled start time, and make sure
     * When playing forward, we call start() at the animation's scheduled start time, and make sure
     * to pump a frame at the animation's scheduled end time.
     * to pump a frame at the animation's scheduled end time.
@@ -993,11 +1007,10 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
                if (event.mEvent == AnimationEvent.ANIMATION_END) {
                if (event.mEvent == AnimationEvent.ANIMATION_END) {
                    mPlayingSet.add(event.mNode);
                    mPlayingSet.add(event.mNode);
                    node.mAnimation.startWithoutPulsing(true);
                    node.mAnimation.startWithoutPulsing(true);
                    node.mAnimation.doAnimationFrame(0);
                    pulseFrame(node, 0);
                } else if (event.mEvent == AnimationEvent.ANIMATION_DELAY_ENDED && !node.mEnded) {
                } else if (event.mEvent == AnimationEvent.ANIMATION_DELAY_ENDED && !node.mEnded) {
                    // end event:
                    // end event:
                    node.mEnded =
                    pulseFrame(node, getPlayTimeForNode(playTime, node));
                            node.mAnimation.doAnimationFrame(getPlayTimeForNode(playTime, node));
                }
                }
            }
            }
        } else {
        } else {
@@ -1007,14 +1020,19 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
                if (event.mEvent == AnimationEvent.ANIMATION_START) {
                if (event.mEvent == AnimationEvent.ANIMATION_START) {
                    mPlayingSet.add(event.mNode);
                    mPlayingSet.add(event.mNode);
                    node.mAnimation.startWithoutPulsing(false);
                    node.mAnimation.startWithoutPulsing(false);
                    node.mAnimation.doAnimationFrame(0);
                    pulseFrame(node, 0);
                } else if (event.mEvent == AnimationEvent.ANIMATION_END && !node.mEnded) {
                } else if (event.mEvent == AnimationEvent.ANIMATION_END && !node.mEnded) {
                    // start event:
                    // start event:
                    node.mEnded =
                    pulseFrame(node, getPlayTimeForNode(playTime, node));
                            node.mAnimation.doAnimationFrame(getPlayTimeForNode(playTime, node));
                }
            }
            }
        }
        }
    }
    }

    private void pulseFrame(Node node, long frameTime) {
        if (!node.mEnded) {
            node.mEnded = node.mAnimation.pulseAnimationFrame(frameTime);
        }
    }
    }


    private long getPlayTimeForNode(long overallPlayTime, Node node) {
    private long getPlayTimeForNode(long overallPlayTime, Node node) {
+39 −6
Original line number Original line Diff line number Diff line
@@ -68,7 +68,7 @@ import java.util.HashMap;
 * </div>
 * </div>
 */
 */
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
public class ValueAnimator extends Animator {
public class ValueAnimator extends Animator implements AnimationHandler.AnimationFrameCallback {
    private static final String TAG = "ValueAnimator";
    private static final String TAG = "ValueAnimator";
    private static final boolean DEBUG = false;
    private static final boolean DEBUG = false;


@@ -224,6 +224,12 @@ public class ValueAnimator extends Animator {
     */
     */
    private boolean mSelfPulse = true;
    private boolean mSelfPulse = true;


    /**
     * Whether or not the animator has been requested to start without pulsing. This flag gets set
     * in startWithoutPulsing(), and reset in start().
     */
    private boolean mSuppressSelfPulseRequested = false;

    /**
    /**
     * The time interpolator to be used. The elapsed fraction of the animation will be passed
     * The time interpolator to be used. The elapsed fraction of the animation will be passed
     * through this interpolator to calculate the interpolated fraction, which is then used to
     * through this interpolator to calculate the interpolated fraction, which is then used to
@@ -997,12 +1003,12 @@ public class ValueAnimator extends Animator {
     *
     *
     * @param playBackwards Whether the ValueAnimator should start playing in reverse.
     * @param playBackwards Whether the ValueAnimator should start playing in reverse.
     */
     */
    private void start(boolean playBackwards, boolean selfPulse) {
    private void start(boolean playBackwards) {
        if (Looper.myLooper() == null) {
        if (Looper.myLooper() == null) {
            throw new AndroidRuntimeException("Animators may only be run on Looper threads");
            throw new AndroidRuntimeException("Animators may only be run on Looper threads");
        }
        }
        mReversing = playBackwards;
        mReversing = playBackwards;
        mSelfPulse = selfPulse;
        mSelfPulse = !mSuppressSelfPulseRequested;
        // Special case: reversing from seek-to-0 should act as if not seeked at all.
        // Special case: reversing from seek-to-0 should act as if not seeked at all.
        if (playBackwards && mSeekFraction != -1 && mSeekFraction != 0) {
        if (playBackwards && mSeekFraction != -1 && mSeekFraction != 0) {
            if (mRepeatCount == INFINITE) {
            if (mRepeatCount == INFINITE) {
@@ -1041,12 +1047,18 @@ public class ValueAnimator extends Animator {
    }
    }


    void startWithoutPulsing(boolean inReverse) {
    void startWithoutPulsing(boolean inReverse) {
        start(inReverse, false);
        mSuppressSelfPulseRequested = true;
        if (inReverse) {
            reverse();
        } else {
            start();
        }
        mSuppressSelfPulseRequested = false;
    }
    }


    @Override
    @Override
    public void start() {
    public void start() {
        start(false, true);
        start(false);
    }
    }


    @Override
    @Override
@@ -1150,7 +1162,7 @@ public class ValueAnimator extends Animator {
            mReversing = !mReversing;
            mReversing = !mReversing;
            end();
            end();
        } else {
        } else {
            start(true, true);
            start(true);
        }
        }
    }
    }


@@ -1364,6 +1376,11 @@ public class ValueAnimator extends Animator {
        animateValue(endFraction);
        animateValue(endFraction);
    }
    }


    @Override
    boolean isInitialized() {
        return mInitialized;
    }

    /**
    /**
     * Processes a frame of the animation, adjusting the start time if needed.
     * Processes a frame of the animation, adjusting the start time if needed.
     *
     *
@@ -1430,6 +1447,20 @@ public class ValueAnimator extends Animator {
        return finished;
        return finished;
    }
    }


    @Override
    boolean pulseAnimationFrame(long frameTime) {
        if (mSelfPulse) {
            // Pulse animation frame will *always* be after calling start(). If mSelfPulse isn't
            // set to false at this point, that means child animators did not call super's start().
            // This can happen when the Animator is just a non-animating wrapper around a real
            // functional animation. In this case, we can't really pulse a frame into the animation,
            // because the animation cannot necessarily be properly initialized (i.e. no start/end
            // values set).
            return false;
        }
        return doAnimationFrame(frameTime);
    }

    private void addOneShotCommitCallback() {
    private void addOneShotCommitCallback() {
        if (!mSelfPulse) {
        if (!mSelfPulse) {
            return;
            return;
@@ -1514,6 +1545,8 @@ public class ValueAnimator extends Animator {
        anim.mFirstFrameTime = -1;
        anim.mFirstFrameTime = -1;
        anim.mOverallFraction = 0;
        anim.mOverallFraction = 0;
        anim.mCurrentFraction = 0;
        anim.mCurrentFraction = 0;
        anim.mSelfPulse = true;
        anim.mSuppressSelfPulseRequested = false;


        PropertyValuesHolder[] oldValues = mValues;
        PropertyValuesHolder[] oldValues = mValues;
        if (oldValues != null) {
        if (oldValues != null) {