Loading packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewAppearance.java +12 −3 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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() { Loading packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuViewAppearanceTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -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); } } Loading
packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewAppearance.java +12 −3 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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() { Loading
packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/MenuViewAppearanceTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -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); } }