From 3c79503330d4ae12c74746e471c141e24923ac2b Mon Sep 17 00:00:00 2001 From: Candice Lo Date: Wed, 14 Jun 2023 09:23:15 +0000 Subject: [PATCH] Match default magnifier window size to Medium in settings We would like to initialize the magnifier to be Medium size, which is one of the sizes that provided through magnification settings panel icon buttons, so that users could get back to the initial window size easily. Since we are following the sizes provided by the settings panel, we will need to rethink if those provided sizes are appropriate and useful for users with different screen sizes. We would like to deal with the issue in a separate bug. Bug: 265363901 Test: manually - check the magnifier is initialized to be Medium size Test: atest WindowMagnificationControllerTest Change-Id: I37762e002cb766b06f99817c87a25c9539faed6d --- packages/SystemUI/res/values/dimens.xml | 1 - .../WindowMagnificationController.java | 32 ++++++++++--------- .../WindowMagnificationControllerTest.java | 22 +++++++------ 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 5a15dcec52233..fd5416efd0ca5 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1188,7 +1188,6 @@ 3dp 3dp - 300dp 24dp 18sp diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java index 6c8f8f39646e1..197aa90723cb1 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java @@ -124,7 +124,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold private float mScale; /** - * MagnificationFrame represents the bound of {@link #mMirrorSurface} and is constrained + * MagnificationFrame represents the bound of {@link #mMirrorSurfaceView} and is constrained * by the {@link #mMagnificationFrameBoundary}. * We use MagnificationFrame to calculate the position of {@link #mMirrorView}. * We combine MagnificationFrame with {@link #mMagnificationFrameOffsetX} and @@ -272,8 +272,8 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold com.android.internal.R.integer.config_shortAnimTime); updateDimensions(); - final Size windowSize = getDefaultWindowSizeWithWindowBounds(mWindowBounds); - setMagnificationFrame(windowSize.getWidth(), windowSize.getHeight(), + final Size windowFrameSize = getDefaultMagnificationWindowFrameSize(); + setMagnificationFrame(windowFrameSize.getWidth(), windowFrameSize.getHeight(), mWindowBounds.width() / 2, mWindowBounds.height() / 2); computeBounceAnimationScale(); @@ -381,12 +381,16 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold if (!mMagnificationSizeScaleOptions.contains(index)) { return; } - final float scale = mMagnificationSizeScaleOptions.get(index, 1.0f); - final int initSize = Math.min(mWindowBounds.width(), mWindowBounds.height()) / 3; - int size = (int) (initSize * scale); + int size = getMagnificationWindowSizeFromIndex(index); setWindowSize(size, size); } + int getMagnificationWindowSizeFromIndex(@MagnificationSize int index) { + final float scale = mMagnificationSizeScaleOptions.get(index, 1.0f); + int initSize = Math.min(mWindowBounds.width(), mWindowBounds.height()) / 3; + return (int) (initSize * scale) - (int) (initSize * scale) % 2; + } + void setEditMagnifierSizeMode(boolean enable) { mEditSizeEnable = enable; applyResourcesValues(); @@ -519,12 +523,12 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold return false; } mWindowBounds.set(currentWindowBounds); - final Size windowSize = getDefaultWindowSizeWithWindowBounds(mWindowBounds); + final Size windowFrameSize = getDefaultMagnificationWindowFrameSize(); final float newCenterX = (getCenterX()) * mWindowBounds.width() / oldWindowBounds.width(); final float newCenterY = (getCenterY()) * mWindowBounds.height() / oldWindowBounds.height(); - setMagnificationFrame(windowSize.getWidth(), windowSize.getHeight(), (int) newCenterX, - (int) newCenterY); + setMagnificationFrame(windowFrameSize.getWidth(), windowFrameSize.getHeight(), + (int) newCenterX, (int) newCenterY); calculateMagnificationFrameBoundary(); return true; } @@ -745,12 +749,10 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold mMagnificationFrame.set(initX, initY, initX + width, initY + height); } - private Size getDefaultWindowSizeWithWindowBounds(Rect windowBounds) { - int initSize = Math.min(windowBounds.width(), windowBounds.height()) / 2; - initSize = Math.min(mResources.getDimensionPixelSize(R.dimen.magnification_max_frame_size), - initSize); - initSize += 2 * mMirrorSurfaceMargin; - return new Size(initSize, initSize); + private Size getDefaultMagnificationWindowFrameSize() { + final int defaultSize = getMagnificationWindowSizeFromIndex(MagnificationSize.MEDIUM) + - 2 * mMirrorSurfaceMargin; + return new Size(defaultSize, defaultSize); } /** 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 36cdfe642874f..670ed400681b6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java @@ -100,6 +100,7 @@ import com.google.common.util.concurrent.AtomicDouble; import org.junit.After; import org.junit.Assume; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; @@ -313,10 +314,10 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { assertFalse(rects.isEmpty()); } + @Ignore("The default window size should be constrained after fixing b/288056772") @Test public void enableWindowMagnification_LargeScreen_windowSizeIsConstrained() { - final int screenSize = mContext.getResources().getDimensionPixelSize( - R.dimen.magnification_max_frame_size) * 10; + final int screenSize = mWindowManager.getCurrentWindowMetrics().getBounds().width() * 10; mWindowManager.setWindowBounds(new Rect(0, 0, screenSize, screenSize)); mInstrumentation.runOnMainSync(() -> { @@ -568,26 +569,27 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { mWindowMagnificationController.getCenterY() / testWindowBounds.height(), 0); } + @Test - public void screenSizeIsChangedToLarge_enabled_windowSizeIsConstrained() { + public void screenSizeIsChangedToLarge_enabled_defaultWindowSize() { mInstrumentation.runOnMainSync(() -> { mWindowMagnificationController.enableWindowMagnificationInternal(Float.NaN, Float.NaN, Float.NaN); }); - final int screenSize = mContext.getResources().getDimensionPixelSize( - R.dimen.magnification_max_frame_size) * 10; + final int screenSize = mWindowManager.getCurrentWindowMetrics().getBounds().width() * 10; mWindowManager.setWindowBounds(new Rect(0, 0, screenSize, screenSize)); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationController.onConfigurationChanged(ActivityInfo.CONFIG_SCREEN_SIZE); }); - final int halfScreenSize = screenSize / 2; + final int defaultWindowSize = + mWindowMagnificationController.getMagnificationWindowSizeFromIndex( + WindowMagnificationSettings.MagnificationSize.MEDIUM); 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); + + assertTrue(params.width == defaultWindowSize); + assertTrue(params.height == defaultWindowSize); } @Test