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

Commit c5971125 authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Apply round corner when expand PiP

When expanding from PiP to full-screen mode, make sure the round corner
is applied during the animation and reset at the end if not in desktop
windowing mode.

Flag: com.android.wm.shell.enable_pip2
Bug: 416337465
Video: http://recall/-/aaaaaabFQoRHlzixHdtY/eeTP3fnK1PirXtUc4VkhNt
Test: atest WMShellUnitTests:PipExpandAnimatorTest
Test: Manual expand PiP to full-screen, see Video
Change-Id: Ia566cc9495cf1871955c5180b13969fb80360600
parent 0676e931
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -86,6 +86,11 @@ public class PipExpandAnimator extends ValueAnimator {
            super.onAnimationEnd(animation);
            if (mFinishTransaction != null) {
                onExpandAnimationUpdate(mFinishTransaction, 1f);
                // Reset the corner radius at the end, if not in desktop windowing mode.
                if (!mIsPipInDesktopMode) {
                    mPipSurfaceTransactionHelper.round(mFinishTransaction, mLeash,
                            false /* applyCornerRadius */);
                }
            }
            if (mAnimationEndCallback != null) {
                mAnimationEndCallback.run();
@@ -183,7 +188,9 @@ public class PipExpandAnimator extends ValueAnimator {
                    mAnimatedRect, insets, degrees, x, y,
                    true /* isExpanding */, mRotation == ROTATION_90);
        }
        mPipSurfaceTransactionHelper.round(tx, mLeash, mIsPipInDesktopMode /* applyCornerRadius */)
        // Apply round corner during the animation, it will be reset at the end if not in desktop
        // windowing mode.
        mPipSurfaceTransactionHelper.round(tx, mLeash, true /* applyCornerRadius */)
                .shadow(tx, mLeash, false /* applyShadowRadius */);
    }

+31 −2
Original line number Diff line number Diff line
@@ -173,6 +173,31 @@ public class PipExpandAnimatorTest {
        verify(mMockEndCallback).run();
    }

    @Test
    public void onAnimationUpdate_expand_setRoundCornersWithoutShadow() {
        mRotation = Surface.ROTATION_0;
        mBaseBounds = new Rect(0, 0, 1_000, 2_000);
        mStartBounds = new Rect(500, 1_000, 1_000, 2_000);
        mEndBounds = new Rect(mBaseBounds);
        mPipExpandAnimator = new PipExpandAnimator(mMockContext,
                new PipSurfaceTransactionHelper(mMockContext), mTestLeash,
                mMockStartTransaction, mMockFinishTransaction,
                mBaseBounds, mStartBounds, mEndBounds, mSourceRectHint,
                mRotation, false /* isPipInDesktopMode */);
        mPipExpandAnimator.setSurfaceControlTransactionFactory(mMockFactory);

        mPipExpandAnimator.setAnimationStartCallback(mMockStartCallback);
        mPipExpandAnimator.setAnimationEndCallback(mMockEndCallback);
        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
            mPipExpandAnimator.start();
            clearInvocations(mMockTransaction);
            mPipExpandAnimator.setCurrentFraction(0.5f);
        });

        verify(mMockTransaction).setCornerRadius(mTestLeash, CORNER_RADIUS);
        verify(mMockTransaction).setShadowRadius(mTestLeash, 0f);
    }

    @Test
    public void onAnimationEnd_expand_leashIsFullscreen() {
        mRotation = Surface.ROTATION_0;
@@ -191,16 +216,18 @@ public class PipExpandAnimatorTest {
        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
            mPipExpandAnimator.start();
            clearInvocations(mMockTransaction);
            clearInvocations(mMockFinishTransaction);
            mPipExpandAnimator.end();
        });

        verify(mMockTransaction).setCrop(mTestLeash, mEndBounds);
        verify(mMockTransaction).setCornerRadius(mTestLeash, 0f);
        verify(mMockTransaction).setCornerRadius(mTestLeash, CORNER_RADIUS);
        verify(mMockTransaction).setShadowRadius(mTestLeash, 0f);
        verify(mMockFinishTransaction).setCornerRadius(mTestLeash, 0f);
    }

    @Test
    public void onAnimationEnd_expand_isInDesktopMode_setRoundedCorners() {
    public void onAnimationEnd_expandInDesktopMode_setRoundedCorners() {
        mRotation = Surface.ROTATION_0;
        mBaseBounds = new Rect(0, 0, 1_000, 2_000);
        mStartBounds = new Rect(500, 1_000, 1_000, 2_000);
@@ -217,11 +244,13 @@ public class PipExpandAnimatorTest {
        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
            mPipExpandAnimator.start();
            clearInvocations(mMockTransaction);
            clearInvocations(mMockFinishTransaction);
            mPipExpandAnimator.end();
        });

        verify(mMockTransaction).setCrop(mTestLeash, mEndBounds);
        verify(mMockTransaction).setCornerRadius(mTestLeash, CORNER_RADIUS);
        verify(mMockTransaction).setShadowRadius(mTestLeash, 0f);
        verify(mMockFinishTransaction).setCornerRadius(mTestLeash, CORNER_RADIUS);
    }
}