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

Commit 05476b3a authored by Ben Lin's avatar Ben Lin
Browse files

Change PiP stash to be based on velocity rather than position.

Also only allow stashing if user starts dragging from that edge.

Bug: 165793553
Test: Stash PIP via flinging
Change-Id: Icfd6d8d580cfb96b148f7712d0aedfcee1f30b2d
parent 8817872a
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -368,12 +368,11 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
    }

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

    private void movetoTarget(
+13 −12
Original line number Diff line number Diff line
@@ -64,11 +64,7 @@ import java.util.function.Consumer;
public class PipTouchHandler {
    private static final String TAG = "PipTouchHandler";

    /** Duration of the dismiss scrim fading in/out. */
    private static final int DISMISS_TRANSITION_DURATION_MS = 200;

    /* The multiplier to apply scale the target size by when applying the magnetic field radius */
    private static final float MAGNETIC_FIELD_RADIUS_MULTIPLIER = 1.25f;
    private static final float STASH_MINIMUM_VELOCITY_X = 3000.f;

    // Allow PIP to resize to a slightly bigger state upon touch
    private final boolean mEnableResize;
@@ -710,6 +706,7 @@ public class PipTouchHandler {
        private final Point mStartPosition = new Point();
        private final PointF mDelta = new PointF();
        private boolean mShouldHideMenuAfterFling;
        private float mDownSavedFraction = -1f;

        @Override
        public void onDown(PipTouchState touchState) {
@@ -722,6 +719,7 @@ public class PipTouchHandler {
            mStartPosition.set(bounds.left, bounds.top);
            mMovementWithinDismiss = touchState.getDownTouchPosition().y >= mMovementBounds.bottom;
            mMotionHelper.setSpringingToTouch(false);
            mDownSavedFraction = mPipBoundsHandler.getSnapFraction(mPipBoundsState.getBounds());

            // If the menu is still visible then just poke the menu
            // so that it will timeout after the user stops touching it
@@ -790,13 +788,15 @@ public class PipTouchHandler {

                // Reset the touch state on up before the fling settles
                mTouchState.reset();
                final Rect animatingBounds = getPossiblyAnimatingBounds();
                // If User releases the PIP window while it's out of the display bounds, put
                // PIP into stashed mode.
                if (mEnableStash
                        && (animatingBounds.right > mPipBoundsState.getDisplayBounds().right
                        || animatingBounds.left < mPipBoundsState.getDisplayBounds().left)) {
                    mMotionHelper.stashToEdge(vel.x, vel.y, this::stashEndAction /* endAction */);
                // If user flings the PIP window above the minimum velocity, stash PIP.
                // Only allow stashing to the edge if the user starts dragging the PIP from that
                // edge.
                if (mEnableStash && !mPipBoundsState.isStashed()
                        && ((vel.x > STASH_MINIMUM_VELOCITY_X
                        && mDownSavedFraction > 1f && mDownSavedFraction < 2f)
                        || (vel.x < -STASH_MINIMUM_VELOCITY_X
                        && mDownSavedFraction > 3f && mDownSavedFraction < 4f))) {
                    mMotionHelper.stashToEdge(vel.x, this::stashEndAction /* endAction */);
                } else {
                    mMotionHelper.flingToSnapTarget(vel.x, vel.y,
                            this::flingEndAction /* endAction */);
@@ -834,6 +834,7 @@ public class PipTouchHandler {
                    mTouchState.scheduleDoubleTapTimeoutCallback();
                }
            }
            mDownSavedFraction = -1f;
            return true;
        }