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

Commit ca128c5f authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Update size constraints on aspect ratio change

With the recent change ag/26603167, PipController could miss the chance
to update the size constraints. As a result,
PipResizeGestureHelper#finishResize uses staled max size information at
the end of pinch-resize.

It's fixed in this CL as to let PipTouchHandler subscribe to aspect
ratio from PipBoundsState, which serves as the source of truth.

Long term, we should cleanup / consolidate the logic right now scatter
in PipTaskOrganizer / PipController / etc.

Video: http://recall/-/aaaaaabFQoRHlzixHdtY/kZmKG4c8SiBS7fjg67Qek
Bug: 335311217
Test: manual, follow the reproduce steps
Change-Id: Ie5c7ad2536ecbbf6c1a015b60328de30dae7e10e
parent 8517bf06
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@ public class PipBoundsState {
    private @Nullable Runnable mOnMinimalSizeChangeCallback;
    private @Nullable TriConsumer<Boolean, Integer, Boolean> mOnShelfVisibilityChangeCallback;
    private List<Consumer<Rect>> mOnPipExclusionBoundsChangeCallbacks = new ArrayList<>();
    private List<Consumer<Float>> mOnAspectRatioChangedCallbacks = new ArrayList<>();

    // the size of the current bounds relative to the max size spec
    private float mBoundsScale;
@@ -297,7 +298,12 @@ public class PipBoundsState {

    /** Set the PIP aspect ratio. */
    public void setAspectRatio(float aspectRatio) {
        if (Float.compare(mAspectRatio, aspectRatio) != 0) {
            mAspectRatio = aspectRatio;
            for (Consumer<Float> callback : mOnAspectRatioChangedCallbacks) {
                callback.accept(mAspectRatio);
            }
        }
    }

    /** Get the PIP aspect ratio. */
@@ -527,6 +533,23 @@ public class PipBoundsState {
        mOnPipExclusionBoundsChangeCallbacks.remove(onPipExclusionBoundsChangeCallback);
    }

    /** Adds callback to listen on aspect ratio change. */
    public void addOnAspectRatioChangedCallback(
            @NonNull Consumer<Float> onAspectRatioChangedCallback) {
        if (!mOnAspectRatioChangedCallbacks.contains(onAspectRatioChangedCallback)) {
            mOnAspectRatioChangedCallbacks.add(onAspectRatioChangedCallback);
            onAspectRatioChangedCallback.accept(mAspectRatio);
        }
    }

    /** Removes callback to listen on aspect ratio change. */
    public void removeOnAspectRatioChangedCallback(
            @NonNull Consumer<Float> onAspectRatioChangedCallback) {
        if (mOnAspectRatioChangedCallbacks.contains(onAspectRatioChangedCallback)) {
            mOnAspectRatioChangedCallbacks.remove(onAspectRatioChangedCallback);
        }
    }

    public LauncherState getLauncherState() {
        return mLauncherState;
    }
+1 −0
Original line number Diff line number Diff line
@@ -219,6 +219,7 @@ public class PipTouchHandler {
                mMotionHelper, pipTaskOrganizer, mPipBoundsAlgorithm.getSnapAlgorithm(),
                this::onAccessibilityShowMenu, this::updateMovementBounds,
                this::animateToUnStashedState, mainExecutor);
        mPipBoundsState.addOnAspectRatioChangedCallback(this::updateMinMaxSize);

        // TODO(b/181599115): This should really be initializes as part of the pip controller, but
        // until all PIP implementations derive from the controller, just initialize the touch handler
+1 −0
Original line number Diff line number Diff line
@@ -208,6 +208,7 @@ public class PipTouchHandler {
                new PipResizeGestureHandler(context, pipBoundsAlgorithm, pipBoundsState,
                        mTouchState, this::updateMovementBounds, pipUiEventLogger,
                        menuController, mainExecutor, mPipPerfHintController);
        mPipBoundsState.addOnAspectRatioChangedCallback(this::updateMinMaxSize);

        if (PipUtils.isPip2ExperimentEnabled()) {
            shellInit.addInitCallback(this::onInit, this);