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

Commit 000a5c3b authored by Josh Yang's avatar Josh Yang
Browse files

Fix overscroll detection on watch.

The overscroll detection doesn't work well when user scrolls diagonally
at the edge. E.g. when user swipes right when the view top is at top,
the swipe was considered overscroll if the finger has a very minor delta
with upwards direction.

This change fixes this issue by determining the swipe direction based on
the larger delta value between x and y axis.

Flag: EXEMPT small bug fix
Bug: 350679840
Test: atest FullScreenMagnificationGestureHandlerTest
Change-Id: I75f9b50157c621ba5a602cecef03c1dbb7ab41ad
parent 9e11b523
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -1659,11 +1659,12 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
        }
        float dX = event.getX() - firstPointerDownLocation.x;
        float dY = event.getY() - firstPointerDownLocation.y;
        if (isAtLeftEdge() && dX > 0) {
        if (isAtLeftEdge() && isScrollingLeft(dX, dY)) {
            return OVERSCROLL_LEFT_EDGE;
        } else if (isAtRightEdge() && dX < 0) {
        } else if (isAtRightEdge() && isScrollingRight(dX, dY)) {
            return OVERSCROLL_RIGHT_EDGE;
        } else if ((isAtTopEdge() && dY > 0) || (isAtBottomEdge() && dY < 0)) {
        } else if ((isAtTopEdge() && isScrollingUp(dX, dY))
                || (isAtBottomEdge() && isScrollingDown(dX, dY))) {
            return OVERSCROLL_VERTICAL_EDGE;
        }
        return OVERSCROLL_NONE;
@@ -1673,18 +1674,34 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
        return mFullScreenMagnificationController.isAtLeftEdge(mDisplayId, mOverscrollEdgeSlop);
    }

    private static boolean isScrollingLeft(float dX, float dY) {
        return Math.abs(dX) > Math.abs(dY) && dX > 0;
    }

    private boolean isAtRightEdge() {
        return mFullScreenMagnificationController.isAtRightEdge(mDisplayId, mOverscrollEdgeSlop);
    }

    private static boolean isScrollingRight(float dX, float dY) {
        return Math.abs(dX) > Math.abs(dY) && dX < 0;
    }

    private boolean isAtTopEdge() {
        return mFullScreenMagnificationController.isAtTopEdge(mDisplayId, mOverscrollEdgeSlop);
    }

    private static boolean isScrollingUp(float dX, float dY) {
        return Math.abs(dX) < Math.abs(dY) && dY > 0;
    }

    private boolean isAtBottomEdge() {
        return mFullScreenMagnificationController.isAtBottomEdge(mDisplayId, mOverscrollEdgeSlop);
    }

    private static boolean isScrollingDown(float dX, float dY) {
        return Math.abs(dX) < Math.abs(dY) && dY < 0;
    }

    private boolean pointerValid(PointF pointerDownLocation) {
        return !(Float.isNaN(pointerDownLocation.x) && Float.isNaN(pointerDownLocation.y));
    }
+47 −0
Original line number Diff line number Diff line
@@ -983,6 +983,53 @@ public class FullScreenMagnificationGestureHandlerTest {
        assertTrue(isZoomed());
    }

    @Test
    public void testSingleFingerOverscrollAtTopEdge_isWatch_scrollDiagonally_noOverscroll() {
        assumeTrue(isWatch());
        goFromStateIdleTo(STATE_SINGLE_PANNING);
        float centerX =
                (INITIAL_MAGNIFICATION_BOUNDS.right + INITIAL_MAGNIFICATION_BOUNDS.left) / 2.0f;
        mFullScreenMagnificationController.setCenter(
                DISPLAY_0, centerX, INITIAL_MAGNIFICATION_BOUNDS.top, false, 1);
        final float swipeMinDistance = ViewConfiguration.get(mContext).getScaledTouchSlop() + 1;
        PointF initCoords =
                new PointF(
                        mFullScreenMagnificationController.getCenterX(DISPLAY_0),
                        mFullScreenMagnificationController.getCenterY(DISPLAY_0));
        PointF edgeCoords = new PointF(initCoords.x, initCoords.y);
        // Scroll diagonally towards top-right with a bigger right delta
        edgeCoords.offset(swipeMinDistance * 2, swipeMinDistance);

        swipeAndHold(initCoords, edgeCoords);

        assertTrue(mMgh.mOverscrollHandler.mOverscrollState == mMgh.OVERSCROLL_NONE);
        assertTrue(isZoomed());
    }

    @Test
    public void
            testSingleFingerOverscrollAtTopEdge_isWatch_scrollDiagonally_expectedOverscrollState() {
        assumeTrue(isWatch());
        goFromStateIdleTo(STATE_SINGLE_PANNING);
        float centerX =
                (INITIAL_MAGNIFICATION_BOUNDS.right + INITIAL_MAGNIFICATION_BOUNDS.left) / 2.0f;
        mFullScreenMagnificationController.setCenter(
                DISPLAY_0, centerX, INITIAL_MAGNIFICATION_BOUNDS.top, false, 1);
        final float swipeMinDistance = ViewConfiguration.get(mContext).getScaledTouchSlop() + 1;
        PointF initCoords =
                new PointF(
                        mFullScreenMagnificationController.getCenterX(DISPLAY_0),
                        mFullScreenMagnificationController.getCenterY(DISPLAY_0));
        PointF edgeCoords = new PointF(initCoords.x, initCoords.y);
        // Scroll diagonally towards top-right with a bigger top delta
        edgeCoords.offset(swipeMinDistance, swipeMinDistance * 2);

        swipeAndHold(initCoords, edgeCoords);

        assertTrue(mMgh.mOverscrollHandler.mOverscrollState == mMgh.OVERSCROLL_VERTICAL_EDGE);
        assertTrue(isZoomed());
    }

    @Test
    public void testSingleFingerScrollAtEdge_isWatch_noOverscroll() {
        assumeTrue(isWatch());