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

Commit 0d12785d authored by ztenghui's avatar ztenghui Committed by Android (Google) Code Review
Browse files

Merge "Add more reverse support to AnimatedVD" into lmp-dev

parents 71940885 7bc6a3f0
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -356,6 +356,22 @@ public abstract class Animator implements Cloneable {
    public void setTarget(Object target) {
    }

    // Hide reverse() and canReverse() for now since reverse() only work for simple
    // cases, like we don't support sequential, neither startDelay.
    // TODO: make reverse() works for all the Animators.
    /**
     * @hide
     */
    public boolean canReverse() {
        return false;
    }

    /**
     * @hide
     */
    public void reverse() {
    }

    /**
     * <p>An animation listener receives notifications from an animation.
     * Notifications indicate animation related events, such as the end or the
+39 −2
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public final class AnimatorSet extends Animator {
    // was set on this AnimatorSet, so it should not be passed down to the children.
    private TimeInterpolator mInterpolator = null;


    private boolean mReversible = true;
    /**
     * Sets up this AnimatorSet to play all of the supplied animations at the same time.
     * This is equivalent to calling {@link #play(Animator)} with the first animator in the
@@ -177,6 +177,7 @@ public final class AnimatorSet extends Animator {
            if (items.length == 1) {
                play(items[0]);
            } else {
                mReversible = false;
                for (int i = 0; i < items.length - 1; ++i) {
                    play(items[i]).before(items[i+1]);
                }
@@ -196,6 +197,7 @@ public final class AnimatorSet extends Animator {
            if (items.size() == 1) {
                play(items.get(0));
            } else {
                mReversible = false;
                for (int i = 0; i < items.size() - 1; ++i) {
                    play(items.get(i)).before(items.get(i+1));
                }
@@ -407,6 +409,9 @@ public final class AnimatorSet extends Animator {
     */
    @Override
    public void setStartDelay(long startDelay) {
        if (mStartDelay > 0) {
            mReversible = false;
        }
        mStartDelay = startDelay;
    }

@@ -626,6 +631,7 @@ public final class AnimatorSet extends Animator {
        anim.mNodeMap = new HashMap<Animator, Node>();
        anim.mNodes = new ArrayList<Node>();
        anim.mSortedNodes = new ArrayList<Node>();
        anim.mReversible = mReversible;

        // Walk through the old nodes list, cloning each node and adding it to the new nodemap.
        // One problem is that the old node dependencies point to nodes in the old AnimatorSet.
@@ -907,6 +913,35 @@ public final class AnimatorSet extends Animator {
        }
    }

    /**
     * @hide
     */
    @Override
    public boolean canReverse() {
        if (!mReversible)  {
            return false;
        }
        // Loop to make sure all the Nodes can reverse.
        for (Node node : mNodes) {
            if (!node.animation.canReverse() || node.animation.getStartDelay() > 0) {
                return false;
            }
        }
        return true;
    }

    /**
     * @hide
     */
    @Override
    public void reverse() {
        if (canReverse()) {
            for (Node node : mNodes) {
                node.animation.reverse();
            }
        }
    }

    /**
     * Dependency holds information about the node that some other node is
     * dependent upon and the nature of that dependency.
@@ -1124,6 +1159,7 @@ public final class AnimatorSet extends Animator {
         * {@link AnimatorSet#play(Animator)} method ends.
         */
        public Builder before(Animator anim) {
            mReversible = false;
            Node node = mNodeMap.get(anim);
            if (node == null) {
                node = new Node(anim);
@@ -1144,6 +1180,7 @@ public final class AnimatorSet extends Animator {
         * {@link AnimatorSet#play(Animator)} method to play.
         */
        public Builder after(Animator anim) {
            mReversible = false;
            Node node = mNodeMap.get(anim);
            if (node == null) {
                node = new Node(anim);
+9 −0
Original line number Diff line number Diff line
@@ -1038,6 +1038,7 @@ public class ValueAnimator extends Animator {
     * play backwards. This behavior is only set for the current animation; future playing
     * of the animation will use the default behavior of playing forward.
     */
    @Override
    public void reverse() {
        mPlayingBackwards = !mPlayingBackwards;
        if (mPlayingState == RUNNING) {
@@ -1052,6 +1053,14 @@ public class ValueAnimator extends Animator {
        }
    }

    /**
     * @hide
     */
    @Override
    public boolean canReverse() {
        return true;
    }

    /**
     * Called internally to end an animation by removing it from the animations list. Must be
     * called on the UI thread.
+10 −3
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.util.LongSparseLongArray;
import android.util.SparseIntArray;
import android.util.StateSet;
@@ -62,6 +63,8 @@ import java.io.IOException;
 * @attr ref android.R.styleable#DrawableStates_state_pressed
 */
public class AnimatedStateListDrawable extends StateListDrawable {
    private static final String LOGTAG = AnimatedStateListDrawable.class.getSimpleName();

    private static final String ELEMENT_TRANSITION = "transition";
    private static final String ELEMENT_ITEM = "item";

@@ -302,13 +305,13 @@ public class AnimatedStateListDrawable extends StateListDrawable {

        @Override
        public boolean canReverse() {
            return true;
            return mAvd.canReverse();
        }

        @Override
        public void start() {
            if (mReversed) {
                mAvd.reverse();
                reverse();
            } else {
                mAvd.start();
            }
@@ -316,7 +319,11 @@ public class AnimatedStateListDrawable extends StateListDrawable {

        @Override
        public void reverse() {
            if (canReverse()) {
                mAvd.reverse();
            } else {
                Log.w(LOGTAG, "Reverse() is called on a drawable can't reverse");
            }
        }

        @Override
+21 −3
Original line number Diff line number Diff line
@@ -337,15 +337,33 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable {
     * Reverses ongoing animations or starts pending animations in reverse.
     * <p>
     * NOTE: Only works of all animations are ValueAnimators.
     * @hide
     */
    void reverse() {
    public void reverse() {
        final ArrayList<Animator> animators = mAnimatedVectorState.mAnimators;
        final int size = animators.size();
        for (int i = 0; i < size; i++) {
            final Animator animator = animators.get(i);
            if (animator instanceof ValueAnimator) {
                ((ValueAnimator) animator).reverse();
            if (animator.canReverse()) {
                animator.reverse();
            } else {
                Log.w(LOGTAG, "AnimatedVectorDrawable can't reverse()");
            }
        }
    }

    /**
     * @hide
     */
    public boolean canReverse() {
        final ArrayList<Animator> animators = mAnimatedVectorState.mAnimators;
        final int size = animators.size();
        for (int i = 0; i < size; i++) {
            final Animator animator = animators.get(i);
            if (!animator.canReverse()) {
                return false;
            }
        }
        return true;
    }
}
Loading