blob: b6c120b5123bd6aabab5fe6bb02454313a92250b (
plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
package de.androvdr.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
/**
* Created by lado on 04.05.15.
*/
public class AnimatedTextView extends TextView {
private static final int IS_ANIMATING_TAG_ID = "isAnimating".hashCode();
private Animation fadeInAnimation;
private Animation fadeOutAnimation;
public AnimatedTextView(Context context) {
super(context);
initAnimations(context);
}
public AnimatedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
initAnimations(context);
}
public AnimatedTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initAnimations(context);
}
public void initAnimations(Context context) {
fadeInAnimation = AnimationUtils.loadAnimation(this.getContext(), android.R.anim.fade_in);
fadeOutAnimation = new AlphaAnimation(1.0f, 0.0f);
fadeOutAnimation.setDuration(100);
fadeInAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
setAnimatingFlag(true);
}
@Override
public void onAnimationEnd(Animation animation) {
setAnimatingFlag(false);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
fadeOutAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
setAnimatingFlag(false);
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
setAnimatingFlag(false);
}
public void fadeOut() {
if (getVisibility() == View.VISIBLE) {
startAnimation(fadeOutAnimation);
setVisibility(View.INVISIBLE);
}
}
public void fadeIn() {
//if (getVisibility() == View.INVISIBLE && !isAnimating()) {
// startAnimation(fadeInAnimation);
setVisibility(View.VISIBLE);
// }
}
private boolean isAnimating() {
return (Boolean) getTag(IS_ANIMATING_TAG_ID) == true;
}
private void setAnimatingFlag(boolean isAnimating) {
setTag(IS_ANIMATING_TAG_ID, new Boolean(isAnimating));
}
}
|