-
Notifications
You must be signed in to change notification settings - Fork 451
/
Copy pathWoWoTextViewTextAnimation.java
62 lines (49 loc) · 2.03 KB
/
WoWoTextViewTextAnimation.java
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
package com.nightonke.wowoviewpager.Animation;
import android.animation.TimeInterpolator;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.nightonke.wowoviewpager.Enum.Typewriter;
import static com.nightonke.wowoviewpager.WoWoViewPager.TAG;
/**
* Created by Weiping Huang at 14:14 on 2017/3/30
* For Personal Open Source
* Contact me at [email protected] or [email protected]
* For more projects: https://github.com/Nightonke
*
* Animation to change text in an instance of TextView.
*/
public class WoWoTextViewTextAnimation extends TextPageAnimation {
public WoWoTextViewTextAnimation(int page, float startOffset, float endOffset, int ease, TimeInterpolator interpolator, boolean useSameEaseEnumBack, String fromText, String toText, Typewriter typewriter) {
super(page, startOffset, endOffset, ease, interpolator, useSameEaseEnumBack, fromText, toText, typewriter);
}
@Override
protected void toStartState(View view) {
setText(view, fromText);
}
@Override
protected void toMiddleState(View view, float offset) {
setText(view, typewriter.type(fromText, toText, offset));
}
@Override
protected void toEndState(View view) {
setText(view, toText);
}
private void setText(View view, String text) {
if (view instanceof TextView) ((TextView) view).setText(text);
else try {
TextView.class.cast(view).setText(text);
} catch (ClassCastException c) {
Log.w(TAG, "View must be an instance of TextView in WoWoTextViewTextAnimation");
}
}
public static Builder builder() {
return new Builder();
}
public static class Builder extends TextPageAnimation.Builder<WoWoTextViewTextAnimation.Builder> {
public WoWoTextViewTextAnimation build() {
checkUninitializedAttributes();
return new WoWoTextViewTextAnimation(page, startOffset, endOffset, ease, interpolator, useSameEaseEnumBack, fromText, toText, typewriter);
}
}
}