diff options
| -rw-r--r-- | api/current.txt | 1 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 5 | ||||
| -rw-r--r-- | core/java/android/widget/Editor.java | 3 | ||||
| -rw-r--r-- | core/java/android/widget/Magnifier.java | 49 |
4 files changed, 33 insertions, 25 deletions
diff --git a/api/current.txt b/api/current.txt index 03ebe6d2f62e..28fd57763079 100644 --- a/api/current.txt +++ b/api/current.txt @@ -50443,6 +50443,7 @@ package android.view { method protected float getLeftFadingEdgeStrength(); method protected int getLeftPaddingOffset(); method public final boolean getLocalVisibleRect(android.graphics.Rect); + method public void getLocationInSurface(@NonNull @Size(2) int[]); method public void getLocationInWindow(@Size(2) int[]); method public void getLocationOnScreen(@Size(2) int[]); method public android.graphics.Matrix getMatrix(); diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index ab2cc6669631..bf0f4e29a4f3 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -11095,11 +11095,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * <p>Computes the coordinates of this view in its surface. The argument * must be an array of two integers. After the method returns, the array * contains the x and y location in that order.</p> - * @hide + * * @param location an array of two integers in which to hold the coordinates */ - @UnsupportedAppUsage - public void getLocationInSurface(@Size(2) int[] location) { + public void getLocationInSurface(@NonNull @Size(2) int[] location) { getLocationInWindow(location); if (mAttachInfo != null && mAttachInfo.mViewRootImpl != null) { location[0] += mAttachInfo.mViewRootImpl.mWindowAttributes.surfaceInsets.left; diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index b6ec5f936fbd..c9ef038b78de 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -4984,9 +4984,6 @@ public class Editor { if (magnifierTopLeft == null) { return; } - final Rect surfaceInsets = - mTextView.getViewRootImpl().mWindowAttributes.surfaceInsets; - magnifierTopLeft.offset(-surfaceInsets.left, -surfaceInsets.top); final Rect magnifierRect = new Rect(magnifierTopLeft.x, magnifierTopLeft.y, magnifierTopLeft.x + mMagnifierAnimator.mMagnifier.getWidth(), magnifierTopLeft.y + mMagnifierAnimator.mMagnifier.getHeight()); diff --git a/core/java/android/widget/Magnifier.java b/core/java/android/widget/Magnifier.java index 50e883679eb9..08799cfb5d4c 100644 --- a/core/java/android/widget/Magnifier.java +++ b/core/java/android/widget/Magnifier.java @@ -471,13 +471,13 @@ public final class Magnifier { } /** - * Returns the top left coordinates of the magnifier, relative to the surface of the - * main application window. They will be determined by the coordinates of the last - * {@link #show(float, float)} or {@link #show(float, float, float, float)} call, adjusted - * to take into account any potential clamping behavior. The method can be used immediately - * after a #show call to find out where the magnifier will be positioned. However, the - * position of the magnifier will not be updated in the same frame due to the async - * copying of the content copying and of the magnifier rendering. + * Returns the top left coordinates of the magnifier, relative to the main application + * window. They will be determined by the coordinates of the last {@link #show(float, float)} + * or {@link #show(float, float, float, float)} call, adjusted to take into account any + * potential clamping behavior. The method can be used immediately after a #show + * call to find out where the magnifier will be positioned. However, the position of the + * magnifier will not be updated visually in the same frame, due to the async nature of + * the content copying and of the magnifier rendering. * The method will return {@code null} if #show has not yet been called, or if the last * operation performed was a #dismiss. * @@ -488,15 +488,18 @@ public final class Magnifier { if (mWindow == null) { return null; } - return new Point(getCurrentClampedWindowCoordinates()); + final Point position = getCurrentClampedWindowCoordinates(); + position.offset(-mParentSurface.mInsets.left, -mParentSurface.mInsets.top); + return new Point(position); } /** * Returns the top left coordinates of the magnifier source (i.e. the view region going to - * be magnified and copied to the magnifier), relative to the surface the content is copied - * from. The content will be copied: + * be magnified and copied to the magnifier), relative to the window or surface the content + * is copied from. The content will be copied: * - if the magnified view is a {@link SurfaceView}, from the surface backing it - * - otherwise, from the surface of the main application window + * - otherwise, from the surface backing the main application window, and the coordinates + * returned will be relative to the main application window * The method will return {@code null} if #show has not yet been called, or if the last * operation performed was a #dismiss. * @@ -507,7 +510,9 @@ public final class Magnifier { if (mWindow == null) { return null; } - return new Point(mPixelCopyRequestRect.left, mPixelCopyRequestRect.top); + final Point position = new Point(mPixelCopyRequestRect.left, mPixelCopyRequestRect.top); + position.offset(-mContentCopySurface.mInsets.left, -mContentCopySurface.mInsets.top); + return new Point(position); } /** @@ -531,7 +536,7 @@ public final class Magnifier { viewRootImpl.getHeight() + surfaceInsets.top + surfaceInsets.bottom; validMainWindowSurface = new SurfaceInfo(viewRootImpl.getSurfaceControl(), mainWindowSurface, - surfaceWidth, surfaceHeight, true); + surfaceWidth, surfaceHeight, surfaceInsets, true); } } // Get the surface backing the magnified view, if it is a SurfaceView. @@ -544,7 +549,7 @@ public final class Magnifier { if (sc != null && sc.isValid()) { final Rect surfaceFrame = surfaceHolder.getSurfaceFrame(); validSurfaceViewSurface = new SurfaceInfo(sc, surfaceViewSurface, - surfaceFrame.right, surfaceFrame.bottom, false); + surfaceFrame.right, surfaceFrame.bottom, new Rect(), false); } } @@ -708,9 +713,13 @@ public final class Magnifier { final Rect windowBounds; if (mParentSurface.mIsMainWindowSurface) { final Insets systemInsets = mView.getRootWindowInsets().getSystemWindowInsets(); - windowBounds = new Rect(systemInsets.left, systemInsets.top, - mParentSurface.mWidth - systemInsets.right, - mParentSurface.mHeight - systemInsets.bottom); + windowBounds = new Rect( + systemInsets.left + mParentSurface.mInsets.left, + systemInsets.top + mParentSurface.mInsets.top, + mParentSurface.mWidth - systemInsets.right - mParentSurface.mInsets.right, + mParentSurface.mHeight - systemInsets.bottom + - mParentSurface.mInsets.bottom + ); } else { windowBounds = new Rect(0, 0, mParentSurface.mWidth, mParentSurface.mHeight); } @@ -725,21 +734,23 @@ public final class Magnifier { * Contains a surface and metadata corresponding to it. */ private static class SurfaceInfo { - public static final SurfaceInfo NULL = new SurfaceInfo(null, null, 0, 0, false); + public static final SurfaceInfo NULL = new SurfaceInfo(null, null, 0, 0, null, false); private Surface mSurface; private SurfaceControl mSurfaceControl; private int mWidth; private int mHeight; + private Rect mInsets; private boolean mIsMainWindowSurface; SurfaceInfo(final SurfaceControl surfaceControl, final Surface surface, - final int width, final int height, + final int width, final int height, final Rect insets, final boolean isMainWindowSurface) { mSurfaceControl = surfaceControl; mSurface = surface; mWidth = width; mHeight = height; + mInsets = insets; mIsMainWindowSurface = isMainWindowSurface; } } |