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

Commit 24bfcf7e authored by Tiger Huang's avatar Tiger Huang Committed by Android (Google) Code Review
Browse files

Merge "Revert "Make action mode view extend into system insets area"" into main

parents 05bdf35e 29918fbc
Loading
Loading
Loading
Loading
+51 −79
Original line number Diff line number Diff line
@@ -120,7 +120,6 @@ import com.android.internal.view.menu.MenuHelper;
import com.android.internal.widget.ActionBarContextView;
import com.android.internal.widget.BackgroundFallback;
import com.android.internal.widget.floatingtoolbar.FloatingToolbar;
import com.android.window.flags.Flags;

import java.util.List;
import java.util.concurrent.Executor;
@@ -1004,8 +1003,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
    public void onWindowSystemUiVisibilityChanged(int visible) {
        updateColorViews(null /* insets */, true /* animate */);

        if (!Flags.actionModeEdgeToEdge()
                && mStatusGuard != null && mStatusGuard.getVisibility() == VISIBLE) {
        if (mStatusGuard != null && mStatusGuard.getVisibility() == VISIBLE) {
            updateStatusGuardColor();
        }
    }
@@ -1042,7 +1040,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
        }
        mFrameOffsets.set(insets.getSystemWindowInsetsAsRect());
        insets = updateColorViews(insets, true /* animate */);
        insets = updateActionModeInsets(insets);
        insets = updateStatusGuard(insets);
        if (getForeground() != null) {
            drawableChanged();
        }
@@ -1594,7 +1592,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
        }
    }

    private WindowInsets updateActionModeInsets(WindowInsets insets) {
    private WindowInsets updateStatusGuard(WindowInsets insets) {
        boolean showStatusGuard = false;
        // Show the status guard when the non-overlay contextual action bar is showing
        if (mPrimaryActionModeView != null) {
@@ -1610,37 +1608,15 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
                    final Rect rect = mTempRect;

                    // Apply the insets that have not been applied by the contentParent yet.
                    final WindowInsets innerInsets =
                    WindowInsets innerInsets =
                            mWindow.mContentParent.computeSystemWindowInsets(insets, rect);
                    final boolean consumesSystemWindowInsetsTop;
                    if (Flags.actionModeEdgeToEdge()) {
                        final Insets newPadding = innerInsets.getSystemWindowInsets();
                        final Insets newMargin = innerInsets.getInsets(
                                WindowInsets.Type.navigationBars());

                        // Don't extend into navigation bar area so the width can align with status
                        // bar color view.
                        if (mlp.leftMargin != newMargin.left
                                || mlp.rightMargin != newMargin.right) {
                            mlpChanged = true;
                            mlp.leftMargin = newMargin.left;
                            mlp.rightMargin = newMargin.right;
                        }

                        mPrimaryActionModeView.setPadding(
                                newPadding.left - newMargin.left,
                                newPadding.top,
                                newPadding.right - newMargin.right,
                                0);
                        consumesSystemWindowInsetsTop = newPadding.top > 0;
                    } else {
                    int newTopMargin = innerInsets.getSystemWindowInsetTop();
                    int newLeftMargin = innerInsets.getSystemWindowInsetLeft();
                    int newRightMargin = innerInsets.getSystemWindowInsetRight();

                        // Must use root window insets for the guard, because the color views
                        // consume the navigation bar inset if the window does not request
                        // LAYOUT_HIDE_NAV - but the status guard is attached at the root.
                    // Must use root window insets for the guard, because the color views consume
                    // the navigation bar inset if the window does not request LAYOUT_HIDE_NAV - but
                    // the status guard is attached at the root.
                    WindowInsets rootInsets = getRootWindowInsets();
                    int newGuardLeftMargin = rootInsets.getSystemWindowInsetLeft();
                    int newGuardRightMargin = rootInsets.getSystemWindowInsetRight();
@@ -1681,8 +1657,6 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
                        // If it wasn't previously shown, the color may be stale
                        updateStatusGuardColor();
                    }
                        consumesSystemWindowInsetsTop = showStatusGuard;
                    }

                    // We only need to consume the insets if the action
                    // mode is overlaid on the app content (e.g. it's
@@ -1690,24 +1664,22 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
                    // screen_simple_overlay_action_mode.xml).
                    final boolean nonOverlay = (mWindow.getLocalFeaturesPrivate()
                            & (1 << Window.FEATURE_ACTION_MODE_OVERLAY)) == 0;
                    if (nonOverlay && consumesSystemWindowInsetsTop) {
                    if (nonOverlay && showStatusGuard) {
                        insets = insets.inset(0, insets.getSystemWindowInsetTop(), 0, 0);
                    }
                } else {
                    if (!Flags.actionModeEdgeToEdge()) {
                    // reset top margin
                    if (mlp.topMargin != 0 || mlp.leftMargin != 0 || mlp.rightMargin != 0) {
                        mlpChanged = true;
                        mlp.topMargin = 0;
                    }
                }
                }
                if (mlpChanged) {
                    mPrimaryActionModeView.setLayoutParams(mlp);
                }
            }
        }
        if (!Flags.actionModeEdgeToEdge() && mStatusGuard != null) {
        if (mStatusGuard != null) {
            mStatusGuard.setVisibility(showStatusGuard ? VISIBLE : GONE);
        }
        return insets;
@@ -2211,7 +2183,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
        for (int i = getChildCount() - 1; i >= 0; i--) {
            View v = getChildAt(i);
            if (v != mStatusColorViewState.view && v != mNavigationColorViewState.view
                    && (Flags.actionModeEdgeToEdge() || v != mStatusGuard)) {
                    && v != mStatusGuard) {
                removeViewAt(i);
            }
        }
+4 −8
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import android.widget.TextView;

import com.android.internal.R;
import com.android.internal.view.menu.MenuBuilder;
import com.android.window.flags.Flags;

/**
 * @hide
@@ -316,14 +315,12 @@ public class ActionBarContextView extends AbsActionBarView {

        final int contentWidth = MeasureSpec.getSize(widthMeasureSpec);

        final int maxHeight = !Flags.actionModeEdgeToEdge() && mContentHeight > 0
                ? mContentHeight : MeasureSpec.getSize(heightMeasureSpec);
        int maxHeight = mContentHeight > 0 ?
                mContentHeight : MeasureSpec.getSize(heightMeasureSpec);

        final int verticalPadding = getPaddingTop() + getPaddingBottom();
        int availableWidth = contentWidth - getPaddingLeft() - getPaddingRight();
        final int height = Flags.actionModeEdgeToEdge()
                ? mContentHeight > 0 ? mContentHeight : maxHeight
                : maxHeight - verticalPadding;
        final int height = maxHeight - verticalPadding;
        final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);

        if (mClose != null) {
@@ -379,8 +376,7 @@ public class ActionBarContextView extends AbsActionBarView {
            }
            setMeasuredDimension(contentWidth, measuredHeight);
        } else {
            setMeasuredDimension(contentWidth, Flags.actionModeEdgeToEdge()
                    ? mContentHeight + verticalPadding : maxHeight);
            setMeasuredDimension(contentWidth, maxHeight);
        }
    }

+46 −39
Original line number Diff line number Diff line
@@ -294,24 +294,54 @@ public class ActionBarOverlayLayout extends ViewGroup implements DecorContentPar
        }
    }

    private boolean setMargin(View view, int left, int top, int right, int bottom) {
    private boolean applyInsets(View view, Rect insets, boolean toPadding,
            boolean left, boolean top, boolean right, boolean bottom) {
        boolean changed;
        if (toPadding) {
            changed = setMargin(view, EMPTY_RECT, left, top, right, bottom);
            changed |= setPadding(view, insets, left, top, right, bottom);
        } else {
            changed = setPadding(view, EMPTY_RECT, left, top, right, bottom);
            changed |= setMargin(view, insets, left, top, right, bottom);
        }
        return changed;
    }

    private boolean setPadding(View view, Rect insets,
            boolean left, boolean top, boolean right, boolean bottom) {
        if ((left && view.getPaddingLeft() != insets.left)
                || (top && view.getPaddingTop() != insets.top)
                || (right && view.getPaddingRight() != insets.right)
                || (bottom && view.getPaddingBottom() != insets.bottom)) {
            view.setPadding(
                    left ? insets.left : view.getPaddingLeft(),
                    top ? insets.top : view.getPaddingTop(),
                    right ? insets.right : view.getPaddingRight(),
                    bottom ? insets.bottom : view.getPaddingBottom());
            return true;
        }
        return false;
    }

    private boolean setMargin(View view,  Rect insets,
            boolean left, boolean top, boolean right, boolean bottom) {
        final LayoutParams lp = (LayoutParams) view.getLayoutParams();
        boolean changed = false;
        if (lp.leftMargin != left) {
        if (left && lp.leftMargin != insets.left) {
            changed = true;
            lp.leftMargin = left;
            lp.leftMargin = insets.left;
        }
        if (lp.topMargin != top) {
        if (top && lp.topMargin != insets.top) {
            changed = true;
            lp.topMargin = top;
            lp.topMargin = insets.top;
        }
        if (lp.rightMargin != right) {
        if (right && lp.rightMargin != insets.right) {
            changed = true;
            lp.rightMargin = right;
            lp.rightMargin = insets.right;
        }
        if (lp.bottomMargin != bottom) {
        if (bottom && lp.bottomMargin != insets.bottom) {
            changed = true;
            lp.bottomMargin = bottom;
            lp.bottomMargin = insets.bottom;
        }
        return changed;
    }
@@ -337,30 +367,12 @@ public class ActionBarOverlayLayout extends ViewGroup implements DecorContentPar
        final Insets sysInsets = insets.getSystemWindowInsets();
        mSystemInsets.set(sysInsets.left, sysInsets.top, sysInsets.right, sysInsets.bottom);

        boolean changed = false;
        if (mActionBarExtendsIntoSystemInsets) {
            // Don't extend into navigation bar area so the width can align with status bar
            // color view.
            final Insets navBarInsets = insets.getInsets(WindowInsets.Type.navigationBars());
            final int paddingLeft = sysInsets.left - navBarInsets.left;
            final int paddingRight = sysInsets.right - navBarInsets.right;
            mActionBarTop.setPadding(paddingLeft, sysInsets.top, paddingRight, 0);
            changed |= setMargin(
                    mActionBarTop, navBarInsets.left, 0, navBarInsets.right, 0);
        // The top and bottom action bars are always within the content area.
        boolean changed = applyInsets(mActionBarTop, mSystemInsets,
                mActionBarExtendsIntoSystemInsets, true, true, true, false);
        if (mActionBarBottom != null) {
                mActionBarBottom.setPadding(paddingLeft, 0, paddingRight, sysInsets.bottom);
                changed |= setMargin(
                        mActionBarBottom, navBarInsets.left, 0, navBarInsets.right, 0);
            }
        } else {
            mActionBarTop.setPadding(0, 0, 0, 0);
            changed |= setMargin(
                    mActionBarTop, sysInsets.left, sysInsets.top, sysInsets.right, 0);
            if (mActionBarBottom != null) {
                mActionBarBottom.setPadding(0, 0, 0, 0);
                changed |= setMargin(
                        mActionBarTop, sysInsets.left, 0, sysInsets.right, sysInsets.bottom);
            }
            changed |= applyInsets(mActionBarBottom, mSystemInsets,
                    mActionBarExtendsIntoSystemInsets, true, false, true, true);
        }

        // Cannot use the result of computeSystemWindowInsets, because that consumes the
@@ -509,12 +521,7 @@ public class ActionBarOverlayLayout extends ViewGroup implements DecorContentPar
                );
            }
        }
        setMargin(
                mContent,
                mContentInsets.left,
                mContentInsets.top,
                mContentInsets.right,
                mContentInsets.bottom);
        setMargin(mContent, mContentInsets, true, true, true, true);

        if (!mLastInnerInsets.equals(mInnerInsets)) {
            // If the inner insets have changed, we need to dispatch this down to