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

Commit 0ec1299c authored by Ben Lin's avatar Ben Lin Committed by Automerger Merge Worker
Browse files

Merge "Update PiP exclusion bounds in TaskBarDelegate." into sc-v2-dev am: c34133ad

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16434534

Change-Id: Ibc6f0eb3c87274aa7bd72e6ba0c104792b3b0447
parents 298efb93 c34133ad
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -112,11 +112,17 @@ public interface Pip {
    default void showPictureInPictureMenu() {}

    /**
     * Called by NavigationBar in order to listen in for PiP bounds change. This is mostly used
     * for times where the PiP bounds could conflict with SystemUI elements, such as a stashed
     * PiP and the Back-from-Edge gesture.
     * Called by NavigationBar and TaskbarDelegate in order to listen in for PiP bounds change. This
     * is mostly used for times where the PiP bounds could conflict with SystemUI elements, such as
     * a stashed PiP and the Back-from-Edge gesture.
     */
    default void setPipExclusionBoundsChangeListener(Consumer<Rect> listener) { }
    default void addPipExclusionBoundsChangeListener(Consumer<Rect> listener) { }

    /**
     * Remove a callback added previously. This is used when NavigationBar is removed from the
     * view hierarchy or destroyed.
     */
    default void removePipExclusionBoundsChangeListener(Consumer<Rect> listener) { }

    /**
     * Dump the current state and information if need.
+18 −8
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ import com.android.wm.shell.common.DisplayLayout;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;

@@ -89,7 +91,7 @@ public final class PipBoundsState {

    private @Nullable Runnable mOnMinimalSizeChangeCallback;
    private @Nullable TriConsumer<Boolean, Integer, Boolean> mOnShelfVisibilityChangeCallback;
    private @Nullable Consumer<Rect> mOnPipExclusionBoundsChangeCallback;
    private List<Consumer<Rect>> mOnPipExclusionBoundsChangeCallbacks = new ArrayList<>();

    public PipBoundsState(@NonNull Context context) {
        mContext = context;
@@ -108,8 +110,8 @@ public final class PipBoundsState {
    /** Set the current PIP bounds. */
    public void setBounds(@NonNull Rect bounds) {
        mBounds.set(bounds);
        if (mOnPipExclusionBoundsChangeCallback != null) {
            mOnPipExclusionBoundsChangeCallback.accept(bounds);
        for (Consumer<Rect> callback : mOnPipExclusionBoundsChangeCallbacks) {
            callback.accept(bounds);
        }
    }

@@ -407,17 +409,25 @@ public final class PipBoundsState {
    }

    /**
     * Set a callback to watch out for PiP bounds. This is mostly used by SystemUI's
     * Add a callback to watch out for PiP bounds. This is mostly used by SystemUI's
     * Back-gesture handler, to avoid conflicting with PiP when it's stashed.
     */
    public void setPipExclusionBoundsChangeCallback(
    public void addPipExclusionBoundsChangeCallback(
            @Nullable Consumer<Rect> onPipExclusionBoundsChangeCallback) {
        mOnPipExclusionBoundsChangeCallback = onPipExclusionBoundsChangeCallback;
        if (mOnPipExclusionBoundsChangeCallback != null) {
            mOnPipExclusionBoundsChangeCallback.accept(getBounds());
        mOnPipExclusionBoundsChangeCallbacks.add(onPipExclusionBoundsChangeCallback);
        for (Consumer<Rect> callback : mOnPipExclusionBoundsChangeCallbacks) {
            callback.accept(getBounds());
        }
    }

    /**
     * Remove a callback that was previously added.
     */
    public void removePipExclusionBoundsChangeCallback(
            @Nullable Consumer<Rect> onPipExclusionBoundsChangeCallback) {
        mOnPipExclusionBoundsChangeCallbacks.remove(onPipExclusionBoundsChangeCallback);
    }

    /** Source of truth for the current bounds of PIP that may be in motion. */
    public static class MotionBoundsState {
        /** The bounds used when PIP is in motion (e.g. during a drag or animation) */
+9 −2
Original line number Diff line number Diff line
@@ -843,9 +843,16 @@ public class PipController implements PipTransitionController.PipTransitionCallb
        }

        @Override
        public void setPipExclusionBoundsChangeListener(Consumer<Rect> listener) {
        public void addPipExclusionBoundsChangeListener(Consumer<Rect> listener) {
            mMainExecutor.execute(() -> {
                mPipBoundsState.setPipExclusionBoundsChangeCallback(listener);
                mPipBoundsState.addPipExclusionBoundsChangeCallback(listener);
            });
        }

        @Override
        public void removePipExclusionBoundsChangeListener(Consumer<Rect> listener) {
            mMainExecutor.execute(() -> {
                mPipBoundsState.removePipExclusionBoundsChangeCallback(listener);
            });
        }

+1 −1
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ public class PipBoundsStateTest extends ShellTestCase {
        final Rect newBounds = new Rect(50, 50, 100, 75);
        mPipBoundsState.setBounds(currentBounds);

        mPipBoundsState.setPipExclusionBoundsChangeCallback(callback);
        mPipBoundsState.addPipExclusionBoundsChangeCallback(callback);
        // Setting the listener immediately calls back with the current bounds.
        verify(callback).accept(currentBounds);

+2 −1
Original line number Diff line number Diff line
@@ -628,7 +628,7 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
        mNavBarHelper.registerNavTaskStateUpdater(mNavbarTaskbarStateUpdater);

        mSplitScreenOptional.ifPresent(mNavigationBarView::registerDockedListener);
        mPipOptional.ifPresent(mNavigationBarView::registerPipExclusionBoundsChangeListener);
        mPipOptional.ifPresent(mNavigationBarView::addPipExclusionBoundsChangeListener);

        prepareNavigationBarView();
        checkNavBarModes();
@@ -699,6 +699,7 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
        mHandler.removeCallbacks(mOnVariableDurationHomeLongClick);
        mHandler.removeCallbacks(mEnableLayoutTransitions);
        mNavBarHelper.removeNavTaskStateUpdater(mNavbarTaskbarStateUpdater);
        mPipOptional.ifPresent(mNavigationBarView::removePipExclusionBoundsChangeListener);
        mFrame = null;
        mNavigationBarView = null;
        mOrientationHandle = null;
Loading