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

Commit 63336329 authored by Ben Lin's avatar Ben Lin Committed by Android (Google) Code Review
Browse files

Merge "Add PiP exclusion logic in EdgeBackGestureHandler."

parents bebcc04c accac9b5
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -184,4 +184,11 @@ public interface Pip {
    default void stopSwipePipToHome(ComponentName componentName, Rect destinationBounds) {
        return;
    }

    /**
     * Called by NavigationBar in order to listen in for PiP bounds change. This is mostly used
     * for times where the PiP bounds could conflict with SystemUI elements, such as a stashed
     * PiP and the Back-from-Edge gesture.
     */
    default void setPipExclusionBoundsChangeListener(Consumer<Rect> listener) { }
}
+10 −0
Original line number Diff line number Diff line
@@ -472,6 +472,16 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac
        mReentryBounds.set(reentryBounds);
    }

    /**
     * Set a listener to watch out for PiP bounds. This is mostly used by SystemUI's
     * Back-gesture handler, to avoid conflicting with PiP when it's stashed.
     */
    @Override
    public void setPipExclusionBoundsChangeListener(
            Consumer<Rect> pipExclusionBoundsChangeListener) {
        mTouchHandler.setPipExclusionBoundsChangeListener(pipExclusionBoundsChangeListener);
    }

    @Override
    public void onPipTransitionFinished(ComponentName activity, int direction) {
        onPipTransitionFinishedOrCanceled(direction);
+32 −19
Original line number Diff line number Diff line
@@ -262,8 +262,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
                    .spring(FloatProperties.RECT_X, toBounds.left, mSpringConfig)
                    .spring(FloatProperties.RECT_Y, toBounds.top, mSpringConfig);

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

@@ -292,7 +291,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
                .spring(FloatProperties.RECT_HEIGHT, desiredHeight, mSpringConfig)
                .withEndActions(after);

        startBoundsAnimator(destinationX, destinationY, false);
        startBoundsAnimator(destinationX, destinationY);
    }

    /** Set whether we're springing-to-touch to catch up after being stuck in the dismiss target. */
@@ -364,21 +363,24 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
     * Flings the PiP to the closest snap target.
     */
    void flingToSnapTarget(
            float velocityX, float velocityY, @Nullable Runnable endAction) {
        movetoTarget(velocityX, velocityY, endAction, false /* isStash */);
            float velocityX, float velocityY, @Nullable Runnable postBoundsUpdateCallback) {
        movetoTarget(velocityX, velocityY, postBoundsUpdateCallback, false /* isStash */);
    }

    /**
     * Stash PiP to the closest edge.
     */
    void stashToEdge(
            float velocityX, float velocityY, @Nullable Runnable endAction) {
            float velocityX, float velocityY, @Nullable Runnable postBoundsUpdateCallback) {
        mPipBoundsState.setStashed(velocityX < 0 ? STASH_TYPE_LEFT : STASH_TYPE_RIGHT);
        movetoTarget(velocityX, velocityY, endAction, true /* isStash */);
        movetoTarget(velocityX, velocityY, postBoundsUpdateCallback, true /* isStash */);
    }

    private void movetoTarget(
            float velocityX, float velocityY, @Nullable Runnable endAction, boolean isStash) {
            float velocityX,
            float velocityY,
            @Nullable Runnable postBoundsUpdateCallback,
            boolean isStash) {
        // If we're flinging to a snap target now, we're not springing to catch up to the touch
        // location now.
        mSpringingToTouch = false;
@@ -390,8 +392,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
                        FloatProperties.RECT_X, velocityX, isStash ? mStashConfigX : mFlingConfigX,
                        mSpringConfig, true /* flingMustReachMinOrMax */)
                .flingThenSpring(
                        FloatProperties.RECT_Y, velocityY, mFlingConfigY, mSpringConfig)
                .withEndActions(endAction);
                        FloatProperties.RECT_Y, velocityY, mFlingConfigY, mSpringConfig);

        final float leftEdge = isStash
                ? mPipBoundsState.getStashOffset() - mPipBoundsState.getBounds().width()
@@ -407,7 +408,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
                PhysicsAnimator.estimateFlingEndValue(startValueY, velocityY, mFlingConfigY);

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

    /**
@@ -423,8 +424,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        mTemporaryBoundsPhysicsAnimator
                .spring(FloatProperties.RECT_X, bounds.left, springConfig)
                .spring(FloatProperties.RECT_Y, bounds.top, springConfig);
        startBoundsAnimator(bounds.left /* toX */, bounds.top /* toY */,
                false /* dismiss */);
        startBoundsAnimator(bounds.left /* toX */, bounds.top /* toY */);
    }

    /**
@@ -440,8 +440,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
                .withEndActions(this::dismissPip);

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

        mDismissalPending = false;
    }
@@ -516,14 +515,21 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
                mPipBoundsState.getDisplayBounds().right - mPipBoundsState.getStashOffset());
    }

    private void startBoundsAnimator(float toX, float toY) {
        startBoundsAnimator(toX, toY, null /* postBoundsUpdateCallback */);
    }

    /**
     * Starts the physics animator which will update the animated PIP bounds using physics
     * animations, as well as the TimeAnimator which will apply those bounds to PIP.
     *
     * 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.
     *
     * If one wishes to supply a callback after all the 'real' bounds update has happened,
     * pass @param postBoundsUpdateCallback.
     */
    private void startBoundsAnimator(float toX, float toY, boolean dismiss) {
    private void startBoundsAnimator(float toX, float toY, Runnable postBoundsUpdateCallback) {
        if (!mSpringingToTouch) {
            cancelPhysicsAnimation();
        }
@@ -535,10 +541,17 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
                (int) toY + getBounds().height()));

        if (!mTemporaryBoundsPhysicsAnimator.isRunning()) {
            if (postBoundsUpdateCallback != null) {
                mTemporaryBoundsPhysicsAnimator
                        .addUpdateListener(mResizePipUpdateListener)
                        .withEndActions(this::onBoundsPhysicsAnimationEnd,
                                postBoundsUpdateCallback);
            } else {
                mTemporaryBoundsPhysicsAnimator
                        .addUpdateListener(mResizePipUpdateListener)
                        .withEndActions(this::onBoundsPhysicsAnimationEnd);
            }
        }

        mTemporaryBoundsPhysicsAnimator.start();
    }
+26 −1
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ import com.android.wm.shell.pip.PipTaskOrganizer;
import com.android.wm.shell.pip.PipUiEventLogger;

import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.function.Consumer;

/**
 * Manages all the touch handling for PIP on the Phone, including moving, dismissing and expanding
@@ -78,6 +80,7 @@ public class PipTouchHandler {

    private PipResizeGestureHandler mPipResizeGestureHandler;
    private IPinnedStackController mPinnedStackController;
    private WeakReference<Consumer<Rect>> mPipExclusionBoundsChangeListener;

    private final PipMenuActivityController mMenuController;
    private final AccessibilityManager mAccessibilityManager;
@@ -259,6 +262,11 @@ public class PipTouchHandler {

            mFloatingContentCoordinator.onContentRemoved(mMotionHelper);
        }
        // Reset exclusion to none.
        if (mPipExclusionBoundsChangeListener != null
                && mPipExclusionBoundsChangeListener.get() != null) {
            mPipExclusionBoundsChangeListener.get().accept(new Rect());
        }
        mPipResizeGestureHandler.onActivityUnpinned();
    }

@@ -788,7 +796,7 @@ public class PipTouchHandler {
                if (mEnableStash
                        && (animatingBounds.right > mPipBoundsState.getDisplayBounds().right
                        || animatingBounds.left < mPipBoundsState.getDisplayBounds().left)) {
                    mMotionHelper.stashToEdge(vel.x, vel.y, this::flingEndAction /* endAction */);
                    mMotionHelper.stashToEdge(vel.x, vel.y, this::stashEndAction /* endAction */);
                } else {
                    mMotionHelper.flingToSnapTarget(vel.x, vel.y,
                            this::flingEndAction /* endAction */);
@@ -829,14 +837,31 @@ public class PipTouchHandler {
            return true;
        }

        private void stashEndAction() {
            if (mPipExclusionBoundsChangeListener != null
                    && mPipExclusionBoundsChangeListener.get() != null) {
                mPipExclusionBoundsChangeListener.get().accept(mPipBoundsState.getBounds());
            }
        }

        private void flingEndAction() {
            if (mShouldHideMenuAfterFling) {
                // If the menu is not visible, then we can still be showing the activity for the
                // dismiss overlay, so just finish it after the animation completes
                mMenuController.hideMenu();
            }
            // Reset exclusion to none.
            if (mPipExclusionBoundsChangeListener != null
                    && mPipExclusionBoundsChangeListener.get() != null) {
                mPipExclusionBoundsChangeListener.get().accept(new Rect());
            }
        }
    }

    void setPipExclusionBoundsChangeListener(Consumer<Rect> pipExclusionBoundsChangeListener) {
        mPipExclusionBoundsChangeListener = new WeakReference<>(pipExclusionBoundsChangeListener);
        pipExclusionBoundsChangeListener.accept(mPipBoundsState.getBounds());
    }

    /**
     * Updates the current movement bounds based on whether the menu is currently visible and
+3 −0
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ import com.android.systemui.statusbar.policy.DataSaverController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.NetworkController;
import com.android.systemui.util.leak.LeakDetector;
import com.android.wm.shell.pip.Pip;
import com.android.wm.shell.splitscreen.SplitScreen;

import java.util.Optional;
@@ -208,6 +209,7 @@ public class DependencyProvider {
            SysUiState sysUiFlagsContainer,
            BroadcastDispatcher broadcastDispatcher,
            CommandQueue commandQueue,
            Optional<Pip> pipOptional,
            Optional<SplitScreen> splitScreenOptional,
            Optional<Recents> recentsOptional,
            Lazy<StatusBar> statusBarLazy,
@@ -230,6 +232,7 @@ public class DependencyProvider {
                sysUiFlagsContainer,
                broadcastDispatcher,
                commandQueue,
                pipOptional,
                splitScreenOptional,
                recentsOptional,
                statusBarLazy,
Loading