[Android] [PATCH 4/8] extract bitmap decoding to AsyncTask
Adrien Maglo
magsoft at videolan.org
Thu Mar 6 10:45:09 CET 2014
Le 04/03/2014 23:33, Yu Lin a écrit :
> ---
> .../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);
> }
I think there may be a synchronization issue here.
Nothing prevent the view v and therefore its holder to be assigned to an
other item before the execution of doInBackground() or onPostExecute().
Best regards,
--
MagSoft
More information about the Android
mailing list