diff options
| author | 2022-09-27 01:52:54 +0000 | |
|---|---|---|
| committer | 2022-11-11 12:00:44 -0800 | |
| commit | e72f621e389d057b0f2ed001820517f2379abedc (patch) | |
| tree | 077ebd23d5610018ba9e7f88fe7ef1fc2222d7a3 | |
| parent | eb803fd53e0222285b5b475c0e120873933c430c (diff) | |
feat(magnification settings): Add Diagonal resize handles for Window magnification
Test: `atest SystemUITests:com.android.systemui.accessibility.WindowMagnificationControllerTest`
Bug: b/188136191
Change-Id: I270689671765f4287f91689e5acb82711bef4885
11 files changed, 413 insertions, 48 deletions
diff --git a/packages/SystemUI/res/drawable/accessibility_window_magnification_button_bg.xml b/packages/SystemUI/res/drawable/accessibility_window_magnification_button_bg.xml new file mode 100644 index 000000000000..eefe36459f9c --- /dev/null +++ b/packages/SystemUI/res/drawable/accessibility_window_magnification_button_bg.xml @@ -0,0 +1,26 @@ +<!--
+ Copyright (C) 2022 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <solid android:color="@color/accessibility_window_magnifier_button_bg" />
+ <size
+ android:width="40dp"
+ android:height="40dp"/>
+ <corners android:radius="2dp"/>
+ <stroke
+ android:color="@color/accessibility_window_magnifier_button_bg_stroke"
+ android:width="1dp" />
+ </shape>
\ No newline at end of file diff --git a/packages/SystemUI/res/drawable/ic_magnification_corner_bottom_left.xml b/packages/SystemUI/res/drawable/ic_magnification_corner_bottom_left.xml new file mode 100644 index 000000000000..d25cd6558116 --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_magnification_corner_bottom_left.xml @@ -0,0 +1,33 @@ +<!-- + Copyright (C) 2022 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:pathData="M0,24l0,-4l24,-0l0,4z" + android:strokeWidth="1" + android:fillColor="@color/accessibility_window_magnifier_corner_view_color" + android:fillType="evenOdd" + android:strokeColor="#00000000"/> + <path + android:pathData="M0,24l0,-24l4,-0l0,24z" + android:strokeWidth="1" + android:fillColor="@color/accessibility_window_magnifier_corner_view_color" + android:fillType="evenOdd" + android:strokeColor="#00000000"/> +</vector> diff --git a/packages/SystemUI/res/drawable/ic_magnification_corner_bottom_right.xml b/packages/SystemUI/res/drawable/ic_magnification_corner_bottom_right.xml new file mode 100644 index 000000000000..bb6df3ac1b32 --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_magnification_corner_bottom_right.xml @@ -0,0 +1,33 @@ +<!-- + Copyright (C) 2022 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:pathData="M24,24l-4,-0l-0,-24l4,-0z" + android:strokeWidth="1" + android:fillColor="@color/accessibility_window_magnifier_corner_view_color" + android:fillType="evenOdd" + android:strokeColor="#00000000"/> + <path + android:pathData="M24,24l-24,-0l-0,-4l24,-0z" + android:strokeWidth="1" + android:fillColor="@color/accessibility_window_magnifier_corner_view_color" + android:fillType="evenOdd" + android:strokeColor="#00000000"/> +</vector> diff --git a/packages/SystemUI/res/drawable/ic_magnification_corner_top_left.xml b/packages/SystemUI/res/drawable/ic_magnification_corner_top_left.xml new file mode 100644 index 000000000000..8f259309b747 --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_magnification_corner_top_left.xml @@ -0,0 +1,33 @@ +<!-- + Copyright (C) 2022 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:pathData="M0,0h4v24h-4z" + android:strokeWidth="1" + android:fillColor="@color/accessibility_window_magnifier_corner_view_color" + android:fillType="evenOdd" + android:strokeColor="#00000000"/> + <path + android:pathData="M0,0h24v4h-24z" + android:strokeWidth="1" + android:fillColor="@color/accessibility_window_magnifier_corner_view_color" + android:fillType="evenOdd" + android:strokeColor="#00000000"/> +</vector> diff --git a/packages/SystemUI/res/drawable/ic_magnification_corner_top_right.xml b/packages/SystemUI/res/drawable/ic_magnification_corner_top_right.xml new file mode 100644 index 000000000000..291db44ba8ba --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_magnification_corner_top_right.xml @@ -0,0 +1,33 @@ +<!-- + Copyright (C) 2022 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:pathData="M24,0l-0,4l-24,0l-0,-4z" + android:strokeWidth="1" + android:fillColor="@color/accessibility_window_magnifier_corner_view_color" + android:fillType="evenOdd" + android:strokeColor="#00000000"/> + <path + android:pathData="M24,0l-0,24l-4,0l-0,-24z" + android:strokeWidth="1" + android:fillColor="@color/accessibility_window_magnifier_corner_view_color" + android:fillType="evenOdd" + android:strokeColor="#00000000"/> +</vector> diff --git a/packages/SystemUI/res/layout/window_magnifier_view.xml b/packages/SystemUI/res/layout/window_magnifier_view.xml index 0bff47ccf722..0be732855dee 100644 --- a/packages/SystemUI/res/layout/window_magnifier_view.xml +++ b/packages/SystemUI/res/layout/window_magnifier_view.xml @@ -40,19 +40,22 @@ android:id="@+id/top_handle" android:layout_width="match_parent" android:layout_height="@dimen/magnification_border_drag_size" - android:layout_alignParentTop="true"/> + android:layout_alignParentTop="true" + android:accessibilityTraversalAfter="@id/left_handle"/> <View android:id="@+id/right_handle" android:layout_width="@dimen/magnification_border_drag_size" android:layout_height="match_parent" - android:layout_alignParentEnd="true"/> + android:layout_alignParentEnd="true" + android:accessibilityTraversalAfter="@id/top_handle"/> <View android:id="@+id/bottom_handle" android:layout_width="match_parent" android:layout_height="@dimen/magnification_border_drag_size" - android:layout_alignParentBottom="true"/> + android:layout_alignParentBottom="true" + android:accessibilityTraversalAfter="@id/right_handle"/> <SurfaceView android:id="@+id/surface_view" @@ -62,6 +65,58 @@ </RelativeLayout> <ImageView + android:id="@+id/top_right_corner" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="@dimen/magnification_outer_border_margin" + android:layout_gravity="right|top" + android:paddingTop="@dimen/magnifier_drag_handle_padding" + android:paddingEnd="@dimen/magnifier_drag_handle_padding" + android:scaleType="center" + android:contentDescription="@string/magnification_drag_corner_to_resize" + android:src="@drawable/ic_magnification_corner_top_right" + android:accessibilityTraversalAfter="@id/top_left_corner"/> + + <ImageView + android:id="@+id/top_left_corner" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="@dimen/magnification_outer_border_margin" + android:layout_gravity="left|top" + android:paddingTop="@dimen/magnifier_drag_handle_padding" + android:paddingStart="@dimen/magnifier_drag_handle_padding" + android:scaleType="center" + android:contentDescription="@string/magnification_drag_corner_to_resize" + android:src="@drawable/ic_magnification_corner_top_left" + android:accessibilityTraversalAfter="@id/bottom_handle"/> + + <ImageView + android:id="@+id/bottom_right_corner" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="@dimen/magnification_outer_border_margin" + android:layout_gravity="right|bottom" + android:paddingEnd="@dimen/magnifier_drag_handle_padding" + android:paddingBottom="@dimen/magnifier_drag_handle_padding" + android:scaleType="center" + android:contentDescription="@string/magnification_drag_corner_to_resize" + android:src="@drawable/ic_magnification_corner_bottom_right" + android:accessibilityTraversalAfter="@id/top_right_corner"/> + + <ImageView + android:id="@+id/bottom_left_corner" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="@dimen/magnification_outer_border_margin" + android:layout_gravity="left|bottom" + android:paddingStart="@dimen/magnifier_drag_handle_padding" + android:paddingBottom="@dimen/magnifier_drag_handle_padding" + android:scaleType="center" + android:contentDescription="@string/magnification_drag_corner_to_resize" + android:src="@drawable/ic_magnification_corner_bottom_left" + android:accessibilityTraversalAfter="@id/bottom_right_corner"/> + + <ImageView android:id="@+id/drag_handle" android:layout_width="@dimen/magnification_drag_view_size" android:layout_height="@dimen/magnification_drag_view_size" diff --git a/packages/SystemUI/res/values/colors.xml b/packages/SystemUI/res/values/colors.xml index 9e8bef06270b..7b29a232aa92 100644 --- a/packages/SystemUI/res/values/colors.xml +++ b/packages/SystemUI/res/values/colors.xml @@ -172,6 +172,10 @@ <color name="accessibility_magnifier_bg">#FCFCFC</color> <color name="accessibility_magnifier_bg_stroke">#E0E0E0</color> <color name="accessibility_magnifier_icon_color">#252525</color> + <color name="accessibility_window_magnifier_button_bg">#0680FD</color> + <color name="accessibility_window_magnifier_icon_color">#FAFAFA</color> + <color name="accessibility_window_magnifier_button_bg_stroke">#252525</color> + <color name="accessibility_window_magnifier_corner_view_color">#0680FD</color> <!-- Volume dialog colors --> <color name="volume_dialog_background_color">@android:color/transparent</color> diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 9324e8f3babb..8c1ffb2920ab 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -2118,6 +2118,8 @@ <string name="magnification_mode_switch_state_window">Magnify part of screen</string> <!-- Click action label for magnification switch. [CHAR LIMIT=NONE] --> <string name="magnification_mode_switch_click_label">Switch</string> + <!-- Label of the corner of a rectangle that you can tap and drag to resize the magnification area. [CHAR LIMIT=NONE] --> + <string name="magnification_drag_corner_to_resize">Drag corner to resize</string> <!-- Title of the magnification option button allow diagonal scrolling [CHAR LIMIT=NONE]--> <string name="accessibility_allow_diagonal_scrolling">Allow diagonal scrolling</string> diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java index e3c04a379fe4..25462a2bc9e9 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java @@ -158,6 +158,10 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold private View mTopDrag; private View mRightDrag; private View mBottomDrag; + private ImageView mTopLeftCornerView; + private ImageView mTopRightCornerView; + private ImageView mBottomLeftCornerView; + private ImageView mBottomRightCornerView; private final Configuration mConfiguration; @NonNull @@ -357,13 +361,15 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold return false; } - private void changeMagnificationSize(@MagnificationSize int index) { + @VisibleForTesting + void changeMagnificationSize(@MagnificationSize int index) { final int initSize = Math.min(mWindowBounds.width(), mWindowBounds.height()) / 3; int size = (int) (initSize * MAGNIFICATION_SCALE_OPTIONS[index]); setWindowSize(size, size); } - private void setEditMagnifierSizeMode(boolean enable) { + @VisibleForTesting + void setEditMagnifierSizeMode(boolean enable) { mEditSizeEnable = enable; applyResourcesValues(); @@ -641,10 +647,37 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold Region regionInsideDragBorder = new Region(mBorderDragSize, mBorderDragSize, mMirrorView.getWidth() - mBorderDragSize, mMirrorView.getHeight() - mBorderDragSize); + + Region tapExcludeRegion = new Region(); + Rect dragArea = new Rect(); mDragView.getHitRect(dragArea); - regionInsideDragBorder.op(dragArea, Region.Op.DIFFERENCE); + Rect topLeftArea = new Rect(); + mTopLeftCornerView.getHitRect(topLeftArea); + + Rect topRightArea = new Rect(); + mTopRightCornerView.getHitRect(topRightArea); + + Rect bottomLeftArea = new Rect(); + mBottomLeftCornerView.getHitRect(bottomLeftArea); + + Rect bottomRightArea = new Rect(); + mBottomRightCornerView.getHitRect(bottomRightArea); + + Rect closeArea = new Rect(); + mCloseView.getHitRect(closeArea); + + // add tapExcludeRegion for Drag or close + tapExcludeRegion.op(dragArea, Region.Op.UNION); + tapExcludeRegion.op(topLeftArea, Region.Op.UNION); + tapExcludeRegion.op(topRightArea, Region.Op.UNION); + tapExcludeRegion.op(bottomLeftArea, Region.Op.UNION); + tapExcludeRegion.op(bottomRightArea, Region.Op.UNION); + tapExcludeRegion.op(closeArea, Region.Op.UNION); + + regionInsideDragBorder.op(tapExcludeRegion, Region.Op.DIFFERENCE); + return regionInsideDragBorder; } @@ -758,6 +791,10 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold mRightDrag = mMirrorView.findViewById(R.id.right_handle); mBottomDrag = mMirrorView.findViewById(R.id.bottom_handle); mCloseView = mMirrorView.findViewById(R.id.close_button); + mTopRightCornerView = mMirrorView.findViewById(R.id.top_right_corner); + mTopLeftCornerView = mMirrorView.findViewById(R.id.top_left_corner); + mBottomRightCornerView = mMirrorView.findViewById(R.id.bottom_right_corner); + mBottomLeftCornerView = mMirrorView.findViewById(R.id.bottom_left_corner); mDragView.setOnTouchListener(this); mLeftDrag.setOnTouchListener(this); @@ -765,6 +802,10 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold mRightDrag.setOnTouchListener(this); mBottomDrag.setOnTouchListener(this); mCloseView.setOnTouchListener(this); + mTopLeftCornerView.setOnTouchListener(this); + mTopRightCornerView.setOnTouchListener(this); + mBottomLeftCornerView.setOnTouchListener(this); + mBottomRightCornerView.setOnTouchListener(this); } /** @@ -833,8 +874,16 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold @Override public boolean onTouch(View v, MotionEvent event) { - if (v == mDragView || v == mLeftDrag || v == mTopDrag || v == mRightDrag - || v == mBottomDrag || v == mCloseView) { + if (v == mDragView + || v == mLeftDrag + || v == mTopDrag + || v == mRightDrag + || v == mBottomDrag + || v == mTopLeftCornerView + || v == mTopRightCornerView + || v == mBottomLeftCornerView + || v == mBottomRightCornerView + || v == mCloseView) { return mGestureDetector.onTouch(v, event); } return false; @@ -1197,7 +1246,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold @Override public boolean onDrag(View view, float offsetX, float offsetY) { if (mEditSizeEnable) { - changeWindowSize(view, offsetX, offsetY); + return changeWindowSize(view, offsetX, offsetY); } else { move((int) offsetX, (int) offsetY); } @@ -1222,13 +1271,47 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold if (mEditSizeEnable) { mDragView.setVisibility(View.GONE); mCloseView.setVisibility(View.VISIBLE); + mTopRightCornerView.setVisibility(View.VISIBLE); + mTopLeftCornerView.setVisibility(View.VISIBLE); + mBottomRightCornerView.setVisibility(View.VISIBLE); + mBottomLeftCornerView.setVisibility(View.VISIBLE); } else { mDragView.setVisibility(View.VISIBLE); mCloseView.setVisibility(View.GONE); + mTopRightCornerView.setVisibility(View.GONE); + mTopLeftCornerView.setVisibility(View.GONE); + mBottomRightCornerView.setVisibility(View.GONE); + mBottomLeftCornerView.setVisibility(View.GONE); } } - public boolean changeWindowSize(View view, float offsetX, float offsetY) { + private boolean changeWindowSize(View view, float offsetX, float offsetY) { + if (view == mLeftDrag) { + changeMagnificationFrameSize(offsetX, 0, 0, 0); + } else if (view == mRightDrag) { + changeMagnificationFrameSize(0, 0, offsetX, 0); + } else if (view == mTopDrag) { + changeMagnificationFrameSize(0, offsetY, 0, 0); + } else if (view == mBottomDrag) { + changeMagnificationFrameSize(0, 0, 0, offsetY); + } else if (view == mTopLeftCornerView) { + changeMagnificationFrameSize(offsetX, offsetY, 0, 0); + } else if (view == mTopRightCornerView) { + changeMagnificationFrameSize(0, offsetY, offsetX, 0); + } else if (view == mBottomLeftCornerView) { + changeMagnificationFrameSize(offsetX, 0, 0, offsetY); + } else if (view == mBottomRightCornerView) { + changeMagnificationFrameSize(0, 0, offsetX, offsetY); + } else { + return false; + } + + return true; + } + + private void changeMagnificationFrameSize( + float leftOffset, float topOffset, float rightOffset, + float bottomOffset) { boolean bRTL = isRTL(mContext); final int initSize = Math.min(mWindowBounds.width(), mWindowBounds.height()) / 3; @@ -1238,54 +1321,26 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold Rect tempRect = new Rect(); tempRect.set(mMagnificationFrame); - if (view == mLeftDrag) { - if (bRTL) { - tempRect.right += offsetX; - if (tempRect.right > mWindowBounds.width()) { - return false; - } - } else { - tempRect.left += offsetX; - if (tempRect.left < 0) { - return false; - } - } - } else if (view == mRightDrag) { - if (bRTL) { - tempRect.left += offsetX; - if (tempRect.left < 0) { - return false; - } - } else { - tempRect.right += offsetX; - if (tempRect.right > mWindowBounds.width()) { - return false; - } - } - } else if (view == mTopDrag) { - tempRect.top += offsetY; - if (tempRect.top < 0) { - return false; - } - } else if (view == mBottomDrag) { - tempRect.bottom += offsetY; - if (tempRect.bottom > mWindowBounds.height()) { - return false; - } + if (bRTL) { + tempRect.left += (int) (rightOffset); + tempRect.right += (int) (leftOffset); + } else { + tempRect.right += (int) (rightOffset); + tempRect.left += (int) (leftOffset); } + tempRect.top += (int) (topOffset); + tempRect.bottom += (int) (bottomOffset); if (tempRect.width() < initSize || tempRect.height() < initSize || tempRect.width() > maxWidthSize || tempRect.height() > maxHeightSize) { - return false; + return; } - mMagnificationFrame.set(tempRect); computeBounceAnimationScale(); calculateMagnificationFrameBoundary(); modifyWindowMagnification(true); - return true; } private static boolean isRTL(Context context) { diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java index 9cffd5d609a7..069c0f656d7b 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java @@ -103,7 +103,7 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest MagnificationSize.LARGE, }) /** Denotes the Magnification size type. */ - @interface MagnificationSize { + public @interface MagnificationSize { int NONE = 0; int SMALL = 1; int MEDIUM = 2; 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 69ccc8b88bd8..57ca9c064224 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java @@ -903,6 +903,97 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { } @Test + public void changeMagnificationSize_expectedWindowSize() { + final Rect bounds = mWindowManager.getCurrentWindowMetrics().getBounds(); + + final float magnificationScaleLarge = 2.5f; + final int initSize = Math.min(bounds.width(), bounds.height()) / 3; + final int magnificationSize = (int) (initSize * magnificationScaleLarge); + + final int expectedWindowHeight = magnificationSize; + final int expectedWindowWidth = magnificationSize; + + mInstrumentation.runOnMainSync( + () -> + mWindowMagnificationController.enableWindowMagnificationInternal( + Float.NaN, Float.NaN, Float.NaN)); + + final AtomicInteger actualWindowHeight = new AtomicInteger(); + final AtomicInteger actualWindowWidth = new AtomicInteger(); + mInstrumentation.runOnMainSync( + () -> { + mWindowMagnificationController.changeMagnificationSize( + WindowMagnificationSettings.MagnificationSize.LARGE); + actualWindowHeight.set(mWindowManager.getLayoutParamsFromAttachedView().height); + actualWindowWidth.set(mWindowManager.getLayoutParamsFromAttachedView().width); + }); + + assertEquals(expectedWindowHeight, actualWindowHeight.get()); + assertEquals(expectedWindowWidth, actualWindowWidth.get()); + } + + @Test + public void editModeOnDragCorner_resizesWindow() { + final Rect bounds = mWindowManager.getCurrentWindowMetrics().getBounds(); + + final int startingSize = (int) (bounds.width() / 2); + + mInstrumentation.runOnMainSync( + () -> + mWindowMagnificationController.enableWindowMagnificationInternal( + Float.NaN, Float.NaN, Float.NaN)); + + final AtomicInteger actualWindowHeight = new AtomicInteger(); + final AtomicInteger actualWindowWidth = new AtomicInteger(); + + mInstrumentation.runOnMainSync( + () -> { + mWindowMagnificationController.setWindowSize(startingSize, startingSize); + mWindowMagnificationController.setEditMagnifierSizeMode(true); + }); + + waitForIdleSync(); + + mInstrumentation.runOnMainSync( + () -> { + mWindowMagnificationController + .onDrag(getInternalView(R.id.bottom_right_corner), 2f, 1f); + actualWindowHeight.set(mWindowManager.getLayoutParamsFromAttachedView().height); + actualWindowWidth.set(mWindowManager.getLayoutParamsFromAttachedView().width); + }); + + assertEquals(startingSize + 1, actualWindowHeight.get()); + assertEquals(startingSize + 2, actualWindowWidth.get()); + } + + @Test + public void editModeOnDragEdge_resizesWindowInOnlyOneDirection() { + final Rect bounds = mWindowManager.getCurrentWindowMetrics().getBounds(); + + final int startingSize = (int) (bounds.width() / 2f); + + mInstrumentation.runOnMainSync( + () -> + mWindowMagnificationController.enableWindowMagnificationInternal( + Float.NaN, Float.NaN, Float.NaN)); + + final AtomicInteger actualWindowHeight = new AtomicInteger(); + final AtomicInteger actualWindowWidth = new AtomicInteger(); + + mInstrumentation.runOnMainSync( + () -> { + mWindowMagnificationController.setWindowSize(startingSize, startingSize); + mWindowMagnificationController.setEditMagnifierSizeMode(true); + mWindowMagnificationController + .onDrag(getInternalView(R.id.bottom_handle), 2f, 1f); + actualWindowHeight.set(mWindowManager.getLayoutParamsFromAttachedView().height); + actualWindowWidth.set(mWindowManager.getLayoutParamsFromAttachedView().width); + }); + assertEquals(startingSize + 1, actualWindowHeight.get()); + assertEquals(startingSize, actualWindowWidth.get()); + } + + @Test public void setWindowCenterOutOfScreen_enabled_magnificationCenterIsInsideTheScreen() { final int minimumWindowSize = mResources.getDimensionPixelSize( |