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

Commit 8788f905 authored by George Mount's avatar George Mount Committed by Android (Google) Code Review
Browse files

Revert "Animator start and stop notifications during seek"

Revert submission 20714313-animator_listener

Reason for revert: b/265243616

Reverted changes: /q/submissionid:20714313-animator_listener

Change-Id: I6530f99a8fafcba01c42cb5561805e49b2c888a0
parent 0d61567d
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -547,6 +547,7 @@ public abstract class Animator implements Cloneable {
     */
    void skipToEndValue(boolean inReverse) {}


    /**
     * Internal use only.
     *
@@ -564,13 +565,13 @@ public abstract class Animator implements Cloneable {
     * repetition. lastPlayTime is similar and is used to calculate how many repeats have been
     * done between the two times.
     */
    void animateValuesInRange(long currentPlayTime, long lastPlayTime, boolean notify) {}
    void animateValuesInRange(long currentPlayTime, long lastPlayTime) {}

    /**
     * Internal use only. This animates any animation that has ended since lastPlayTime.
     * If an animation hasn't been finished, no change will be made.
     */
    void animateSkipToEnds(long currentPlayTime, long lastPlayTime, boolean notify) {}
    void animateSkipToEnds(long currentPlayTime, long lastPlayTime) {}

    /**
     * Internal use only. Adds all start times (after delay) to and end times to times.
+42 −94
Original line number Diff line number Diff line
@@ -188,11 +188,6 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
     */
    private long[] mChildStartAndStopTimes;

    /**
     * Tracks whether we've notified listeners of the onAnimationStart() event.
     */
    private boolean mStartListenersCalled;

    // This is to work around a bug in b/34736819. This needs to be removed once app team
    // fixes their side.
    private AnimatorListenerAdapter mAnimationEndListener = new AnimatorListenerAdapter() {
@@ -741,38 +736,19 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
            startAnimation();
        }

        notifyStartListeners(inReverse);
        if (isEmptySet) {
            // In the case of empty AnimatorSet, or 0 duration scale, we will trigger the
            // onAnimationEnd() right away.
            end();
        }
    }

    private void notifyStartListeners(boolean inReverse) {
        if (mListeners != null && !mStartListenersCalled) {
        if (mListeners != null) {
            ArrayList<AnimatorListener> tmpListeners =
                    (ArrayList<AnimatorListener>) mListeners.clone();
            int numListeners = tmpListeners.size();
            for (int i = 0; i < numListeners; ++i) {
                AnimatorListener listener = tmpListeners.get(i);
                listener.onAnimationStart(this, inReverse);
            }
                tmpListeners.get(i).onAnimationStart(this, inReverse);
            }
        mStartListenersCalled = true;
    }

    private void notifyEndListeners(boolean inReverse) {
        if (mListeners != null && mStartListenersCalled) {
            ArrayList<AnimatorListener> tmpListeners =
                    (ArrayList<AnimatorListener>) mListeners.clone();
            int numListeners = tmpListeners.size();
            for (int i = 0; i < numListeners; ++i) {
                AnimatorListener listener = tmpListeners.get(i);
                listener.onAnimationEnd(this, inReverse);
        }
        if (isEmptySet) {
            // In the case of empty AnimatorSet, or 0 duration scale, we will trigger the
            // onAnimationEnd() right away.
            end();
        }
        mStartListenersCalled = false;
    }

    // Returns true if set is empty or contains nothing but animator sets with no start delay.
@@ -847,8 +823,7 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
    private void animateBasedOnPlayTime(
            long currentPlayTime,
            long lastPlayTime,
            boolean inReverse,
            boolean notify
            boolean inReverse
    ) {
        if (currentPlayTime < 0 || lastPlayTime < -1) {
            throw new UnsupportedOperationException("Error: Play time should never be negative.");
@@ -879,8 +854,8 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
            while (index < endIndex) {
                long playTime = startEndTimes[index];
                if (lastPlayTime != playTime) {
                    animateSkipToEnds(playTime, lastPlayTime, notify);
                    animateValuesInRange(playTime, lastPlayTime, notify);
                    animateSkipToEnds(playTime, lastPlayTime);
                    animateValuesInRange(playTime, lastPlayTime);
                    lastPlayTime = playTime;
                }
                index++;
@@ -890,15 +865,15 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
                index--;
                long playTime = startEndTimes[index];
                if (lastPlayTime != playTime) {
                    animateSkipToEnds(playTime, lastPlayTime, notify);
                    animateValuesInRange(playTime, lastPlayTime, notify);
                    animateSkipToEnds(playTime, lastPlayTime);
                    animateValuesInRange(playTime, lastPlayTime);
                    lastPlayTime = playTime;
                }
            }
        }
        if (currentPlayTime != lastPlayTime) {
            animateSkipToEnds(currentPlayTime, lastPlayTime, notify);
            animateValuesInRange(currentPlayTime, lastPlayTime, notify);
            animateSkipToEnds(currentPlayTime, lastPlayTime);
            animateValuesInRange(currentPlayTime, lastPlayTime);
        }
    }

@@ -918,13 +893,10 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
    }

    @Override
    void animateSkipToEnds(long currentPlayTime, long lastPlayTime, boolean notify) {
    void animateSkipToEnds(long currentPlayTime, long lastPlayTime) {
        initAnimation();

        if (lastPlayTime > currentPlayTime) {
            if (notify) {
                notifyStartListeners(true);
            }
            for (int i = mEvents.size() - 1; i >= 0; i--) {
                AnimationEvent event = mEvents.get(i);
                Node node = event.mNode;
@@ -932,31 +904,23 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
                        && node.mStartTime != DURATION_INFINITE
                ) {
                    Animator animator = node.mAnimation;
                    long start = node.mStartTime;
                    long start = node.mStartTime + animator.getStartDelay();
                    long end = node.mTotalDuration == DURATION_INFINITE
                            ? Long.MAX_VALUE : node.mEndTime;
                    if (currentPlayTime <= start && start < lastPlayTime) {
                        animator.animateSkipToEnds(
                                0,
                                lastPlayTime - node.mStartTime,
                                notify
                                start - node.mStartTime,
                                lastPlayTime - node.mStartTime
                        );
                    } else if (start <= currentPlayTime && currentPlayTime <= end) {
                        animator.animateSkipToEnds(
                                currentPlayTime - node.mStartTime,
                                lastPlayTime - node.mStartTime,
                                notify
                                lastPlayTime - node.mStartTime
                        );
                    }
                }
            }
            if (currentPlayTime <= 0 && notify) {
                notifyEndListeners(true);
            }
        } else {
            if (notify) {
                notifyStartListeners(false);
            }
            int eventsSize = mEvents.size();
            for (int i = 0; i < eventsSize; i++) {
                AnimationEvent event = mEvents.get(i);
@@ -965,48 +929,29 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
                        && node.mStartTime != DURATION_INFINITE
                ) {
                    Animator animator = node.mAnimation;
                    long start = node.mStartTime;
                    long start = node.mStartTime + animator.getStartDelay();
                    long end = node.mTotalDuration == DURATION_INFINITE
                            ? Long.MAX_VALUE : node.mEndTime;
                    if (lastPlayTime < end && end <= currentPlayTime) {
                        animator.animateSkipToEnds(
                                end - node.mStartTime,
                                lastPlayTime - node.mStartTime,
                                notify
                                lastPlayTime - node.mStartTime
                        );
                    } else if (start <= currentPlayTime && currentPlayTime <= end) {
                        animator.animateSkipToEnds(
                                currentPlayTime - node.mStartTime,
                                lastPlayTime - node.mStartTime,
                                notify
                                lastPlayTime - node.mStartTime
                        );
                    }
                }
            }
            if (currentPlayTime >= getTotalDuration() && notify) {
                notifyEndListeners(false);
            }
        }
    }

    @Override
    void animateValuesInRange(long currentPlayTime, long lastPlayTime, boolean notify) {
    void animateValuesInRange(long currentPlayTime, long lastPlayTime) {
        initAnimation();

        if (notify) {
            if (lastPlayTime < 0 || (lastPlayTime == 0 && currentPlayTime > 0)) {
                notifyStartListeners(false);
            } else {
                long duration = getTotalDuration();
                if (duration >= 0
                        && (lastPlayTime > duration || (lastPlayTime == duration
                        && currentPlayTime < duration))
                ) {
                    notifyStartListeners(true);
                }
            }
        }

        int eventsSize = mEvents.size();
        for (int i = 0; i < eventsSize; i++) {
            AnimationEvent event = mEvents.get(i);
@@ -1015,17 +960,13 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
                    && node.mStartTime != DURATION_INFINITE
            ) {
                Animator animator = node.mAnimation;
                long start = node.mStartTime;
                long start = node.mStartTime + animator.getStartDelay();
                long end = node.mTotalDuration == DURATION_INFINITE
                        ? Long.MAX_VALUE : node.mEndTime;
                if ((start < currentPlayTime && currentPlayTime < end)
                        || (start == currentPlayTime && lastPlayTime < start)
                        || (end == currentPlayTime && lastPlayTime > end)
                ) {
                if (start < currentPlayTime && currentPlayTime < end) {
                    animator.animateValuesInRange(
                            currentPlayTime - node.mStartTime,
                            Math.max(-1, lastPlayTime - node.mStartTime),
                            notify
                            Math.max(-1, lastPlayTime - node.mStartTime)
                    );
                }
            }
@@ -1080,11 +1021,6 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
     * set to this time; it will simply set the time to this value and perform any appropriate
     * actions based on that time. If the animation is already running, then setCurrentPlayTime()
     * will set the current playing time to this value and continue playing from that point.
     * On {@link Build.VERSION_CODES#UPSIDE_DOWN_CAKE} and above, an AnimatorSet
     * that hasn't been {@link #start()}ed, will issue
     * {@link android.animation.Animator.AnimatorListener#onAnimationStart(Animator, boolean)}
     * and {@link android.animation.Animator.AnimatorListener#onAnimationEnd(Animator, boolean)}
     * events.
     *
     * @param playTime The time, in milliseconds, to which the animation is advanced or rewound.
     *                 Unless the animation is reversing, the playtime is considered the time since
@@ -1106,12 +1042,12 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim

        initAnimation();

        long lastPlayTime = mSeekState.getPlayTime();
        if (!isStarted() || isPaused()) {
            if (mReversing && !isStarted()) {
                throw new UnsupportedOperationException("Error: Something went wrong. mReversing"
                        + " should not be set when AnimatorSet is not started.");
            }
            long lastPlayTime = mSeekState.getPlayTime();
            if (!mSeekState.isActive()) {
                findLatestEventIdForTime(0);
                initChildren();
@@ -1119,10 +1055,14 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim
                skipToEndValue(!mReversing);
                mSeekState.setPlayTime(0, mReversing);
            }
        }
        animateBasedOnPlayTime(playTime, lastPlayTime, mReversing, true);
            animateBasedOnPlayTime(playTime, lastPlayTime, mReversing);
            mSeekState.setPlayTime(playTime, mReversing);
        } else {
            // If the animation is running, just set the seek time and wait until the next frame
            // (i.e. doAnimationFrame(...)) to advance the animation.
            mSeekState.setPlayTime(playTime, mReversing);
        }
    }

    /**
     * Returns the milliseconds elapsed since the start of the animation.
@@ -1161,7 +1101,7 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim

            long previousTime = -1;
            for (long time : times) {
                animateBasedOnPlayTime(time, previousTime, false, false);
                animateBasedOnPlayTime(time, previousTime, false);
                previousTime = time;
            }
        }
@@ -1457,7 +1397,15 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim

        // No longer receive callbacks
        removeAnimationCallback();
        notifyEndListeners(mReversing);
        // Call end listener
        if (mListeners != null) {
            ArrayList<AnimatorListener> tmpListeners =
                    (ArrayList<AnimatorListener>) mListeners.clone();
            int numListeners = tmpListeners.size();
            for (int i = 0; i < numListeners; ++i) {
                tmpListeners.get(i).onAnimationEnd(this, mReversing);
            }
        }
        removeAnimationEndListener();
        mSelfPulse = true;
        mReversing = false;
+27 −48
Original line number Diff line number Diff line
@@ -1108,30 +1108,18 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio
        }
    }

    private void notifyStartListeners(boolean isReversing) {
    private void notifyStartListeners() {
        if (mListeners != null && !mStartListenersCalled) {
            ArrayList<AnimatorListener> tmpListeners =
                    (ArrayList<AnimatorListener>) mListeners.clone();
            int numListeners = tmpListeners.size();
            for (int i = 0; i < numListeners; ++i) {
                tmpListeners.get(i).onAnimationStart(this, isReversing);
                tmpListeners.get(i).onAnimationStart(this, mReversing);
            }
        }
        mStartListenersCalled = true;
    }

    private void notifyEndListeners(boolean isReversing) {
        if (mListeners != null && mStartListenersCalled) {
            ArrayList<AnimatorListener> tmpListeners =
                    (ArrayList<AnimatorListener>) mListeners.clone();
            int numListeners = tmpListeners.size();
            for (int i = 0; i < numListeners; ++i) {
                tmpListeners.get(i).onAnimationEnd(this, isReversing);
            }
        }
        mStartListenersCalled = false;
    }

    /**
     * Start the animation playing. This version of start() takes a boolean flag that indicates
     * whether the animation should play in reverse. The flag is usually false, but may be set
@@ -1222,7 +1210,7 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio
        if ((mStarted || mRunning) && mListeners != null) {
            if (!mRunning) {
                // If it's not yet running, then start listeners weren't called. Call them now.
                notifyStartListeners(mReversing);
                notifyStartListeners();
            }
            int listenersSize = mListeners.size();
            if (listenersSize > 0) {
@@ -1336,14 +1324,22 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio
        boolean notify = (mStarted || mRunning) && mListeners != null;
        if (notify && !mRunning) {
            // If it's not yet running, then start listeners weren't called. Call them now.
            notifyStartListeners(mReversing);
            notifyStartListeners();
        }
        mRunning = false;
        mStarted = false;
        mStartListenersCalled = false;
        mLastFrameTime = -1;
        mFirstFrameTime = -1;
        mStartTime = -1;
        notifyEndListeners(mReversing);
        if (notify && mListeners != null) {
            ArrayList<AnimatorListener> tmpListeners =
                    (ArrayList<AnimatorListener>) mListeners.clone();
            int numListeners = tmpListeners.size();
            for (int i = 0; i < numListeners; ++i) {
                tmpListeners.get(i).onAnimationEnd(this, mReversing);
            }
        }
        // mReversing needs to be reset *after* notifying the listeners for the end callbacks.
        mReversing = false;
        if (Trace.isTagEnabled(Trace.TRACE_TAG_VIEW)) {
@@ -1370,8 +1366,9 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio
        } else {
            mOverallFraction = 0f;
        }

        notifyStartListeners(mReversing);
        if (mListeners != null) {
            notifyStartListeners();
        }
    }

    /**
@@ -1462,22 +1459,13 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio
     * will be called.
     */
    @Override
    void animateValuesInRange(long currentPlayTime, long lastPlayTime, boolean notify) {
        if (currentPlayTime < 0 || lastPlayTime < -1) {
    void animateValuesInRange(long currentPlayTime, long lastPlayTime) {
        if (currentPlayTime < mStartDelay || lastPlayTime < -1) {
            throw new UnsupportedOperationException("Error: Play time should never be negative.");
        }

        initAnimation();
        long duration = getTotalDuration();
        if (notify) {
            if (lastPlayTime < 0 || (lastPlayTime == 0 && currentPlayTime > 0)) {
                notifyStartListeners(false);
            } else if (lastPlayTime > duration
                    || (lastPlayTime == duration && currentPlayTime < duration)
            ) {
                notifyStartListeners(true);
            }
        }
        if (duration >= 0) {
            lastPlayTime = Math.min(duration, lastPlayTime);
        }
@@ -1486,8 +1474,8 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio

        // Check whether repeat callback is needed only when repeat count is non-zero
        if (mRepeatCount > 0) {
            int iteration = Math.max(0, (int) (currentPlayTime / mDuration));
            int lastIteration = Math.max(0, (int) (lastPlayTime / mDuration));
            int iteration = (int) (currentPlayTime / mDuration);
            int lastIteration = (int) (lastPlayTime / mDuration);

            // Clamp iteration to [0, mRepeatCount]
            iteration = Math.min(iteration, mRepeatCount);
@@ -1503,33 +1491,24 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio
            }
        }

        if (mRepeatCount != INFINITE && currentPlayTime > (mRepeatCount + 1) * mDuration) {
        if (mRepeatCount != INFINITE && currentPlayTime >= (mRepeatCount + 1) * mDuration) {
            throw new IllegalStateException("Can't animate a value outside of the duration");
        } else {
            // Find the current fraction:
            float fraction = Math.max(0, currentPlayTime) / (float) mDuration;
            float fraction = currentPlayTime / (float) mDuration;
            fraction = getCurrentIterationFraction(fraction, false);
            animateValue(fraction);
        }
    }

    @Override
    void animateSkipToEnds(long currentPlayTime, long lastPlayTime, boolean notify) {
        boolean inReverse = currentPlayTime < lastPlayTime;
        boolean doSkip;
        if (currentPlayTime <= 0 && lastPlayTime > 0) {
            doSkip = true;
    void animateSkipToEnds(long currentPlayTime, long lastPlayTime) {
        if (currentPlayTime <= mStartDelay && lastPlayTime > mStartDelay) {
            skipToEndValue(true);
        } else {
            long duration = getTotalDuration();
            doSkip = duration >= 0 && currentPlayTime >= duration && lastPlayTime < duration;
        }
        if (doSkip) {
            if (notify) {
                notifyStartListeners(inReverse);
            }
            skipToEndValue(inReverse);
            if (notify) {
                notifyEndListeners(inReverse);
            if (duration >= 0 && currentPlayTime >= duration && lastPlayTime < duration) {
                skipToEndValue(false);
            }
        }
    }