26
26
import android .app .Activity ;
27
27
import android .graphics .Color ;
28
28
import android .graphics .Path ;
29
+ import android .graphics .drawable .ClipDrawable ;
29
30
import android .os .Bundle ;
31
+ import android .os .Handler ;
30
32
import android .text .Layout ;
31
33
import android .util .TypedValue ;
34
+ import android .view .Gravity ;
32
35
import android .widget .Button ;
33
36
import android .widget .EditText ;
34
37
import android .widget .ImageView ;
35
38
import com .example .textdrawable .drawable .TextDrawable ;
36
39
37
- public class MyActivity extends Activity {
40
+ public class MyActivity extends Activity implements Runnable {
38
41
//Row One
39
42
ImageView mImageOne , mImageTwo ;
40
43
//Row Two
41
44
ImageView mImageThree , mImageFour ;
42
45
//Row Three
43
- EditText mEditText ;
46
+ ImageView mImageFive ;
44
47
//Row Four
48
+ EditText mEditText ;
49
+ //Row Five
45
50
Button mButton ;
46
51
47
52
@ Override
@@ -53,12 +58,37 @@ public void onCreate(Bundle savedInstanceState) {
53
58
mImageTwo = (ImageView ) findViewById (R .id .image2 );
54
59
mImageThree = (ImageView ) findViewById (R .id .image3 );
55
60
mImageFour = (ImageView ) findViewById (R .id .image4 );
61
+ mImageFive = (ImageView ) findViewById (R .id .image5 );
56
62
mEditText = (EditText ) findViewById (R .id .edittext1 );
57
63
mButton = (Button ) findViewById (R .id .button1 );
58
64
59
65
loadDrawables ();
60
66
}
61
67
68
+ @ Override
69
+ protected void onResume () {
70
+ super .onResume ();
71
+ //Start the animation
72
+ mAnimator .post (this );
73
+ }
74
+
75
+ @ Override
76
+ protected void onPause () {
77
+ super .onPause ();
78
+ //Stop the animation
79
+ mAnimator .removeCallbacksAndMessages (null );
80
+ }
81
+
82
+ private Handler mAnimator = new Handler ();
83
+ private int mLevel = 0 ;
84
+ @ Override
85
+ public void run () {
86
+ mLevel = (mLevel += 25 ) % 10000 ;
87
+ mImageFive .setImageLevel (mLevel );
88
+
89
+ mAnimator .postDelayed (this , 10 );
90
+ }
91
+
62
92
private void loadDrawables () {
63
93
/*
64
94
* Create a simple TextDrawable with all default settings.
@@ -105,6 +135,16 @@ private void loadDrawables() {
105
135
mImageThree .setImageDrawable (d );
106
136
mImageFour .setImageDrawable (d );
107
137
138
+ /*
139
+ * Wrap a simple TextDrawable in a ClipDrawable to animate. One convenient
140
+ * advantage of ImageView is we can call setLevel() on the view itself to affect
141
+ * the Drawable content.
142
+ */
143
+ d = new TextDrawable (this );
144
+ d .setText ("SHOW ME TEXT" );
145
+ ClipDrawable clip = new ClipDrawable (d , Gravity .LEFT , ClipDrawable .HORIZONTAL );
146
+ mImageFive .setImageDrawable (clip );
147
+
108
148
/*
109
149
* Construct a simple TextDrawable to act as a static prefix
110
150
* inside of an EditText element
0 commit comments