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

Commit 282cdebd authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Crop the center when no source rect hint

When there is no source rect hint, forge a crop that matches the given
aspect ratio and centered, therefore we can use a consolidated animation
path and fix the issue with the round corner, which was inproperly
scaled in the past.

Flag: NONE bug fix
Bug: 298409662
Test: Test the overlay in both gesture and button navigation mode,\
      with both YouTube and Google Maps,\
      in both folded and unfolded mode.
Change-Id: I8ae48b999159a51eda2ff41c49cdb3c4e1541176
parent 97157614
Loading
Loading
Loading
Loading
+22 −27
Original line number Diff line number Diff line
@@ -154,8 +154,23 @@ public class SwipePipToHomeAnimator extends RectFSpringAnim {
        }

        if (sourceRectHint.isEmpty()) {
            mSourceRectHint.setEmpty();
            mSourceHintRectInsets = null;
            // Crop a Rect matches the aspect ratio and pivots at the center point.
            // To make the animation path simplified.
            final float aspectRatio = destinationBounds.width()
                    / (float) destinationBounds.height();
            if ((appBounds.width() / (float) appBounds.height()) > aspectRatio) {
                // use the full height.
                mSourceRectHint.set(0, 0,
                        (int) (appBounds.height() * aspectRatio), appBounds.height());
                mSourceRectHint.offset(
                        (appBounds.width() - mSourceRectHint.width()) / 2, 0);
            } else {
                // use the full width.
                mSourceRectHint.set(0, 0,
                        appBounds.width(), (int) (appBounds.width() / aspectRatio));
                mSourceRectHint.offset(
                        0, (appBounds.height() - mSourceRectHint.height()) / 2);
            }

            // Create a new overlay layer. We do not call detach on this instance, it's propagated
            // to other classes like PipTaskOrganizer / RecentsAnimationController to complete
@@ -168,11 +183,11 @@ public class SwipePipToHomeAnimator extends RectFSpringAnim {
            Log.d(TAG, getContentOverlay() + " is created: " + reasonForCreateOverlay);
        } else {
            mSourceRectHint.set(sourceRectHint);
            mSourceHintRectInsets = new Rect(sourceRectHint.left - appBounds.left,
                    sourceRectHint.top - appBounds.top,
                    appBounds.right - sourceRectHint.right,
                    appBounds.bottom - sourceRectHint.bottom);
        }
        mSourceHintRectInsets = new Rect(mSourceRectHint.left - appBounds.left,
                mSourceRectHint.top - appBounds.top,
                appBounds.right - mSourceRectHint.right,
                appBounds.bottom - mSourceRectHint.bottom);

        addAnimatorListener(new AnimationSuccessListener() {
            @Override
@@ -217,27 +232,7 @@ public class SwipePipToHomeAnimator extends RectFSpringAnim {
        if (mPipContentOverlay != null) {
            mPipContentOverlay.onAnimationUpdate(tx, mCurrentBounds, progress);
        }
        final PictureInPictureSurfaceTransaction op;
        if (mSourceHintRectInsets == null) {
            // no source rect hint been set, directly scale the window down
            op = onAnimationScale(progress, tx, mCurrentBounds);
        } else {
            // scale and crop according to the source rect hint
            op = onAnimationScaleAndCrop(progress, tx, mCurrentBounds);
        }
        return op;
    }

    /** scale the window directly with no source rect hint being set */
    private PictureInPictureSurfaceTransaction onAnimationScale(
            float progress, SurfaceControl.Transaction tx, Rect bounds) {
        if (mFromRotation == Surface.ROTATION_90 || mFromRotation == Surface.ROTATION_270) {
            final RotatedPosition rotatedPosition = getRotatedPosition(progress);
            return mSurfaceTransactionHelper.scale(tx, mLeash, mAppBounds, bounds,
                    rotatedPosition.degree, rotatedPosition.positionX, rotatedPosition.positionY);
        } else {
            return mSurfaceTransactionHelper.scale(tx, mLeash, mAppBounds, bounds);
        }
        return onAnimationScaleAndCrop(progress, tx, mCurrentBounds);
    }

    /** scale and crop the window with source rect hint */