forked from isl-org/OpenBot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FadeableTextView.kt
57 lines (47 loc) · 1.31 KB
/
FadeableTextView.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Developed for the OpenBot project (https://openbot.org) by:
*
* Ivo Zivkov
* izivkov@gmail.com
*
* Date: 2020-12-27, 10:56 p.m.
*/
package org.openbot.controller.customComponents
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ObjectAnimator
import android.content.Context
import android.os.CountDownTimer
import android.util.AttributeSet
class FadeableTextView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : com.google.android.material.textview.MaterialTextView(context, attrs, defStyleAttr) {
init {
show ()
}
fun start () {
object : CountDownTimer(3000, 1000) {
override fun onTick(millisUntilFinished: Long) {
}
override fun onFinish() {
fadeOut()
}
}.start()
}
fun show() {
visibility = VISIBLE
}
fun hide() {
visibility = INVISIBLE
}
fun fadeOut() {
val fadeOut = ObjectAnimator.ofFloat(this, "alpha", 1f, 0f)
fadeOut.duration = 500
fadeOut.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
hide()
}
})
fadeOut.start()
}
}