diff options
| author | Christian Mehlmauer <FireFart@gmail.com> | 2010-05-20 21:02:04 +0200 |
|---|---|---|
| committer | Christian Mehlmauer <FireFart@gmail.com> | 2010-06-12 12:13:18 +0200 |
| commit | 62e92d7a2a3fd2798901ec2e7c452ff0e4067163 (patch) | |
| tree | f2e9f60c4735feb3a6e443a15578de58d0fb54d2 /samples/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.java | |
| parent | 4b5c09f29e37c8d07dcba57e4c4da13089a9d63d (diff) | |
Cleaned up Samples by removing unsed imports and variables.
Changed deprecated Config.LOGD to Config.DEBUG
Removed unnecessary whitespaces
Change-Id: I01414dd83eb6f9a41e56762dd7fc00e7f1115039
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.java | 55 |
1 files changed, 28 insertions, 27 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 88f0c1d2f..6a8b54265 100644 --- a/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.java +++ b/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.java @@ -18,36 +18,36 @@ package com.example.android.apis.graphics; import com.example.android.apis.R; -import android.app.Activity; import android.content.Context; import android.graphics.*; import android.graphics.drawable.*; import android.os.Bundle; -import android.view.KeyEvent; import android.view.*; -import java.io.IOException; import java.io.InputStream; import java.io.ByteArrayOutputStream; public class BitmapDecode extends GraphicsActivity { - + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new SampleView(this)); } - + private static class SampleView extends View { private Bitmap mBitmap; private Bitmap mBitmap2; private Bitmap mBitmap3; private Bitmap mBitmap4; private Drawable mDrawable; - + private Movie mMovie; private long mMovieStart; - + + //Set to false to use decodeByteArray + private static final boolean DECODE_STREAM = true; + private static byte[] streamToBytes(InputStream is) { ByteArrayOutputStream os = new ByteArrayOutputStream(1024); byte[] buffer = new byte[1024]; @@ -60,33 +60,33 @@ public class BitmapDecode extends GraphicsActivity { } return os.toByteArray(); } - + public SampleView(Context context) { super(context); setFocusable(true); - + java.io.InputStream is; is = context.getResources().openRawResource(R.drawable.beach); - + BitmapFactory.Options opts = new BitmapFactory.Options(); Bitmap bm; - + opts.inJustDecodeBounds = true; bm = BitmapFactory.decodeStream(is, null, opts); - + // now opts.outWidth and opts.outHeight are the dimension of the // bitmap, even though bm is null - + opts.inJustDecodeBounds = false; // this will request the bm opts.inSampleSize = 4; // scaled down by 4 bm = BitmapFactory.decodeStream(is, null, opts); - + mBitmap = bm; - + // decode an image with transparency is = context.getResources().openRawResource(R.drawable.frog); mBitmap2 = BitmapFactory.decodeStream(is); - + // create a deep copy of it using getPixels() into different configs int w = mBitmap2.getWidth(); int h = mBitmap2.getHeight(); @@ -96,32 +96,34 @@ public class BitmapDecode extends GraphicsActivity { Bitmap.Config.ARGB_8888); mBitmap4 = Bitmap.createBitmap(pixels, 0, w, w, h, Bitmap.Config.ARGB_4444); - + mDrawable = context.getResources().getDrawable(R.drawable.button); mDrawable.setBounds(150, 20, 300, 100); - + is = context.getResources().openRawResource(R.drawable.animated_gif); - if (true) { + + if (DECODE_STREAM) { mMovie = Movie.decodeStream(is); } else { byte[] array = streamToBytes(is); mMovie = Movie.decodeByteArray(array, 0, array.length); } } - - @Override protected void onDraw(Canvas canvas) { - canvas.drawColor(0xFFCCCCCC); - + + @Override + protected void onDraw(Canvas canvas) { + canvas.drawColor(0xFFCCCCCC); + Paint p = new Paint(); p.setAntiAlias(true); - + canvas.drawBitmap(mBitmap, 10, 10, null); canvas.drawBitmap(mBitmap2, 10, 170, null); canvas.drawBitmap(mBitmap3, 110, 170, null); canvas.drawBitmap(mBitmap4, 210, 170, null); - + mDrawable.draw(canvas); - + long now = android.os.SystemClock.uptimeMillis(); if (mMovieStart == 0) { // first time mMovieStart = now; @@ -140,4 +142,3 @@ public class BitmapDecode extends GraphicsActivity { } } } - |
