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:
@@ -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
|
||||||
|
).apply {
|
||||||
|
duration = PULSE_APPEAR_DURATION
|
||||||
|
interpolator = Interpolators.STANDARD_DECELERATE
|
||||||
|
addUpdateListener(this@FaceScanningOverlay::updateRimProgress)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hide() {
|
||||||
|
visibility = INVISIBLE
|
||||||
|
hideOverlayRunnable?.run()
|
||||||
|
hideOverlayRunnable = null
|
||||||
|
requestLayout()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateRimProgress(animator: ValueAnimator) {
|
||||||
|
rimProgress = animator.animatedValue as Float
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
PULSE_RADIUS_OUT, PULSE_RADIUS_IN).apply {
|
||||||
duration = PULSE_DURATION_INWARDS
|
duration = HALF_PULSE_DURATION
|
||||||
interpolator = Interpolators.STANDARD
|
interpolator = Interpolators.STANDARD
|
||||||
addUpdateListener(ValueAnimator.AnimatorUpdateListener {
|
repeatCount = 11 // Pulse inwards and outwards, reversing direction, 6 times
|
||||||
animation: ValueAnimator ->
|
repeatMode = ValueAnimator.REVERSE
|
||||||
rimProgress = animation.animatedValue as Float
|
addUpdateListener(this@FaceScanningOverlay::updateRimProgress)
|
||||||
invalidate()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
val pulseOutwards = ValueAnimator.ofFloat(
|
|
||||||
PULSE_RADIUS_IN, PULSE_RADIUS_OUT).apply {
|
|
||||||
duration = PULSE_DURATION_OUTWARDS
|
|
||||||
interpolator = Interpolators.STANDARD
|
|
||||||
addUpdateListener(ValueAnimator.AnimatorUpdateListener {
|
|
||||||
animation: ValueAnimator ->
|
|
||||||
rimProgress = animation.animatedValue as Float
|
|
||||||
invalidate()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
playSequentially(pulseInwards, pulseOutwards)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user