Skip to content

Commit

Permalink
Add animated example.
Browse files Browse the repository at this point in the history
  • Loading branch information
devunwired committed Dec 28, 2012
1 parent 7dad38d commit b6a9aca
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
14 changes: 10 additions & 4 deletions res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,34 @@
<ImageView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_height="100dp"
android:scaleType="center"/>
<ImageView
android:id="@+id/image2"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_height="100dp"
android:scaleType="centerCrop"/>
</TableRow>

<TableRow>
<ImageView
android:id="@+id/image3"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_height="100dp"
android:scaleType="center" />
<ImageView
android:id="@+id/image4"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_height="100dp"
android:scaleType="fitCenter" />
</TableRow>

<ImageView
android:id="@+id/image5"
android:layout_width="match_parent"
android:layout_height="100dp"
android:scaleType="fitCenter" />

<EditText
android:id="@+id/edittext1"
android:layout_width="match_parent"
Expand Down
44 changes: 42 additions & 2 deletions src/com/example/textdrawable/MyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,27 @@
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.drawable.ClipDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.text.Layout;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import com.example.textdrawable.drawable.TextDrawable;

public class MyActivity extends Activity {
public class MyActivity extends Activity implements Runnable {
//Row One
ImageView mImageOne, mImageTwo;
//Row Two
ImageView mImageThree, mImageFour;
//Row Three
EditText mEditText;
ImageView mImageFive;
//Row Four
EditText mEditText;
//Row Five
Button mButton;

@Override
Expand All @@ -53,12 +58,37 @@ public void onCreate(Bundle savedInstanceState) {
mImageTwo = (ImageView) findViewById(R.id.image2);
mImageThree = (ImageView) findViewById(R.id.image3);
mImageFour = (ImageView) findViewById(R.id.image4);
mImageFive = (ImageView) findViewById(R.id.image5);
mEditText = (EditText) findViewById(R.id.edittext1);
mButton = (Button) findViewById(R.id.button1);

loadDrawables();
}

@Override
protected void onResume() {
super.onResume();
//Start the animation
mAnimator.post(this);
}

@Override
protected void onPause() {
super.onPause();
//Stop the animation
mAnimator.removeCallbacksAndMessages(null);
}

private Handler mAnimator = new Handler();
private int mLevel = 0;
@Override
public void run() {
mLevel = (mLevel += 25) % 10000;
mImageFive.setImageLevel(mLevel);

mAnimator.postDelayed(this, 10);
}

private void loadDrawables() {
/*
* Create a simple TextDrawable with all default settings.
Expand Down Expand Up @@ -105,6 +135,16 @@ private void loadDrawables() {
mImageThree.setImageDrawable(d);
mImageFour.setImageDrawable(d);

/*
* Wrap a simple TextDrawable in a ClipDrawable to animate. One convenient
* advantage of ImageView is we can call setLevel() on the view itself to affect
* the Drawable content.
*/
d = new TextDrawable(this);
d.setText("SHOW ME TEXT");
ClipDrawable clip = new ClipDrawable(d, Gravity.LEFT, ClipDrawable.HORIZONTAL);
mImageFive.setImageDrawable(clip);

/*
* Construct a simple TextDrawable to act as a static prefix
* inside of an EditText element
Expand Down

0 comments on commit b6a9aca

Please sign in to comment.