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

Commit 1e0ac5a1 authored by Chet Haase's avatar Chet Haase
Browse files

Fix Sequencer end events when terminated early

Change-Id: I3e10d17000182419219dbd1243d42cd0ecda7aa0
parent 363e035f
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -394,7 +394,8 @@ public class Animator<T> extends Animatable {
                        for (int i = 0; i < count; ++i) {
                            Animator anim = pendingCopy.get(i);
                            // If the animation has a startDelay, place it on the delayed list
                            if (anim.mStartDelay == 0) {
                            if (anim.mStartDelay == 0 || anim.mPlayingState == ENDED ||
                                    anim.mPlayingState == CANCELED) {
                                anim.startAnimation();
                            } else {
                                sDelayedAnims.add(anim);
@@ -700,14 +701,14 @@ public class Animator<T> extends Animatable {

    @Override
    public void end() {
        if (!sAnimations.contains(this) &&
                (Thread.currentThread() == Looper.getMainLooper().getThread())) {
            // Special case if the animation has not yet started. Set the end value.
            long endTime = mDuration;
            if (mRepeatCount > 0) {
                endTime += mRepeatCount * mDuration;
        if (!sAnimations.contains(this) && !sPendingAnimations.contains(this)) {
            // Special case if the animation has not yet started; get it ready for ending
            mStartedDelay = false;
            sPendingAnimations.add(this);
            if (sAnimationHandler == null) {
                sAnimationHandler = new AnimationHandler();
            }
            setCurrentPlayTime(endTime);
            sAnimationHandler.sendEmptyMessage(ANIMATION_START);
        }
        // Just set the ENDED flag - this causes the animation to end the next time a frame
        // is processed.
@@ -716,7 +717,8 @@ public class Animator<T> extends Animatable {

    @Override
    public boolean isRunning() {
        return mPlayingState == RUNNING;
        // ENDED or CANCELED indicate that it has been ended or canceled, but not processed yet
        return (mPlayingState == RUNNING || mPlayingState == ENDED || mPlayingState == CANCELED);
    }

    /**
@@ -862,6 +864,7 @@ public class Animator<T> extends Animatable {
            // Fall through to set done flag
        case CANCELED:
            done = true;
            mPlayingState = STOPPED;
            break;
        }

+17 −1
Original line number Diff line number Diff line
@@ -236,6 +236,12 @@ public final class Sequencer extends Animatable {
        if (mSortedNodes.size() != mNodes.size()) {
            // hasn't been started yet - sort the nodes now, then end them
            sortNodes();
            for (Node node : mSortedNodes) {
                if (mSequenceListener == null) {
                    mSequenceListener = new SequencerAnimatableListener(this);
                }
                node.animation.addListener(mSequenceListener);
            }
        }
        if (mSortedNodes.size() > 0) {
            for (Node node : mSortedNodes) {
@@ -486,10 +492,12 @@ public final class Sequencer extends Animatable {
        public void onAnimationEnd(Animatable animation) {
            animation.removeListener(this);
            mPlayingSet.remove(animation);
            Node animNode = mSequencer.mNodeMap.get(animation);
            animNode.done = true;
            ArrayList<Node> sortedNodes = mSequencer.mSortedNodes;
            boolean allDone = true;
            for (Node node : sortedNodes) {
                if (node.animation.isRunning()) {
                if (!node.done) {
                    allDone = false;
                    break;
                }
@@ -573,6 +581,7 @@ public final class Sequencer extends Animatable {
                        }
                    }
                }
                node.done = false;
            }
        }
    }
@@ -639,6 +648,13 @@ public final class Sequencer extends Animatable {
         */
        public ArrayList<Node> nodeDependents = null;

        /**
         * Flag indicating whether the animation in this node is finished. This flag
         * is used by Sequencer to check, as each animation ends, whether all child animations
         * are done and it's time to send out an end event for the entire Sequencer.
         */
        public boolean done = false;

        /**
         * Constructs the Node with the animation that it encapsulates. A Node has no
         * dependencies by default; dependencies are added via the addDependency()