diff options
author | Shan Huang <shanh@google.com> | 2022-06-21 18:13:38 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-06-21 18:13:38 +0000 |
commit | 1deb1af4a7a7f6407ebd661da9a54812e5362a2c (patch) | |
tree | 06cecd498cafa3cd76e4a4deffb97c7429ac0126 | |
parent | 77f103bc325ba194313fbfe0c44d06658fc6b978 (diff) | |
parent | db78c194d8dd8774c77d0ec8e8913b3eeaef8325 (diff) | |
download | base-1deb1af4a7a7f6407ebd661da9a54812e5362a2c.tar.gz |
Merge "Pass the values of the MotionEvent instead of the event instance itself to BackAnimation." into tm-dev
4 files changed, 21 insertions, 18 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimation.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimation.java index e71a59d26740..8c0affb0a432 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimation.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimation.java @@ -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. diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java index 0cb56d72004d..0cf2b28921e1 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java @@ -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; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java index fcfcbfa091db..e7c5cb2183db 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java @@ -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; diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/NavigationBarEdgePanel.java b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/NavigationBarEdgePanel.java index a74c59618c95..eba9d3fdcab8 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/NavigationBarEdgePanel.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/NavigationBarEdgePanel.java @@ -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); } |