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

Commit e3279da4 authored by Shan Huang's avatar Shan Huang Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE Use spring-y progress in back to home animation." into tm-qpr-dev

parents ac29981a f31bf4e1
Loading
Loading
Loading
Loading
+31 −25
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.view.SurfaceControl;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.window.BackEvent;
import android.window.BackProgressAnimator;
import android.window.IOnBackInvokedCallback;

import com.android.launcher3.AbstractFloatingView;
@@ -90,6 +91,7 @@ public class LauncherBackAnimationController {
    private float mBackProgress = 0;
    private boolean mBackInProgress = false;
    private IOnBackInvokedCallback mBackCallback;
    private BackProgressAnimator mProgressAnimator = new BackProgressAnimator();

    public LauncherBackAnimationController(
            QuickstepLauncher launcher,
@@ -118,30 +120,41 @@ public class LauncherBackAnimationController {
        mBackCallback = new IOnBackInvokedCallback.Stub() {
            @Override
            public void onBackCancelled() {
                handler.post(() -> resetPositionAnimated());
                handler.post(() -> {
                    resetPositionAnimated();
                    mProgressAnimator.reset();
                });
            }

            @Override
            public void onBackInvoked() {
                handler.post(() -> startTransition());
                handler.post(() -> {
                    startTransition();
                    mProgressAnimator.reset();
                });
            }

            @Override
            public void onBackProgressed(BackEvent backEvent) {
                mBackProgress = backEvent.getProgress();
                handler.post(() -> {
                    mProgressAnimator.onBackProgressed(backEvent);
                });
            }

            @Override
            public void onBackStarted(BackEvent backEvent) {
                handler.post(() -> {
                    startBack(backEvent);
                    mProgressAnimator.onBackStarted(backEvent, event -> {
                        mBackProgress = event.getProgress();
                        // TODO: Update once the interpolation curve spec is finalized.
                        mBackProgress =
                                1 - (1 - mBackProgress) * (1 - mBackProgress) * (1
                                        - mBackProgress);
                if (!mBackInProgress) {
                    startBack(backEvent);
                } else {
                    updateBackProgress(mBackProgress, backEvent);
                }
                        updateBackProgress(mBackProgress, event);
                    });
                });
            }

            @Override
            public void onBackStarted() { }
        };
        SystemUiProxy.INSTANCE.get(mLauncher).setBackToLauncherCallback(mBackCallback);
    }
@@ -169,6 +182,7 @@ public class LauncherBackAnimationController {
        if (mBackCallback != null) {
            SystemUiProxy.INSTANCE.get(mLauncher).clearBackToLauncherCallback(mBackCallback);
        }
        mProgressAnimator.reset();
        mBackCallback = null;
    }

@@ -187,28 +201,20 @@ public class LauncherBackAnimationController {

        // TODO(b/218916755): Offset start rectangle in multiwindow mode.
        mStartRect.set(mBackTarget.windowConfiguration.getMaxBounds());
        mCurrentRect.set(mStartRect);
    }

    private void updateBackProgress(float progress, BackEvent event) {
        if (mBackTarget == null) {
        if (!mBackInProgress || mBackTarget == null) {
            return;
        }
        float screenWidth = mStartRect.width();
        float screenHeight = mStartRect.height();
        float dX = Math.abs(event.getTouchX() - mInitialTouchPos.x);
        // The 'follow width' is the width of the window if it completely matches
        // the gesture displacement.
        float followWidth = screenWidth - dX;
        // The 'progress width' is the width of the window if it strictly linearly interpolates
        // to minimum scale base on progress.
        float progressWidth = Utilities.mapRange(progress, 1, MIN_WINDOW_SCALE) * screenWidth;
        // The final width is derived from interpolating between the follow with and progress width
        // using gesture progress.
        float width = Utilities.mapRange(progress, followWidth, progressWidth);
        float width = Utilities.mapRange(progress, 1, MIN_WINDOW_SCALE) * screenWidth;
        float height = screenHeight / screenWidth * width;
        float deltaYRatio = (event.getTouchY() - mInitialTouchPos.y) / screenHeight;
        // Base the window movement in the Y axis on the touch movement in the Y axis.
        float deltaY = (float) Math.sin(deltaYRatio * Math.PI * 0.5f) * mWindowMaxDeltaY;
        float deltaY = (float) Math.sin(deltaYRatio * Math.PI * 0.5f) * mWindowMaxDeltaY * progress;
        // Move the window along the Y axis.
        float top = (screenHeight - height) * 0.5f + deltaY;
        // Move the window along the X axis.