Coverage Summary for Class: EmbeddedBlockRevealAnimation (cloud.mindbox.mobile_sdk.embedded)
| Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| EmbeddedBlockRevealAnimation |
100%
(6/6)
|
75%
(3/4)
|
100%
(29/29)
|
98.9%
(185/187)
|
| EmbeddedBlockRevealAnimation$1 |
100%
(1/1)
|
50%
(1/2)
|
100%
(1/1)
|
75%
(6/8)
|
| EmbeddedBlockRevealAnimation$crossfade$1$2 |
100%
(2/2)
|
100%
(2/2)
|
100%
(4/4)
|
100%
(18/18)
|
| EmbeddedBlockRevealAnimation$growHeight$1$2 |
100%
(2/2)
|
50%
(1/2)
|
100%
(6/6)
|
93.5%
(29/31)
|
| Total |
100%
(11/11)
|
70%
(7/10)
|
100%
(40/40)
|
97.5%
(238/244)
|
package cloud.mindbox.mobile_sdk.embedded
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
import android.os.Build
import android.view.View
import android.view.animation.PathInterpolator
import cloud.mindbox.mobile_sdk.models.Milliseconds
import cloud.mindbox.mobile_sdk.utils.Constants
internal open class EmbeddedBlockRevealAnimation(
val duration: Milliseconds = Constants.Embedded.revealAnimationDuration,
private val areSystemAnimationsEnabled: () -> Boolean = {
Build.VERSION.SDK_INT < Build.VERSION_CODES.O || ValueAnimator.areAnimatorsEnabled()
},
) {
val isEnabled: Boolean
get() = areSystemAnimationsEnabled()
private val revealInterpolator = PathInterpolator(0.42f, 0f, 0.58f, 1f)
open fun crossfade(incoming: View, outgoing: View?, onEnd: () -> Unit): Animator =
ValueAnimator.ofFloat(0f, 1f).apply {
incoming.alpha = 0f
this.duration = this@EmbeddedBlockRevealAnimation.duration.interval
interpolator = revealInterpolator
addUpdateListener { animator ->
val shown = animator.animatedValue as Float
incoming.alpha = shown
outgoing?.alpha = 1f - shown
}
addListener(
object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
incoming.alpha = 1f
outgoing?.alpha = 0f
onEnd()
}
},
)
start()
}
open fun growHeight(view: View, targetHeight: Int, onEnd: () -> Unit): Animator =
ValueAnimator.ofInt(0, targetHeight).apply {
this.duration = this@EmbeddedBlockRevealAnimation.duration.interval
interpolator = revealInterpolator
addUpdateListener { animator ->
view.layoutParams?.let { params ->
params.height = animator.animatedValue as Int
view.requestLayout()
}
}
addListener(
object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
view.layoutParams?.let { params ->
params.height = targetHeight
view.requestLayout()
}
onEnd()
}
},
)
start()
}
}