Merge "Enforfce a minimum padding to ensure space for the privacy dot" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
995fce704b
@@ -1266,6 +1266,8 @@
|
|||||||
<!-- Three privacy items. This value must not be exceeded -->
|
<!-- Three privacy items. This value must not be exceeded -->
|
||||||
<dimen name="ongoing_appops_chip_max_width">76dp</dimen>
|
<dimen name="ongoing_appops_chip_max_width">76dp</dimen>
|
||||||
<dimen name="ongoing_appops_dot_diameter">6dp</dimen>
|
<dimen name="ongoing_appops_dot_diameter">6dp</dimen>
|
||||||
|
<!-- Total minimum padding to enforce to ensure that the dot can always show -->
|
||||||
|
<dimen name="ongoing_appops_dot_min_padding">20dp</dimen>
|
||||||
|
|
||||||
<dimen name="ongoing_appops_dialog_side_margins">@dimen/notification_shade_content_margin_horizontal</dimen>
|
<dimen name="ongoing_appops_dialog_side_margins">@dimen/notification_shade_content_margin_horizontal</dimen>
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.phone
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
|
import android.util.Log
|
||||||
import android.util.Pair
|
import android.util.Pair
|
||||||
import android.view.DisplayCutout
|
import android.view.DisplayCutout
|
||||||
import android.view.View.LAYOUT_DIRECTION_RTL
|
import android.view.View.LAYOUT_DIRECTION_RTL
|
||||||
@@ -155,13 +156,30 @@ class StatusBarContentInsetsProvider @Inject constructor(
|
|||||||
val dc = context.display.cutout
|
val dc = context.display.cutout
|
||||||
val currentRotation = RotationUtils.getExactRotation(context)
|
val currentRotation = RotationUtils.getExactRotation(context)
|
||||||
|
|
||||||
|
val isRtl = rotatedResources.configuration.layoutDirection == LAYOUT_DIRECTION_RTL
|
||||||
|
val roundedCornerPadding = rotatedResources
|
||||||
|
.getDimensionPixelSize(R.dimen.rounded_corner_content_padding)
|
||||||
|
val minDotWidth = rotatedResources
|
||||||
|
.getDimensionPixelSize(R.dimen.ongoing_appops_dot_min_padding)
|
||||||
|
|
||||||
|
val minLeft: Int
|
||||||
|
val minRight: Int
|
||||||
|
if (isRtl) {
|
||||||
|
minLeft = max(minDotWidth, roundedCornerPadding)
|
||||||
|
minRight = roundedCornerPadding
|
||||||
|
} else {
|
||||||
|
minLeft = roundedCornerPadding
|
||||||
|
minRight = max(minDotWidth, roundedCornerPadding)
|
||||||
|
}
|
||||||
|
|
||||||
return calculateInsetsForRotationWithRotatedResources(
|
return calculateInsetsForRotationWithRotatedResources(
|
||||||
currentRotation,
|
currentRotation,
|
||||||
targetRotation,
|
targetRotation,
|
||||||
dc,
|
dc,
|
||||||
windowManager.maximumWindowMetrics,
|
windowManager.maximumWindowMetrics,
|
||||||
rotatedResources.getDimensionPixelSize(R.dimen.status_bar_height),
|
rotatedResources.getDimensionPixelSize(R.dimen.status_bar_height),
|
||||||
rotatedResources.getDimensionPixelSize(R.dimen.rounded_corner_content_padding))
|
minLeft,
|
||||||
|
minRight)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array<out String>) {
|
override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array<out String>) {
|
||||||
@@ -212,9 +230,12 @@ fun getPrivacyChipBoundingRectForInsets(
|
|||||||
* Calculates the exact left and right positions for the status bar contents for the given
|
* Calculates the exact left and right positions for the status bar contents for the given
|
||||||
* rotation
|
* rotation
|
||||||
*
|
*
|
||||||
* @param rot rotation for which to query the margins
|
* @param currentRotation current device rotation
|
||||||
* @param context systemui context
|
* @param targetRotation rotation for which to calculate the status bar content rect
|
||||||
* @param rotatedResources resources constructed with the proper orientation set
|
* @param displayCutout [DisplayCutout] for the curren display. possibly null
|
||||||
|
* @param windowMetrics [WindowMetrics] for the current window
|
||||||
|
* @param statusBarHeight height of the status bar for the target rotation
|
||||||
|
* @param roundedCornerPadding from rounded_corner_content_padding
|
||||||
*
|
*
|
||||||
* @see [RotationUtils#getResourcesForRotation]
|
* @see [RotationUtils#getResourcesForRotation]
|
||||||
*/
|
*/
|
||||||
@@ -224,7 +245,8 @@ fun calculateInsetsForRotationWithRotatedResources(
|
|||||||
displayCutout: DisplayCutout?,
|
displayCutout: DisplayCutout?,
|
||||||
windowMetrics: WindowMetrics,
|
windowMetrics: WindowMetrics,
|
||||||
statusBarHeight: Int,
|
statusBarHeight: Int,
|
||||||
roundedCornerPadding: Int
|
minLeft: Int,
|
||||||
|
minRight: Int
|
||||||
): Rect {
|
): Rect {
|
||||||
/*
|
/*
|
||||||
TODO: Check if this is ever used for devices with no rounded corners
|
TODO: Check if this is ever used for devices with no rounded corners
|
||||||
@@ -242,7 +264,8 @@ fun calculateInsetsForRotationWithRotatedResources(
|
|||||||
rotZeroBounds.bottom,
|
rotZeroBounds.bottom,
|
||||||
currentBounds.width(),
|
currentBounds.width(),
|
||||||
currentBounds.height(),
|
currentBounds.height(),
|
||||||
roundedCornerPadding,
|
minLeft,
|
||||||
|
minRight,
|
||||||
targetRotation,
|
targetRotation,
|
||||||
currentRotation)
|
currentRotation)
|
||||||
|
|
||||||
@@ -256,7 +279,10 @@ fun calculateInsetsForRotationWithRotatedResources(
|
|||||||
* @param sbHeight appropriate status bar height for this rotation
|
* @param sbHeight appropriate status bar height for this rotation
|
||||||
* @param width display width calculated for ROTATION_NONE
|
* @param width display width calculated for ROTATION_NONE
|
||||||
* @param height display height calculated for ROTATION_NONE
|
* @param height display height calculated for ROTATION_NONE
|
||||||
* @param roundedCornerPadding rounded_corner_content_padding dimension
|
* @param cWidth display width in our current rotation
|
||||||
|
* @param cHeight display height in our current rotation
|
||||||
|
* @param minLeft the minimum padding to enforce on the left
|
||||||
|
* @param minRight the minimum padding to enforce on the right
|
||||||
* @param targetRotation the rotation for which to calculate margins
|
* @param targetRotation the rotation for which to calculate margins
|
||||||
* @param currentRotation the rotation from which the display cutout was generated
|
* @param currentRotation the rotation from which the display cutout was generated
|
||||||
*
|
*
|
||||||
@@ -270,7 +296,8 @@ private fun getStatusBarLeftRight(
|
|||||||
height: Int,
|
height: Int,
|
||||||
cWidth: Int,
|
cWidth: Int,
|
||||||
cHeight: Int,
|
cHeight: Int,
|
||||||
roundedCornerPadding: Int,
|
minLeft: Int,
|
||||||
|
minRight: Int,
|
||||||
@Rotation targetRotation: Int,
|
@Rotation targetRotation: Int,
|
||||||
@Rotation currentRotation: Int
|
@Rotation currentRotation: Int
|
||||||
): Rect {
|
): Rect {
|
||||||
@@ -279,9 +306,9 @@ private fun getStatusBarLeftRight(
|
|||||||
|
|
||||||
val cutoutRects = dc?.boundingRects
|
val cutoutRects = dc?.boundingRects
|
||||||
if (cutoutRects == null || cutoutRects.isEmpty()) {
|
if (cutoutRects == null || cutoutRects.isEmpty()) {
|
||||||
return Rect(roundedCornerPadding,
|
return Rect(minLeft,
|
||||||
0,
|
0,
|
||||||
logicalDisplayWidth - roundedCornerPadding,
|
logicalDisplayWidth - minRight,
|
||||||
sbHeight)
|
sbHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,8 +321,8 @@ private fun getStatusBarLeftRight(
|
|||||||
// Size of the status bar window for the given rotation relative to our exact rotation
|
// Size of the status bar window for the given rotation relative to our exact rotation
|
||||||
val sbRect = sbRect(relativeRotation, sbHeight, Pair(cWidth, cHeight))
|
val sbRect = sbRect(relativeRotation, sbHeight, Pair(cWidth, cHeight))
|
||||||
|
|
||||||
var leftMargin = roundedCornerPadding
|
var leftMargin = minLeft
|
||||||
var rightMargin = roundedCornerPadding
|
var rightMargin = minRight
|
||||||
for (cutoutRect in cutoutRects) {
|
for (cutoutRect in cutoutRects) {
|
||||||
// There is at most one non-functional area per short edge of the device. So if the status
|
// There is at most one non-functional area per short edge of the device. So if the status
|
||||||
// bar doesn't share a short edge with the cutout, we can ignore its insets because there
|
// bar doesn't share a short edge with the cutout, we can ignore its insets because there
|
||||||
@@ -306,11 +333,11 @@ private fun getStatusBarLeftRight(
|
|||||||
|
|
||||||
if (cutoutRect.touchesLeftEdge(relativeRotation, cWidth, cHeight)) {
|
if (cutoutRect.touchesLeftEdge(relativeRotation, cWidth, cHeight)) {
|
||||||
|
|
||||||
val l = max(roundedCornerPadding, cutoutRect.logicalWidth(relativeRotation))
|
val l = max(minLeft, cutoutRect.logicalWidth(relativeRotation))
|
||||||
leftMargin = max(l, leftMargin)
|
leftMargin = max(l, leftMargin)
|
||||||
} else if (cutoutRect.touchesRightEdge(relativeRotation, cWidth, cHeight)) {
|
} else if (cutoutRect.touchesRightEdge(relativeRotation, cWidth, cHeight)) {
|
||||||
val logicalWidth = cutoutRect.logicalWidth(relativeRotation)
|
val logicalWidth = cutoutRect.logicalWidth(relativeRotation)
|
||||||
rightMargin = max(roundedCornerPadding, logicalWidth)
|
rightMargin = max(minRight, logicalWidth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
@Test
|
@Test
|
||||||
fun testGetBoundingRectForPrivacyChipForRotation_noCutout() {
|
fun testGetBoundingRectForPrivacyChipForRotation_noCutout() {
|
||||||
val screenBounds = Rect(0, 0, 1080, 2160)
|
val screenBounds = Rect(0, 0, 1080, 2160)
|
||||||
val roundedCornerPadding = 20
|
val minLeftPadding = 20
|
||||||
|
val minRightPadding = 20
|
||||||
val sbHeightPortrait = 100
|
val sbHeightPortrait = 100
|
||||||
val sbHeightLandscape = 60
|
val sbHeightLandscape = 60
|
||||||
val currentRotation = ROTATION_NONE
|
val currentRotation = ROTATION_NONE
|
||||||
@@ -64,7 +65,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
null,
|
null,
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
|
|
||||||
var chipBounds = getPrivacyChipBoundingRectForInsets(bounds, dotWidth, chipWidth, isRtl)
|
var chipBounds = getPrivacyChipBoundingRectForInsets(bounds, dotWidth, chipWidth, isRtl)
|
||||||
/* 1080 - 20 (rounded corner) - 30 (chip),
|
/* 1080 - 20 (rounded corner) - 30 (chip),
|
||||||
@@ -92,7 +94,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
dc,
|
dc,
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
|
|
||||||
chipBounds = getPrivacyChipBoundingRectForInsets(bounds, dotWidth, chipWidth, isRtl)
|
chipBounds = getPrivacyChipBoundingRectForInsets(bounds, dotWidth, chipWidth, isRtl)
|
||||||
/* 2160 - 20 (rounded corner) - 30 (chip),
|
/* 2160 - 20 (rounded corner) - 30 (chip),
|
||||||
@@ -118,7 +121,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
// GIVEN a device in portrait mode with width < height and a display cutout in the top-left
|
// GIVEN a device in portrait mode with width < height and a display cutout in the top-left
|
||||||
val screenBounds = Rect(0, 0, 1080, 2160)
|
val screenBounds = Rect(0, 0, 1080, 2160)
|
||||||
val dcBounds = Rect(0, 0, 100, 100)
|
val dcBounds = Rect(0, 0, 100, 100)
|
||||||
val roundedCornerPadding = 20
|
val minLeftPadding = 20
|
||||||
|
val minRightPadding = 20
|
||||||
val sbHeightPortrait = 100
|
val sbHeightPortrait = 100
|
||||||
val sbHeightLandscape = 60
|
val sbHeightLandscape = 60
|
||||||
val currentRotation = ROTATION_NONE
|
val currentRotation = ROTATION_NONE
|
||||||
@@ -131,7 +135,7 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
var targetRotation = ROTATION_NONE
|
var targetRotation = ROTATION_NONE
|
||||||
var expectedBounds = Rect(dcBounds.right,
|
var expectedBounds = Rect(dcBounds.right,
|
||||||
0,
|
0,
|
||||||
screenBounds.right - roundedCornerPadding,
|
screenBounds.right - minRightPadding,
|
||||||
sbHeightPortrait)
|
sbHeightPortrait)
|
||||||
|
|
||||||
var bounds = calculateInsetsForRotationWithRotatedResources(
|
var bounds = calculateInsetsForRotationWithRotatedResources(
|
||||||
@@ -140,14 +144,15 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
dc,
|
dc,
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
targetRotation = ROTATION_LANDSCAPE
|
targetRotation = ROTATION_LANDSCAPE
|
||||||
expectedBounds = Rect(dcBounds.height(),
|
expectedBounds = Rect(dcBounds.height(),
|
||||||
0,
|
0,
|
||||||
screenBounds.height() - roundedCornerPadding,
|
screenBounds.height() - minRightPadding,
|
||||||
sbHeightLandscape)
|
sbHeightLandscape)
|
||||||
|
|
||||||
bounds = calculateInsetsForRotationWithRotatedResources(
|
bounds = calculateInsetsForRotationWithRotatedResources(
|
||||||
@@ -156,16 +161,17 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
dc,
|
dc,
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
// THEN the side that does NOT share a short side with the display cutout ignores the
|
// THEN the side that does NOT share a short side with the display cutout ignores the
|
||||||
// display cutout bounds
|
// display cutout bounds
|
||||||
targetRotation = ROTATION_UPSIDE_DOWN
|
targetRotation = ROTATION_UPSIDE_DOWN
|
||||||
expectedBounds = Rect(roundedCornerPadding,
|
expectedBounds = Rect(minLeftPadding,
|
||||||
0,
|
0,
|
||||||
screenBounds.width() - roundedCornerPadding,
|
screenBounds.width() - minRightPadding,
|
||||||
sbHeightPortrait)
|
sbHeightPortrait)
|
||||||
|
|
||||||
bounds = calculateInsetsForRotationWithRotatedResources(
|
bounds = calculateInsetsForRotationWithRotatedResources(
|
||||||
@@ -174,13 +180,14 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
dc,
|
dc,
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
// Phone in portrait, seascape (rot_270) bounds
|
// Phone in portrait, seascape (rot_270) bounds
|
||||||
targetRotation = ROTATION_SEASCAPE
|
targetRotation = ROTATION_SEASCAPE
|
||||||
expectedBounds = Rect(roundedCornerPadding,
|
expectedBounds = Rect(minLeftPadding,
|
||||||
0,
|
0,
|
||||||
screenBounds.height() - dcBounds.height(),
|
screenBounds.height() - dcBounds.height(),
|
||||||
sbHeightLandscape)
|
sbHeightLandscape)
|
||||||
@@ -191,7 +198,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
dc,
|
dc,
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
}
|
}
|
||||||
@@ -205,7 +213,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
val screenBounds = Rect(0, 0, 1080, 2160)
|
val screenBounds = Rect(0, 0, 1080, 2160)
|
||||||
// cutout centered at the top
|
// cutout centered at the top
|
||||||
val dcBounds = Rect(490, 0, 590, 100)
|
val dcBounds = Rect(490, 0, 590, 100)
|
||||||
val roundedCornerPadding = 20
|
val minLeftPadding = 20
|
||||||
|
val minRightPadding = 20
|
||||||
val sbHeightPortrait = 100
|
val sbHeightPortrait = 100
|
||||||
val sbHeightLandscape = 60
|
val sbHeightLandscape = 60
|
||||||
val currentRotation = ROTATION_NONE
|
val currentRotation = ROTATION_NONE
|
||||||
@@ -216,9 +225,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
// THEN only the landscape/seascape rotations should avoid the cutout area because of the
|
// THEN only the landscape/seascape rotations should avoid the cutout area because of the
|
||||||
// potential letterboxing
|
// potential letterboxing
|
||||||
var targetRotation = ROTATION_NONE
|
var targetRotation = ROTATION_NONE
|
||||||
var expectedBounds = Rect(roundedCornerPadding,
|
var expectedBounds = Rect(minLeftPadding,
|
||||||
0,
|
0,
|
||||||
screenBounds.right - roundedCornerPadding,
|
screenBounds.right - minRightPadding,
|
||||||
sbHeightPortrait)
|
sbHeightPortrait)
|
||||||
|
|
||||||
var bounds = calculateInsetsForRotationWithRotatedResources(
|
var bounds = calculateInsetsForRotationWithRotatedResources(
|
||||||
@@ -227,14 +236,15 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
dc,
|
dc,
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
targetRotation = ROTATION_LANDSCAPE
|
targetRotation = ROTATION_LANDSCAPE
|
||||||
expectedBounds = Rect(dcBounds.height(),
|
expectedBounds = Rect(dcBounds.height(),
|
||||||
0,
|
0,
|
||||||
screenBounds.height() - roundedCornerPadding,
|
screenBounds.height() - minRightPadding,
|
||||||
sbHeightLandscape)
|
sbHeightLandscape)
|
||||||
|
|
||||||
bounds = calculateInsetsForRotationWithRotatedResources(
|
bounds = calculateInsetsForRotationWithRotatedResources(
|
||||||
@@ -243,14 +253,15 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
dc,
|
dc,
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
targetRotation = ROTATION_UPSIDE_DOWN
|
targetRotation = ROTATION_UPSIDE_DOWN
|
||||||
expectedBounds = Rect(roundedCornerPadding,
|
expectedBounds = Rect(minLeftPadding,
|
||||||
0,
|
0,
|
||||||
screenBounds.right - roundedCornerPadding,
|
screenBounds.right - minRightPadding,
|
||||||
sbHeightPortrait)
|
sbHeightPortrait)
|
||||||
|
|
||||||
bounds = calculateInsetsForRotationWithRotatedResources(
|
bounds = calculateInsetsForRotationWithRotatedResources(
|
||||||
@@ -259,12 +270,13 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
dc,
|
dc,
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
targetRotation = ROTATION_SEASCAPE
|
targetRotation = ROTATION_SEASCAPE
|
||||||
expectedBounds = Rect(roundedCornerPadding,
|
expectedBounds = Rect(minLeftPadding,
|
||||||
0,
|
0,
|
||||||
screenBounds.height() - dcBounds.height(),
|
screenBounds.height() - dcBounds.height(),
|
||||||
sbHeightLandscape)
|
sbHeightLandscape)
|
||||||
@@ -275,7 +287,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
dc,
|
dc,
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
}
|
}
|
||||||
@@ -285,7 +298,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
// GIVEN device in portrait mode, where width < height and no cutout
|
// GIVEN device in portrait mode, where width < height and no cutout
|
||||||
val currentRotation = ROTATION_NONE
|
val currentRotation = ROTATION_NONE
|
||||||
val screenBounds = Rect(0, 0, 1080, 2160)
|
val screenBounds = Rect(0, 0, 1080, 2160)
|
||||||
val roundedCornerPadding = 20
|
val minLeftPadding = 20
|
||||||
|
val minRightPadding = 20
|
||||||
val sbHeightPortrait = 100
|
val sbHeightPortrait = 100
|
||||||
val sbHeightLandscape = 60
|
val sbHeightLandscape = 60
|
||||||
|
|
||||||
@@ -293,9 +307,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
|
|
||||||
// THEN content insets should only use rounded corner padding
|
// THEN content insets should only use rounded corner padding
|
||||||
var targetRotation = ROTATION_NONE
|
var targetRotation = ROTATION_NONE
|
||||||
var expectedBounds = Rect(roundedCornerPadding,
|
var expectedBounds = Rect(minLeftPadding,
|
||||||
0,
|
0,
|
||||||
screenBounds.right - roundedCornerPadding,
|
screenBounds.right - minRightPadding,
|
||||||
sbHeightPortrait)
|
sbHeightPortrait)
|
||||||
|
|
||||||
var bounds = calculateInsetsForRotationWithRotatedResources(
|
var bounds = calculateInsetsForRotationWithRotatedResources(
|
||||||
@@ -304,13 +318,14 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
null, /* no cutout */
|
null, /* no cutout */
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
targetRotation = ROTATION_LANDSCAPE
|
targetRotation = ROTATION_LANDSCAPE
|
||||||
expectedBounds = Rect(roundedCornerPadding,
|
expectedBounds = Rect(minLeftPadding,
|
||||||
0,
|
0,
|
||||||
screenBounds.height() - roundedCornerPadding,
|
screenBounds.height() - minRightPadding,
|
||||||
sbHeightLandscape)
|
sbHeightLandscape)
|
||||||
|
|
||||||
bounds = calculateInsetsForRotationWithRotatedResources(
|
bounds = calculateInsetsForRotationWithRotatedResources(
|
||||||
@@ -319,13 +334,14 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
null, /* no cutout */
|
null, /* no cutout */
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
targetRotation = ROTATION_UPSIDE_DOWN
|
targetRotation = ROTATION_UPSIDE_DOWN
|
||||||
expectedBounds = Rect(roundedCornerPadding,
|
expectedBounds = Rect(minLeftPadding,
|
||||||
0,
|
0,
|
||||||
screenBounds.width() - roundedCornerPadding,
|
screenBounds.width() - minRightPadding,
|
||||||
sbHeightPortrait)
|
sbHeightPortrait)
|
||||||
|
|
||||||
bounds = calculateInsetsForRotationWithRotatedResources(
|
bounds = calculateInsetsForRotationWithRotatedResources(
|
||||||
@@ -334,13 +350,14 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
null, /* no cutout */
|
null, /* no cutout */
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
targetRotation = ROTATION_LANDSCAPE
|
targetRotation = ROTATION_LANDSCAPE
|
||||||
expectedBounds = Rect(roundedCornerPadding,
|
expectedBounds = Rect(minLeftPadding,
|
||||||
0,
|
0,
|
||||||
screenBounds.height() - roundedCornerPadding,
|
screenBounds.height() - minRightPadding,
|
||||||
sbHeightLandscape)
|
sbHeightLandscape)
|
||||||
|
|
||||||
bounds = calculateInsetsForRotationWithRotatedResources(
|
bounds = calculateInsetsForRotationWithRotatedResources(
|
||||||
@@ -349,7 +366,41 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
null, /* no cutout */
|
null, /* no cutout */
|
||||||
windowMetrics,
|
windowMetrics,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
roundedCornerPadding)
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testMinLeftRight_accountsForDisplayCutout() {
|
||||||
|
// GIVEN a device in portrait mode with width < height and a display cutout in the top-left
|
||||||
|
val screenBounds = Rect(0, 0, 1080, 2160)
|
||||||
|
val dcBounds = Rect(0, 0, 100, 100)
|
||||||
|
val minLeftPadding = 80
|
||||||
|
val minRightPadding = 150
|
||||||
|
val sbHeightPortrait = 100
|
||||||
|
val sbHeightLandscape = 60
|
||||||
|
val currentRotation = ROTATION_NONE
|
||||||
|
|
||||||
|
`when`(windowMetrics.bounds).thenReturn(screenBounds)
|
||||||
|
`when`(dc.boundingRects).thenReturn(listOf(dcBounds))
|
||||||
|
|
||||||
|
// THEN left should be set to the display cutout width, and right should use the minRight
|
||||||
|
var targetRotation = ROTATION_NONE
|
||||||
|
var expectedBounds = Rect(dcBounds.right,
|
||||||
|
0,
|
||||||
|
screenBounds.right - minRightPadding,
|
||||||
|
sbHeightPortrait)
|
||||||
|
|
||||||
|
var bounds = calculateInsetsForRotationWithRotatedResources(
|
||||||
|
currentRotation,
|
||||||
|
targetRotation,
|
||||||
|
dc,
|
||||||
|
windowMetrics,
|
||||||
|
sbHeightPortrait,
|
||||||
|
minLeftPadding,
|
||||||
|
minRightPadding)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user