Merge "Fix back taking multiple swipes." into tm-dev

This commit is contained in:
Shan Huang
2022-03-30 15:00:45 +00:00
committed by Android (Google) Code Review
4 changed files with 22 additions and 6 deletions

View File

@@ -16,6 +16,7 @@
package com.android.wm.shell.back;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.window.BackEvent;
@@ -29,8 +30,14 @@ 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
* 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, @BackEvent.SwipeEdge int swipeEdge);
void onBackMotion(MotionEvent event, int action, @BackEvent.SwipeEdge int swipeEdge);
/**
* Sets whether the back gesture is past the trigger threshold or not.

View File

@@ -138,8 +138,9 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
}
@Override
public void onBackMotion(MotionEvent event, @BackEvent.SwipeEdge int swipeEdge) {
mShellExecutor.execute(() -> onMotionEvent(event, swipeEdge));
public void onBackMotion(
MotionEvent event, int action, @BackEvent.SwipeEdge int swipeEdge) {
mShellExecutor.execute(() -> onMotionEvent(event, action, swipeEdge));
}
@Override
@@ -209,13 +210,13 @@ 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, @BackEvent.SwipeEdge int swipeEdge) {
int action = event.getActionMasked();
public void onMotionEvent(MotionEvent event, int action, @BackEvent.SwipeEdge int swipeEdge) {
if (action == MotionEvent.ACTION_DOWN) {
initAnimation(event);
} else if (action == MotionEvent.ACTION_MOVE) {
onMove(event, swipeEdge);
} else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
ProtoLog.d(WM_SHELL_BACK_PREVIEW, "Finishing gesture with event: %s", event);
onGestureFinished();
}
}

View File

@@ -118,6 +118,7 @@ public class BackAnimationControllerTest {
BackNavigationInfo.TYPE_CROSS_ACTIVITY);
mController.onMotionEvent(
MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0),
MotionEvent.ACTION_DOWN,
BackEvent.EDGE_LEFT);
verify(mTransaction).setBuffer(screenshotSurface, hardwareBuffer);
verify(mTransaction).setVisibility(screenshotSurface, true);
@@ -133,9 +134,11 @@ public class BackAnimationControllerTest {
BackNavigationInfo.TYPE_CROSS_ACTIVITY);
mController.onMotionEvent(
MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0),
MotionEvent.ACTION_DOWN,
BackEvent.EDGE_LEFT);
mController.onMotionEvent(
MotionEvent.obtain(10, 0, MotionEvent.ACTION_MOVE, 100, 100, 0),
MotionEvent.ACTION_MOVE,
BackEvent.EDGE_LEFT);
verify(mTransaction).setPosition(animationTarget.leash, 100, 100);
verify(mTransaction, atLeastOnce()).apply();
@@ -151,12 +154,14 @@ public class BackAnimationControllerTest {
// Check that back start is dispatched.
mController.onMotionEvent(
MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0),
MotionEvent.ACTION_DOWN,
BackEvent.EDGE_LEFT);
verify(mIOnBackInvokedCallback).onBackStarted();
// Check that back progress is dispatched.
mController.onMotionEvent(
MotionEvent.obtain(10, 0, MotionEvent.ACTION_MOVE, 100, 100, 0),
MotionEvent.ACTION_MOVE,
BackEvent.EDGE_LEFT);
ArgumentCaptor<BackEvent> backEventCaptor = ArgumentCaptor.forClass(BackEvent.class);
verify(mIOnBackInvokedCallback).onBackProgressed(backEventCaptor.capture());
@@ -166,6 +171,7 @@ public class BackAnimationControllerTest {
mController.setTriggerBack(true); // Fake trigger back
mController.onMotionEvent(
MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0),
MotionEvent.ACTION_UP,
BackEvent.EDGE_LEFT);
verify(mIOnBackInvokedCallback).onBackInvoked();
}

View File

@@ -480,7 +480,9 @@ public class NavigationBarEdgePanel extends View implements NavigationEdgeBackPl
public void onMotionEvent(MotionEvent event) {
if (mBackAnimation != null) {
mBackAnimation.onBackMotion(
event, mIsLeftPanel ? BackEvent.EDGE_LEFT : BackEvent.EDGE_RIGHT);
event,
event.getActionMasked(),
mIsLeftPanel ? BackEvent.EDGE_LEFT : BackEvent.EDGE_RIGHT);
}
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();