diff options
| author | 2022-10-24 00:27:34 +0000 | |
|---|---|---|
| committer | 2022-10-24 00:27:34 +0000 | |
| commit | c9f364c06bca8f8865dfbdf043417c5c03522149 (patch) | |
| tree | 787344e45382ee0fa9f1acb5ef4790dfdf692b03 | |
| parent | 68b128d4840aac78511b39ada0c33e857940e8c2 (diff) | |
| parent | 53e391d8a5a8321209dbb517b505fc997332e568 (diff) | |
Merge changes If4e2ba62,Iefd7e8e8 into tm-qpr-dev am: b0d018239d am: 53e391d8a5
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20256624
Change-Id: Ic7e4d8e3129b7d7bd4a042bda38b4110ec5d1428
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/FaceScanningOverlay.kt | 239 |
1 files changed, 135 insertions, 104 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/FaceScanningOverlay.kt b/packages/SystemUI/src/com/android/systemui/FaceScanningOverlay.kt index e69adbd8b634..3e0fa455d39e 100644 --- a/packages/SystemUI/src/com/android/systemui/FaceScanningOverlay.kt +++ b/packages/SystemUI/src/com/android/systemui/FaceScanningOverlay.kt @@ -19,6 +19,7 @@ package com.android.systemui import android.animation.Animator import android.animation.AnimatorListenerAdapter import android.animation.AnimatorSet +import android.animation.TimeInterpolator import android.animation.ValueAnimator import android.content.Context import android.graphics.Canvas @@ -95,32 +96,6 @@ class FaceScanningOverlay( } } - 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 { - return false // instead, we always update the visibility whenever face scanning starts/ends - } - override fun enableShowProtection(show: Boolean) { val showScanningAnimNow = keyguardUpdateMonitor.isFaceDetectionRunning && show if (showScanningAnimNow == showScanningAnim) { @@ -163,54 +138,14 @@ class FaceScanningOverlay( } rimAnimator?.cancel() - rimAnimator = AnimatorSet().apply { - if (showScanningAnim) { - // animate in camera protection, rim, and then pulse in/out - playSequentially( - cameraProtectionAnimator, - createRimAppearAnimator(), - createPulseAnimator() - ) - } else { - val rimDisappearAnimator = ValueAnimator.ofFloat( - rimProgress, - if (faceAuthSucceeded) PULSE_RADIUS_SUCCESS - else SHOW_CAMERA_PROTECTION_SCALE - ).apply { - duration = - if (faceAuthSucceeded) PULSE_SUCCESS_DISAPPEAR_DURATION - else PULSE_ERROR_DISAPPEAR_DURATION - interpolator = - if (faceAuthSucceeded) Interpolators.STANDARD_DECELERATE - else Interpolators.STANDARD - addUpdateListener(this@FaceScanningOverlay::updateRimProgress) - addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator) { - rimProgress = HIDDEN_RIM_SCALE - invalidate() - } - }) - } - if (faceAuthSucceeded) { - val successOpacityAnimator = ValueAnimator.ofInt(255, 0).apply { - duration = PULSE_SUCCESS_DISAPPEAR_DURATION - interpolator = Interpolators.LINEAR - addUpdateListener(this@FaceScanningOverlay::updateRimAlpha) - addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator) { - rimPaint.alpha = 255 - invalidate() - } - }) - } - val rimSuccessAnimator = AnimatorSet() - rimSuccessAnimator.playTogether(rimDisappearAnimator, successOpacityAnimator) - playTogether(rimSuccessAnimator, cameraProtectionAnimator) - } else { - playTogether(rimDisappearAnimator, cameraProtectionAnimator) - } - } - + rimAnimator = if (showScanningAnim) { + createFaceScanningRimAnimator() + } else if (faceAuthSucceeded) { + createFaceSuccessRimAnimator() + } else { + createFaceNotSuccessRimAnimator() + } + rimAnimator?.apply { addListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator) { rimAnimator = null @@ -219,7 +154,132 @@ class FaceScanningOverlay( } } }) - start() + } + rimAnimator?.start() + } + + override fun updateVisOnUpdateCutout(): Boolean { + return false // instead, we always update the visibility whenever face scanning starts/ends + } + + override fun updateProtectionBoundingPath() { + super.updateProtectionBoundingPath() + rimRect.set(protectionRect) + rimRect.scale(rimProgress) + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + if (mBounds.isEmpty()) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + return + } + if (showScanningAnim) { + // Make sure that our measured height encompasses the extra space for the animation + mTotalBounds.union(mBoundingRect) + mTotalBounds.union( + rimRect.left.toInt(), + rimRect.top.toInt(), + rimRect.right.toInt(), + rimRect.bottom.toInt()) + setMeasuredDimension( + resolveSizeAndState(mTotalBounds.width(), widthMeasureSpec, 0), + resolveSizeAndState(mTotalBounds.height(), heightMeasureSpec, 0)) + } else { + setMeasuredDimension( + resolveSizeAndState(mBoundingRect.width(), widthMeasureSpec, 0), + resolveSizeAndState(mBoundingRect.height(), heightMeasureSpec, 0)) + } + } + + 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) + } + + private fun createFaceSuccessRimAnimator(): AnimatorSet { + val rimSuccessAnimator = AnimatorSet() + rimSuccessAnimator.playTogether( + createRimDisappearAnimator( + PULSE_RADIUS_SUCCESS, + PULSE_SUCCESS_DISAPPEAR_DURATION, + Interpolators.STANDARD_DECELERATE + ), + createSuccessOpacityAnimator(), + ) + return AnimatorSet().apply { + playTogether(rimSuccessAnimator, cameraProtectionAnimator) + } + } + + private fun createFaceNotSuccessRimAnimator(): AnimatorSet { + return AnimatorSet().apply { + playTogether( + createRimDisappearAnimator( + SHOW_CAMERA_PROTECTION_SCALE, + PULSE_ERROR_DISAPPEAR_DURATION, + Interpolators.STANDARD + ), + cameraProtectionAnimator, + ) + } + } + + private fun createRimDisappearAnimator( + endValue: Float, + animDuration: Long, + timeInterpolator: TimeInterpolator + ): ValueAnimator { + return ValueAnimator.ofFloat(rimProgress, endValue).apply { + duration = animDuration + interpolator = timeInterpolator + addUpdateListener(this@FaceScanningOverlay::updateRimProgress) + addListener(object : AnimatorListenerAdapter() { + override fun onAnimationEnd(animation: Animator) { + rimProgress = HIDDEN_RIM_SCALE + invalidate() + } + }) + } + } + + private fun createSuccessOpacityAnimator(): ValueAnimator { + return ValueAnimator.ofInt(255, 0).apply { + duration = PULSE_SUCCESS_DISAPPEAR_DURATION + interpolator = Interpolators.LINEAR + addUpdateListener(this@FaceScanningOverlay::updateRimAlpha) + addListener(object : AnimatorListenerAdapter() { + override fun onAnimationEnd(animation: Animator) { + rimPaint.alpha = 255 + invalidate() + } + }) + } + } + + private fun createFaceScanningRimAnimator(): AnimatorSet { + return AnimatorSet().apply { + playSequentially( + cameraProtectionAnimator, + createRimAppearAnimator(), + createPulseAnimator() + ) } } @@ -267,35 +327,6 @@ class FaceScanningOverlay( } } - override fun updateProtectionBoundingPath() { - super.updateProtectionBoundingPath() - rimRect.set(protectionRect) - rimRect.scale(rimProgress) - } - - override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - if (mBounds.isEmpty()) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec) - return - } - if (showScanningAnim) { - // Make sure that our measured height encompasses the extra space for the animation - mTotalBounds.union(mBoundingRect) - mTotalBounds.union( - rimRect.left.toInt(), - rimRect.top.toInt(), - rimRect.right.toInt(), - rimRect.bottom.toInt()) - setMeasuredDimension( - resolveSizeAndState(mTotalBounds.width(), widthMeasureSpec, 0), - resolveSizeAndState(mTotalBounds.height(), heightMeasureSpec, 0)) - } else { - setMeasuredDimension( - resolveSizeAndState(mBoundingRect.width(), widthMeasureSpec, 0), - resolveSizeAndState(mBoundingRect.height(), heightMeasureSpec, 0)) - } - } - private val keyguardUpdateMonitorCallback = object : KeyguardUpdateMonitorCallback() { override fun onBiometricAuthenticated( userId: Int, |