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

Commit 5c764985 authored by Chet Haase's avatar Chet Haase
Browse files

Implement reversing functionality for Animator

Change-Id: I5cf32363a363c17a1d5c5dd0c602b06dc9ebc785
parent 468c3230
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -20079,6 +20079,17 @@
 visibility="public"
>
</method>
<method name="isRunning"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="removeUpdateListener"
 return="void"
 abstract="false"
@@ -20092,6 +20103,17 @@
<parameter name="listener" type="android.animation.Animator.AnimatorUpdateListener">
</parameter>
</method>
<method name="reverse"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="setCurrentPlayTime"
 return="void"
 abstract="false"
+36 −3
Original line number Diff line number Diff line
@@ -422,7 +422,6 @@ public class Animator extends Animatable {
            mEvaluator = (mValueType == int.class) ? sIntEvaluator :
                (mValueType == double.class) ? sDoubleEvaluator : sFloatEvaluator;
        }
        mPlayingBackwards = false;
        mCurrentIteration = 0;
        mInitialized = true;
    }
@@ -790,7 +789,8 @@ public class Animator extends Animatable {
        }
    }

    public void start() {
    private void start(boolean playBackwards) {
        mPlayingBackwards = playBackwards;
        mPlayingState = STOPPED;
        sPendingAnimations.add(this);
        if (sAnimationHandler == null) {
@@ -801,6 +801,12 @@ public class Animator extends Animatable {
        sAnimationHandler.sendEmptyMessage(ANIMATION_START);
    }

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

    @Override
    public void cancel() {
        if (mListeners != null) {
            ArrayList<AnimatableListener> tmpListeners =
@@ -814,12 +820,40 @@ public class Animator extends Animatable {
        mPlayingState = CANCELED;
    }

    @Override
    public void end() {
        // Just set the ENDED flag - this causes the animation to end the next time a frame
        // is processed.
        mPlayingState = ENDED;
    }

    /**
     * Returns whether this Animator is currently running (having been started and not yet ended).
     * @return Wehther the Animator is running.
     */
    public boolean isRunning() {
        return mPlayingState == RUNNING;
    }

    /**
     * Plays the Animator in reverse. If the animation is already running,
     * it will stop itself and play backwards from the point reached when reverse was called.
     * If the animation is not currently running, then it will start from the end and
     * play backwards. This behavior is only set for the current animation; future playing
     * of the animation will use the default behavior of playing forward.
     */
    public void reverse() {
        mPlayingBackwards = !mPlayingBackwards;
        if (mPlayingState == RUNNING) {
            long currentTime = AnimationUtils.currentAnimationTimeMillis();
            long currentPlayTime = currentTime - mStartTime;
            long timeLeft = mDuration - currentPlayTime;
            mStartTime = currentTime - timeLeft;
        } else {
            start(true);
        }
    }

    /**
     * Called internally to end an animation by removing it from the animations list. Must be
     * called on the UI thread.
@@ -892,7 +926,6 @@ public class Animator extends Animatable {
     * <code>repeatCount</code> has been exceeded and the animation should be ended.
     */
    private boolean animationFrame(long currentTime) {

        boolean done = false;

        if (mPlayingState == STOPPED) {