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

Commit c396ff18 authored by Hongwei Wang's avatar Hongwei Wang Committed by Android (Google) Code Review
Browse files

Merge "Deprecate min/max size in PipResizeGestureHandler" into main

parents 97b622ac 65116965
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -345,7 +345,6 @@ public class PipController implements ConfigurationChangeListener,
            return;
            return;
        }
        }


        mPipTouchHandler.updateMinMaxSize(mPipBoundsState.getAspectRatio());
        mPipMenuController.hideMenu();
        mPipMenuController.hideMenu();


        if (mPipTransitionState.isInFixedRotation()) {
        if (mPipTransitionState.isInFixedRotation()) {
@@ -366,6 +365,8 @@ public class PipController implements ConfigurationChangeListener,
            mPipBoundsState.setBounds(toBounds);
            mPipBoundsState.setBounds(toBounds);
        }
        }
        t.setBounds(mPipTransitionState.getPipTaskToken(), mPipBoundsState.getBounds());
        t.setBounds(mPipTransitionState.getPipTaskToken(), mPipBoundsState.getBounds());
        // Update the size spec in PipBoundsState afterwards.
        mPipBoundsState.updateMinMaxSize(mPipBoundsState.getAspectRatio());
    }
    }


    private void setDisplayLayout(DisplayLayout layout) {
    private void setDisplayLayout(DisplayLayout layout) {
+14 −33
Original line number Original line Diff line number Diff line
@@ -81,8 +81,6 @@ public class PipResizeGestureHandler implements
    private final PointF mDownSecondPoint = new PointF();
    private final PointF mDownSecondPoint = new PointF();
    private final PointF mLastPoint = new PointF();
    private final PointF mLastPoint = new PointF();
    private final PointF mLastSecondPoint = new PointF();
    private final PointF mLastSecondPoint = new PointF();
    private final Point mMaxSize = new Point();
    private final Point mMinSize = new Point();
    private final Rect mLastResizeBounds = new Rect();
    private final Rect mLastResizeBounds = new Rect();
    private final Rect mUserResizeBounds = new Rect();
    private final Rect mUserResizeBounds = new Rect();
    private final Rect mDownBounds = new Rect();
    private final Rect mDownBounds = new Rect();
@@ -95,7 +93,6 @@ public class PipResizeGestureHandler implements
    private boolean mIsEnabled;
    private boolean mIsEnabled;
    private boolean mEnablePinchResize;
    private boolean mEnablePinchResize;
    private boolean mEnableDragCornerResize;
    private boolean mEnableDragCornerResize;
    private boolean mIsSysUiStateValid;
    private boolean mThresholdCrossed;
    private boolean mThresholdCrossed;
    private boolean mOngoingPinchToResize = false;
    private boolean mOngoingPinchToResize = false;
    private boolean mWaitingForBoundsChangeTransition = false;
    private boolean mWaitingForBoundsChangeTransition = false;
@@ -152,7 +149,6 @@ public class PipResizeGestureHandler implements
    }
    }


    void init() {
    void init() {
        mContext.getDisplay().getRealSize(mMaxSize);
        reloadResources();
        reloadResources();


        final Resources res = mContext.getResources();
        final Resources res = mContext.getResources();
@@ -163,15 +159,6 @@ public class PipResizeGestureHandler implements
        reloadResources();
        reloadResources();
    }
    }


    /**
     * Called when SysUI state changed.
     *
     * @param isSysUiStateValid Is SysUI valid or not.
     */
    public void onSystemUiStateChanged(boolean isSysUiStateValid) {
        mIsSysUiStateValid = isSysUiStateValid;
    }

    private void reloadResources() {
    private void reloadResources() {
        mPipDragToResizeHandler.reloadResources();
        mPipDragToResizeHandler.reloadResources();
        mTouchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();
        mTouchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();
@@ -287,13 +274,15 @@ public class PipResizeGestureHandler implements
                }
                }
            }
            }


            final Point minSize = mPipBoundsState.getMinSize();
            final Point maxSize = mPipBoundsState.getMaxSize();
            if (mOngoingPinchToResize) {
            if (mOngoingPinchToResize) {
                mPipPinchToResizeHandler.onPinchResize(mv, mDownPoint, mDownSecondPoint,
                mPipPinchToResizeHandler.onPinchResize(mv, mDownPoint, mDownSecondPoint,
                        mDownBounds, mLastPoint, mLastSecondPoint, mLastResizeBounds, mTouchSlop,
                        mDownBounds, mLastPoint, mLastSecondPoint, mLastResizeBounds, mTouchSlop,
                        mMinSize, mMaxSize);
                        minSize, maxSize);
            } else if (mEnableDragCornerResize) {
            } else if (mEnableDragCornerResize) {
                mPipDragToResizeHandler.onDragCornerResize(mv, mLastResizeBounds, mDownPoint,
                mPipDragToResizeHandler.onDragCornerResize(mv, mLastResizeBounds, mDownPoint,
                        mDownBounds, mMinSize, mMaxSize, mTouchSlop);
                        mDownBounds, minSize, maxSize, mTouchSlop);
            }
            }
        }
        }
    }
    }
@@ -327,7 +316,7 @@ public class PipResizeGestureHandler implements
                if (mEnablePinchResize && ev.getPointerCount() == 2) {
                if (mEnablePinchResize && ev.getPointerCount() == 2) {
                    mPipPinchToResizeHandler.onPinchResize(ev, mDownPoint, mDownSecondPoint,
                    mPipPinchToResizeHandler.onPinchResize(ev, mDownPoint, mDownSecondPoint,
                            mDownBounds, mLastPoint, mLastSecondPoint, mLastResizeBounds,
                            mDownBounds, mLastPoint, mLastSecondPoint, mLastResizeBounds,
                            mTouchSlop, mMinSize, mMaxSize);
                            mTouchSlop, mPipBoundsState.getMinSize(), mPipBoundsState.getMaxSize());
                    mOngoingPinchToResize = mAllowGesture;
                    mOngoingPinchToResize = mAllowGesture;
                    return mAllowGesture;
                    return mAllowGesture;
                }
                }
@@ -407,16 +396,19 @@ public class PipResizeGestureHandler implements
            return;
            return;
        }
        }


        final Point minSize = mPipBoundsState.getMinSize();
        final Point maxSize = mPipBoundsState.getMaxSize();

        // If user resize is pretty close to max size, just auto resize to max.
        // If user resize is pretty close to max size, just auto resize to max.
        if (mLastResizeBounds.width() >= PINCH_RESIZE_AUTO_MAX_RATIO * mMaxSize.x
        if (mLastResizeBounds.width() >= PINCH_RESIZE_AUTO_MAX_RATIO * maxSize.x
                || mLastResizeBounds.height() >= PINCH_RESIZE_AUTO_MAX_RATIO * mMaxSize.y) {
                || mLastResizeBounds.height() >= PINCH_RESIZE_AUTO_MAX_RATIO * maxSize.y) {
            resizeRectAboutCenter(mLastResizeBounds, mMaxSize.x, mMaxSize.y);
            resizeRectAboutCenter(mLastResizeBounds, maxSize.x, maxSize.y);
        }
        }


        // If user resize is smaller than min size, auto resize to min
        // If user resize is smaller than min size, auto resize to min
        if (mLastResizeBounds.width() < mMinSize.x
        if (mLastResizeBounds.width() < minSize.x
                || mLastResizeBounds.height() < mMinSize.y) {
                || mLastResizeBounds.height() < minSize.y) {
            resizeRectAboutCenter(mLastResizeBounds, mMinSize.x, mMinSize.y);
            resizeRectAboutCenter(mLastResizeBounds, minSize.x, minSize.y);
        }
        }


        // get the current movement bounds
        // get the current movement bounds
@@ -472,15 +464,6 @@ public class PipResizeGestureHandler implements
        mInputMonitor.pilferPointers();
        mInputMonitor.pilferPointers();
    }
    }



    void updateMaxSize(int maxX, int maxY) {
        mMaxSize.set(maxX, maxY);
    }

    void updateMinSize(int minX, int minY) {
        mMinSize.set(minX, minY);
    }

    void setOhmOffset(int offset) {
    void setOhmOffset(int offset) {
        mOhmOffset = offset;
        mOhmOffset = offset;
    }
    }
@@ -568,8 +551,6 @@ public class PipResizeGestureHandler implements
        pw.println(innerPrefix + "mEnableDragCornerResize=" + mEnableDragCornerResize);
        pw.println(innerPrefix + "mEnableDragCornerResize=" + mEnableDragCornerResize);
        pw.println(innerPrefix + "mThresholdCrossed=" + mThresholdCrossed);
        pw.println(innerPrefix + "mThresholdCrossed=" + mThresholdCrossed);
        pw.println(innerPrefix + "mOhmOffset=" + mOhmOffset);
        pw.println(innerPrefix + "mOhmOffset=" + mOhmOffset);
        pw.println(innerPrefix + "mMinSize=" + mMinSize);
        pw.println(innerPrefix + "mMaxSize=" + mMaxSize);
    }
    }


    class PipResizeInputEventReceiver extends BatchedInputEventReceiver {
    class PipResizeInputEventReceiver extends BatchedInputEventReceiver {
+1 −44
Original line number Original line Diff line number Diff line
@@ -230,10 +230,7 @@ public class PipTouchHandler implements PipTransitionState.PipTransitionStateCha
                pipBoundsState, mTouchState, mPipScheduler, mPipTransitionState, pipUiEventLogger,
                pipBoundsState, mTouchState, mPipScheduler, mPipTransitionState, pipUiEventLogger,
                menuController, this::getMovementBounds, mPipDisplayLayoutState, pipDesktopState,
                menuController, this::getMovementBounds, mPipDisplayLayoutState, pipDesktopState,
                mainExecutor, mPipPerfHintController);
                mainExecutor, mPipPerfHintController);
        mPipBoundsState.addOnAspectRatioChangedCallback(aspectRatio -> {
        mPipBoundsState.addOnAspectRatioChangedCallback(aspectRatio -> onAspectRatioChanged());
            updateMinMaxSize(aspectRatio);
            onAspectRatioChanged();
        });


        mMoveOnShelVisibilityChanged = () -> {
        mMoveOnShelVisibilityChanged = () -> {
            if (mIsImeShowing && mImeHeight > mShelfHeight) {
            if (mIsImeShowing && mImeHeight > mShelfHeight) {
@@ -418,15 +415,6 @@ public class PipTouchHandler implements PipTransitionState.PipTransitionStateCha
        mMainExecutor.executeDelayed(mMoveOnShelVisibilityChanged, PIP_KEEP_CLEAR_AREAS_DELAY);
        mMainExecutor.executeDelayed(mMoveOnShelVisibilityChanged, PIP_KEEP_CLEAR_AREAS_DELAY);
    }
    }


    /**
     * Called when SysUI state changed.
     *
     * @param isSysUiStateValid Is SysUI valid or not.
     */
    public void onSystemUiStateChanged(boolean isSysUiStateValid) {
        mPipResizeGestureHandler.onSystemUiStateChanged(isSysUiStateValid);
    }

    void adjustBoundsForRotation(Rect outBounds, Rect curBounds, Rect insetBounds) {
    void adjustBoundsForRotation(Rect outBounds, Rect curBounds, Rect insetBounds) {
        final Rect toMovementBounds = new Rect();
        final Rect toMovementBounds = new Rect();
        mPipBoundsAlgorithm.getMovementBounds(outBounds, insetBounds, toMovementBounds, 0);
        mPipBoundsAlgorithm.getMovementBounds(outBounds, insetBounds, toMovementBounds, 0);
@@ -480,8 +468,6 @@ public class PipTouchHandler implements PipTransitionState.PipTransitionStateCha
                mPipBoundsState.getExpandedBounds(), insetBounds, expandedMovementBounds,
                mPipBoundsState.getExpandedBounds(), insetBounds, expandedMovementBounds,
                bottomOffset);
                bottomOffset);


        updatePipSizeConstraints(normalBounds, aspectRatio);

        // The extra offset does not really affect the movement bounds, but are applied based on the
        // The extra offset does not really affect the movement bounds, but are applied based on the
        // current state (ime showing, or shelf offset) when we need to actually shift
        // current state (ime showing, or shelf offset) when we need to actually shift
        int extraOffset = Math.max(
        int extraOffset = Math.max(
@@ -506,35 +492,6 @@ public class PipTouchHandler implements PipTransitionState.PipTransitionStateCha
        }
        }
    }
    }


    /**
     * Update the values for min/max allowed size of picture in picture window based on the aspect
     * ratio.
     * @param aspectRatio aspect ratio to use for the calculation of min/max size
     */
    public void updateMinMaxSize(float aspectRatio) {
        updatePipSizeConstraints(mPipBoundsState.getNormalBounds(),
                aspectRatio);
    }

    private void updatePipSizeConstraints(Rect normalBounds,
            float aspectRatio) {
        if (mPipResizeGestureHandler.isUsingPinchToZoom()) {
            updatePinchResizeSizeConstraints(aspectRatio);
        } else {
            mPipResizeGestureHandler.updateMinSize(normalBounds.width(), normalBounds.height());
            mPipResizeGestureHandler.updateMaxSize(mPipBoundsState.getExpandedBounds().width(),
                    mPipBoundsState.getExpandedBounds().height());
        }
    }

    private void updatePinchResizeSizeConstraints(float aspectRatio) {
        mPipBoundsState.updateMinMaxSize(aspectRatio);
        mPipResizeGestureHandler.updateMinSize(mPipBoundsState.getMinSize().x,
                mPipBoundsState.getMinSize().y);
        mPipResizeGestureHandler.updateMaxSize(mPipBoundsState.getMaxSize().x,
                mPipBoundsState.getMaxSize().y);
    }

    /**
    /**
     * TODO Add appropriate description
     * TODO Add appropriate description
     */
     */