Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ebbcd2da authored by Mihai Popa's avatar Mihai Popa Committed by android-build-merger
Browse files

[Magnifier-29] Expose size and zoom in the API

am: 17ea3058

Change-Id: I2c4fc371ba1ddc3605b6976a648f8ba802b76f96
parents 9f605941 17ea3058
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -53395,6 +53395,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();
  }
+44 −19
Original line number Diff line number Diff line
@@ -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);
        }
    }