2016-03-19 15:39:19 +01:00
|
|
|
package eu.kanade.tachiyomi.widget
|
|
|
|
|
|
|
|
import android.animation.Animator
|
|
|
|
import android.content.Context
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewAnimationUtils
|
2020-07-31 16:29:32 +02:00
|
|
|
import androidx.core.animation.doOnEnd
|
2020-07-25 17:55:47 +02:00
|
|
|
import androidx.core.view.isInvisible
|
|
|
|
import androidx.core.view.isVisible
|
2016-03-19 15:39:19 +01:00
|
|
|
|
|
|
|
class RevealAnimationView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
2020-04-25 20:24:45 +02:00
|
|
|
View(context, attrs) {
|
2016-03-19 15:39:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-08 00:46:31 +01:00
|
|
|
// Make the view visible.
|
2020-07-25 17:55:47 +02:00
|
|
|
this.isVisible = true
|
2016-03-19 15:39:19 +01:00
|
|
|
|
2020-01-08 00:46:31 +01:00
|
|
|
// Create the animation (the final radius is zero).
|
|
|
|
val anim = ViewAnimationUtils.createCircularReveal(
|
2020-09-14 00:48:20 +02:00
|
|
|
this,
|
|
|
|
centerX,
|
|
|
|
centerY,
|
|
|
|
initialRadius.toFloat(),
|
|
|
|
0f
|
2020-04-25 20:24:45 +02:00
|
|
|
)
|
2016-03-19 15:39:19 +01:00
|
|
|
|
2020-01-08 00:46:31 +01:00
|
|
|
// Set duration of animation.
|
|
|
|
anim.duration = 500
|
2016-03-19 15:39:19 +01:00
|
|
|
|
2020-01-08 00:46:31 +01:00
|
|
|
// make the view invisible when the animation is done
|
2020-07-31 16:29:32 +02:00
|
|
|
anim.doOnEnd {
|
|
|
|
this@RevealAnimationView.isInvisible = true
|
|
|
|
}
|
2016-03-19 15:39:19 +01:00
|
|
|
|
2020-01-08 00:46:31 +01:00
|
|
|
anim.start()
|
2016-03-19 15:39:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills the animation view with a animation
|
|
|
|
*
|
|
|
|
* @param centerX x starting point
|
|
|
|
* @param centerY y starting point
|
|
|
|
* @param listener animation listener
|
2021-04-01 04:20:24 +02:00
|
|
|
*
|
|
|
|
* @return sdk version lower then 21
|
2016-03-19 15:39:19 +01:00
|
|
|
*/
|
2021-04-01 04:20:24 +02:00
|
|
|
fun showRevealEffect(centerX: Int, centerY: Int, listener: Animator.AnimatorListener): Boolean {
|
2020-07-25 17:55:47 +02:00
|
|
|
this.isVisible = true
|
2016-03-19 15:39:19 +01:00
|
|
|
|
2020-01-08 00:46:31 +01:00
|
|
|
val height = this.height
|
2016-03-19 15:39:19 +01:00
|
|
|
|
2020-01-08 00:46:31 +01:00
|
|
|
// Create animation
|
|
|
|
val anim = ViewAnimationUtils.createCircularReveal(
|
2020-09-14 00:48:20 +02:00
|
|
|
this,
|
|
|
|
centerX,
|
|
|
|
centerY,
|
|
|
|
0f,
|
|
|
|
height.toFloat()
|
2020-04-25 20:24:45 +02:00
|
|
|
)
|
2016-03-19 15:39:19 +01:00
|
|
|
|
2020-01-08 00:46:31 +01:00
|
|
|
// Set duration of animation
|
|
|
|
anim.duration = 350
|
2016-03-19 15:39:19 +01:00
|
|
|
|
2020-01-08 00:46:31 +01:00
|
|
|
anim.addListener(listener)
|
|
|
|
anim.start()
|
2021-04-01 04:20:24 +02:00
|
|
|
return true
|
2016-03-19 15:39:19 +01:00
|
|
|
}
|
|
|
|
}
|