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

Commit 551b0792 authored by Ben Lin's avatar Ben Lin Committed by Automerger Merge Worker
Browse files

Merge "Avoid #finalResizePip after dismissal of PIP." into rvc-dev am: cb0af9f8

Change-Id: I9e1637f88aecf0d0970aa1f76554abfdca16e9e5
parents 3222c426 cb0af9f8
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -399,11 +399,12 @@ public class PipMenuActivity extends Activity {
    }

    private void hideMenu(Runnable animationEndCallback) {
        hideMenu(animationEndCallback, true /* notifyMenuVisibility */, false /* isDismissing */);
        hideMenu(animationEndCallback, true /* notifyMenuVisibility */, false /* isDismissing */,
                true /* animate */);
    }

    private void hideMenu(final Runnable animationFinishedRunnable, boolean notifyMenuVisibility,
            boolean isDismissing) {
            boolean isDismissing, boolean animate) {
        if (mMenuState != MENU_STATE_NONE) {
            cancelDelayedFinish();
            if (notifyMenuVisibility) {
@@ -419,7 +420,7 @@ public class PipMenuActivity extends Activity {
                    mDismissButton.getAlpha(), 0f);
            mMenuContainerAnimator.playTogether(menuAnim, settingsAnim, dismissAnim);
            mMenuContainerAnimator.setInterpolator(Interpolators.ALPHA_OUT);
            mMenuContainerAnimator.setDuration(MENU_FADE_DURATION);
            mMenuContainerAnimator.setDuration(animate ? MENU_FADE_DURATION : 0);
            mMenuContainerAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
@@ -582,16 +583,20 @@ public class PipMenuActivity extends Activity {
        hideMenu(() -> {
            sendEmptyMessage(PipMenuActivityController.MESSAGE_EXPAND_PIP,
                    "Could not notify controller to expand PIP");
        }, false /* notifyMenuVisibility */, false /* isDismissing */);
        }, false /* notifyMenuVisibility */, false /* isDismissing */, true /* animate */);
    }

    private void dismissPip() {
        // Since tapping on the close-button invokes a double-tap wait callback in PipTouchHandler,
        // we want to disable animating the fadeout animation of the buttons in order to call on
        // PipTouchHandler#onPipDismiss fast enough.
        final boolean animate = mMenuState != MENU_STATE_CLOSE;
        // Do not notify menu visibility when hiding the menu, the controller will do this when it
        // handles the message
        hideMenu(() -> {
            sendEmptyMessage(PipMenuActivityController.MESSAGE_DISMISS_PIP,
                    "Could not notify controller to dismiss PIP");
        }, false /* notifyMenuVisibility */, true /* isDismissing */);
        }, false /* notifyMenuVisibility */, true /* isDismissing */, animate);
    }

    private void showSettings() {
+14 −14
Original line number Diff line number Diff line
@@ -237,7 +237,8 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
                    .spring(FloatProperties.RECT_Y, toBounds.top, mSpringConfig)
                    .withEndActions(() -> mSpringingToTouch = false);

            startBoundsAnimator(toBounds.left /* toX */, toBounds.top /* toY */);
            startBoundsAnimator(toBounds.left /* toX */, toBounds.top /* toY */,
                    false /* dismiss */);
        }
    }

@@ -334,7 +335,8 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        final float estimatedFlingYEndValue =
                PhysicsAnimator.estimateFlingEndValue(mBounds.top, velocityY, mFlingConfigY);

        startBoundsAnimator(xEndValue /* toX */, estimatedFlingYEndValue /* toY */);
        startBoundsAnimator(xEndValue /* toX */, estimatedFlingYEndValue /* toY */,
                false /* dismiss */);
    }

    /**
@@ -346,30 +348,26 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        mAnimatedBoundsPhysicsAnimator
                .spring(FloatProperties.RECT_X, bounds.left, springConfig)
                .spring(FloatProperties.RECT_Y, bounds.top, springConfig);
        startBoundsAnimator(bounds.left /* toX */, bounds.top /* toY */);
        startBoundsAnimator(bounds.left /* toX */, bounds.top /* toY */,
                false /* dismiss */);
    }

    /**
     * Animates the dismissal of the PiP off the edge of the screen.
     */
    void animateDismiss(float velocityX, float velocityY, @Nullable Runnable updateAction) {
    void animateDismiss() {
        mAnimatedBounds.set(mBounds);

        // Animate off the bottom of the screen, then dismiss PIP.
        mAnimatedBoundsPhysicsAnimator
                .spring(FloatProperties.RECT_Y,
                        mBounds.bottom + mBounds.height(),
                        velocityY,
                        0,
                        mSpringConfig)
                .withEndActions(this::dismissPip);

        // If we were provided with an update action, run it whenever there's an update.
        if (updateAction != null) {
            mAnimatedBoundsPhysicsAnimator.addUpdateListener(
                    (target, values) -> updateAction.run());
        }

        startBoundsAnimator(mBounds.left /* toX */, mBounds.bottom + mBounds.height() /* toY */);
        startBoundsAnimator(mBounds.left /* toX */, mBounds.bottom + mBounds.height() /* toY */,
                true /* dismiss */);
    }

    /**
@@ -440,7 +438,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
     * This will also add end actions to the bounds animator that cancel the TimeAnimator and update
     * the 'real' bounds to equal the final animated bounds.
     */
    private void startBoundsAnimator(float toX, float toY) {
    private void startBoundsAnimator(float toX, float toY, boolean dismiss) {
        if (!mSpringingToTouch) {
            cancelAnimations();
        }
@@ -456,7 +454,9 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,

        mAnimatedBoundsPhysicsAnimator
                .withEndActions(() -> {
                    if (!dismiss) {
                        mPipTaskOrganizer.scheduleFinishResizePip(mAnimatedBounds);
                    }
                    mAnimatingToBounds.setEmpty();
                })
                .addUpdateListener(mResizePipUpdateListener)
+2 −1
Original line number Diff line number Diff line
@@ -197,6 +197,7 @@ public class PipTouchHandler {
            if (topPipActivity.first != null) {
                MetricsLoggerWrapper.logPictureInPictureDismissByTap(mContext, topPipActivity);
            }
            mTouchState.removeDoubleTapTimeoutCallback();
            mMotionHelper.dismissPip();
        }

@@ -297,7 +298,7 @@ public class PipTouchHandler {
            @Override
            public void onReleasedInTarget(@NonNull MagnetizedObject.MagneticTarget target) {
                mHandler.post(() -> {
                    mMotionHelper.animateDismiss(0, 0, null);
                    mMotionHelper.animateDismiss();
                    hideDismissTarget();
                });

+8 −0
Original line number Diff line number Diff line
@@ -318,6 +318,14 @@ public class PipTouchState {
        return -1;
    }

    /**
     * Removes the timeout callback if it's in queue.
     */
    public void removeDoubleTapTimeoutCallback() {
        mIsWaitingForDoubleTap = false;
        mHandler.removeCallbacks(mDoubleTapTimeoutCallback);
    }

    void addMovementToVelocityTracker(MotionEvent event) {
        if (mVelocityTracker == null) {
            return;