[Magnifier-29] Expose size and zoom in the API
The CL exposes the size and the zoom of the magnifier in the public API.
These are required for implementing a number of UX requests in WebView
and Chrome - see the two bugs referenced.
Also, the CL fixes a bug in the #getContent() TestApi, which was
returning the bitmap before (instead of after) scaling.
Bug: 70608551
Bug: 72314536
Test: atest CtsWidgetTestCases:android.widget.cts.MagnifierTest
Change-Id: Idc583b923010d7dca075b05b6f4dbafa74cfec1f
(cherry picked from commit e1b93ddcbd)
Merged-In: Idc583b923010d7dca075b05b6f4dbafa74cfec1f
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user