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

Commit 601dc853 authored by Joshua Tsuji's avatar Joshua Tsuji
Browse files

Don't sync pinned stack bounds due to onDown unless we're not animating.

This was causing PIP to be offset from the touch position if it was dragged before its animation ended.

This also fixes a bug where mAnimatingToBounds was actually empty during animations, because we were calling cancelAnimations() after setting it.

Test: fling pip, then grab it immediately and drag it
Bug: 153094531
Change-Id: Ic51e1a79e597a0cbe4b0d3e7a238f8c92d8712c0
parent 898dda39
Loading
Loading
Loading
Loading
+33 −14
Original line number Diff line number Diff line
@@ -162,7 +162,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
    }

    /**
     * Synchronizes the current bounds with the pinned stack.
     * Synchronizes the current bounds with the pinned stack, cancelling any ongoing animations.
     */
    void synchronizePinnedStackBounds() {
        cancelAnimations();
@@ -177,6 +177,21 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        }
    }

    /**
     * Synchronizes the current bounds with either the pinned stack, or the ongoing animation. This
     * is done to prepare for a touch gesture.
     */
    void synchronizePinnedStackBoundsForTouchGesture() {
        if (mAnimatingToBounds.isEmpty()) {
            // If we're not animating anywhere, sync normally.
            synchronizePinnedStackBounds();
        } else {
            // If we're animating, set the current bounds to the animated bounds. That way, the
            // touch gesture will begin at the most recent animated location of the bounds.
            mBounds.set(mAnimatedBounds);
        }
    }

    /**
     * Tries to move the pinned stack to the given {@param bounds}.
     */
@@ -295,13 +310,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        final float estimatedFlingYEndValue =
                PhysicsAnimator.estimateFlingEndValue(mBounds.top, velocityY, mFlingConfigY);

        setAnimatingToBounds(new Rect(
                (int) xEndValue,
                (int) estimatedFlingYEndValue,
                (int) xEndValue + mBounds.width(),
                (int) estimatedFlingYEndValue + mBounds.height()));

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

    /**
@@ -322,9 +331,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        mAnimatedBoundsPhysicsAnimator
                .spring(FloatProperties.RECT_X, bounds.left, springConfig)
                .spring(FloatProperties.RECT_Y, bounds.top, springConfig);
        startBoundsAnimation();

        setAnimatingToBounds(bounds);
        startBoundsAnimator(bounds.left /* toX */, bounds.top /* toY */);
    }

    /**
@@ -349,7 +356,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
                    (target, values) -> updateAction.run());
        }

        startBoundsAnimation();
        startBoundsAnimator(dismissEndPoint.x /* toX */, dismissEndPoint.y /* toY */);
    }

    /**
@@ -418,11 +425,23 @@ 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 startBoundsAnimation() {
    private void startBoundsAnimator(float toX, float toY) {
        cancelAnimations();

        // Set animatingToBounds directly to avoid allocating a new Rect, but then call
        // setAnimatingToBounds to run the normal logic for changing animatingToBounds.
        mAnimatingToBounds.set(
                (int) toX,
                (int) toY,
                (int) toX + mBounds.width(),
                (int) toY + mBounds.height());
        setAnimatingToBounds(mAnimatingToBounds);

        mAnimatedBoundsPhysicsAnimator
                .withEndActions(() ->  mPipTaskOrganizer.scheduleFinishResizePip(mAnimatedBounds))
                .withEndActions(() -> {
                    mPipTaskOrganizer.scheduleFinishResizePip(mAnimatedBounds);
                    mAnimatingToBounds.setEmpty();
                })
                .addUpdateListener(mResizePipUpdateListener)
                .start();
    }
+1 −1
Original line number Diff line number Diff line
@@ -384,7 +384,7 @@ public class PipTouchHandler {

        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                mMotionHelper.synchronizePinnedStackBounds();
                mMotionHelper.synchronizePinnedStackBoundsForTouchGesture();
                mGesture.onDown(mTouchState);
                break;
            }