diff options
3 files changed, 29 insertions, 26 deletions
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 5a15dcec5223..fd5416efd0ca 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1188,7 +1188,6 @@ <dimen name="magnification_window_drag_corner_stroke">3dp</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> <!-- Magnification settings panel --> <dimen name="magnification_setting_view_margin">24dp</dimen> <dimen name="magnification_setting_text_size">18sp</dimen> diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java index 6c8f8f39646e..197aa90723cb 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 36cdfe642874..670ed400681b 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 |