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

Commit b63e9281 authored by Johannes Gallmann's avatar Johannes Gallmann Committed by Android (Google) Code Review
Browse files

Merge "Update mInitTouchX when restarting back gesture" into main

parents a6c11721 5acf2cb6
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