Loading core/java/android/view/InsetsState.java +2 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import static android.internal.perfetto.protos.Insetsstate.InsetsStateProto.SOUR import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_STABLE; import static android.view.WindowInsets.Type.SIZE; import static android.view.WindowInsets.Type.captionBar; import static android.view.WindowInsets.Type.defaultCompatible; import static android.view.WindowInsets.Type.displayCutout; import static android.view.WindowInsets.Type.ime; import static android.view.WindowInsets.Type.indexOf; Loading Loading @@ -193,7 +194,7 @@ public class InsetsState implements Parcelable { final int softInputAdjustMode = legacySoftInputMode & SOFT_INPUT_MASK_ADJUST; @InsetsType int compatInsetsTypes = systemBars() | displayCutout(); int compatInsetsTypes = defaultCompatible(); if (softInputAdjustMode == SOFT_INPUT_ADJUST_RESIZE) { compatInsetsTypes |= ime(); } Loading core/java/android/view/WindowInsets.java +35 −16 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import static android.view.WindowInsets.Type.STATUS_BARS; import static android.view.WindowInsets.Type.SYSTEM_GESTURES; import static android.view.WindowInsets.Type.TAPPABLE_ELEMENT; import static android.view.WindowInsets.Type.all; import static android.view.WindowInsets.Type.defaultCompatible; import static android.view.WindowInsets.Type.displayCutout; import static android.view.WindowInsets.Type.ime; import static android.view.WindowInsets.Type.indexOf; Loading Loading @@ -139,7 +140,7 @@ public final class WindowInsets { static { CONSUMED = new WindowInsets(createCompatTypeMap(null), createCompatTypeMap(null), createCompatVisibilityMap(createCompatTypeMap(null)), false, 0, false, 0, null, null, null, null, systemBars(), false, null, null, 0, 0); null, null, null, defaultCompatible(), false, null, null, 0, 0); } /** Loading Loading @@ -281,7 +282,7 @@ public final class WindowInsets { @UnsupportedAppUsage public WindowInsets(@Nullable Rect systemWindowInsets) { this(createCompatTypeMap(systemWindowInsets), null, new boolean[SIZE], false, 0, false, 0, null, null, null, null, systemBars(), false /* compatIgnoreVisibility */, null, null, null, null, defaultCompatible(), false /* compatIgnoreVisibility */, new Rect[SIZE][], null, 0, 0); } Loading Loading @@ -358,8 +359,8 @@ public final class WindowInsets { * </p> * * @return The system window insets * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} * instead. * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR * {@link Type#displayCutout()} instead. */ @Deprecated @NonNull Loading Loading @@ -442,8 +443,8 @@ public final class WindowInsets { * </p> * * @return The left system window inset * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} * instead. * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR * {@link Type#displayCutout()} instead. */ @Deprecated public int getSystemWindowInsetLeft() { Loading @@ -458,8 +459,8 @@ public final class WindowInsets { * </p> * * @return The top system window inset * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} * instead. * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR * {@link Type#displayCutout()} instead. */ @Deprecated public int getSystemWindowInsetTop() { Loading @@ -474,8 +475,8 @@ public final class WindowInsets { * </p> * * @return The right system window inset * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} * instead. * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR * {@link Type#displayCutout()} instead. */ @Deprecated public int getSystemWindowInsetRight() { Loading @@ -490,8 +491,8 @@ public final class WindowInsets { * </p> * * @return The bottom system window inset * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} * instead. * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR * {@link Type#displayCutout()} instead. */ @Deprecated public int getSystemWindowInsetBottom() { Loading @@ -506,8 +507,8 @@ public final class WindowInsets { * </p> * * @return true if any of the system window inset values are nonzero * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} * instead. * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR * {@link Type#displayCutout()} instead. */ @Deprecated public boolean hasSystemWindowInsets() { Loading Loading @@ -1411,6 +1412,8 @@ public final class WindowInsets { private final Rect[][] mTypeBoundingRectsMap; @NonNull private final Rect[][] mTypeMaxBoundingRectsMap; private final @InsetsType int mCompatInsetTypes; private final boolean mCompatIgnoreVisibility; private boolean mSystemInsetsConsumed = true; private boolean mStableInsetsConsumed = true; Loading Loading @@ -1442,6 +1445,8 @@ public final class WindowInsets { mTypeVisibilityMap = new boolean[SIZE]; mTypeBoundingRectsMap = new Rect[SIZE][]; mTypeMaxBoundingRectsMap = new Rect[SIZE][]; mCompatInsetTypes = defaultCompatible(); mCompatIgnoreVisibility = false; } /** Loading @@ -1453,6 +1458,8 @@ public final class WindowInsets { mTypeInsetsMap = insets.mTypeInsetsMap.clone(); mTypeMaxInsetsMap = insets.mTypeMaxInsetsMap.clone(); mTypeVisibilityMap = insets.mTypeVisibilityMap.clone(); mCompatInsetTypes = insets.mCompatInsetsTypes; mCompatIgnoreVisibility = insets.mCompatIgnoreVisibility; mSystemInsetsConsumed = insets.mSystemWindowInsetsConsumed; mStableInsetsConsumed = insets.mStableInsetsConsumed; mDisplayCutout = displayCutoutCopyConstructorArgument(insets); Loading @@ -1478,7 +1485,8 @@ public final class WindowInsets { * * @see #getSystemWindowInsets() * @return itself * @deprecated Use {@link #setInsets(int, Insets)} with {@link Type#systemBars()}. * @deprecated Use {@link #setInsets(int, Insets)} with {@link Type#systemBars()} or * {@link Type#displayCutout()}. */ @Deprecated @NonNull Loading Loading @@ -1827,7 +1835,7 @@ public final class WindowInsets { mStableInsetsConsumed ? null : mTypeMaxInsetsMap, mTypeVisibilityMap, mIsRound, mForceConsumingTypes, mForceConsumingOpaqueCaptionBar, mSuppressScrimTypes, mDisplayCutout, mRoundedCorners, mPrivacyIndicatorBounds, mDisplayShape, systemBars(), false /* compatIgnoreVisibility */, mDisplayShape, mCompatInsetTypes, mCompatIgnoreVisibility, mSystemInsetsConsumed ? null : mTypeBoundingRectsMap, mStableInsetsConsumed ? null : mTypeMaxBoundingRectsMap, mFrameWidth, mFrameHeight); Loading Loading @@ -2060,6 +2068,17 @@ public final class WindowInsets { return STATUS_BARS | NAVIGATION_BARS | CAPTION_BAR | SYSTEM_OVERLAYS; } /** * @return Default compatible types. * * @see #getSystemWindowInsets() * @hide */ @InsetsType public static int defaultCompatible() { return systemBars() | displayCutout(); } /** * @return Default visible types. * Loading core/tests/coretests/src/android/view/WindowInsetsTest.java +47 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,10 @@ package android.view; import static android.view.WindowInsets.Type.SIZE; import static android.view.WindowInsets.Type.captionBar; import static android.view.WindowInsets.Type.displayCutout; import static android.view.WindowInsets.Type.ime; import static android.view.WindowInsets.Type.navigationBars; import static android.view.WindowInsets.Type.statusBars; import static android.view.WindowInsets.Type.systemBars; import static org.junit.Assert.assertEquals; Loading Loading @@ -72,6 +76,49 @@ public class WindowInsetsTest { assertEquals(Insets.of(0, 10, 0, 0), windowInsets.getSystemWindowInsets()); } @Test public void builder_copy_compatInsetTypes() { final Insets[] insets = new Insets[SIZE]; final Insets[] maxInsets = new Insets[SIZE]; final boolean[] visible = new boolean[SIZE]; final int compatInsetTypes = systemBars() | displayCutout() | ime(); final WindowInsets windowInsets = new WindowInsets(insets, maxInsets, visible, false, 0, false, 0, null, null, null, DisplayShape.NONE, compatInsetTypes, false /* compatIgnoreVisibility */, null, null, 0, 0); final WindowInsets modified = new WindowInsets.Builder(windowInsets) .setInsets(statusBars(), Insets.of(0, 10, 0, 0)) .setInsets(navigationBars(), Insets.of(0, 0, 20, 0)) .setInsets(displayCutout(), Insets.of(30, 0, 0, 0)) .setInsets(ime(), Insets.of(0, 0, 0, 40)) .build(); assertEquals(Insets.of(30, 10, 20, 40), modified.getSystemWindowInsets()); } @Test public void builder_copy_compatIgnoreVisibility() { final Insets[] insets = new Insets[SIZE]; final Insets[] maxInsets = new Insets[SIZE]; final boolean[] visible = new boolean[SIZE]; final int compatInsetTypes = systemBars() | displayCutout(); final WindowInsets windowInsets = new WindowInsets(insets, maxInsets, visible, false, 0, false, 0, null, null, null, DisplayShape.NONE, compatInsetTypes, true /* compatIgnoreVisibility */, null, null, 0, 0); final WindowInsets modified = new WindowInsets.Builder(windowInsets) .setInsetsIgnoringVisibility(statusBars(), Insets.of(0, 10, 0, 0)) .setInsetsIgnoringVisibility(navigationBars(), Insets.of(0, 0, 20, 0)) .setInsetsIgnoringVisibility(displayCutout(), Insets.of(30, 0, 0, 0)) .build(); assertEquals(Insets.of(30, 10, 20, 0), modified.getSystemWindowInsets()); } @Test public void builder_displayCutout_getSystemWindowInsets() { final WindowInsets windowInsets = new WindowInsets.Builder() .setInsets(displayCutout(), Insets.of(0, 10, 0, 0)) .build(); assertEquals(Insets.of(0, 10, 0, 0), windowInsets.getSystemWindowInsets()); } @Test public void testSetBoundingRectsInBuilder_noInsets_preservedInWindowInsets() { final List<Rect> rects = List.of(new Rect(0, 0, 50, 100)); Loading Loading
core/java/android/view/InsetsState.java +2 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import static android.internal.perfetto.protos.Insetsstate.InsetsStateProto.SOUR import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_STABLE; import static android.view.WindowInsets.Type.SIZE; import static android.view.WindowInsets.Type.captionBar; import static android.view.WindowInsets.Type.defaultCompatible; import static android.view.WindowInsets.Type.displayCutout; import static android.view.WindowInsets.Type.ime; import static android.view.WindowInsets.Type.indexOf; Loading Loading @@ -193,7 +194,7 @@ public class InsetsState implements Parcelable { final int softInputAdjustMode = legacySoftInputMode & SOFT_INPUT_MASK_ADJUST; @InsetsType int compatInsetsTypes = systemBars() | displayCutout(); int compatInsetsTypes = defaultCompatible(); if (softInputAdjustMode == SOFT_INPUT_ADJUST_RESIZE) { compatInsetsTypes |= ime(); } Loading
core/java/android/view/WindowInsets.java +35 −16 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import static android.view.WindowInsets.Type.STATUS_BARS; import static android.view.WindowInsets.Type.SYSTEM_GESTURES; import static android.view.WindowInsets.Type.TAPPABLE_ELEMENT; import static android.view.WindowInsets.Type.all; import static android.view.WindowInsets.Type.defaultCompatible; import static android.view.WindowInsets.Type.displayCutout; import static android.view.WindowInsets.Type.ime; import static android.view.WindowInsets.Type.indexOf; Loading Loading @@ -139,7 +140,7 @@ public final class WindowInsets { static { CONSUMED = new WindowInsets(createCompatTypeMap(null), createCompatTypeMap(null), createCompatVisibilityMap(createCompatTypeMap(null)), false, 0, false, 0, null, null, null, null, systemBars(), false, null, null, 0, 0); null, null, null, defaultCompatible(), false, null, null, 0, 0); } /** Loading Loading @@ -281,7 +282,7 @@ public final class WindowInsets { @UnsupportedAppUsage public WindowInsets(@Nullable Rect systemWindowInsets) { this(createCompatTypeMap(systemWindowInsets), null, new boolean[SIZE], false, 0, false, 0, null, null, null, null, systemBars(), false /* compatIgnoreVisibility */, null, null, null, null, defaultCompatible(), false /* compatIgnoreVisibility */, new Rect[SIZE][], null, 0, 0); } Loading Loading @@ -358,8 +359,8 @@ public final class WindowInsets { * </p> * * @return The system window insets * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} * instead. * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR * {@link Type#displayCutout()} instead. */ @Deprecated @NonNull Loading Loading @@ -442,8 +443,8 @@ public final class WindowInsets { * </p> * * @return The left system window inset * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} * instead. * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR * {@link Type#displayCutout()} instead. */ @Deprecated public int getSystemWindowInsetLeft() { Loading @@ -458,8 +459,8 @@ public final class WindowInsets { * </p> * * @return The top system window inset * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} * instead. * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR * {@link Type#displayCutout()} instead. */ @Deprecated public int getSystemWindowInsetTop() { Loading @@ -474,8 +475,8 @@ public final class WindowInsets { * </p> * * @return The right system window inset * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} * instead. * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR * {@link Type#displayCutout()} instead. */ @Deprecated public int getSystemWindowInsetRight() { Loading @@ -490,8 +491,8 @@ public final class WindowInsets { * </p> * * @return The bottom system window inset * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} * instead. * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR * {@link Type#displayCutout()} instead. */ @Deprecated public int getSystemWindowInsetBottom() { Loading @@ -506,8 +507,8 @@ public final class WindowInsets { * </p> * * @return true if any of the system window inset values are nonzero * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} * instead. * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR * {@link Type#displayCutout()} instead. */ @Deprecated public boolean hasSystemWindowInsets() { Loading Loading @@ -1411,6 +1412,8 @@ public final class WindowInsets { private final Rect[][] mTypeBoundingRectsMap; @NonNull private final Rect[][] mTypeMaxBoundingRectsMap; private final @InsetsType int mCompatInsetTypes; private final boolean mCompatIgnoreVisibility; private boolean mSystemInsetsConsumed = true; private boolean mStableInsetsConsumed = true; Loading Loading @@ -1442,6 +1445,8 @@ public final class WindowInsets { mTypeVisibilityMap = new boolean[SIZE]; mTypeBoundingRectsMap = new Rect[SIZE][]; mTypeMaxBoundingRectsMap = new Rect[SIZE][]; mCompatInsetTypes = defaultCompatible(); mCompatIgnoreVisibility = false; } /** Loading @@ -1453,6 +1458,8 @@ public final class WindowInsets { mTypeInsetsMap = insets.mTypeInsetsMap.clone(); mTypeMaxInsetsMap = insets.mTypeMaxInsetsMap.clone(); mTypeVisibilityMap = insets.mTypeVisibilityMap.clone(); mCompatInsetTypes = insets.mCompatInsetsTypes; mCompatIgnoreVisibility = insets.mCompatIgnoreVisibility; mSystemInsetsConsumed = insets.mSystemWindowInsetsConsumed; mStableInsetsConsumed = insets.mStableInsetsConsumed; mDisplayCutout = displayCutoutCopyConstructorArgument(insets); Loading @@ -1478,7 +1485,8 @@ public final class WindowInsets { * * @see #getSystemWindowInsets() * @return itself * @deprecated Use {@link #setInsets(int, Insets)} with {@link Type#systemBars()}. * @deprecated Use {@link #setInsets(int, Insets)} with {@link Type#systemBars()} or * {@link Type#displayCutout()}. */ @Deprecated @NonNull Loading Loading @@ -1827,7 +1835,7 @@ public final class WindowInsets { mStableInsetsConsumed ? null : mTypeMaxInsetsMap, mTypeVisibilityMap, mIsRound, mForceConsumingTypes, mForceConsumingOpaqueCaptionBar, mSuppressScrimTypes, mDisplayCutout, mRoundedCorners, mPrivacyIndicatorBounds, mDisplayShape, systemBars(), false /* compatIgnoreVisibility */, mDisplayShape, mCompatInsetTypes, mCompatIgnoreVisibility, mSystemInsetsConsumed ? null : mTypeBoundingRectsMap, mStableInsetsConsumed ? null : mTypeMaxBoundingRectsMap, mFrameWidth, mFrameHeight); Loading Loading @@ -2060,6 +2068,17 @@ public final class WindowInsets { return STATUS_BARS | NAVIGATION_BARS | CAPTION_BAR | SYSTEM_OVERLAYS; } /** * @return Default compatible types. * * @see #getSystemWindowInsets() * @hide */ @InsetsType public static int defaultCompatible() { return systemBars() | displayCutout(); } /** * @return Default visible types. * Loading
core/tests/coretests/src/android/view/WindowInsetsTest.java +47 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,10 @@ package android.view; import static android.view.WindowInsets.Type.SIZE; import static android.view.WindowInsets.Type.captionBar; import static android.view.WindowInsets.Type.displayCutout; import static android.view.WindowInsets.Type.ime; import static android.view.WindowInsets.Type.navigationBars; import static android.view.WindowInsets.Type.statusBars; import static android.view.WindowInsets.Type.systemBars; import static org.junit.Assert.assertEquals; Loading Loading @@ -72,6 +76,49 @@ public class WindowInsetsTest { assertEquals(Insets.of(0, 10, 0, 0), windowInsets.getSystemWindowInsets()); } @Test public void builder_copy_compatInsetTypes() { final Insets[] insets = new Insets[SIZE]; final Insets[] maxInsets = new Insets[SIZE]; final boolean[] visible = new boolean[SIZE]; final int compatInsetTypes = systemBars() | displayCutout() | ime(); final WindowInsets windowInsets = new WindowInsets(insets, maxInsets, visible, false, 0, false, 0, null, null, null, DisplayShape.NONE, compatInsetTypes, false /* compatIgnoreVisibility */, null, null, 0, 0); final WindowInsets modified = new WindowInsets.Builder(windowInsets) .setInsets(statusBars(), Insets.of(0, 10, 0, 0)) .setInsets(navigationBars(), Insets.of(0, 0, 20, 0)) .setInsets(displayCutout(), Insets.of(30, 0, 0, 0)) .setInsets(ime(), Insets.of(0, 0, 0, 40)) .build(); assertEquals(Insets.of(30, 10, 20, 40), modified.getSystemWindowInsets()); } @Test public void builder_copy_compatIgnoreVisibility() { final Insets[] insets = new Insets[SIZE]; final Insets[] maxInsets = new Insets[SIZE]; final boolean[] visible = new boolean[SIZE]; final int compatInsetTypes = systemBars() | displayCutout(); final WindowInsets windowInsets = new WindowInsets(insets, maxInsets, visible, false, 0, false, 0, null, null, null, DisplayShape.NONE, compatInsetTypes, true /* compatIgnoreVisibility */, null, null, 0, 0); final WindowInsets modified = new WindowInsets.Builder(windowInsets) .setInsetsIgnoringVisibility(statusBars(), Insets.of(0, 10, 0, 0)) .setInsetsIgnoringVisibility(navigationBars(), Insets.of(0, 0, 20, 0)) .setInsetsIgnoringVisibility(displayCutout(), Insets.of(30, 0, 0, 0)) .build(); assertEquals(Insets.of(30, 10, 20, 0), modified.getSystemWindowInsets()); } @Test public void builder_displayCutout_getSystemWindowInsets() { final WindowInsets windowInsets = new WindowInsets.Builder() .setInsets(displayCutout(), Insets.of(0, 10, 0, 0)) .build(); assertEquals(Insets.of(0, 10, 0, 0), windowInsets.getSystemWindowInsets()); } @Test public void testSetBoundingRectsInBuilder_noInsets_preservedInWindowInsets() { final List<Rect> rects = List.of(new Rect(0, 0, 50, 100)); Loading