[Android] [PATCH 4/8] extract bitmap decoding to AsyncTask

Yu Lin yu.lin.86 at gmail.com
Tue Mar 4 23:33:42 CET 2014


---
 .../vlc/gui/audio/AudioBrowserListAdapter.java     |   21 ++++++++++++++++---
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
index f477492..4961ac7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
@@ -31,6 +31,7 @@ import org.videolan.vlc.R;
 
 import android.content.Context;
 import android.graphics.Bitmap;
+import android.os.AsyncTask;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -204,10 +205,22 @@ public class AudioBrowserListAdapter extends BaseAdapter {
         RelativeLayout.LayoutParams paramsCover;
         if (mItemType == ITEM_WITH_COVER) {
             Media media = mItems.get(position).mMediaList.get(0);
-            Bitmap cover = AudioUtil.getCover(v.getContext(), media, 64);
-            if (cover == null)
-                cover = BitmapCache.GetFromResource(v, R.drawable.icon);
-            holder.cover.setImageBitmap(cover);
+            new AsyncTask<Object, Void, Bitmap>() {
+                ViewHolder holder;
+                protected Bitmap doInBackground(Object... args) {
+                    View v = (View) args[0];
+                    Media media = (Media) args[1];
+                    this.holder = (ViewHolder) args[2];
+                    Bitmap cover = AudioUtil.getCover(v.getContext(), media, 64);
+                    if (cover == null)
+                        cover = BitmapCache.GetFromResource(v, R.drawable.icon);
+                    return cover;
+                }
+
+                protected void onPostExecute(Bitmap cover) {
+                    holder.cover.setImageBitmap(cover);
+                }
+            }.execute(v, media, holder);
             int size = (int) mContext.getResources().getDimension(R.dimen.audio_browser_item_size);
             paramsCover = new RelativeLayout.LayoutParams(size, size);
         }
-- 
1.7.4.4



More information about the Android mailing list