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

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

Merge "Update size constraints on aspect ratio change" into main

parents ef9f1d6e ca128c5f
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);