Merge changes If4e2ba62,Iefd7e8e8 into tm-qpr-dev
* changes: Move private methods together below overriden public methods. Refactor deeply nested rim animator into three cases for scanning, success, not successful
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user