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

Commit d5c89ab0 authored by Annie Lin's avatar Annie Lin Committed by Android (Google) Code Review
Browse files

Merge "[Interactive Divider] Snap to the closest position in the fling...

Merge "[Interactive Divider] Snap to the closest position in the fling direction when fling is triggered." into main
parents fd030200 e190227e
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -718,17 +718,30 @@ class DividerPresenter implements View.OnTouchListener {
            if (dividerPosition >= minPosition && dividerPosition <= maxPosition) {
                return dividerPosition;
            }
            int[] possiblePositions = {0, minPosition, maxPosition, fullyExpandedPosition};
            return snap(dividerPosition, possiblePositions);
            final int[] snapPositions = {0, minPosition, maxPosition, fullyExpandedPosition};
            return snap(dividerPosition, snapPositions);
        }
        if (velocity < 0) {
            return minPosition;
        return dividerPositionForFling(
                dividerPosition, minPosition, maxPosition, velocity);
    }

    /**
     * Returns the closest position that is in the fling direction.
     */
    private static int dividerPositionForFling(int dividerPosition, int minPosition,
            int maxPosition, float velocity) {
        final boolean isBackwardDirection = velocity < 0;
        if (isBackwardDirection) {
            return dividerPosition < maxPosition ? minPosition : maxPosition;
        } else {
            return maxPosition;
            return dividerPosition > minPosition ? maxPosition : minPosition;
        }
    }

    /** Calculates the snapped divider position based on the possible positions and distance. */
    /**
     * Returns the snapped position from a list of possible positions. Currently, this method
     * snaps to the closest position by distance from the divider position.
     */
    private static int snap(int dividerPosition, int[] possiblePositions) {
        int snappedPosition = dividerPosition;
        float minDistance = Float.MAX_VALUE;
+38 −12
Original line number Diff line number Diff line
@@ -715,25 +715,51 @@ public class DividerPresenterTest {
                        nonFlingVelocity,
                        displayDensity));

        // Divider position is greater than minPosition and the velocity is enough for fling
        // Divider position is in the closed to maxPosition bounds and the velocity is enough for
        // backward fling
        assertEquals(
                30, // minPosition
                2000, // maxPosition
                DividerPresenter.dividerPositionWithDraggingToFullscreenAllowed(
                        50 /* dividerPosition */,
                        30 /* minPosition */,
                        900 /* maxPosition */,
                        1200 /* fullyExpandedPosition */,
                        2200 /* dividerPosition */,
                        1000 /* minPosition */,
                        2000 /* maxPosition */,
                        2500 /* fullyExpandedPosition */,
                        -flingVelocity,
                        displayDensity));

        // Divider position is less than maxPosition and the velocity is enough for fling
        // Divider position is not in the closed to maxPosition bounds and the velocity is enough
        // for backward fling
        assertEquals(
                900, // maxPosition
                1000, // minPosition
                DividerPresenter.dividerPositionWithDraggingToFullscreenAllowed(
                        800 /* dividerPosition */,
                        30 /* minPosition */,
                        900 /* maxPosition */,
                        1200 /* fullyExpandedPosition */,
                        1200 /* dividerPosition */,
                        1000 /* minPosition */,
                        2000 /* maxPosition */,
                        2500 /* fullyExpandedPosition */,
                        -flingVelocity,
                        displayDensity));

        // Divider position is in the closed to minPosition bounds and the velocity is enough for
        // forward fling
        assertEquals(
                1000, // minPosition
                DividerPresenter.dividerPositionWithDraggingToFullscreenAllowed(
                        500 /* dividerPosition */,
                        1000 /* minPosition */,
                        2000 /* maxPosition */,
                        2500 /* fullyExpandedPosition */,
                        flingVelocity,
                        displayDensity));

        // Divider position is not in the closed to minPosition bounds and the velocity is enough
        // for forward fling
        assertEquals(
                2000, // maxPosition
                DividerPresenter.dividerPositionWithDraggingToFullscreenAllowed(
                        1200 /* dividerPosition */,
                        1000 /* minPosition */,
                        2000 /* maxPosition */,
                        2500 /* fullyExpandedPosition */,
                        flingVelocity,
                        displayDensity));
    }