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

Commit 130209ed authored by Riley Jones's avatar Riley Jones Committed by Android (Google) Code Review
Browse files

Merge "Fix for FAB positioning" into main

parents 24d32a2b a8bacfb5
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);
    }
}