[Android] [PATCH 5/8] extract bitmap decoding to AsyncTask
Yu Lin
yu.lin.86 at gmail.com
Tue Mar 4 23:33:43 CET 2014
---
.../vlc/gui/audio/widget/CoverMediaSwitcher.java | 24 ++++++++++++++-----
1 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/widget/CoverMediaSwitcher.java b/vlc-android/src/org/videolan/vlc/gui/audio/widget/CoverMediaSwitcher.java
index 2aa78ab..aa2a65b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/widget/CoverMediaSwitcher.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/widget/CoverMediaSwitcher.java
@@ -27,6 +27,7 @@ import org.videolan.vlc.widget.AudioMediaSwitcher;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.os.AsyncTask;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@@ -37,12 +38,21 @@ public class CoverMediaSwitcher extends AudioMediaSwitcher {
}
protected void addMediaView(LayoutInflater inflater, String title, String artist, Bitmap cover) {
- AnimatedCoverView coverView = new AnimatedCoverView(inflater.getContext(), null);
-
- if (cover == null)
- cover = BitmapFactory.decodeResource(getResources(), R.drawable.cone);
- coverView.setImageBitmap(cover);
-
- addView(coverView);
+ final AnimatedCoverView coverView = new AnimatedCoverView(inflater.getContext(), null);
+
+ new AsyncTask<Bitmap, Void, Bitmap>() {
+ protected Bitmap doInBackground(Bitmap... args) {
+ Bitmap cover = args[0];
+ if (cover == null)
+ cover = BitmapFactory.decodeResource(getResources(), R.drawable.cone);
+ return cover;
+ }
+
+ protected void onPostExecute(Bitmap cover) {
+ coverView.setImageBitmap(cover);
+
+ addView(coverView);
+ }
+ }.execute(cover);
}
}
--
1.7.4.4
More information about the Android
mailing list