[Android] [PATCH 6/8] extract bitmap decoding to AsyncTask
Yu Lin
yu.lin.86 at gmail.com
Tue Mar 4 23:33:44 CET 2014
---
.../videolan/vlc/gui/video/VideoListAdapter.java | 67 +++++++++++++-------
1 files changed, 44 insertions(+), 23 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index b817c2f..c6a5ff1 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -33,6 +33,7 @@ import org.videolan.vlc.Util;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
+import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@@ -167,29 +168,8 @@ public class VideoListAdapter extends ArrayAdapter<Media>
Media media = getItem(position);
- /* Thumbnail */
- Bitmap thumbnail = Util.getPictureFromCache(media);
- if (thumbnail == null) {
- // missing thumbnail
- thumbnail = BitmapCache.GetFromResource(v, R.drawable.thumbnail);
- }
- else if (thumbnail.getWidth() == 1 && thumbnail.getHeight() == 1) {
- // dummy thumbnail
- thumbnail = BitmapCache.GetFromResource(v, R.drawable.icon);
- }
- //FIXME Warning: the thumbnails are upscaled in the grid view!
- holder.thumbnail.setImageBitmap(thumbnail);
-
- /* Color state */
- ColorStateList titleColor = v.getResources().getColorStateList(
- Util.getResourceFromAttribute(mContext, R.attr.list_title));
- holder.title.setTextColor(titleColor);
-
- if (media instanceof MediaGroup)
- fillGroupView(holder, media);
- else
- fillVideoView(holder, media);
-
+ GetThumbnail task = new GetThumbnail(holder, v, media);
+ task.execute();
return v;
}
@@ -246,4 +226,45 @@ public class VideoListAdapter extends ArrayAdapter<Media>
public boolean isListMode() {
return mListMode;
}
+
+ class GetThumbnail extends AsyncTask<Void, Void, Bitmap> {
+ ViewHolder holder;
+ View v;
+ Media media;
+
+ GetThumbnail(ViewHolder holder, View v, Media media) {
+ this.holder = holder;
+ this.v = v;
+ this.media = media;
+ }
+
+ protected Bitmap doInBackground(Void... args) {
+ /* Thumbnail */
+ Bitmap thumbnail = Util.getPictureFromCache(media);
+ if (thumbnail == null) {
+ // missing thumbnail
+ thumbnail = BitmapCache.GetFromResource(v, R.drawable.thumbnail);
+ }
+ else if (thumbnail.getWidth() == 1 && thumbnail.getHeight() == 1) {
+ // dummy thumbnail
+ thumbnail = BitmapCache.GetFromResource(v, R.drawable.icon);
+ }
+ return thumbnail;
+ }
+
+ protected void onPostExecute(Bitmap thumbnail) {
+ //FIXME Warning: the thumbnails are upscaled in the grid view!
+ holder.thumbnail.setImageBitmap(thumbnail);
+
+ /* Color state */
+ ColorStateList titleColor = v.getResources().getColorStateList(
+ Util.getResourceFromAttribute(mContext, R.attr.list_title));
+ holder.title.setTextColor(titleColor);
+
+ if (media instanceof MediaGroup)
+ fillGroupView(holder, media);
+ else
+ fillVideoView(holder, media);
+ }
+ }
}
--
1.7.4.4
More information about the Android
mailing list