diff options
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/WindowManager/Shell/src/com/android/wm/shell/back/TouchTracker.java | 4 | ||||
| -rw-r--r-- | libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/TouchTrackerTest.kt | 65 |
2 files changed, 69 insertions, 0 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/TouchTracker.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/TouchTracker.java index 6213f628dfd3..8f04f126960c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/TouchTracker.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/TouchTracker.java @@ -63,6 +63,10 @@ class TouchTracker { if ((touchX < mStartThresholdX && mSwipeEdge == BackEvent.EDGE_LEFT) || (touchX > mStartThresholdX && mSwipeEdge == BackEvent.EDGE_RIGHT)) { mStartThresholdX = touchX; + if ((mSwipeEdge == BackEvent.EDGE_LEFT && mStartThresholdX < mInitTouchX) + || (mSwipeEdge == BackEvent.EDGE_RIGHT && mStartThresholdX > mInitTouchX)) { + mInitTouchX = mStartThresholdX; + } } mLatestTouchX = touchX; mLatestTouchY = touchY; diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/TouchTrackerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/TouchTrackerTest.kt index bf07dccd0658..6dbb1e2b8d92 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/TouchTrackerTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/TouchTrackerTest.kt @@ -170,6 +170,71 @@ class TouchTrackerTest { nonLinearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / nonLinearTarget) } + @Test + fun restartingGesture_resetsInitialTouchX_leftEdge() { + val linearTracker = linearTouchTracker() + linearTracker.setGestureStartLocation(INITIAL_X_LEFT_EDGE, 0f, BackEvent.EDGE_LEFT) + var touchX = 100f + val velocityX = 0f + val velocityY = 0f + + // assert that progress is increased when increasing touchX + linearTracker.update(touchX, 0f, velocityX, velocityY) + linearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / MAX_DISTANCE) + + // assert that progress is reset to 0 when start location is updated + linearTracker.updateStartLocation() + linearTracker.assertProgress(0f) + + // assert that progress remains 0 when touchX is decreased + touchX -= 50 + linearTracker.update(touchX, 0f, velocityX, velocityY) + linearTracker.assertProgress(0f) + + // assert that progress uses new minimal touchX for progress calculation + val newInitialTouchX = touchX + touchX += 100 + linearTracker.update(touchX, 0f, velocityX, velocityY) + linearTracker.assertProgress((touchX - newInitialTouchX) / MAX_DISTANCE) + + // assert the same for triggerBack==true + linearTracker.triggerBack = true + linearTracker.assertProgress((touchX - newInitialTouchX) / MAX_DISTANCE) + } + + @Test + fun restartingGesture_resetsInitialTouchX_rightEdge() { + val linearTracker = linearTouchTracker() + linearTracker.setGestureStartLocation(INITIAL_X_RIGHT_EDGE, 0f, BackEvent.EDGE_RIGHT) + + var touchX = INITIAL_X_RIGHT_EDGE - 100f + val velocityX = 0f + val velocityY = 0f + + // assert that progress is increased when decreasing touchX + linearTracker.update(touchX, 0f, velocityX, velocityY) + linearTracker.assertProgress((INITIAL_X_RIGHT_EDGE - touchX) / MAX_DISTANCE) + + // assert that progress is reset to 0 when start location is updated + linearTracker.updateStartLocation() + linearTracker.assertProgress(0f) + + // assert that progress remains 0 when touchX is increased + touchX += 50 + linearTracker.update(touchX, 0f, velocityX, velocityY) + linearTracker.assertProgress(0f) + + // assert that progress uses new maximal touchX for progress calculation + val newInitialTouchX = touchX + touchX -= 100 + linearTracker.update(touchX, 0f, velocityX, velocityY) + linearTracker.assertProgress((newInitialTouchX - touchX) / MAX_DISTANCE) + + // assert the same for triggerBack==true + linearTracker.triggerBack = true + linearTracker.assertProgress((newInitialTouchX - touchX) / MAX_DISTANCE) + } + companion object { private const val MAX_DISTANCE = 500f private const val LINEAR_DISTANCE = 400f |