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

Commit 16195929 authored by Liran Binyamin's avatar Liran Binyamin Committed by Android (Google) Code Review
Browse files

Merge "Create a root view for bubbles" into main

parents 2c1ffb4a 2795a48e
Loading
Loading
Loading
Loading
+25 −19
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ import android.view.ViewGroup;
import android.view.ViewRootImpl;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.window.IMultitaskingController;
import android.window.ScreenCapture;
import android.window.ScreenCapture.SynchronousScreenCaptureListener;
@@ -228,6 +229,7 @@ public class BubbleController implements ConfigurationChangeListener,

    private final BubbleLogger mLogger;
    private final BubbleData mBubbleData;
    private final FrameLayout mBubblesRootView;
    @Nullable private BubbleStackView mStackView;
    @Nullable private BubbleBarLayerView mLayerView;
    private BubbleIconFactory mBubbleIconFactory;
@@ -402,6 +404,7 @@ public class BubbleController implements ConfigurationChangeListener,
        mResizabilityChecker = resizabilityChecker;
        mHomeIntentProvider = homeIntentProvider;
        shellInit.addInitCallback(this::onInit, this);
        mBubblesRootView = new FrameLayout(mContext);
    }

    private void registerOneHandedState(OneHandedController oneHanded) {
@@ -1010,6 +1013,9 @@ public class BubbleController implements ConfigurationChangeListener,
                mLayerView = new BubbleBarLayerView(mContext, this, mBubbleData, mLogger);
                mLayerView.setUnBubbleConversationCallback(mSysuiProxy::onUnbubbleConversation);
            }
            if (mLayerView.getParent() == null) {
                mBubblesRootView.addView(mLayerView);
            }
        } else {
            if (mStackView == null) {
                BubbleStackViewManager bubbleStackViewManager =
@@ -1023,11 +1029,14 @@ public class BubbleController implements ConfigurationChangeListener,
                }
                mStackView.setUnbubbleConversationCallback(mSysuiProxy::onUnbubbleConversation);
            }
            if (mStackView.getParent() == null) {
                mBubblesRootView.addView(mStackView);
            }
        }
        addToWindowManagerMaybe();
    }

    /** Adds the appropriate view to WindowManager if it's not already there. */
    /** Adds the root view to WindowManager if it's not already there. */
    private void addToWindowManagerMaybe() {
        // If already added, don't add it.
        if (mAddedToWindowManager) {
@@ -1071,9 +1080,9 @@ public class BubbleController implements ConfigurationChangeListener,
                mBubbleData.getOverflow().initialize(
                        mExpandedViewManager, mStackView, mBubblePositioner);
            }
            mWindowManager.addView(mBubblesRootView, mWmLayoutParams);
            // (TODO: b/273314541) some duplication in the inset listener
            if (isShowingAsBubbleBar()) {
                mWindowManager.addView(mLayerView, mWmLayoutParams);
                mLayerView.setOnApplyWindowInsetsListener((view, windowInsets) -> {
                    if (!windowInsets.equals(mWindowInsets) && mLayerView != null) {
                        mWindowInsets = windowInsets;
@@ -1083,7 +1092,6 @@ public class BubbleController implements ConfigurationChangeListener,
                    return windowInsets;
                });
            } else {
                mWindowManager.addView(mStackView, mWmLayoutParams);
                mStackView.setOnApplyWindowInsetsListener((view, windowInsets) -> {
                    if (!windowInsets.equals(mWindowInsets) && mStackView != null) {
                        mWindowInsets = windowInsets;
@@ -1114,11 +1122,16 @@ public class BubbleController implements ConfigurationChangeListener,
                    : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                            | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
            mWmLayoutParams.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
            mWindowManager.updateViewLayout(mBubblesRootView, mWmLayoutParams);
        }
    }

    private void removeViewsFromRootView() {
        if (mStackView != null) {
                mWindowManager.updateViewLayout(mStackView, mWmLayoutParams);
            } else if (mLayerView != null) {
                mWindowManager.updateViewLayout(mLayerView, mWmLayoutParams);
            mBubblesRootView.removeView(mStackView);
        }
        if (mLayerView != null) {
            mBubblesRootView.removeView(mLayerView);
        }
    }

@@ -1140,14 +1153,8 @@ public class BubbleController implements ConfigurationChangeListener,
            }
        });
        try {
            if (mStackView != null) {
                mWindowManager.removeView(mStackView);
                mBubbleData.getOverflow().cleanUpExpandedState();
            }
            if (mLayerView != null) {
                mWindowManager.removeView(mLayerView);
            mWindowManager.removeView(mBubblesRootView);
            mBubbleData.getOverflow().cleanUpExpandedState();
            }
        } catch (IllegalArgumentException e) {
            // This means the stack has already been removed - it shouldn't happen, but ignore if it
            // does, since we wanted it removed anyway.
@@ -1861,9 +1868,8 @@ public class BubbleController implements ConfigurationChangeListener,
        // TaskView.
        mBubbleData.getBubbles().forEach(b -> b.cleanupViews(/* cleanupTaskView= */ false));

        // remove the current bubble container from window manager, null it out, and create a new
        // container based on the current mode.
        removeFromWindowManagerMaybe();
        // replace the current views in the root view based on the mode we're switching to
        removeViewsFromRootView();
        mLayerView = null;
        mStackView = null;