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

Commit 4b6ef995 authored by Mihai Popa's avatar Mihai Popa
Browse files

[Magnifier - 15] Fix magnifier window positioning

This CL fixes the positioning of the magnifier window when the magnified
view is attached to a window with non-zero insets in its surface. The
magnifier PopupWindow is a panel window attached to the magnified view's
window, so its positioning has to be computed relative to this window.
However, previously the coordinates were computed relative to the view's
surface.

Bug: 72417421
Bug: 63531115
Test: bit CtsWidgetTestCases:android.widget.cts.MagnifierTest
Change-Id: I27aebd210d7596316f48fc55bfd6a37934624916
parent 81fc6325
Loading
Loading
Loading
Loading
+21 −14
Original line number Diff line number Diff line
@@ -190,27 +190,34 @@ public final class Magnifier {
        }
    }

    private void configureCoordinates(float xPosInView, float yPosInView) {
        final float posX;
        final float posY;

    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.
        final float contentPosX;
        final float contentPosY;
        if (mView instanceof SurfaceView) {
            // No offset required if the backing Surface matches the size of the SurfaceView.
            posX = xPosInView;
            posY = yPosInView;
            contentPosX = xPosInView;
            contentPosY = yPosInView;
        } else {
            mView.getLocationInSurface(mViewCoordinatesInSurface);
            posX = xPosInView + mViewCoordinatesInSurface[0];
            posY = yPosInView + mViewCoordinatesInSurface[1];
            contentPosX = xPosInView + mViewCoordinatesInSurface[0];
            contentPosY = yPosInView + mViewCoordinatesInSurface[1];
        }
        mCenterZoomCoords.x = Math.round(contentPosX);
        mCenterZoomCoords.y = Math.round(contentPosY);

        mCenterZoomCoords.x = Math.round(posX);
        mCenterZoomCoords.y = Math.round(posY);

        final int verticalMagnifierOffset = mView.getContext().getResources().getDimensionPixelSize(
        // Compute the position of the magnifier window. These have to be relative to the window
        // of the view the magnifier is attached to, as the magnifier popup is a panel window
        // attached to that window.
        final int[] viewCoordinatesInWindow = new int[2];
        mView.getLocationInWindow(viewCoordinatesInWindow);
        final int verticalOffset = mView.getContext().getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.magnifier_offset);
        mWindowCoords.x = mCenterZoomCoords.x - mWindowWidth / 2;
        mWindowCoords.y = mCenterZoomCoords.y - mWindowHeight / 2 - verticalMagnifierOffset;
        final float magnifierPosX = xPosInView + viewCoordinatesInWindow[0];
        final float magnifierPosY = yPosInView + viewCoordinatesInWindow[1] - verticalOffset;
        mWindowCoords.x = Math.round(magnifierPosX - mWindowWidth / 2);
        mWindowCoords.y = Math.round(magnifierPosY - mWindowHeight / 2);
    }

    private void performPixelCopy(final int startXInSurface, final int startYInSurface) {