Skip to content

Instantly share code, notes, and snippets.

@virendersran01
Forked from macieknajbar/ClickDrawable.kt
Created July 8, 2020 07:21
Show Gist options
  • Save virendersran01/02f699ddd44bc14d6c0d308be3efdda6 to your computer and use it in GitHub Desktop.
Save virendersran01/02f699ddd44bc14d6c0d308be3efdda6 to your computer and use it in GitHub Desktop.
class ClickDrawable(layers: Array<out Drawable> = arrayOf()) : LayerDrawable(layers) {
private val mask: Drawable =
ColorDrawable(0xFF00FFFF.toInt()).apply { alpha = 0 }
init {
addLayer(mask)
}
@Keep
private fun setMaskAlpha(alpha: Int) {
mask.alpha = alpha
invalidateSelf()
}
private fun colorMask(fromAlpha: Int, toAlpha: Int) {
val anim = ObjectAnimator.ofInt(this, "maskAlpha", fromAlpha, toAlpha, fromAlpha)
anim.duration = DURATION
anim.interpolator = LinearInterpolator()
anim.start()
}
private fun setClickActive(active: Boolean) {
if (mActive != active) {
mActive = active
if (active && canStart) {
colorMask(0, 64)
}
}
}
@Keep
private fun setBounds(value: Float) { … }
private companion object {
const val DURATION = 225L
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment