summaryrefslogtreecommitdiff
path: root/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.java
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:04:04 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:04:04 -0800
commite943f2fd8e7623ba3ea12bb65294d30446db4174 (patch)
treeeda2f24648d61fb33f3fa754d9fb4b5693517e0c /samples/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.java
parent5c11852110eeb03dc5a69111354b383f98d15336 (diff)
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'samples/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.java')
-rw-r--r--samples/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.java37
1 files changed, 31 insertions, 6 deletions
diff --git a/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.java b/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.java
index eb5712fc9..88f0c1d2f 100644
--- a/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.java
+++ b/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.java
@@ -28,6 +28,7 @@ import android.view.*;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
public class BitmapDecode extends GraphicsActivity {
@@ -47,6 +48,19 @@ public class BitmapDecode extends GraphicsActivity {
private Movie mMovie;
private long mMovieStart;
+ private static byte[] streamToBytes(InputStream is) {
+ ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
+ byte[] buffer = new byte[1024];
+ int len;
+ try {
+ while ((len = is.read(buffer)) >= 0) {
+ os.write(buffer, 0, len);
+ }
+ } catch (java.io.IOException e) {
+ }
+ return os.toByteArray();
+ }
+
public SampleView(Context context) {
super(context);
setFocusable(true);
@@ -87,7 +101,12 @@ public class BitmapDecode extends GraphicsActivity {
mDrawable.setBounds(150, 20, 300, 100);
is = context.getResources().openRawResource(R.drawable.animated_gif);
- mMovie = Movie.decodeStream(is);
+ if (true) {
+ mMovie = Movie.decodeStream(is);
+ } else {
+ byte[] array = streamToBytes(is);
+ mMovie = Movie.decodeByteArray(array, 0, array.length);
+ }
}
@Override protected void onDraw(Canvas canvas) {
@@ -107,11 +126,17 @@ public class BitmapDecode extends GraphicsActivity {
if (mMovieStart == 0) { // first time
mMovieStart = now;
}
- int relTime = (int)((now - mMovieStart) % mMovie.duration());
- mMovie.setTime(relTime);
- mMovie.draw(canvas, getWidth() - mMovie.width(),
- getHeight() - mMovie.height());
- invalidate();
+ if (mMovie != null) {
+ int dur = mMovie.duration();
+ if (dur == 0) {
+ dur = 1000;
+ }
+ int relTime = (int)((now - mMovieStart) % dur);
+ mMovie.setTime(relTime);
+ mMovie.draw(canvas, getWidth() - mMovie.width(),
+ getHeight() - mMovie.height());
+ invalidate();
+ }
}
}
}