Merge "Prevent privacy dot overlapped by cutout" into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
efec66249d
@@ -156,18 +156,21 @@ class StatusBarContentInsetsProvider @Inject constructor(
|
|||||||
val isRtl = rotatedResources.configuration.layoutDirection == LAYOUT_DIRECTION_RTL
|
val isRtl = rotatedResources.configuration.layoutDirection == LAYOUT_DIRECTION_RTL
|
||||||
val roundedCornerPadding = rotatedResources
|
val roundedCornerPadding = rotatedResources
|
||||||
.getDimensionPixelSize(R.dimen.rounded_corner_content_padding)
|
.getDimensionPixelSize(R.dimen.rounded_corner_content_padding)
|
||||||
val minDotWidth = if (isPrivacyDotEnabled)
|
val minDotPadding = if (isPrivacyDotEnabled)
|
||||||
rotatedResources.getDimensionPixelSize(R.dimen.ongoing_appops_dot_min_padding)
|
rotatedResources.getDimensionPixelSize(R.dimen.ongoing_appops_dot_min_padding)
|
||||||
else 0
|
else 0
|
||||||
|
val dotWidth = if (isPrivacyDotEnabled)
|
||||||
|
rotatedResources.getDimensionPixelSize(R.dimen.ongoing_appops_dot_diameter)
|
||||||
|
else 0
|
||||||
|
|
||||||
val minLeft: Int
|
val minLeft: Int
|
||||||
val minRight: Int
|
val minRight: Int
|
||||||
if (isRtl) {
|
if (isRtl) {
|
||||||
minLeft = max(minDotWidth, roundedCornerPadding)
|
minLeft = max(minDotPadding, roundedCornerPadding)
|
||||||
minRight = roundedCornerPadding
|
minRight = roundedCornerPadding
|
||||||
} else {
|
} else {
|
||||||
minLeft = roundedCornerPadding
|
minLeft = roundedCornerPadding
|
||||||
minRight = max(minDotWidth, roundedCornerPadding)
|
minRight = max(minDotPadding, roundedCornerPadding)
|
||||||
}
|
}
|
||||||
|
|
||||||
return calculateInsetsForRotationWithRotatedResources(
|
return calculateInsetsForRotationWithRotatedResources(
|
||||||
@@ -177,7 +180,9 @@ class StatusBarContentInsetsProvider @Inject constructor(
|
|||||||
context.resources.configuration.windowConfiguration.maxBounds,
|
context.resources.configuration.windowConfiguration.maxBounds,
|
||||||
SystemBarUtils.getStatusBarHeight(context),
|
SystemBarUtils.getStatusBarHeight(context),
|
||||||
minLeft,
|
minLeft,
|
||||||
minRight)
|
minRight,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getStatusBarPaddingTop(@Rotation rotation: Int? = null): Int {
|
fun getStatusBarPaddingTop(@Rotation rotation: Int? = null): Int {
|
||||||
@@ -246,10 +251,13 @@ fun getPrivacyChipBoundingRectForInsets(
|
|||||||
*
|
*
|
||||||
* @param currentRotation current device rotation
|
* @param currentRotation current device rotation
|
||||||
* @param targetRotation rotation for which to calculate the status bar content rect
|
* @param targetRotation rotation for which to calculate the status bar content rect
|
||||||
* @param displayCutout [DisplayCutout] for the curren display. possibly null
|
* @param displayCutout [DisplayCutout] for the current display. possibly null
|
||||||
* @param windowMetrics [WindowMetrics] for the current window
|
* @param windowMetrics [WindowMetrics] for the current window
|
||||||
* @param statusBarHeight height of the status bar for the target rotation
|
* @param statusBarHeight height of the status bar for the target rotation
|
||||||
* @param roundedCornerPadding from rounded_corner_content_padding
|
* @param minLeft the minimum padding to enforce on the left
|
||||||
|
* @param minRight the minimum padding to enforce on the right
|
||||||
|
* @param isRtl current layout direction is Right-To-Left or not
|
||||||
|
* @param dotWidth privacy dot image width (0 if privacy dot is disabled)
|
||||||
*
|
*
|
||||||
* @see [RotationUtils#getResourcesForRotation]
|
* @see [RotationUtils#getResourcesForRotation]
|
||||||
*/
|
*/
|
||||||
@@ -260,7 +268,9 @@ fun calculateInsetsForRotationWithRotatedResources(
|
|||||||
maxBounds: Rect,
|
maxBounds: Rect,
|
||||||
statusBarHeight: Int,
|
statusBarHeight: Int,
|
||||||
minLeft: Int,
|
minLeft: Int,
|
||||||
minRight: Int
|
minRight: Int,
|
||||||
|
isRtl: Boolean,
|
||||||
|
dotWidth: 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
|
||||||
@@ -279,6 +289,8 @@ fun calculateInsetsForRotationWithRotatedResources(
|
|||||||
maxBounds.height(),
|
maxBounds.height(),
|
||||||
minLeft,
|
minLeft,
|
||||||
minRight,
|
minRight,
|
||||||
|
isRtl,
|
||||||
|
dotWidth,
|
||||||
targetRotation,
|
targetRotation,
|
||||||
currentRotation)
|
currentRotation)
|
||||||
|
|
||||||
@@ -296,6 +308,8 @@ fun calculateInsetsForRotationWithRotatedResources(
|
|||||||
* @param cHeight display height in our current rotation
|
* @param cHeight display height in our current rotation
|
||||||
* @param minLeft the minimum padding to enforce on the left
|
* @param minLeft the minimum padding to enforce on the left
|
||||||
* @param minRight the minimum padding to enforce on the right
|
* @param minRight the minimum padding to enforce on the right
|
||||||
|
* @param isRtl current layout direction is Right-To-Left or not
|
||||||
|
* @param dotWidth privacy dot image width (0 if privacy dot is disabled)
|
||||||
* @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
|
||||||
*
|
*
|
||||||
@@ -311,6 +325,8 @@ private fun getStatusBarLeftRight(
|
|||||||
cHeight: Int,
|
cHeight: Int,
|
||||||
minLeft: Int,
|
minLeft: Int,
|
||||||
minRight: Int,
|
minRight: Int,
|
||||||
|
isRtl: Boolean,
|
||||||
|
dotWidth: Int,
|
||||||
@Rotation targetRotation: Int,
|
@Rotation targetRotation: Int,
|
||||||
@Rotation currentRotation: Int
|
@Rotation currentRotation: Int
|
||||||
): Rect {
|
): Rect {
|
||||||
@@ -345,13 +361,16 @@ private fun getStatusBarLeftRight(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cutoutRect.touchesLeftEdge(relativeRotation, cWidth, cHeight)) {
|
if (cutoutRect.touchesLeftEdge(relativeRotation, cWidth, cHeight)) {
|
||||||
|
var logicalWidth = cutoutRect.logicalWidth(relativeRotation)
|
||||||
val l = max(minLeft, cutoutRect.logicalWidth(relativeRotation))
|
if (isRtl) logicalWidth += dotWidth
|
||||||
leftMargin = max(l, leftMargin)
|
leftMargin = max(logicalWidth, leftMargin)
|
||||||
} else if (cutoutRect.touchesRightEdge(relativeRotation, cWidth, cHeight)) {
|
} else if (cutoutRect.touchesRightEdge(relativeRotation, cWidth, cHeight)) {
|
||||||
val logicalWidth = cutoutRect.logicalWidth(relativeRotation)
|
var logicalWidth = cutoutRect.logicalWidth(relativeRotation)
|
||||||
rightMargin = max(minRight, logicalWidth)
|
if (!isRtl) logicalWidth += dotWidth
|
||||||
|
rightMargin = max(rightMargin, logicalWidth)
|
||||||
}
|
}
|
||||||
|
// TODO(b/203626889): Fix the scenario when config_mainBuiltInDisplayCutoutRectApproximation
|
||||||
|
// is very close to but not directly touch edges.
|
||||||
}
|
}
|
||||||
|
|
||||||
return Rect(leftMargin, 0, logicalDisplayWidth - rightMargin, sbHeight)
|
return Rect(leftMargin, 0, logicalDisplayWidth - rightMargin, sbHeight)
|
||||||
|
|||||||
@@ -86,7 +86,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
|
|
||||||
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),
|
||||||
@@ -115,7 +117,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
|
|
||||||
chipBounds = getPrivacyChipBoundingRectForInsets(bounds, dotWidth, chipWidth, isRtl)
|
chipBounds = getPrivacyChipBoundingRectForInsets(bounds, dotWidth, chipWidth, isRtl)
|
||||||
/* 2160 - 20 (rounded corner) - 30 (chip),
|
/* 2160 - 20 (rounded corner) - 30 (chip),
|
||||||
@@ -146,6 +150,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
val sbHeightPortrait = 100
|
val sbHeightPortrait = 100
|
||||||
val sbHeightLandscape = 60
|
val sbHeightLandscape = 60
|
||||||
val currentRotation = ROTATION_NONE
|
val currentRotation = ROTATION_NONE
|
||||||
|
val isRtl = false
|
||||||
|
val dotWidth = 10
|
||||||
|
|
||||||
`when`(dc.boundingRects).thenReturn(listOf(dcBounds))
|
`when`(dc.boundingRects).thenReturn(listOf(dcBounds))
|
||||||
|
|
||||||
@@ -164,7 +170,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
@@ -181,7 +189,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
@@ -200,7 +210,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
@@ -208,7 +220,7 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
targetRotation = ROTATION_SEASCAPE
|
targetRotation = ROTATION_SEASCAPE
|
||||||
expectedBounds = Rect(minLeftPadding,
|
expectedBounds = Rect(minLeftPadding,
|
||||||
0,
|
0,
|
||||||
screenBounds.height() - dcBounds.height(),
|
screenBounds.height() - dcBounds.height() - dotWidth,
|
||||||
sbHeightLandscape)
|
sbHeightLandscape)
|
||||||
|
|
||||||
bounds = calculateInsetsForRotationWithRotatedResources(
|
bounds = calculateInsetsForRotationWithRotatedResources(
|
||||||
@@ -218,7 +230,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
}
|
}
|
||||||
@@ -237,6 +251,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
val sbHeightPortrait = 100
|
val sbHeightPortrait = 100
|
||||||
val sbHeightLandscape = 60
|
val sbHeightLandscape = 60
|
||||||
val currentRotation = ROTATION_NONE
|
val currentRotation = ROTATION_NONE
|
||||||
|
val isRtl = false
|
||||||
|
val dotWidth = 10
|
||||||
|
|
||||||
`when`(dc.boundingRects).thenReturn(listOf(dcBounds))
|
`when`(dc.boundingRects).thenReturn(listOf(dcBounds))
|
||||||
|
|
||||||
@@ -255,7 +271,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
@@ -272,7 +290,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
@@ -289,14 +309,16 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
targetRotation = ROTATION_SEASCAPE
|
targetRotation = ROTATION_SEASCAPE
|
||||||
expectedBounds = Rect(minLeftPadding,
|
expectedBounds = Rect(minLeftPadding,
|
||||||
0,
|
0,
|
||||||
screenBounds.height() - dcBounds.height(),
|
screenBounds.height() - dcBounds.height() - dotWidth,
|
||||||
sbHeightLandscape)
|
sbHeightLandscape)
|
||||||
|
|
||||||
bounds = calculateInsetsForRotationWithRotatedResources(
|
bounds = calculateInsetsForRotationWithRotatedResources(
|
||||||
@@ -306,7 +328,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
}
|
}
|
||||||
@@ -320,6 +344,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
val minRightPadding = 20
|
val minRightPadding = 20
|
||||||
val sbHeightPortrait = 100
|
val sbHeightPortrait = 100
|
||||||
val sbHeightLandscape = 60
|
val sbHeightLandscape = 60
|
||||||
|
val isRtl = false
|
||||||
|
val dotWidth = 10
|
||||||
|
|
||||||
// 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
|
||||||
@@ -335,7 +361,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
targetRotation = ROTATION_LANDSCAPE
|
targetRotation = ROTATION_LANDSCAPE
|
||||||
@@ -351,7 +379,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
targetRotation = ROTATION_UPSIDE_DOWN
|
targetRotation = ROTATION_UPSIDE_DOWN
|
||||||
@@ -367,7 +397,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
|
|
||||||
targetRotation = ROTATION_LANDSCAPE
|
targetRotation = ROTATION_LANDSCAPE
|
||||||
@@ -383,7 +415,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightLandscape,
|
sbHeightLandscape,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,6 +431,8 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
val sbHeightPortrait = 100
|
val sbHeightPortrait = 100
|
||||||
val sbHeightLandscape = 60
|
val sbHeightLandscape = 60
|
||||||
val currentRotation = ROTATION_NONE
|
val currentRotation = ROTATION_NONE
|
||||||
|
val isRtl = false
|
||||||
|
val dotWidth = 10
|
||||||
|
|
||||||
`when`(dc.boundingRects).thenReturn(listOf(dcBounds))
|
`when`(dc.boundingRects).thenReturn(listOf(dcBounds))
|
||||||
|
|
||||||
@@ -414,7 +450,9 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
|
|||||||
screenBounds,
|
screenBounds,
|
||||||
sbHeightPortrait,
|
sbHeightPortrait,
|
||||||
minLeftPadding,
|
minLeftPadding,
|
||||||
minRightPadding)
|
minRightPadding,
|
||||||
|
isRtl,
|
||||||
|
dotWidth)
|
||||||
|
|
||||||
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
assertRects(expectedBounds, bounds, currentRotation, targetRotation)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user