Merge pull request #10686 from t895/version-check

android: Fix input overlay version check
This commit is contained in:
bunnei 2023-06-09 15:27:21 -07:00 committed by GitHub
commit 55b543f466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 10 deletions

View File

@ -765,18 +765,20 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
// If we have API access, calculate the safe area to draw the overlay // If we have API access, calculate the safe area to draw the overlay
var cutoutLeft = 0 var cutoutLeft = 0
var cutoutBottom = 0 var cutoutBottom = 0
val insets = context.windowManager.currentWindowMetrics.windowInsets.displayCutout if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (insets != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { val insets = context.windowManager.currentWindowMetrics.windowInsets.displayCutout
if (insets.boundingRectTop.bottom != 0 && insets.boundingRectTop.bottom > maxY / 2) if (insets != null) {
insets.boundingRectTop.bottom.toFloat() else maxY if (insets.boundingRectTop.bottom != 0 && insets.boundingRectTop.bottom > maxY / 2)
if (insets.boundingRectRight.left != 0 && insets.boundingRectRight.left > maxX / 2) insets.boundingRectTop.bottom.toFloat() else maxY
insets.boundingRectRight.left.toFloat() else maxX if (insets.boundingRectRight.left != 0 && insets.boundingRectRight.left > maxX / 2)
insets.boundingRectRight.left.toFloat() else maxX
minX = insets.boundingRectLeft.right - insets.boundingRectLeft.left minX = insets.boundingRectLeft.right - insets.boundingRectLeft.left
minY = insets.boundingRectBottom.top - insets.boundingRectBottom.bottom minY = insets.boundingRectBottom.top - insets.boundingRectBottom.bottom
cutoutLeft = insets.boundingRectRight.right - insets.boundingRectRight.left cutoutLeft = insets.boundingRectRight.right - insets.boundingRectRight.left
cutoutBottom = insets.boundingRectTop.top - insets.boundingRectTop.bottom cutoutBottom = insets.boundingRectTop.top - insets.boundingRectTop.bottom
}
} }
// This makes sure that if we have an inset on one side of the screen, we mirror it on // This makes sure that if we have an inset on one side of the screen, we mirror it on