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

Commit a8bacfb5 authored by Riley Jones's avatar Riley Jones
Browse files

Fix for FAB positioning

Adds extra check to vertical position to ensure it does not exceed top or bottom bounds

Bug: 401445232
Test: atest MenuViewApperanceTest
Test: Drag and release FAB ontop of status bar. It should not be possible for the FAB to come to rest while overlapping the bar.
Flag: EXEMPT small internal change
Change-Id: Ibcb294c5a40e810b61dd9d442d53de4c4c0ccc8c
parent f18caa57
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -317,14 +317,14 @@ class MenuViewAppearance {
    public static float avoidVerticalDisplayCutout(
            float y, float menuHeight, Rect bounds, Rect cutout) {
        if (cutout.top > y + menuHeight || cutout.bottom < y) {
            return y;
            return clampVerticalPosition(y, menuHeight, bounds.top, bounds.bottom);
        }

        boolean topAvailable = cutout.top - bounds.top >= menuHeight;
        boolean bottomAvailable = bounds.bottom - cutout.bottom >= menuHeight;
        boolean topOrBottom;
        if (!topAvailable && !bottomAvailable) {
            return y;
            return clampVerticalPosition(y, menuHeight, bounds.top, bounds.bottom);
        } else if (topAvailable && !bottomAvailable) {
            topOrBottom = true;
        } else if (!topAvailable && bottomAvailable) {
@@ -332,7 +332,16 @@ class MenuViewAppearance {
        } else {
            topOrBottom = y + menuHeight * 0.5f < cutout.centerY();
        }
        return (topOrBottom) ? cutout.top - menuHeight : cutout.bottom;

        float finalPosition = (topOrBottom) ? cutout.top - menuHeight : cutout.bottom;
        return clampVerticalPosition(finalPosition, menuHeight, bounds.top, bounds.bottom);
    }

    private static float clampVerticalPosition(
            float position, float height, float min, float max) {
        position = Float.max(min + height / 2, position);
        position = Float.min(max - height / 2, position);
        return position;
    }

    boolean isMenuOnLeftSide() {
+21 −0
Original line number Diff line number Diff line
@@ -69,4 +69,25 @@ public class MenuViewAppearanceTest extends SysuiTestCase {

        assertThat(end_y).isEqualTo(end_y);
    }

    @Test
    public void avoidVerticalDisplayCutout_doesNotExceedTopBounds() {
        final int y = DRAGGABLE_BOUNDS.top - 100;

        final float end_y = MenuViewAppearance.avoidVerticalDisplayCutout(
                y, MENU_HEIGHT, DRAGGABLE_BOUNDS, new Rect(0, 5, 0, 6));

        assertThat(end_y).isGreaterThan(DRAGGABLE_BOUNDS.top);
    }


    @Test
    public void avoidVerticalDisplayCutout_doesNotExceedBottomBounds() {
        final int y = DRAGGABLE_BOUNDS.bottom + 100;

        final float end_y = MenuViewAppearance.avoidVerticalDisplayCutout(
                y, MENU_HEIGHT, DRAGGABLE_BOUNDS, new Rect(0, 5, 0, 6));

        assertThat(end_y).isLessThan(DRAGGABLE_BOUNDS.bottom);
    }
}