2016-03-19 10:39:19 -04:00
|
|
|
package eu.kanade.tachiyomi.widget
|
|
|
|
|
|
|
|
import android.animation.Animator
|
|
|
|
import android.animation.AnimatorListenerAdapter
|
|
|
|
import android.content.Context
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewAnimationUtils
|
|
|
|
|
|
|
|
class RevealAnimationView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
|
|
|
View(context, attrs) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the animation view with a animation
|
|
|
|
*
|
|
|
|
* @param centerX x starting point
|
|
|
|
* @param centerY y starting point
|
|
|
|
* @param initialRadius size of radius of animation
|
|
|
|
*/
|
|
|
|
fun hideRevealEffect(centerX: Int, centerY: Int, initialRadius: Int) {
|
2020-01-07 18:46:31 -05:00
|
|
|
// Make the view visible.
|
|
|
|
this.visibility = View.VISIBLE
|
2016-03-19 10:39:19 -04:00
|
|
|
|
2020-01-07 18:46:31 -05:00
|
|
|
// Create the animation (the final radius is zero).
|
|
|
|
val anim = ViewAnimationUtils.createCircularReveal(
|
|
|
|
this, centerX, centerY, initialRadius.toFloat(), 0f)
|
2016-03-19 10:39:19 -04:00
|
|
|
|
2020-01-07 18:46:31 -05:00
|
|
|
// Set duration of animation.
|
|
|
|
anim.duration = 500
|
2016-03-19 10:39:19 -04:00
|
|
|
|
2020-01-07 18:46:31 -05:00
|
|
|
// make the view invisible when the animation is done
|
|
|
|
anim.addListener(object : AnimatorListenerAdapter() {
|
|
|
|
override fun onAnimationEnd(animation: Animator) {
|
|
|
|
super.onAnimationEnd(animation)
|
|
|
|
this@RevealAnimationView.visibility = View.INVISIBLE
|
|
|
|
}
|
|
|
|
})
|
2016-03-19 10:39:19 -04:00
|
|
|
|
2020-01-07 18:46:31 -05:00
|
|
|
anim.start()
|
2016-03-19 10:39:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills the animation view with a animation
|
|
|
|
*
|
|
|
|
* @param centerX x starting point
|
|
|
|
* @param centerY y starting point
|
|
|
|
* @param listener animation listener
|
|
|
|
*
|
|
|
|
* @return sdk version lower then 21
|
|
|
|
*/
|
|
|
|
fun showRevealEffect(centerX: Int, centerY: Int, listener: Animator.AnimatorListener): Boolean {
|
2020-01-07 18:46:31 -05:00
|
|
|
this.visibility = View.VISIBLE
|
2016-03-19 10:39:19 -04:00
|
|
|
|
2020-01-07 18:46:31 -05:00
|
|
|
val height = this.height
|
2016-03-19 10:39:19 -04:00
|
|
|
|
2020-01-07 18:46:31 -05:00
|
|
|
// Create animation
|
|
|
|
val anim = ViewAnimationUtils.createCircularReveal(
|
|
|
|
this, centerX, centerY, 0f, height.toFloat())
|
2016-03-19 10:39:19 -04:00
|
|
|
|
2020-01-07 18:46:31 -05:00
|
|
|
// Set duration of animation
|
|
|
|
anim.duration = 350
|
2016-03-19 10:39:19 -04:00
|
|
|
|
2020-01-07 18:46:31 -05:00
|
|
|
anim.addListener(listener)
|
|
|
|
anim.start()
|
|
|
|
return true
|
2016-03-19 10:39:19 -04:00
|
|
|
}
|
|
|
|
}
|