From f2ef6b540c553615624ef1255421fa81b5aa03c3 Mon Sep 17 00:00:00 2001 From: ryanlwlin Date: Wed, 25 Aug 2021 16:21:45 +0800 Subject: [PATCH] Constranit the magnification window size for large screen devices The window size depends on the screen size. However, it is too big for fodlables. We constraint the window size to avoid it. Bug: 194268185 Test: WindowMagnificationControllerTest Change-Id: I16b25560e2a7db324433530a9fa4f310fe2fe529 --- packages/SystemUI/res/values/dimens.xml | 1 + .../WindowMagnificationController.java | 9 ++-- .../WindowMagnificationControllerTest.java | 44 +++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 689f8f7abf4fe..45869e66bc6de 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1339,6 +1339,7 @@ 40dp 3dp + 300dp 4dp diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java index a51e3fcfd50b7..0893e895b102c 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java @@ -499,9 +499,12 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold } private void setMagnificationFrameWith(Rect windowBounds, int centerX, int centerY) { - // Sets the initial frame area for the mirror and places it in the center of the display. - final int initSize = Math.min(windowBounds.width(), windowBounds.height()) / 2 - + 2 * mMirrorSurfaceMargin; + // Sets the initial frame area for the mirror and place it to the given center on the + // display. + int initSize = Math.min(windowBounds.width(), windowBounds.height()) / 2; + initSize = Math.min(mResources.getDimensionPixelSize(R.dimen.magnification_max_frame_size), + initSize); + initSize += 2 * mMirrorSurfaceMargin; final int initX = centerX - initSize / 2; final int initY = centerY - initSize / 2; mMagnificationFrame.set(initX, initY, initX + initSize, initY + initSize); diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java index 77941366b4d3b..b03587fdfa85a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java @@ -170,6 +170,29 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { assertFalse(rects.isEmpty()); } + @Test + public void enableWindowMagnification_LargeScreen_windowSizeIsConstrained() { + final int screenSize = mContext.getResources().getDimensionPixelSize( + R.dimen.magnification_max_frame_size) * 10; + mWindowManager.setWindowBounds(new Rect(0, 0, screenSize, screenSize)); + //We need to initialize new one because the window size is determined when initialization. + final WindowMagnificationController controller = new WindowMagnificationController(mContext, + mHandler, mSfVsyncFrameProvider, + mMirrorWindowControl, mTransaction, mWindowMagnifierCallback, mSysUiState); + + mInstrumentation.runOnMainSync(() -> { + controller.enableWindowMagnification(Float.NaN, Float.NaN, + Float.NaN); + }); + + final int halfScreenSize = screenSize / 2; + WindowManager.LayoutParams params = mWindowManager.getLayoutParamsFromAttachedView(); + // The frame size should be the half of smaller value of window height/width unless it + //exceed the max frame size. + assertTrue(params.width < halfScreenSize); + assertTrue(params.height < halfScreenSize); + } + @Test public void deleteWindowMagnification_destroyControl() { mInstrumentation.runOnMainSync(() -> { @@ -316,6 +339,27 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { mWindowMagnificationController.getCenterY() / testWindowBounds.height(), 0); } + @Test + public void screenSizeIsChangedToLarge_enabled_windowSizeIsConstrained() { + mInstrumentation.runOnMainSync(() -> { + mWindowMagnificationController.enableWindowMagnification(Float.NaN, Float.NaN, + Float.NaN); + }); + final int screenSize = mContext.getResources().getDimensionPixelSize( + R.dimen.magnification_max_frame_size) * 10; + mWindowManager.setWindowBounds(new Rect(0, 0, screenSize, screenSize)); + + mInstrumentation.runOnMainSync(() -> { + mWindowMagnificationController.onConfigurationChanged(ActivityInfo.CONFIG_SCREEN_SIZE); + }); + + final int halfScreenSize = screenSize / 2; + WindowManager.LayoutParams params = mWindowManager.getLayoutParamsFromAttachedView(); + // The frame size should be the half of smaller value of window height/width unless it + //exceed the max frame size. + assertTrue(params.width < halfScreenSize); + assertTrue(params.height < halfScreenSize); + } @Test public void onDensityChanged_enabled_updateDimensionsAndResetWindowMagnification() {