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

Commit 114aeea5 authored by Winson Chung's avatar Winson Chung
Browse files

Ensure we account for insets in minimized state.

- When dragging slightly offscreen to minimize the PIP,
  ensure that the bounds take the insets into account so
  that the user can still interact with the PIP.

Test: Enter PIP in landscape, try to minimize it.

Change-Id: I093a37ba600722d44e50cc68dac77365a2ba062e
parent 7d13f29b
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -128,11 +128,14 @@ public class PipSnapAlgorithm {
    /**
     * Applies the offset to the {@param stackBounds} to adjust it to a minimized state.
     */
    public void applyMinimizedOffset(Rect stackBounds, Rect movementBounds, Point displaySize) {
    public void applyMinimizedOffset(Rect stackBounds, Rect movementBounds, Point displaySize,
            Rect stableInsets) {
        if (stackBounds.left <= movementBounds.centerX()) {
            stackBounds.offsetTo(-stackBounds.width() + mMinimizedVisibleSize, stackBounds.top);
            stackBounds.offsetTo(stableInsets.left + mMinimizedVisibleSize - stackBounds.width(),
                    stackBounds.top);
        } else {
            stackBounds.offsetTo(displaySize.x - mMinimizedVisibleSize, stackBounds.top);
            stackBounds.offsetTo(displaySize.x - stableInsets.right - mMinimizedVisibleSize,
                    stackBounds.top);
        }
    }

+4 −1
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ public class PipTouchHandler implements TunerService.Tunable {
    // Allow the PIP to be "docked" slightly offscreen
    private boolean mEnableMinimizing = true;

    private final Rect mStableInsets = new Rect();
    private final Rect mPinnedStackBounds = new Rect();
    private final Rect mBoundedPinnedStackBounds = new Rect();
    private ValueAnimator mPinnedStackBoundsAnimator = null;
@@ -421,7 +422,8 @@ public class PipTouchHandler implements TunerService.Tunable {
        mContext.getDisplay().getRealSize(displaySize);
        Rect toBounds = mSnapAlgorithm.findClosestSnapBounds(mBoundedPinnedStackBounds,
                mPinnedStackBounds);
        mSnapAlgorithm.applyMinimizedOffset(toBounds, mBoundedPinnedStackBounds, displaySize);
        mSnapAlgorithm.applyMinimizedOffset(toBounds, mBoundedPinnedStackBounds, displaySize,
                mStableInsets);
        mPinnedStackBoundsAnimator = mMotionHelper.createAnimationToBounds(mPinnedStackBounds,
                toBounds, MINIMIZE_STACK_MAX_DURATION, LINEAR_OUT_SLOW_IN,
                mUpdatePinnedStackBoundsListener);
@@ -528,6 +530,7 @@ public class PipTouchHandler implements TunerService.Tunable {
                if (updatePinnedStackBounds) {
                    mPinnedStackBounds.set(info.bounds);
                }
                mWindowManager.getStableInsets(info.displayId, mStableInsets);
                mBoundedPinnedStackBounds.set(mWindowManager.getPictureInPictureMovementBounds(
                        info.displayId));
            }
+7 −3
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ class PinnedStackController {

    // Used to calculate stack bounds across rotations
    private final DisplayInfo mDisplayInfo = new DisplayInfo();
    private final Rect mStableInsets = new Rect();

    // The size and position information that describes where the pinned stack will go by default.
    private int mDefaultStackGravity;
@@ -250,10 +251,12 @@ class PinnedStackController {
    }

    /**
     * @return the repositioned PIP bounds given it's pre-change bounds, and the new display info.
     * @return the repositioned PIP bounds given it's pre-change bounds, and the new display
     *         content.
     */
    Rect onDisplayChanged(Rect preChangeStackBounds, DisplayInfo displayInfo) {
    Rect onDisplayChanged(Rect preChangeStackBounds, DisplayContent displayContent) {
        final Rect postChangeStackBounds = new Rect(preChangeStackBounds);
        final DisplayInfo displayInfo = displayContent.getDisplayInfo();
        if (!mDisplayInfo.equals(displayInfo)) {
            // Calculate the snap fraction of the current stack along the old movement bounds, and
            // then update the stack bounds to the same fraction along the rotated movement bounds.
@@ -269,8 +272,9 @@ class PinnedStackController {
            if (mIsMinimized) {
                final Point displaySize = new Point(mDisplayInfo.logicalWidth,
                        mDisplayInfo.logicalHeight);
                mService.getStableInsetsLocked(displayContent.getDisplayId(), mStableInsets);
                mSnapAlgorithm.applyMinimizedOffset(postChangeStackBounds, postChangeMovementBounds,
                        displaySize);
                        displaySize, mStableInsets);
            }
        }
        return postChangeStackBounds;
+2 −2
Original line number Diff line number Diff line
@@ -413,7 +413,7 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
        switch (mStackId) {
            case PINNED_STACK_ID:
                mTmpRect2 = mDisplayContent.getPinnedStackController().onDisplayChanged(mBounds,
                        getDisplayInfo());
                        mDisplayContent);
                break;
            case DOCKED_STACK_ID:
                repositionDockedStackAfterRotation(mTmpRect2);
@@ -684,7 +684,7 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
        // Update the pinned stack controller after the display info is updated
        if (mStackId == PINNED_STACK_ID) {
            mDisplayContent.getPinnedStackController().onDisplayChanged(oldBounds,
                    getDisplayInfo());
                    mDisplayContent);
        }

        super.onDisplayChanged(dc);