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

Commit 8e96cc0e authored by Ben Lin's avatar Ben Lin Committed by Automerger Merge Worker
Browse files

Merge "PiP: Better rotation angle calculation." into sc-dev am: 5f5968a2

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13496872

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I535858207c3a273ea1406901644d07c3a839ebd8
parents 01c7d07e 5f5968a2
Loading
Loading
Loading
Loading
+32 −19
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ public class PipResizeGestureHandler {
    private boolean mThresholdCrossed0;
    private boolean mThresholdCrossed1;
    private boolean mUsingPinchToZoom = false;
    private float mAngle = 0;
    int mFirstIndex = -1;
    int mSecondIndex = -1;

@@ -420,18 +421,25 @@ public class PipResizeGestureHandler {
                float down1X = mDownSecondaryPoint.x;
                float down1Y = mDownSecondaryPoint.y;

                if (down0X > focusX && down0Y < focusY && down1X < focusX && down1Y > focusY) {
                    // Top right + Bottom left pinch to zoom.
                if ((down0X > focusX && down0Y < focusY && down1X < focusX && down1Y > focusY)
                        || (down1X > focusX && down1Y < focusY
                        && down0X < focusX && down0Y > focusY)) {
                    mAngle = calculateRotationAngle(mLastResizeBounds.centerX(),
                            mLastResizeBounds.centerY(), x0, y0, x1, y1, true);
                } else if ((down0X < focusX && down0Y < focusY
                        && down1X > focusX && down1Y > focusY)
                        || (down1X < focusX && down1Y < focusY
                        && down0X > focusX && down0Y > focusY)) {
                } else if (down1X > focusX && down1Y < focusY
                        && down0X < focusX && down0Y > focusY) {
                    // Top right + Bottom left pinch to zoom.
                    mAngle = calculateRotationAngle(mLastResizeBounds.centerX(),
                            mLastResizeBounds.centerY(), x1, y1, x0, y0, true);
                } else if (down0X < focusX && down0Y < focusY
                        && down1X > focusX && down1Y > focusY) {
                    // Top left + bottom right pinch to zoom.
                    mAngle = calculateRotationAngle(mLastResizeBounds.centerX(),
                            mLastResizeBounds.centerY(), x0, y0, x1, y1, false);
                } else if (down1X < focusX && down1Y < focusY
                        && down0X > focusX && down0Y > focusY) {
                    // Top left + bottom right pinch to zoom.
                    mAngle = calculateRotationAngle(mLastResizeBounds.centerX(),
                            mLastResizeBounds.centerY(), x1, y1, x0, y0, false);
                }

                mLastResizeBounds.set(PipPinchResizingAlgorithm.pinchResize(x0, y0, x1, y1,
@@ -445,21 +453,26 @@ public class PipResizeGestureHandler {
        }
    }

    private float mAngle = 0;

    private float calculateRotationAngle(int focusX, int focusY, float x0, float y0,
            float x1, float y1, boolean positive) {
    private float calculateRotationAngle(int pivotX, int pivotY, float topX, float topY,
            float bottomX, float bottomY, boolean positive) {

        // The base angle is the angle formed by taking the angle between the center horizontal
        // and one of the corners.
        double baseAngle = Math.toDegrees(Math.atan2(Math.abs(mLastResizeBounds.top - focusY),
                Math.abs(mLastResizeBounds.right - focusX)));
        double baseAngle = Math.toDegrees(Math.atan2(Math.abs(mLastResizeBounds.top - pivotY),
                Math.abs(mLastResizeBounds.right - pivotX)));

        double angle0 = mThresholdCrossed0
                ? Math.toDegrees(Math.atan2(Math.abs(y0 - focusY), Math.abs(x0 - focusX)))
                : baseAngle;
        double angle1 = mThresholdCrossed1
                ? Math.toDegrees(Math.atan2(Math.abs(y1 - focusY), Math.abs(x1 - focusX)))
                : baseAngle;
                ? Math.toDegrees(Math.atan2(pivotY - topY, topX - pivotX)) : baseAngle;
        double angle1 = mThresholdCrossed0
                ? Math.toDegrees(Math.atan2(pivotY - bottomY, bottomX - pivotX)) : baseAngle;


        if (positive) {
            angle1 = angle1 < 0 ? 180 + angle1 : angle1 - 180;
        } else {
            angle0 = angle0 < 0 ? -angle0 - 180 : 180 - angle0;
            angle1 = -angle1;
        }

        // Calculate the percentage difference of [0, 90] compare to the base angle.
        double diff0 = (Math.max(0, Math.min(angle0, 90)) - baseAngle) / 90;