Merge "Fix back to home animation restarts on a second swipe." into tm-qpr-dev

This commit is contained in:
Shan Huang
2022-08-10 15:05:52 +00:00
committed by Android (Google) Code Review
2 changed files with 20 additions and 2 deletions

View File

@@ -97,6 +97,8 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
/** Tracks if an uninterruptible transition is in progress */ /** Tracks if an uninterruptible transition is in progress */
private boolean mTransitionInProgress = false; private boolean mTransitionInProgress = false;
/** Tracks if we should start the back gesture on the next motion move event */
private boolean mShouldStartOnNextMoveEvent = false;
/** @see #setTriggerBack(boolean) */ /** @see #setTriggerBack(boolean) */
private boolean mTriggerBack; private boolean mTriggerBack;
@@ -298,12 +300,17 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
if (mTransitionInProgress) { if (mTransitionInProgress) {
return; return;
} }
if (keyAction == MotionEvent.ACTION_MOVE) { if (keyAction == MotionEvent.ACTION_DOWN) {
if (!mBackGestureStarted) { if (!mBackGestureStarted) {
mShouldStartOnNextMoveEvent = true;
}
} else if (keyAction == MotionEvent.ACTION_MOVE) {
if (!mBackGestureStarted && mShouldStartOnNextMoveEvent) {
// Let the animation initialized here to make sure the onPointerDownOutsideFocus // Let the animation initialized here to make sure the onPointerDownOutsideFocus
// could be happened when ACTION_DOWN, it may change the current focus that we // could be happened when ACTION_DOWN, it may change the current focus that we
// would access it when startBackNavigation. // would access it when startBackNavigation.
onGestureStarted(touchX, touchY); onGestureStarted(touchX, touchY);
mShouldStartOnNextMoveEvent = false;
} }
onMove(touchX, touchY, swipeEdge); onMove(touchX, touchY, swipeEdge);
} else if (keyAction == MotionEvent.ACTION_UP || keyAction == MotionEvent.ACTION_CANCEL) { } else if (keyAction == MotionEvent.ACTION_UP || keyAction == MotionEvent.ACTION_CANCEL) {
@@ -437,6 +444,11 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
private void onGestureFinished(boolean fromTouch) { private void onGestureFinished(boolean fromTouch) {
ProtoLog.d(WM_SHELL_BACK_PREVIEW, "onGestureFinished() mTriggerBack == %s", mTriggerBack); ProtoLog.d(WM_SHELL_BACK_PREVIEW, "onGestureFinished() mTriggerBack == %s", mTriggerBack);
if (!mBackGestureStarted) {
finishAnimation();
return;
}
if (fromTouch) { if (fromTouch) {
// Let touch reset the flag otherwise it will start a new back navigation and refresh // Let touch reset the flag otherwise it will start a new back navigation and refresh
// the info when received a new move event. // the info when received a new move event.
@@ -552,6 +564,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
boolean triggerBack = mTriggerBack; boolean triggerBack = mTriggerBack;
mBackNavigationInfo = null; mBackNavigationInfo = null;
mTriggerBack = false; mTriggerBack = false;
mShouldStartOnNextMoveEvent = false;
if (backNavigationInfo == null) { if (backNavigationInfo == null) {
return; return;
} }

View File

@@ -284,9 +284,14 @@ public class BackAnimationControllerTest extends ShellTestCase {
// the previous transition is finished. // the previous transition is finished.
doMotionEvent(MotionEvent.ACTION_DOWN, 0); doMotionEvent(MotionEvent.ACTION_DOWN, 0);
verifyNoMoreInteractions(mIOnBackInvokedCallback); verifyNoMoreInteractions(mIOnBackInvokedCallback);
mController.onBackToLauncherAnimationFinished();
// Verify that more events from a rejected swipe cannot start animation.
doMotionEvent(MotionEvent.ACTION_MOVE, 100);
doMotionEvent(MotionEvent.ACTION_UP, 0);
verifyNoMoreInteractions(mIOnBackInvokedCallback);
// Verify that we start accepting gestures again once transition finishes. // Verify that we start accepting gestures again once transition finishes.
mController.onBackToLauncherAnimationFinished();
doMotionEvent(MotionEvent.ACTION_DOWN, 0); doMotionEvent(MotionEvent.ACTION_DOWN, 0);
doMotionEvent(MotionEvent.ACTION_MOVE, 100); doMotionEvent(MotionEvent.ACTION_MOVE, 100);
verify(mIOnBackInvokedCallback).onBackStarted(); verify(mIOnBackInvokedCallback).onBackStarted();