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

Commit 62c7f1e6 authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Snap to the closest edge when velocity is 0

When user slowly moves the PiP from one edge to the other, there could
be chances that VelocityTrack reports 0 in x-velocity and used to snap
to the right edge, which may not be intuitive to the user if the PiP
window has passed the midpoint.

In this change, we compare the centerX of the PiP window against the
display centerX, and added a boost in velocity towards nearest edge.

Updated also the pip2 counterpart.

Flag: EXEMPT bugfix
Video: http://recall/-/aaaaaabFQoRHlzixHdtY/bnpoNB1sS8Dujtfb5xUKkY
Bug: 323102290
Test: Slowly moves PiP from left to right side, and vice versa
Change-Id: I3b7c4ac14415d75164ba81f8ef471f5cae3f5ed6
parent ba088a63
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -416,6 +416,17 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        // location now.
        mSpringingToTouch = false;

        // Boost the velocityX if it's zero to forcefully push it towards the nearest edge.
        // We don't simply change the xEndValue below since the PhysicsAnimator would rely on the
        // same velocityX to find out which edge to snap to.
        if (velocityX == 0) {
            final int motionCenterX = mPipBoundsState
                    .getMotionBoundsState().getBoundsInMotion().centerX();
            final int displayCenterX = mPipBoundsState
                    .getDisplayBounds().centerX();
            velocityX = (motionCenterX < displayCenterX) ? -0.001f : 0.001f;
        }

        mTemporaryBoundsPhysicsAnimator
                .spring(FloatProperties.RECT_WIDTH, getBounds().width(), mSpringConfig)
                .spring(FloatProperties.RECT_HEIGHT, getBounds().height(), mSpringConfig)
+11 −0
Original line number Diff line number Diff line
@@ -416,6 +416,17 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        // location now.
        mSpringingToTouch = false;

        // Boost the velocityX if it's zero to forcefully push it towards the nearest edge.
        // We don't simply change the xEndValue below since the PhysicsAnimator would rely on the
        // same velocityX to find out which edge to snap to.
        if (velocityX == 0) {
            final int motionCenterX = mPipBoundsState
                    .getMotionBoundsState().getBoundsInMotion().centerX();
            final int displayCenterX = mPipBoundsState
                    .getDisplayBounds().centerX();
            velocityX = (motionCenterX < displayCenterX) ? -0.001f : 0.001f;
        }

        mTemporaryBoundsPhysicsAnimator
                .spring(FloatProperties.RECT_WIDTH, getBounds().width(), mSpringConfig)
                .spring(FloatProperties.RECT_HEIGHT, getBounds().height(), mSpringConfig)