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

Commit 5acf2cb6 authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Update mInitTouchX when restarting back gesture

Bug: 318511153
Flag: ACONFIG com.android.systemui.predictive_back_qs_dialog_anim DEVELOPMENT
Test: atest TouchTrackerTest
Change-Id: I8f252159eeb1a5e1462f57ac4f308a3b80fdf920
parent fd893875
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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;
+65 −0
Original line number Diff line number Diff line
@@ -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