diff --git a/api/current.txt b/api/current.txt index c2f1bc58bf610..e4a629c42937c 100644 --- a/api/current.txt +++ b/api/current.txt @@ -53391,6 +53391,9 @@ package android.widget { public final class Magnifier { ctor public Magnifier(android.view.View); method public void dismiss(); + method public int getHeight(); + method public int getWidth(); + method public float getZoom(); method public void show(float, float); method public void update(); } diff --git a/core/java/android/widget/Magnifier.java b/core/java/android/widget/Magnifier.java index 85f68d7c29f40..3db149a442de6 100644 --- a/core/java/android/widget/Magnifier.java +++ b/core/java/android/widget/Magnifier.java @@ -75,6 +75,8 @@ public final class Magnifier { private final int mWindowWidth; // The height of the window containing the magnifier. private final int mWindowHeight; + // The zoom applied to the view region copied to the magnifier window. + private final float mZoom; // The width of the bitmaps where the magnifier content is copied. private final int mBitmapWidth; // The height of the bitmaps where the magnifier content is copied. @@ -111,10 +113,10 @@ public final class Magnifier { com.android.internal.R.dimen.magnifier_height); mWindowElevation = context.getResources().getDimension( com.android.internal.R.dimen.magnifier_elevation); - final float zoomScale = context.getResources().getFloat( + mZoom = context.getResources().getFloat( com.android.internal.R.dimen.magnifier_zoom_scale); - mBitmapWidth = Math.round(mWindowWidth / zoomScale); - mBitmapHeight = Math.round(mWindowHeight / zoomScale); + mBitmapWidth = Math.round(mWindowWidth / mZoom); + mBitmapHeight = Math.round(mWindowHeight / mZoom); // The view's surface coordinates will not be updated until the magnifier is first shown. mViewCoordinatesInSurface = new int[2]; } @@ -187,21 +189,6 @@ public final class Magnifier { } } - @Nullable - private Surface getValidViewSurface() { - // TODO: deduplicate this against the first part of #performPixelCopy - final Surface surface; - if (mView instanceof SurfaceView) { - surface = ((SurfaceView) mView).getHolder().getSurface(); - } else if (mView.getViewRootImpl() != null) { - surface = mView.getViewRootImpl().mSurface; - } else { - surface = null; - } - - return (surface != null && surface.isValid()) ? surface : null; - } - /** * Dismisses the magnifier from the screen. Calling this on a dismissed magnifier is a no-op. */ @@ -226,6 +213,44 @@ public final class Magnifier { } } + /** + * @return The width of the magnifier window, in pixels. + */ + public int getWidth() { + return mWindowWidth; + } + + /** + * @return The height of the magnifier window, in pixels. + */ + public int getHeight() { + return mWindowHeight; + } + + /** + * @return The zoom applied to the magnified view region copied to the magnifier window. + * If the zoom is x and the magnifier window size is (width, height), the original size + * of the content copied in the magnifier will be (width / x, height / x). + */ + public float getZoom() { + return mZoom; + } + + @Nullable + private Surface getValidViewSurface() { + // TODO: deduplicate this against the first part of #performPixelCopy + final Surface surface; + if (mView instanceof SurfaceView) { + surface = ((SurfaceView) mView).getHolder().getSurface(); + } else if (mView.getViewRootImpl() != null) { + surface = mView.getViewRootImpl().mSurface; + } else { + surface = null; + } + + return (surface != null && surface.isValid()) ? surface : null; + } + private void configureCoordinates(final float xPosInView, final float yPosInView) { // Compute the coordinates of the center of the content going to be displayed in the // magnifier. These are relative to the surface the content is copied from. @@ -602,7 +627,7 @@ public final class Magnifier { return null; } synchronized (mWindow.mLock) { - return mWindow.mBitmap; + return Bitmap.createScaledBitmap(mWindow.mBitmap, mWindowWidth, mWindowHeight, true); } }