Merge changes I7be92814,If0bef656 into tm-qpr-dev

* changes:
  Use single animator with reverse repeats for the face scanning pulse
  Extract duplicated code into methods in FaceScanningOverlay
This commit is contained in:
Chandru S
2022-10-23 13:28:17 +00:00
committed by Android (Google) Code Review

View File

@@ -151,19 +151,12 @@ class FaceScanningOverlay(
if (showScanningAnim) Interpolators.STANDARD_ACCELERATE if (showScanningAnim) Interpolators.STANDARD_ACCELERATE
else if (faceAuthSucceeded) Interpolators.STANDARD else if (faceAuthSucceeded) Interpolators.STANDARD
else Interpolators.STANDARD_DECELERATE else Interpolators.STANDARD_DECELERATE
addUpdateListener(ValueAnimator.AnimatorUpdateListener { addUpdateListener(this@FaceScanningOverlay::updateCameraProtectionProgress)
animation: ValueAnimator ->
cameraProtectionProgress = animation.animatedValue as Float
invalidate()
})
addListener(object : AnimatorListenerAdapter() { addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) { override fun onAnimationEnd(animation: Animator) {
cameraProtectionAnimator = null cameraProtectionAnimator = null
if (!showScanningAnim) { if (!showScanningAnim) {
visibility = View.INVISIBLE hide()
hideOverlayRunnable?.run()
hideOverlayRunnable = null
requestLayout()
} }
} }
}) })
@@ -172,22 +165,12 @@ class FaceScanningOverlay(
rimAnimator?.cancel() rimAnimator?.cancel()
rimAnimator = AnimatorSet().apply { rimAnimator = AnimatorSet().apply {
if (showScanningAnim) { if (showScanningAnim) {
val rimAppearAnimator = ValueAnimator.ofFloat(SHOW_CAMERA_PROTECTION_SCALE,
PULSE_RADIUS_OUT).apply {
duration = PULSE_APPEAR_DURATION
interpolator = Interpolators.STANDARD_DECELERATE
addUpdateListener(ValueAnimator.AnimatorUpdateListener {
animation: ValueAnimator ->
rimProgress = animation.animatedValue as Float
invalidate()
})
}
// animate in camera protection, rim, and then pulse in/out // animate in camera protection, rim, and then pulse in/out
playSequentially(cameraProtectionAnimator, rimAppearAnimator, playSequentially(
createPulseAnimator(), createPulseAnimator(), cameraProtectionAnimator,
createPulseAnimator(), createPulseAnimator(), createRimAppearAnimator(),
createPulseAnimator(), createPulseAnimator()) createPulseAnimator()
)
} else { } else {
val rimDisappearAnimator = ValueAnimator.ofFloat( val rimDisappearAnimator = ValueAnimator.ofFloat(
rimProgress, rimProgress,
@@ -200,11 +183,7 @@ class FaceScanningOverlay(
interpolator = interpolator =
if (faceAuthSucceeded) Interpolators.STANDARD_DECELERATE if (faceAuthSucceeded) Interpolators.STANDARD_DECELERATE
else Interpolators.STANDARD else Interpolators.STANDARD
addUpdateListener(ValueAnimator.AnimatorUpdateListener { addUpdateListener(this@FaceScanningOverlay::updateRimProgress)
animation: ValueAnimator ->
rimProgress = animation.animatedValue as Float
invalidate()
})
addListener(object : AnimatorListenerAdapter() { addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) { override fun onAnimationEnd(animation: Animator) {
rimProgress = HIDDEN_RIM_SCALE rimProgress = HIDDEN_RIM_SCALE
@@ -216,11 +195,7 @@ class FaceScanningOverlay(
val successOpacityAnimator = ValueAnimator.ofInt(255, 0).apply { val successOpacityAnimator = ValueAnimator.ofInt(255, 0).apply {
duration = PULSE_SUCCESS_DISAPPEAR_DURATION duration = PULSE_SUCCESS_DISAPPEAR_DURATION
interpolator = Interpolators.LINEAR interpolator = Interpolators.LINEAR
addUpdateListener(ValueAnimator.AnimatorUpdateListener { addUpdateListener(this@FaceScanningOverlay::updateRimAlpha)
animation: ValueAnimator ->
rimPaint.alpha = animation.animatedValue as Int
invalidate()
})
addListener(object : AnimatorListenerAdapter() { addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) { override fun onAnimationEnd(animation: Animator) {
rimPaint.alpha = 255 rimPaint.alpha = 255
@@ -248,29 +223,47 @@ class FaceScanningOverlay(
} }
} }
fun createPulseAnimator(): AnimatorSet { private fun createRimAppearAnimator(): ValueAnimator {
return AnimatorSet().apply { return ValueAnimator.ofFloat(
val pulseInwards = ValueAnimator.ofFloat( SHOW_CAMERA_PROTECTION_SCALE,
PULSE_RADIUS_OUT, PULSE_RADIUS_IN).apply { PULSE_RADIUS_OUT
duration = PULSE_DURATION_INWARDS ).apply {
interpolator = Interpolators.STANDARD duration = PULSE_APPEAR_DURATION
addUpdateListener(ValueAnimator.AnimatorUpdateListener { interpolator = Interpolators.STANDARD_DECELERATE
animation: ValueAnimator -> addUpdateListener(this@FaceScanningOverlay::updateRimProgress)
rimProgress = animation.animatedValue as Float }
invalidate() }
})
} private fun hide() {
val pulseOutwards = ValueAnimator.ofFloat( visibility = INVISIBLE
PULSE_RADIUS_IN, PULSE_RADIUS_OUT).apply { hideOverlayRunnable?.run()
duration = PULSE_DURATION_OUTWARDS hideOverlayRunnable = null
interpolator = Interpolators.STANDARD requestLayout()
addUpdateListener(ValueAnimator.AnimatorUpdateListener { }
animation: ValueAnimator ->
rimProgress = animation.animatedValue as Float private fun updateRimProgress(animator: ValueAnimator) {
invalidate() rimProgress = animator.animatedValue as Float
}) invalidate()
} }
playSequentially(pulseInwards, pulseOutwards)
private fun updateCameraProtectionProgress(animator: ValueAnimator) {
cameraProtectionProgress = animator.animatedValue as Float
invalidate()
}
private fun updateRimAlpha(animator: ValueAnimator) {
rimPaint.alpha = animator.animatedValue as Int
invalidate()
}
private fun createPulseAnimator(): ValueAnimator {
return ValueAnimator.ofFloat(
PULSE_RADIUS_OUT, PULSE_RADIUS_IN).apply {
duration = HALF_PULSE_DURATION
interpolator = Interpolators.STANDARD
repeatCount = 11 // Pulse inwards and outwards, reversing direction, 6 times
repeatMode = ValueAnimator.REVERSE
addUpdateListener(this@FaceScanningOverlay::updateRimProgress)
} }
} }
@@ -362,8 +355,7 @@ class FaceScanningOverlay(
private const val CAMERA_PROTECTION_APPEAR_DURATION = 250L private const val CAMERA_PROTECTION_APPEAR_DURATION = 250L
private const val PULSE_APPEAR_DURATION = 250L // without start delay private const val PULSE_APPEAR_DURATION = 250L // without start delay
private const val PULSE_DURATION_INWARDS = 500L private const val HALF_PULSE_DURATION = 500L
private const val PULSE_DURATION_OUTWARDS = 500L
private const val PULSE_SUCCESS_DISAPPEAR_DURATION = 400L private const val PULSE_SUCCESS_DISAPPEAR_DURATION = 400L
private const val CAMERA_PROTECTION_SUCCESS_DISAPPEAR_DURATION = 500L // without start delay private const val CAMERA_PROTECTION_SUCCESS_DISAPPEAR_DURATION = 500L // without start delay