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

Commit c418941c authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Fix predictive back progress animating the opposite direction

Bug: 308896129
Test: atest TouchTrackerTest
Change-Id: Iaba64b5b013eb6dc75df75b6071a6b5983cd3cdc
parent 009a0999
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ class TouchTracker {
    private float mLatestVelocityY;
    private float mStartThresholdX;
    private int mSwipeEdge;
    private boolean mCancelled;
    private TouchTrackerState mState = TouchTrackerState.INITIAL;

    void update(float touchX, float touchY, float velocityX, float velocityY) {
@@ -59,9 +58,8 @@ class TouchTracker {
         * If back was previously cancelled but the user has started swiping in the forward
         * direction again, restart back.
         */
        if (mCancelled && ((touchX > mLatestTouchX && mSwipeEdge == BackEvent.EDGE_LEFT)
                || touchX < mLatestTouchX && mSwipeEdge == BackEvent.EDGE_RIGHT)) {
            mCancelled = false;
        if ((touchX < mStartThresholdX && mSwipeEdge == BackEvent.EDGE_LEFT)
                || (touchX > mStartThresholdX && mSwipeEdge == BackEvent.EDGE_RIGHT)) {
            mStartThresholdX = touchX;
        }
        mLatestTouchX = touchX;
@@ -72,7 +70,7 @@ class TouchTracker {

    void setTriggerBack(boolean triggerBack) {
        if (mTriggerBack != triggerBack && !triggerBack) {
            mCancelled = true;
            mStartThresholdX = mLatestTouchX;
        }
        mTriggerBack = triggerBack;
    }
@@ -100,6 +98,8 @@ class TouchTracker {
    void setGestureStartLocation(float touchX, float touchY, int swipeEdge) {
        mInitTouchX = touchX;
        mInitTouchY = touchY;
        mLatestTouchX = touchX;
        mLatestTouchY = touchY;
        mSwipeEdge = swipeEdge;
        mStartThresholdX = mInitTouchX;
    }
@@ -108,7 +108,6 @@ class TouchTracker {
        mInitTouchX = 0;
        mInitTouchY = 0;
        mStartThresholdX = 0;
        mCancelled = false;
        mTriggerBack = false;
        mState = TouchTrackerState.INITIAL;
        mSwipeEdge = BackEvent.EDGE_LEFT;
@@ -126,11 +125,7 @@ class TouchTracker {
    }

    BackMotionEvent createProgressEvent() {
        float progress = 0;
        // Progress is always 0 when back is cancelled and not restarted.
        if (!mCancelled) {
            progress = getProgress(mLatestTouchX);
        }
        float progress = getProgress(mLatestTouchX);
        return createProgressEvent(progress);
    }

@@ -148,7 +143,13 @@ class TouchTracker {
        // The starting threshold is initially the first touch location, and updated to
        // the location everytime back is restarted after being cancelled.
        float startX = mTriggerBack ? mInitTouchX : mStartThresholdX;
        float deltaX = Math.abs(startX - touchX);
        float distance;
        if (mSwipeEdge == BackEvent.EDGE_LEFT) {
            distance = touchX - startX;
        } else {
            distance = startX - touchX;
        }
        float deltaX = Math.max(0f, distance);
        float linearDistance = mLinearDistance;
        float maxDistance = getMaxDistance();
        maxDistance = maxDistance == 0 ? 1 : maxDistance;
+8 −8
Original line number Diff line number Diff line
@@ -71,13 +71,13 @@ class TouchTrackerTest {
        linearTracker.update(touchX, 0f, velocityX, velocityY)
        linearTracker.assertProgress(0f)

        // Restart
        // Restarted, but pre-commit
        val restartX = touchX
        touchX += 10f
        linearTracker.update(touchX, 0f, velocityX, velocityY)
        linearTracker.assertProgress(0f)
        linearTracker.assertProgress((touchX - restartX) / MAX_DISTANCE)

        // Restarted, but pre-commit
        val restartX = touchX
        // continue restart within pre-commit
        touchX += 10f
        linearTracker.update(touchX, 0f, velocityX, velocityY)
        linearTracker.assertProgress((touchX - restartX) / MAX_DISTANCE)
@@ -119,13 +119,13 @@ class TouchTrackerTest {
        linearTracker.update(touchX, 0f, velocityX, velocityY)
        linearTracker.assertProgress(0f)

        // Restart
        // Restarted, but pre-commit
        val restartX = touchX
        touchX -= 10f
        linearTracker.update(touchX, 0f, velocityX, velocityY)
        linearTracker.assertProgress(0f)
        linearTracker.assertProgress((restartX - touchX) / target)

        // Restarted, but pre-commit
        val restartX = touchX
        // continue restart within pre-commit
        touchX -= 10f
        linearTracker.update(touchX, 0f, velocityX, velocityY)
        linearTracker.assertProgress((restartX - touchX) / target)