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

Commit 7277d7e3 authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Polish cross activity animation specs

Bug: 301113228
Flag: ACONFIG com.android.window.flags.predictive_back_system_animations DISABLED
Test: Manual, i.e. testing cross activity back animation on device
Change-Id: I62dccacbc98935b76304fb9d334f713034408044
parent 7c182fd4
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ public final class BackMotionEvent implements Parcelable {
    private final float mProgress;
    private final float mVelocityX;
    private final float mVelocityY;
    private final boolean mTriggerBack;

    @BackEvent.SwipeEdge
    private final int mSwipeEdge;
@@ -54,6 +55,7 @@ public final class BackMotionEvent implements Parcelable {
     *                  Value in pixels/second. {@link Float#NaN} if was not computed.
     * @param velocityY Y velocity computed from the touch point of this event.
     *                  Value in pixels/second. {@link Float#NaN} if was not computed.
     * @param triggerBack Indicates whether the back arrow is in the triggered state or not
     * @param swipeEdge Indicates which edge the swipe starts from.
     * @param departingAnimationTarget The remote animation target of the departing
     *                                 application window.
@@ -64,6 +66,7 @@ public final class BackMotionEvent implements Parcelable {
            float progress,
            float velocityX,
            float velocityY,
            boolean triggerBack,
            @BackEvent.SwipeEdge int swipeEdge,
            @Nullable RemoteAnimationTarget departingAnimationTarget) {
        mTouchX = touchX;
@@ -71,6 +74,7 @@ public final class BackMotionEvent implements Parcelable {
        mProgress = progress;
        mVelocityX = velocityX;
        mVelocityY = velocityY;
        mTriggerBack = triggerBack;
        mSwipeEdge = swipeEdge;
        mDepartingAnimationTarget = departingAnimationTarget;
    }
@@ -81,6 +85,7 @@ public final class BackMotionEvent implements Parcelable {
        mProgress = in.readFloat();
        mVelocityX = in.readFloat();
        mVelocityY = in.readFloat();
        mTriggerBack = in.readBoolean();
        mSwipeEdge = in.readInt();
        mDepartingAnimationTarget = in.readTypedObject(RemoteAnimationTarget.CREATOR);
    }
@@ -110,6 +115,7 @@ public final class BackMotionEvent implements Parcelable {
        dest.writeFloat(mProgress);
        dest.writeFloat(mVelocityX);
        dest.writeFloat(mVelocityY);
        dest.writeBoolean(mTriggerBack);
        dest.writeInt(mSwipeEdge);
        dest.writeTypedObject(mDepartingAnimationTarget, flags);
    }
@@ -156,6 +162,15 @@ public final class BackMotionEvent implements Parcelable {
        return mVelocityY;
    }

    /**
     * Returns whether the back arrow is in the triggered state or not
     *
     * @return boolean indicating whether the back arrow is in the triggered state or not
     */
    public boolean getTriggerBack() {
        return mTriggerBack;
    }

    /**
     * Returns the screen edge that the swipe starts from.
     */
@@ -182,6 +197,7 @@ public final class BackMotionEvent implements Parcelable {
                + ", mProgress=" + mProgress
                + ", mVelocityX=" + mVelocityX
                + ", mVelocityY=" + mVelocityY
                + ", mTriggerBack=" + mTriggerBack
                + ", mSwipeEdge" + mSwipeEdge
                + ", mDepartingAnimationTarget" + mDepartingAnimationTarget
                + "}";
+1 −0
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ public class WindowOnBackInvokedDispatcherTest {
            /* progress = */ 0,
            /* velocityX = */ 0,
            /* velocityY = */ 0,
            /* triggerBack = */ false,
            /* swipeEdge = */ BackEvent.EDGE_LEFT,
            /* departingAnimationTarget = */ null);

+0 −1
Original line number Diff line number Diff line
@@ -21,5 +21,4 @@ package com.android.wm.shell.back;
 */
class BackAnimationConstants {
    static final float UPDATE_SYSUI_FLAGS_THRESHOLD = 0.20f;
    static final float PROGRESS_COMMIT_THRESHOLD = 0.1f;
}
+11 −7
Original line number Diff line number Diff line
@@ -18,9 +18,9 @@ package com.android.wm.shell.back;

import static android.view.RemoteAnimationTarget.MODE_CLOSING;
import static android.view.RemoteAnimationTarget.MODE_OPENING;
import static android.window.BackEvent.EDGE_RIGHT;

import static com.android.internal.jank.InteractionJankMonitor.CUJ_PREDICTIVE_BACK_CROSS_ACTIVITY;
import static com.android.wm.shell.back.BackAnimationConstants.PROGRESS_COMMIT_THRESHOLD;
import static com.android.wm.shell.back.BackAnimationConstants.UPDATE_SYSUI_FLAGS_THRESHOLD;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BACK_PREVIEW;

@@ -91,7 +91,7 @@ public class CrossActivityBackAnimation extends ShellBackAnimation {
                }
            };
    private static final float MIN_WINDOW_ALPHA = 0.01f;
    private static final float WINDOW_X_SHIFT_DP = 96;
    private static final float WINDOW_X_SHIFT_DP = 48;
    private static final int SCALE_FACTOR = 100;
    // TODO(b/264710590): Use the progress commit threshold from ViewConfiguration once it exists.
    private static final float TARGET_COMMIT_PROGRESS = 0.5f;
@@ -126,6 +126,8 @@ public class CrossActivityBackAnimation extends ShellBackAnimation {
    private SurfaceControl.Transaction mTransaction = new SurfaceControl.Transaction();

    private boolean mBackInProgress = false;
    private boolean mIsRightEdge;
    private boolean mTriggerBack = false;

    private PointF mTouchPos = new PointF();
    private IRemoteAnimationFinishedCallback mFinishCallback;
@@ -241,14 +243,15 @@ public class CrossActivityBackAnimation extends ShellBackAnimation {

    private void onGestureProgress(@NonNull BackEvent backEvent) {
        if (!mBackInProgress) {
            mIsRightEdge = backEvent.getSwipeEdge() == EDGE_RIGHT;
            mInitialTouchPos.set(backEvent.getTouchX(), backEvent.getTouchY());
            mBackInProgress = true;
        }
        mTouchPos.set(backEvent.getTouchX(), backEvent.getTouchY());

        float progress = backEvent.getProgress();
        float springProgress = (progress > PROGRESS_COMMIT_THRESHOLD
                ? mapLinear(progress, 0.1f, 1, TARGET_COMMIT_PROGRESS, 1)
        float springProgress = (mTriggerBack
                ? mapLinear(progress, 0f, 1, TARGET_COMMIT_PROGRESS, 1)
                : mapLinear(progress, 0, 1f, 0, TARGET_COMMIT_PROGRESS)) * SCALE_FACTOR;
        mLeavingProgressSpring.animateToFinalPosition(springProgress);
        mEnteringProgressSpring.animateToFinalPosition(springProgress);
@@ -312,7 +315,7 @@ public class CrossActivityBackAnimation extends ShellBackAnimation {
            transformWithProgress(
                    mEnteringProgress,
                    Math.max(
                            smoothstep(ENTER_ALPHA_THRESHOLD, 1, mEnteringProgress),
                            smoothstep(ENTER_ALPHA_THRESHOLD, 0.7f, mEnteringProgress),
                            MIN_WINDOW_ALPHA),  /* alpha */
                    mEnteringTarget.leash,
                    mEnteringRect,
@@ -337,14 +340,13 @@ public class CrossActivityBackAnimation extends ShellBackAnimation {
                    mClosingTarget.leash,
                    mClosingRect,
                    0,
                    mWindowXShift
                    mIsRightEdge ? 0 : mWindowXShift
            );
        }
    }

    private void transformWithProgress(float progress, float alpha, SurfaceControl surface,
            RectF targetRect, float deltaXMin, float deltaXMax) {
        final float touchY = mTouchPos.y;

        final int width = mStartTaskRect.width();
        final int height = mStartTaskRect.height();
@@ -376,12 +378,14 @@ public class CrossActivityBackAnimation extends ShellBackAnimation {
    private final class Callback extends IOnBackInvokedCallback.Default {
        @Override
        public void onBackStarted(BackMotionEvent backEvent) {
            mTriggerBack = backEvent.getTriggerBack();
            mProgressAnimator.onBackStarted(backEvent,
                    CrossActivityBackAnimation.this::onGestureProgress);
        }

        @Override
        public void onBackProgressed(@NonNull BackMotionEvent backEvent) {
            mTriggerBack = backEvent.getTriggerBack();
            mProgressAnimator.onBackProgressed(backEvent);
        }

+2 −0
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ class TouchTracker {
                /* progress = */ 0,
                /* velocityX = */ 0,
                /* velocityY = */ 0,
                /* triggerBack = */ mTriggerBack,
                /* swipeEdge = */ mSwipeEdge,
                /* departingAnimationTarget = */ target);
    }
@@ -195,6 +196,7 @@ class TouchTracker {
                /* progress = */ progress,
                /* velocityX = */ mLatestVelocityX,
                /* velocityY = */ mLatestVelocityY,
                /* triggerBack = */ mTriggerBack,
                /* swipeEdge = */ mSwipeEdge,
                /* departingAnimationTarget = */ null);
    }
Loading