From 059dd66847d19d5b4347ae835fce070b309dda99 Mon Sep 17 00:00:00 2001 From: mincheli Date: Sun, 4 Jul 2021 06:31:22 +0800 Subject: [PATCH] Correct magnification switch button position after screen size is changed This is for the foldable devices. When the screen size is changed when the device is folded or unfolded, the magnification switch button position should be adjusted to keep the X postion stick to the closest screen edge and Y position in the same height ration. https://buganizer.corp.google.com/issues/190365799#comment2 Bug: 190365799 Test: atest MagnificationModeSwitchTest Mannual testing by using adb shell wm size 1080x2280 to change the screen size. Change-Id: Ic73309c9d79fb8476b2de823f8d4d75355c4d944 --- .../MagnificationModeSwitch.java | 3 ++- .../MagnificationModeSwitchTest.java | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java b/packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java index 17178fa8e6067..e521c90961fba 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/MagnificationModeSwitch.java @@ -310,7 +310,8 @@ class MagnificationModeSwitch implements MagnificationGestureDetector.OnGestureL } void onConfigurationChanged(int configDiff) { - if ((configDiff & ActivityInfo.CONFIG_ORIENTATION) != 0) { + if ((configDiff & (ActivityInfo.CONFIG_ORIENTATION | ActivityInfo.CONFIG_SCREEN_SIZE)) + != 0) { final Rect previousDraggableBounds = new Rect(mDraggableWindowBounds); mDraggableWindowBounds.set(getDraggableWindowBounds()); // Keep the Y position with the same height ratio before the window bounds and diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/MagnificationModeSwitchTest.java b/packages/SystemUI/tests/src/com/android/systemui/accessibility/MagnificationModeSwitchTest.java index 5617f1b6316b1..1561b2028748d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/MagnificationModeSwitchTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/MagnificationModeSwitchTest.java @@ -507,6 +507,30 @@ public class MagnificationModeSwitchTest extends SysuiTestCase { expectedY, mWindowManager.getLayoutParamsFromAttachedView().y); } + @Test + public void onScreenSizeChanged_buttonIsShowingOnTheRightSide_expectedPosition() { + final Rect windowBounds = mWindowManager.getCurrentWindowMetrics().getBounds(); + mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN); + final Rect oldDraggableBounds = new Rect(mMagnificationModeSwitch.mDraggableWindowBounds); + final float windowHeightFraction = + (float) (mWindowManager.getLayoutParamsFromAttachedView().y + - oldDraggableBounds.top) / oldDraggableBounds.height(); + + // The window bounds and the draggable bounds are changed due to the screen size change. + final Rect tmpRect = new Rect(windowBounds); + tmpRect.scale(2); + final Rect newWindowBounds = new Rect(tmpRect); + mWindowManager.setWindowBounds(newWindowBounds); + mMagnificationModeSwitch.onConfigurationChanged(ActivityInfo.CONFIG_SCREEN_SIZE); + + final int expectedX = mMagnificationModeSwitch.mDraggableWindowBounds.right; + final int expectedY = (int) (windowHeightFraction + * mMagnificationModeSwitch.mDraggableWindowBounds.height()) + + mMagnificationModeSwitch.mDraggableWindowBounds.top; + assertEquals(expectedX, mWindowManager.getLayoutParamsFromAttachedView().x); + assertEquals(expectedY, mWindowManager.getLayoutParamsFromAttachedView().y); + } + private void assertModeUnchanged(int expectedMode) { final int actualMode = Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE, 0);