From 1dd959d68f9edd0b4c5fe156478ce82ec6917ff4 Mon Sep 17 00:00:00 2001 From: Chandru Date: Fri, 21 Oct 2022 10:36:37 +0000 Subject: [PATCH] Remove duplicated path scaling of camera protection and scanning rim. Bug: 254814998 Test: NA Test: verified manually, both camera protection and face scanning overlay drawn correctly on keyguard. Change-Id: I7ba717c567afbf3a54e87aeefe76db7c7b570684 --- .../android/systemui/FaceScanningOverlay.kt | 73 +++++++++++-------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/FaceScanningOverlay.kt b/packages/SystemUI/src/com/android/systemui/FaceScanningOverlay.kt index 7002811c3c830..f64089177d1f0 100644 --- a/packages/SystemUI/src/com/android/systemui/FaceScanningOverlay.kt +++ b/packages/SystemUI/src/com/android/systemui/FaceScanningOverlay.kt @@ -55,7 +55,7 @@ class FaceScanningOverlay( private val rimRect = RectF() private var cameraProtectionColor = Color.BLACK var faceScanningAnimColor = Utils.getColorAttrDefaultColor(context, - com.android.systemui.R.attr.wallpaperTextColorAccent) + R.attr.wallpaperTextColorAccent) private var cameraProtectionAnimator: ValueAnimator? = null var hideOverlayRunnable: Runnable? = null var faceAuthSucceeded = false @@ -84,38 +84,37 @@ class FaceScanningOverlay( } override fun drawCutoutProtection(canvas: Canvas) { - if (rimProgress > HIDDEN_RIM_SCALE && !protectionRect.isEmpty) { - val rimPath = Path(protectionPath) - val scaleMatrix = Matrix().apply { - val rimBounds = RectF() - rimPath.computeBounds(rimBounds, true) - setScale(rimProgress, rimProgress, rimBounds.centerX(), rimBounds.centerY()) - } - rimPath.transform(scaleMatrix) - rimPaint.style = Paint.Style.FILL - val rimPaintAlpha = rimPaint.alpha - rimPaint.color = ColorUtils.blendARGB( - faceScanningAnimColor, - Color.WHITE, - statusBarStateController.dozeAmount) - rimPaint.alpha = rimPaintAlpha - canvas.drawPath(rimPath, rimPaint) + if (protectionRect.isEmpty) { + return } + if (rimProgress > HIDDEN_RIM_SCALE) { + drawFaceScanningRim(canvas) + } + if (cameraProtectionProgress > HIDDEN_CAMERA_PROTECTION_SCALE) { + drawCameraProtection(canvas) + } + } - if (cameraProtectionProgress > HIDDEN_CAMERA_PROTECTION_SCALE && - !protectionRect.isEmpty) { - val scaledProtectionPath = Path(protectionPath) - val scaleMatrix = Matrix().apply { - val protectionPathRect = RectF() - scaledProtectionPath.computeBounds(protectionPathRect, true) - setScale(cameraProtectionProgress, cameraProtectionProgress, - protectionPathRect.centerX(), protectionPathRect.centerY()) - } - scaledProtectionPath.transform(scaleMatrix) - paint.style = Paint.Style.FILL - paint.color = cameraProtectionColor - canvas.drawPath(scaledProtectionPath, paint) - } + private fun drawFaceScanningRim(canvas: Canvas) { + val rimPath = Path(protectionPath) + scalePath(rimPath, rimProgress) + rimPaint.style = Paint.Style.FILL + val rimPaintAlpha = rimPaint.alpha + rimPaint.color = ColorUtils.blendARGB( + faceScanningAnimColor, + Color.WHITE, + statusBarStateController.dozeAmount + ) + rimPaint.alpha = rimPaintAlpha + canvas.drawPath(rimPath, rimPaint) + } + + private fun drawCameraProtection(canvas: Canvas) { + val scaledProtectionPath = Path(protectionPath) + scalePath(scaledProtectionPath, cameraProtectionProgress) + paint.style = Paint.Style.FILL + paint.color = cameraProtectionColor + canvas.drawPath(scaledProtectionPath, paint) } override fun updateVisOnUpdateCutout(): Boolean { @@ -371,5 +370,17 @@ class FaceScanningOverlay( private const val PULSE_ERROR_DISAPPEAR_DURATION = 200L private const val CAMERA_PROTECTION_ERROR_DISAPPEAR_DURATION = 300L // without start delay + + private fun scalePath(path: Path, scalingFactor: Float) { + val scaleMatrix = Matrix().apply { + val boundingRectangle = RectF() + path.computeBounds(boundingRectangle, true) + setScale( + scalingFactor, scalingFactor, + boundingRectangle.centerX(), boundingRectangle.centerY() + ) + } + path.transform(scaleMatrix) + } } }