mihon/app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationUpDown.kt

52 lines
1.7 KiB
Kotlin
Raw Normal View History

package eu.kanade.tachiyomi.widget
import android.content.Context
import com.google.android.material.floatingactionbutton.FloatingActionButton
import androidx.interpolator.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
2017-10-28 13:12:17 -04:00
@Suppress("unused", "UNUSED_PARAMETER")
class FABAnimationUpDown @JvmOverloads constructor(ctx: Context, attrs: AttributeSet? = null) : FABAnimationBase() {
private val INTERPOLATOR = FastOutSlowInInterpolator()
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
}
}
override fun animateOut(button: FloatingActionButton) {
outAnimation.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
isAnimatingOut = true
}
override fun onAnimationEnd(animation: Animation) {
isAnimatingOut = false
2017-02-02 10:48:18 -05:00
button.visibility = View.INVISIBLE
}
override fun onAnimationRepeat(animation: Animation) {
}
})
button.startAnimation(outAnimation)
}
override fun animateIn(button: FloatingActionButton) {
button.visibility = View.VISIBLE
button.startAnimation(inAnimation)
}
}