Loading core/java/android/view/View.java +9 −0 Original line number Diff line number Diff line Loading @@ -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 core/java/com/android/internal/widget/ActionBarOverlayLayout.java +1 −1 Original line number Diff line number Diff line Loading @@ -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. Loading core/tests/coretests/src/com/android/internal/widget/ActionBarOverlayLayoutTest.java +62 −1 Original line number Diff line number Diff line Loading @@ -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()) Loading @@ -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(); Loading @@ -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(); Loading Loading
core/java/android/view/View.java +9 −0 Original line number Diff line number Diff line Loading @@ -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
core/java/com/android/internal/widget/ActionBarOverlayLayout.java +1 −1 Original line number Diff line number Diff line Loading @@ -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. Loading
core/tests/coretests/src/com/android/internal/widget/ActionBarOverlayLayoutTest.java +62 −1 Original line number Diff line number Diff line Loading @@ -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()) Loading @@ -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(); Loading @@ -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(); Loading