Merge "Fixed not updating waterfall insets in DisplayCutout.inset()" into rvc-dev am: faff9bd887
Change-Id: If7ce784ff9ef545f9fe3183089747e8a6fd08257
This commit is contained in:
@@ -554,26 +554,12 @@ public final class DisplayCutout {
|
|||||||
*/
|
*/
|
||||||
public DisplayCutout inset(int insetLeft, int insetTop, int insetRight, int insetBottom) {
|
public DisplayCutout inset(int insetLeft, int insetTop, int insetRight, int insetBottom) {
|
||||||
if (insetLeft == 0 && insetTop == 0 && insetRight == 0 && insetBottom == 0
|
if (insetLeft == 0 && insetTop == 0 && insetRight == 0 && insetBottom == 0
|
||||||
|| isBoundsEmpty()) {
|
|| (isBoundsEmpty() && mWaterfallInsets.equals(Insets.NONE))) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect safeInsets = new Rect(mSafeInsets);
|
Rect safeInsets = insetInsets(insetLeft, insetTop, insetRight, insetBottom,
|
||||||
|
new Rect(mSafeInsets));
|
||||||
// Note: it's not really well defined what happens when the inset is negative, because we
|
|
||||||
// don't know if the safe inset needs to expand in general.
|
|
||||||
if (insetTop > 0 || safeInsets.top > 0) {
|
|
||||||
safeInsets.top = atLeastZero(safeInsets.top - insetTop);
|
|
||||||
}
|
|
||||||
if (insetBottom > 0 || safeInsets.bottom > 0) {
|
|
||||||
safeInsets.bottom = atLeastZero(safeInsets.bottom - insetBottom);
|
|
||||||
}
|
|
||||||
if (insetLeft > 0 || safeInsets.left > 0) {
|
|
||||||
safeInsets.left = atLeastZero(safeInsets.left - insetLeft);
|
|
||||||
}
|
|
||||||
if (insetRight > 0 || safeInsets.right > 0) {
|
|
||||||
safeInsets.right = atLeastZero(safeInsets.right - insetRight);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we are not cutting off part of the cutout by insetting it on bottom/right, and we also
|
// If we are not cutting off part of the cutout by insetting it on bottom/right, and we also
|
||||||
// don't move it around, we can avoid the allocation and copy of the instance.
|
// don't move it around, we can avoid the allocation and copy of the instance.
|
||||||
@@ -581,6 +567,9 @@ public final class DisplayCutout {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect waterfallInsets = insetInsets(insetLeft, insetTop, insetRight, insetBottom,
|
||||||
|
mWaterfallInsets.toRect());
|
||||||
|
|
||||||
Rect[] bounds = mBounds.getRects();
|
Rect[] bounds = mBounds.getRects();
|
||||||
for (int i = 0; i < bounds.length; ++i) {
|
for (int i = 0; i < bounds.length; ++i) {
|
||||||
if (!bounds[i].equals(ZERO_RECT)) {
|
if (!bounds[i].equals(ZERO_RECT)) {
|
||||||
@@ -588,7 +577,27 @@ public final class DisplayCutout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DisplayCutout(safeInsets, mWaterfallInsets, bounds, false /* copyArguments */);
|
return new DisplayCutout(safeInsets, Insets.of(waterfallInsets), bounds,
|
||||||
|
false /* copyArguments */);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rect insetInsets(int insetLeft, int insetTop, int insetRight, int insetBottom,
|
||||||
|
Rect insets) {
|
||||||
|
// Note: it's not really well defined what happens when the inset is negative, because we
|
||||||
|
// don't know if the safe inset needs to expand in general.
|
||||||
|
if (insetTop > 0 || insets.top > 0) {
|
||||||
|
insets.top = atLeastZero(insets.top - insetTop);
|
||||||
|
}
|
||||||
|
if (insetBottom > 0 || insets.bottom > 0) {
|
||||||
|
insets.bottom = atLeastZero(insets.bottom - insetBottom);
|
||||||
|
}
|
||||||
|
if (insetLeft > 0 || insets.left > 0) {
|
||||||
|
insets.left = atLeastZero(insets.left - insetLeft);
|
||||||
|
}
|
||||||
|
if (insetRight > 0 || insets.right > 0) {
|
||||||
|
insets.right = atLeastZero(insets.right - insetRight);
|
||||||
|
}
|
||||||
|
return insets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -229,6 +229,16 @@ public class DisplayCutoutTest {
|
|||||||
assertEquals(cutout.getSafeInsetBottom(), 96);
|
assertEquals(cutout.getSafeInsetBottom(), 96);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void inset_insets_withWaterfallCutout() throws Exception {
|
||||||
|
DisplayCutout cutout = createCutoutWaterfallOnly(Insets.of(0, 10, 0, 10)).inset(1, 2, 3, 4);
|
||||||
|
|
||||||
|
assertEquals(cutout.getSafeInsetLeft(), 0);
|
||||||
|
assertEquals(cutout.getSafeInsetTop(), 8);
|
||||||
|
assertEquals(cutout.getSafeInsetRight(), 0);
|
||||||
|
assertEquals(cutout.getSafeInsetBottom(), 6);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void inset_insets_consumeInset() throws Exception {
|
public void inset_insets_consumeInset() throws Exception {
|
||||||
DisplayCutout cutout = mCutoutTop.inset(0, 1000, 0, 0);
|
DisplayCutout cutout = mCutoutTop.inset(0, 1000, 0, 0);
|
||||||
@@ -457,7 +467,8 @@ public class DisplayCutoutTest {
|
|||||||
|
|
||||||
private static DisplayCutout createCutoutWaterfallOnly(Insets waterfallInsets) {
|
private static DisplayCutout createCutoutWaterfallOnly(Insets waterfallInsets) {
|
||||||
return new DisplayCutout(
|
return new DisplayCutout(
|
||||||
Insets.of(20, 0, 20, 0),
|
Insets.of(waterfallInsets.left, waterfallInsets.top, waterfallInsets.right,
|
||||||
|
waterfallInsets.bottom),
|
||||||
ZERO_RECT,
|
ZERO_RECT,
|
||||||
ZERO_RECT,
|
ZERO_RECT,
|
||||||
ZERO_RECT,
|
ZERO_RECT,
|
||||||
|
|||||||
Reference in New Issue
Block a user