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

Commit a79aed78 authored by Shan Huang's avatar Shan Huang Committed by Automerger Merge Worker
Browse files

Merge "Pass the values of the MotionEvent instead of the event instance itself...

Merge "Pass the values of the MotionEvent instead of the event instance itself to BackAnimation." into tm-dev am: 1deb1af4

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18963576



Change-Id: I24f8b034e3bfdc15493c8f2a2716985fddc4deab
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents f6c9d9d3 1deb1af4
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -31,13 +31,15 @@ public interface BackAnimation {
    /**
     * Called when a {@link MotionEvent} is generated by a back gesture.
     *
     * @param event the original {@link MotionEvent}
     * @param action the original {@link KeyEvent#getAction()} when the event was dispatched to
     * @param touchX the X touch position of the {@link MotionEvent}.
     * @param touchY the Y touch position of the {@link MotionEvent}.
     * @param keyAction the original {@link KeyEvent#getAction()} when the event was dispatched to
     *               the process. This is forwarded separately because the input pipeline may mutate
     *               the {#event} action state later.
     * @param swipeEdge the edge from which the swipe begins.
     */
    void onBackMotion(MotionEvent event, int action, @BackEvent.SwipeEdge int swipeEdge);
    void onBackMotion(float touchX, float touchY, int keyAction,
            @BackEvent.SwipeEdge int swipeEdge);

    /**
     * Sets whether the back gesture is past the trigger threshold or not.
+14 −13
Original line number Diff line number Diff line
@@ -184,8 +184,8 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont

        @Override
        public void onBackMotion(
                MotionEvent event, int action, @BackEvent.SwipeEdge int swipeEdge) {
            mShellExecutor.execute(() -> onMotionEvent(event, action, swipeEdge));
                float touchX, float touchY, int keyAction, @BackEvent.SwipeEdge int swipeEdge) {
            mShellExecutor.execute(() -> onMotionEvent(touchX, touchY, keyAction, swipeEdge));
        }

        @Override
@@ -256,33 +256,34 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
     * Called when a new motion event needs to be transferred to this
     * {@link BackAnimationController}
     */
    public void onMotionEvent(MotionEvent event, int action, @BackEvent.SwipeEdge int swipeEdge) {
    public void onMotionEvent(float touchX, float touchY, int keyAction,
            @BackEvent.SwipeEdge int swipeEdge) {
        if (mTransitionInProgress) {
            return;
        }
        if (action == MotionEvent.ACTION_MOVE) {
        if (keyAction == MotionEvent.ACTION_MOVE) {
            if (!mBackGestureStarted) {
                // Let the animation initialized here to make sure the onPointerDownOutsideFocus
                // could be happened when ACTION_DOWN, it may change the current focus that we
                // would access it when startBackNavigation.
                initAnimation(event);
                initAnimation(touchX, touchY);
            }
            onMove(event, swipeEdge);
        } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
            onMove(touchX, touchY, swipeEdge);
        } else if (keyAction == MotionEvent.ACTION_UP || keyAction == MotionEvent.ACTION_CANCEL) {
            ProtoLog.d(WM_SHELL_BACK_PREVIEW,
                    "Finishing gesture with event action: %d", action);
                    "Finishing gesture with event action: %d", keyAction);
            onGestureFinished();
        }
    }

    private void initAnimation(MotionEvent event) {
    private void initAnimation(float touchX, float touchY) {
        ProtoLog.d(WM_SHELL_BACK_PREVIEW, "initAnimation mMotionStarted=%b", mBackGestureStarted);
        if (mBackGestureStarted || mBackNavigationInfo != null) {
            Log.e(TAG, "Animation is being initialized but is already started.");
            finishAnimation();
        }

        mInitTouchLocation.set(event.getX(), event.getY());
        mInitTouchLocation.set(touchX, touchY);
        mBackGestureStarted = true;

        try {
@@ -351,18 +352,18 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        mTransaction.setVisibility(screenshotSurface, true);
    }

    private void onMove(MotionEvent event, @BackEvent.SwipeEdge int swipeEdge) {
    private void onMove(float touchX, float touchY, @BackEvent.SwipeEdge int swipeEdge) {
        if (!mBackGestureStarted || mBackNavigationInfo == null) {
            return;
        }
        int deltaX = Math.round(event.getX() - mInitTouchLocation.x);
        int deltaX = Math.round(touchX - mInitTouchLocation.x);
        float progressThreshold = PROGRESS_THRESHOLD >= 0 ? PROGRESS_THRESHOLD : mProgressThreshold;
        float progress = Math.min(Math.max(Math.abs(deltaX) / progressThreshold, 0), 1);
        int backType = mBackNavigationInfo.getType();
        RemoteAnimationTarget animationTarget = mBackNavigationInfo.getDepartingAnimationTarget();

        BackEvent backEvent = new BackEvent(
                event.getX(), event.getY(), progress, swipeEdge, animationTarget);
                touchX, touchY, progress, swipeEdge, animationTarget);
        IOnBackInvokedCallback targetCallback = null;
        if (shouldDispatchToLauncher(backType)) {
            targetCallback = mBackToLauncherCallback;
+1 −1
Original line number Diff line number Diff line
@@ -298,7 +298,7 @@ public class BackAnimationControllerTest {

    private void doMotionEvent(int actionDown, int coordinate) {
        mController.onMotionEvent(
                MotionEvent.obtain(0, mEventTime, actionDown, coordinate, coordinate, 0),
                coordinate, coordinate,
                actionDown,
                BackEvent.EDGE_LEFT);
        mEventTime += 10;
+1 −1
Original line number Diff line number Diff line
@@ -486,7 +486,7 @@ public class NavigationBarEdgePanel extends View implements NavigationEdgeBackPl
    public void onMotionEvent(MotionEvent event) {
        if (mBackAnimation != null) {
            mBackAnimation.onBackMotion(
                    event,
                    event.getX(), event.getY(),
                    event.getActionMasked(),
                    mIsLeftPanel ? BackEvent.EDGE_LEFT : BackEvent.EDGE_RIGHT);
        }