2016-05-27 13:21:21 +02:00
|
|
|
package eu.kanade.tachiyomi.widget
|
2016-02-22 22:36:44 +01:00
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.support.design.widget.FloatingActionButton
|
|
|
|
import android.support.v4.view.animation.FastOutSlowInInterpolator
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.View
|
|
|
|
import android.view.animation.Animation
|
|
|
|
import android.view.animation.AnimationUtils
|
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
|
|
2016-04-28 21:51:50 +02:00
|
|
|
class FABAnimationUpDown @JvmOverloads constructor(ctx: Context, attrs: AttributeSet? = null) : FABAnimationBase() {
|
2016-02-22 22:36:44 +01:00
|
|
|
|
|
|
|
private val INTERPOLATOR = FastOutSlowInInterpolator()
|
|
|
|
|
2016-04-28 21:51:50 +02:00
|
|
|
private val outAnimation by lazy {
|
|
|
|
AnimationUtils.loadAnimation(ctx, R.anim.fab_hide_to_bottom).apply {
|
|
|
|
duration = 200
|
|
|
|
interpolator = INTERPOLATOR
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private val inAnimation by lazy {
|
|
|
|
AnimationUtils.loadAnimation(ctx, R.anim.fab_show_from_bottom).apply {
|
|
|
|
duration = 200
|
|
|
|
interpolator = INTERPOLATOR
|
|
|
|
}
|
|
|
|
}
|
2016-02-22 22:36:44 +01:00
|
|
|
|
|
|
|
override fun animateOut(button: FloatingActionButton) {
|
2016-04-28 21:51:50 +02:00
|
|
|
outAnimation.setAnimationListener(object : Animation.AnimationListener {
|
2016-02-22 22:36:44 +01:00
|
|
|
override fun onAnimationStart(animation: Animation) {
|
2016-04-28 21:51:50 +02:00
|
|
|
isAnimatingOut = true
|
2016-02-22 22:36:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onAnimationEnd(animation: Animation) {
|
2016-04-28 21:51:50 +02:00
|
|
|
isAnimatingOut = false
|
2016-02-22 22:36:44 +01:00
|
|
|
button.visibility = View.GONE
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onAnimationRepeat(animation: Animation) {
|
|
|
|
}
|
|
|
|
})
|
2016-04-28 21:51:50 +02:00
|
|
|
button.startAnimation(outAnimation)
|
2016-02-22 22:36:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun animateIn(button: FloatingActionButton) {
|
|
|
|
button.visibility = View.VISIBLE
|
2016-04-28 21:51:50 +02:00
|
|
|
button.startAnimation(inAnimation)
|
2016-02-22 22:36:44 +01:00
|
|
|
}
|
|
|
|
}
|