I have created my own extension function that checks if the sdk is at least lollipop
inline val buildIsLollipopAndUp: Boolean
get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
However, if I use this, the lint tools can't figure out that I've verified my api level and still gives me new api warnings. Is there anyway to make those warning disappear and have the lint tools recognize my check?
A simple example:
if (buildIsLollipopAndUp) ripple()
else fade()
Where ripple
calls on the circular animation that is only available for lollipop and up, and fade
is the default animation.
My full example:
@SuppressLint("NewApi")
@KauUtils fun View.circularReveal(x: Int = 0, y: Int = 0, offset: Long = 0L, radius: Float = -1.0f, duration: Long = 500L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
if (!isAttachedToWindow) {
onStart?.invoke()
visible()
onFinish?.invoke()
return
}
if (!buildIsLollipopAndUp) return fadeIn(offset, duration, onStart, onFinish)
val r = if (radius >= 0) radius
else Math.max(Math.hypot(x.toDouble(), y.toDouble()), Math.hypot((width - x.toDouble()), (height - y.toDouble()))).toFloat()
val anim = ViewAnimationUtils.createCircularReveal(this, x, y, 0f, r).setDuration(duration)
anim.startDelay = offset
anim.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationStart(animation: Animator?) {
visible()
onStart?.invoke()
}
override fun onAnimationEnd(animation: Animator?) = onFinish?.invoke() ?: Unit
override fun onAnimationCancel(animation: Animator?) = onFinish?.invoke() ?: Unit
})
anim.start()
}
Note that I need the lint suppressor so as to avoid lint warnings