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

Commit 563d4f2d authored by Chet Haase's avatar Chet Haase
Browse files

Make ViewPropertyAnimator ListView-animation-capable

ViewPropertyAnimator now sets the hasTransientState flag in View to tell
it when an animation has started (and unsets it when the animation ends).
This allows ListView to retain views with transient state without recycling them,
which makes ListView item animation possible (because you can't animate a View
if it's being recycled and reused elsewhere as it moves into and out of view).

Change-Id: I75c26a7a56474a76428500afef03a80bb46e04e0
parent f37d87b3
Loading
Loading
Loading
Loading
+28 −11
Original line number Diff line number Diff line
@@ -2471,6 +2471,12 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
    })
    int mSystemUiVisibility;
    /**
     * Reference count for transient state.
     * @see #setHasTransientState(boolean)
     */
    int mTransientStateCount = 0;
    /**
     * Count of how many windows this view has been attached to.
     */
@@ -5400,13 +5406,23 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
    /**
     * Set whether this view is currently tracking transient state that the
     * framework should attempt to preserve when possible.
     * framework should attempt to preserve when possible. This flag is reference counted,
     * so every call to setHasTransientState(true) should be paired with a later call
     * to setHasTransientState(false).
     *
     * @param hasTransientState true if this view has transient state
     */
    public void setHasTransientState(boolean hasTransientState) {
        if (hasTransientState() == hasTransientState) return;
        mTransientStateCount = hasTransientState ? mTransientStateCount + 1 :
                mTransientStateCount - 1;
        if (mTransientStateCount < 0) {
            mTransientStateCount = 0;
            Log.e(VIEW_LOG_TAG, "hasTransientState decremented below 0: " +
                    "unmatched pair of setHasTransientState calls");
        }
        if ((hasTransientState && mTransientStateCount == 1) ||
                (hasTransientState && mTransientStateCount == 0)) {
            // update flag if we've just incremented up from 0 or decremented down to 0
            mPrivateFlags2 = (mPrivateFlags2 & ~HAS_TRANSIENT_STATE) |
                    (hasTransientState ? HAS_TRANSIENT_STATE : 0);
            if (mParent != null) {
@@ -5418,6 +5434,7 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
                }
            }
        }
    }
    /**
     * If this view doesn't do any drawing on its own, set this flag to
+2 −0
Original line number Diff line number Diff line
@@ -714,6 +714,7 @@ public class ViewPropertyAnimator {
     * value accordingly.
     */
    private void startAnimation() {
        mView.setHasTransientState(true);
        ValueAnimator animator = ValueAnimator.ofFloat(1.0f);
        ArrayList<NameValuesHolder> nameValueList =
                (ArrayList<NameValuesHolder>) mPendingAnimations.clone();
@@ -960,6 +961,7 @@ public class ViewPropertyAnimator {

        @Override
        public void onAnimationEnd(Animator animation) {
            mView.setHasTransientState(false);
            if (mListener != null) {
                mListener.onAnimationEnd(animation);
            }