diff options
| author | 2019-07-15 16:42:53 +0000 | |
|---|---|---|
| committer | 2019-07-15 16:42:53 +0000 | |
| commit | afdc2c7100e76f12b0a875a6e6ed9ef60df64d7d (patch) | |
| tree | 2bf67f65c3ba413f62f5f31d0e41f919bb474cd8 | |
| parent | 1abe575e3726b73ad01122cd1c2ab51d2e105ef5 (diff) | |
| parent | 6b5f5e97e83c3d6e020d2a6b0145e3140281851a (diff) | |
Merge "Refined the logic to detect the location of DisplayCutout."
| -rw-r--r-- | core/java/android/view/DisplayCutout.java | 27 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/view/DisplayCutoutTest.java | 4 |
2 files changed, 18 insertions, 13 deletions
diff --git a/core/java/android/view/DisplayCutout.java b/core/java/android/view/DisplayCutout.java index 715181f28076..797c128e514c 100644 --- a/core/java/android/view/DisplayCutout.java +++ b/core/java/android/view/DisplayCutout.java @@ -319,18 +319,23 @@ public final class DisplayCutout { sortedBounds[i] = ZERO_RECT; } if (safeInsets != null && boundingRects != null) { + // There is at most one non-functional area per short edge of the device, but none + // on the long edges, so either a) safeInsets.top and safeInsets.bottom is 0, or + // b) safeInsets.left and safeInset.right is 0. + final boolean topBottomInset = safeInsets.top > 0 || safeInsets.bottom > 0; for (Rect bound : boundingRects) { - // There is at most one non-functional area per short edge of the device, but none - // on the long edges, so either safeInsets.right or safeInsets.bottom must be 0. - // TODO(b/117199965): Refine the logic to handle edge cases. - if (bound.left == 0) { - sortedBounds[BOUNDS_POSITION_LEFT] = bound; - } else if (bound.top == 0) { - sortedBounds[BOUNDS_POSITION_TOP] = bound; - } else if (safeInsets.right > 0) { - sortedBounds[BOUNDS_POSITION_RIGHT] = bound; - } else if (safeInsets.bottom > 0) { - sortedBounds[BOUNDS_POSITION_BOTTOM] = bound; + if (topBottomInset) { + if (bound.top == 0) { + sortedBounds[BOUNDS_POSITION_TOP] = bound; + } else { + sortedBounds[BOUNDS_POSITION_BOTTOM] = bound; + } + } else { + if (bound.left == 0) { + sortedBounds[BOUNDS_POSITION_LEFT] = bound; + } else { + sortedBounds[BOUNDS_POSITION_RIGHT] = bound; + } } } } diff --git a/core/tests/coretests/src/android/view/DisplayCutoutTest.java b/core/tests/coretests/src/android/view/DisplayCutoutTest.java index 182fe78dfa7a..d5a0dfadcbe5 100644 --- a/core/tests/coretests/src/android/view/DisplayCutoutTest.java +++ b/core/tests/coretests/src/android/view/DisplayCutoutTest.java @@ -104,8 +104,8 @@ public class DisplayCutoutTest { @Test public void testExtractBoundsFromList_top_and_bottom() { - Rect safeInsets = new Rect(0, 1, 0, 10); - Rect boundTop = new Rect(80, 0, 120, 10); + Rect safeInsets = new Rect(0, 10, 0, 10); + Rect boundTop = new Rect(0, 0, 120, 10); Rect boundBottom = new Rect(80, 190, 120, 200); assertThat(extractBoundsFromList(safeInsets, Arrays.asList(new Rect[]{boundTop, boundBottom})), |