summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ryan Lin <ryanlwlin@google.com> 2021-09-02 02:27:33 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-09-02 02:27:33 +0000
commit85e113d3b6c67b1788a3bba2b681d446742bd1c5 (patch)
tree3e7b2605b333de53c87ced4586e0b543d17ca504
parent611b3330977d1ad78f7750ef9c1e08528c5d488c (diff)
parentf2ef6b540c553615624ef1255421fa81b5aa03c3 (diff)
Merge "Constranit the magnification window size for large screen devices" into sc-v2-dev
-rw-r--r--packages/SystemUI/res/values/dimens.xml1
-rw-r--r--packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java9
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java44
3 files changed, 51 insertions, 3 deletions
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index 9d37acceefa9..784814d5ca38 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -1338,6 +1338,7 @@
<dimen name="magnifier_up_down_controls_height">40dp</dimen>
<!-- The extra padding to show the whole outer border -->
<dimen name="magnifier_drag_handle_padding">3dp</dimen>
+ <dimen name="magnification_max_frame_size">300dp</dimen>
<!-- Home Controls -->
<dimen name="controls_header_side_margin">4dp</dimen>
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java
index a51e3fcfd50b..0893e895b102 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 323b5fe4636f..3291a7c24867 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java
@@ -171,6 +171,29 @@ public class WindowMagnificationControllerTest extends SysuiTestCase {
}
@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(() -> {
mWindowMagnificationController.enableWindowMagnification(Float.NaN, Float.NaN,
@@ -318,6 +341,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() {