2626import android .app .Activity ;
2727import android .graphics .Color ;
2828import android .graphics .Path ;
29+ import android .graphics .drawable .ClipDrawable ;
2930import android .os .Bundle ;
31+ import android .os .Handler ;
3032import android .text .Layout ;
3133import android .util .TypedValue ;
34+ import android .view .Gravity ;
3235import android .widget .Button ;
3336import android .widget .EditText ;
3437import android .widget .ImageView ;
3538import com .example .textdrawable .drawable .TextDrawable ;
3639
37- public class MyActivity extends Activity {
40+ public class MyActivity extends Activity implements Runnable {
3841 //Row One
3942 ImageView mImageOne , mImageTwo ;
4043 //Row Two
4144 ImageView mImageThree , mImageFour ;
4245 //Row Three
43- EditText mEditText ;
46+ ImageView mImageFive ;
4447 //Row Four
48+ EditText mEditText ;
49+ //Row Five
4550 Button mButton ;
4651
4752 @ Override
@@ -53,12 +58,37 @@ public void onCreate(Bundle savedInstanceState) {
5358 mImageTwo = (ImageView ) findViewById (R .id .image2 );
5459 mImageThree = (ImageView ) findViewById (R .id .image3 );
5560 mImageFour = (ImageView ) findViewById (R .id .image4 );
61+ mImageFive = (ImageView ) findViewById (R .id .image5 );
5662 mEditText = (EditText ) findViewById (R .id .edittext1 );
5763 mButton = (Button ) findViewById (R .id .button1 );
5864
5965 loadDrawables ();
6066 }
6167
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+
6292 private void loadDrawables () {
6393 /*
6494 * Create a simple TextDrawable with all default settings.
@@ -105,6 +135,16 @@ private void loadDrawables() {
105135 mImageThree .setImageDrawable (d );
106136 mImageFour .setImageDrawable (d );
107137
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+
108148 /*
109149 * Construct a simple TextDrawable to act as a static prefix
110150 * inside of an EditText element
0 commit comments