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

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

Merge "Don't fit action bar if decorFitsSystemWindows is false" into main

parents 1604e210 b81d6960
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -13442,6 +13442,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        }
    }
    /**
     * @return True if the window has the {@link OnContentApplyWindowInsetsListener}, and this means
     *         the framework will apply window insets on the content of the window.
     * @hide
     */
    protected boolean hasContentOnApplyWindowInsetsListener() {
        return mAttachInfo != null && mAttachInfo.mContentOnApplyWindowInsetsListener != null;
    }
    /**
     * Sets whether or not this view should account for system screen decorations
     * such as the status bar and inset its content; that is, controlling whether
+1 −1
Original line number Diff line number Diff line
@@ -436,7 +436,7 @@ public class ActionBarOverlayLayout extends ViewGroup implements DecorContentPar
        // overlay.
        mContentInsets.set(mBaseContentInsets);
        mInnerInsets = mBaseInnerInsets;
        if (!mOverlayMode && !stable) {
        if (!mOverlayMode && !stable && hasContentOnApplyWindowInsetsListener()) {
            mContentInsets.top += topInset;
            mContentInsets.bottom += bottomInset;
            // Content view has been shrunk, shrink all insets to match.
+62 −1
Original line number Diff line number Diff line
@@ -169,6 +169,56 @@ public class ActionBarOverlayLayoutTest {
        assertThat(mContentInsetsListener.captured, is(insetsWith(Insets.NONE, NO_CUTOUT)));
    }

    @Test
    public void topInset_cutout_noContentOnApplyWindowInsetsListener() {
        mLayout.setHasContentOnApplyWindowInsetsListener(false);
        mLayout.dispatchApplyWindowInsets(insetsWith(TOP_INSET_5, CUTOUT_5));

        assertThat(mContentInsetsListener.captured, nullValue());

        mLayout.measure(EXACTLY_1000, EXACTLY_1000);

        // Action bar height is added to the top inset
        assertThat(mContentInsetsListener.captured, is(insetsWith(TOP_INSET_25, CUTOUT_5)));
    }

    @Test
    public void topInset_cutout__hasContentOnApplyWindowInsetsListener() {
        mLayout.setHasContentOnApplyWindowInsetsListener(true);
        mLayout.dispatchApplyWindowInsets(insetsWith(TOP_INSET_5, CUTOUT_5));

        assertThat(mContentInsetsListener.captured, nullValue());

        mLayout.measure(EXACTLY_1000, EXACTLY_1000);

        assertThat(mContentInsetsListener.captured, is(insetsWith(Insets.NONE, NO_CUTOUT)));
    }

    @Test
    public void topInset_noCutout_noContentOnApplyWindowInsetsListener() {
        mLayout.setHasContentOnApplyWindowInsetsListener(false);
        mLayout.dispatchApplyWindowInsets(insetsWith(TOP_INSET_5, NO_CUTOUT));

        assertThat(mContentInsetsListener.captured, nullValue());

        mLayout.measure(EXACTLY_1000, EXACTLY_1000);

        // Action bar height is added to the top inset
        assertThat(mContentInsetsListener.captured, is(insetsWith(TOP_INSET_25, NO_CUTOUT)));
    }

    @Test
    public void topInset_noCutout__hasContentOnApplyWindowInsetsListener() {
        mLayout.setHasContentOnApplyWindowInsetsListener(true);
        mLayout.dispatchApplyWindowInsets(insetsWith(TOP_INSET_5, NO_CUTOUT));

        assertThat(mContentInsetsListener.captured, nullValue());

        mLayout.measure(EXACTLY_1000, EXACTLY_1000);

        assertThat(mContentInsetsListener.captured, is(insetsWith(Insets.NONE, NO_CUTOUT)));
    }

    private WindowInsets insetsWith(Insets content, DisplayCutout cutout) {
        final Insets cutoutInsets = cutout != null
                ? Insets.of(cutout.getSafeInsets())
@@ -190,14 +240,16 @@ public class ActionBarOverlayLayoutTest {

    static class TestActionBarOverlayLayout extends ActionBarOverlayLayout {
        private boolean mStable;
        private boolean mHasContentOnApplyWindowInsetsListener;

        public TestActionBarOverlayLayout(Context context) {
            super(context);
            mHasContentOnApplyWindowInsetsListener = true;
        }

        @Override
        public WindowInsets computeSystemWindowInsets(WindowInsets in, Rect outLocalInsets) {
            if (mStable) {
            if (mStable || !hasContentOnApplyWindowInsetsListener()) {
                // Emulate the effect of makeOptionalFitsSystemWindows, because we can't do that
                // without being attached to a window.
                outLocalInsets.setEmpty();
@@ -211,6 +263,15 @@ public class ActionBarOverlayLayoutTest {
            setSystemUiVisibility(stable ? SYSTEM_UI_FLAG_LAYOUT_STABLE : 0);
        }

        void setHasContentOnApplyWindowInsetsListener(boolean hasListener) {
            mHasContentOnApplyWindowInsetsListener = hasListener;
        }

        @Override
        protected boolean hasContentOnApplyWindowInsetsListener() {
            return mHasContentOnApplyWindowInsetsListener;
        }

        @Override
        public int getWindowSystemUiVisibility() {
            return getSystemUiVisibility();