From 7b46c191ca0122c77a6897622f11ffbc7fdc7b42 Mon Sep 17 00:00:00 2001 From: mincheli Date: Mon, 3 Feb 2020 21:17:10 +0800 Subject: [PATCH] Make mirror view able to move close to the screen edges Because magnification mirror view has transparent border, the mirror view unable to move close to the screen edges visually. So we use setTranslationX and setTranslationY to adjust the location of mirror view to achieve it. Bug: 146402201 Bug: 148356962 Test: adb shell settings put secure window_magnification 1 Change-Id: I1491ad8113faaa1a559df776f8c6920935dea505 --- .../WindowMagnificationController.java | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java index 6542e96d4c3f3..5b46746c8d25f 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationController.java @@ -87,6 +87,7 @@ public class WindowMagnificationController implements View.OnTouchListener, Surf private SurfaceView mMirrorSurfaceView; private int mMirrorSurfaceMargin; private int mBorderDragSize; + private int mOuterBorderSize; private View mOverlayView; // The boundary of magnification frame. private final Rect mMagnificationFrameBoundary = new Rect(); @@ -118,6 +119,8 @@ public class WindowMagnificationController implements View.OnTouchListener, Surf R.dimen.magnification_mirror_surface_margin); mBorderDragSize = mResources.getDimensionPixelSize( R.dimen.magnification_border_drag_size); + mOuterBorderSize = mResources.getDimensionPixelSize( + R.dimen.magnification_outer_border_margin); } /** @@ -357,7 +360,7 @@ public class WindowMagnificationController implements View.OnTouchListener, Surf } /** - * Modifies the placement of the mirrored content. + * Modifies the placement of the mirrored content when the position of mMirrorView is updated. */ private void modifyWindowMagnification(SurfaceControl.Transaction t) { Rect sourceBounds = getSourceBounds(mMagnificationFrame, mScale); @@ -365,13 +368,43 @@ public class WindowMagnificationController implements View.OnTouchListener, Surf // ViewRootImpl's position will change mTmpRect.set(0, 0, mMagnificationFrame.width(), mMagnificationFrame.height()); + updateMirrorViewLayout(); + + t.setGeometry(mMirrorSurface, sourceBounds, mTmpRect, Surface.ROTATION_0); + } + + /** + * Updates the layout params of MirrorView and translates MirrorView position when the view is + * moved close to the screen edges. + */ + private void updateMirrorViewLayout() { WindowManager.LayoutParams params = (WindowManager.LayoutParams) mMirrorView.getLayoutParams(); params.x = mMagnificationFrame.left; params.y = mMagnificationFrame.top; + // Translates MirrorView position to make MirrorSurfaceView that is inside MirrorView + // able to move close to the screen edges. + final int maxMirrorViewX = mDisplaySize.x - mMirrorView.getWidth(); + final int maxMirrorViewY = mDisplaySize.y - mMirrorView.getHeight(); + final float translationX; + final float translationY; + if (params.x < 0) { + translationX = Math.max(params.x, -mOuterBorderSize); + } else if (params.x > maxMirrorViewX) { + translationX = Math.min(params.x - maxMirrorViewX, mOuterBorderSize); + } else { + translationX = 0; + } + if (params.y < 0) { + translationY = Math.max(params.y, -mOuterBorderSize); + } else if (params.y > maxMirrorViewY) { + translationY = Math.min(params.y - maxMirrorViewY, mOuterBorderSize); + } else { + translationY = 0; + } + mMirrorView.setTranslationX(translationX); + mMirrorView.setTranslationY(translationY); mWm.updateViewLayout(mMirrorView, params); - - t.setGeometry(mMirrorSurface, sourceBounds, mTmpRect, Surface.ROTATION_0); } @Override