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

Commit 2a0fb977 authored by Arthur Hung's avatar Arthur Hung Committed by Android (Google) Code Review
Browse files

Merge "Let BackProgressAnimator could play cancel animation"

parents b89af275 0956f6e2
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -74,6 +74,9 @@ public final class BackEvent {
     * and animation should seek to its end state. Exact end value may vary depending on
     * and animation should seek to its end state. Exact end value may vary depending on
     * screen size.
     * screen size.
     * </ol>
     * </ol>
     * <li> After the gesture finishes in cancel state, this method keeps getting invoked until the
     * progress value animates back to 0.
     * </ol>
     * In-between locations are linearly interpolated based on horizontal distance from the starting
     * In-between locations are linearly interpolated based on horizontal distance from the starting
     * edge and smooth clamped to 1 when the distance exceeds a system-wide threshold.
     * edge and smooth clamped to 1 when the distance exceeds a system-wide threshold.
     */
     */
+23 −0
Original line number Original line Diff line number Diff line
@@ -16,8 +16,10 @@


package android.window;
package android.window;


import android.annotation.NonNull;
import android.util.FloatProperty;
import android.util.FloatProperty;


import com.android.internal.dynamicanimation.animation.DynamicAnimation;
import com.android.internal.dynamicanimation.animation.SpringAnimation;
import com.android.internal.dynamicanimation.animation.SpringAnimation;
import com.android.internal.dynamicanimation.animation.SpringForce;
import com.android.internal.dynamicanimation.animation.SpringForce;


@@ -126,6 +128,27 @@ public class BackProgressAnimator {
        mProgress = 0;
        mProgress = 0;
    }
    }


    /**
     * Animate the back progress animation from current progress to start position.
     * This should be called when back is cancelled.
     *
     * @param finishCallback the callback to be invoked when the progress is reach to 0.
     */
    public void onBackCancelled(@NonNull Runnable finishCallback) {
        final DynamicAnimation.OnAnimationEndListener listener =
                new DynamicAnimation.OnAnimationEndListener() {
            @Override
            public void onAnimationEnd(DynamicAnimation animation, boolean canceled, float value,
                    float velocity) {
                mSpring.removeEndListener(this);
                finishCallback.run();
                reset();
            }
        };
        mSpring.addEndListener(listener);
        mSpring.animateToFinalPosition(0);
    }

    private void updateProgressValue(float progress) {
    private void updateProgressValue(float progress) {
        if (mLastBackEvent == null || mCallback == null || !mStarted) {
        if (mLastBackEvent == null || mCallback == null || !mStarted) {
            return;
            return;
+6 −5
Original line number Original line Diff line number Diff line
@@ -266,12 +266,13 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
        @Override
        @Override
        public void onBackCancelled() {
        public void onBackCancelled() {
            Handler.getMain().post(() -> {
            Handler.getMain().post(() -> {
                mProgressAnimator.reset();
                mProgressAnimator.onBackCancelled(() -> {
                    final OnBackAnimationCallback callback = getBackAnimationCallback();
                    final OnBackAnimationCallback callback = getBackAnimationCallback();
                    if (callback != null) {
                    if (callback != null) {
                        callback.onBackCancelled();
                        callback.onBackCancelled();
                    }
                    }
                });
                });
            });
        }
        }


        @Override
        @Override
+4 −5
Original line number Original line Diff line number Diff line
@@ -171,6 +171,7 @@ class CrossActivityAnimation {
        mInitialTouchPos.set(0, 0);
        mInitialTouchPos.set(0, 0);
        mEnteringWindowShow = false;
        mEnteringWindowShow = false;
        mEnteringMargin = 0;
        mEnteringMargin = 0;
        mEnteringAnimator = null;


        if (mFinishCallback != null) {
        if (mFinishCallback != null) {
            try {
            try {
@@ -276,7 +277,7 @@ class CrossActivityAnimation {
        }
        }


        // End the fade in animation.
        // End the fade in animation.
        if (mEnteringAnimator.isRunning()) {
        if (mEnteringAnimator != null && mEnteringAnimator.isRunning()) {
            mEnteringAnimator.cancel();
            mEnteringAnimator.cancel();
        }
        }


@@ -329,12 +330,10 @@ class CrossActivityAnimation {
        @Override
        @Override
        public void onBackCancelled() {
        public void onBackCancelled() {
            // End the fade in animation.
            // End the fade in animation.
            if (mEnteringAnimator.isRunning()) {
            if (mEnteringAnimator != null && mEnteringAnimator.isRunning()) {
                mEnteringAnimator.cancel();
                mEnteringAnimator.cancel();
            }
            }
            // TODO (b259608500): Let BackProgressAnimator could play cancel animation.
            mProgressAnimator.onBackCancelled(CrossActivityAnimation.this::finishAnimation);
            mProgressAnimator.reset();
            finishAnimation();
        }
        }


        @Override
        @Override
+1 −2
Original line number Original line Diff line number Diff line
@@ -329,8 +329,7 @@ class CrossTaskBackAnimation {


        @Override
        @Override
        public void onBackCancelled() {
        public void onBackCancelled() {
            mProgressAnimator.reset();
            mProgressAnimator.onBackCancelled(CrossTaskBackAnimation.this::finishAnimation);
            finishAnimation();
        }
        }


        @Override
        @Override
Loading