[Android] Add bitmap caching to VideoListAdapter

Ludovic Fauvet git at videolan.org
Mon Oct 15 19:16:55 CEST 2012


vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Mon Oct 15 19:12:35 2012 +0200| [ab83bd0b97da9d9609f86c7434d43b40c0066c3c] | committer: Ludovic Fauvet

Add bitmap caching to VideoListAdapter

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=ab83bd0b97da9d9609f86c7434d43b40c0066c3c
---

 .../src/org/videolan/vlc/gui/video/VideoListAdapter.java   |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 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 bf0c2f6..14f13dd 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -23,6 +23,7 @@ package org.videolan.vlc.gui.video;
 import java.util.Comparator;
 import java.util.HashMap;
 
+import org.videolan.vlc.BitmapCache;
 import org.videolan.vlc.Media;
 import org.videolan.vlc.R;
 import org.videolan.vlc.Util;
@@ -48,7 +49,6 @@ public class VideoListAdapter extends ArrayAdapter<Media>
     private int mSortDirection = 1;
     private int mSortBy = SORT_BY_TITLE;
     private boolean mListMode = false;
-    private static Bitmap mDefaultThumbnail;
 
     public VideoListAdapter(Context context) {
         super(context, 0);
@@ -154,11 +154,13 @@ public class VideoListAdapter extends ArrayAdapter<Media>
             holder.thumbnail.setImageBitmap(thumbnail);
         } else {
             // set default thumbnail
-            if (mDefaultThumbnail == null) {
-                mDefaultThumbnail = BitmapFactory.decodeResource(
-                        v.getResources(), R.drawable.thumbnail);
+            BitmapCache cache = BitmapCache.getInstance();
+            Bitmap bitmap = cache.getBitmapFromMemCache(R.drawable.thumbnail);
+            if (bitmap == null) {
+                bitmap = BitmapFactory.decodeResource(v.getResources(), R.drawable.thumbnail);
+                cache.addBitmapToMemCache(R.drawable.thumbnail, bitmap);
             }
-            holder.thumbnail.setImageBitmap(mDefaultThumbnail);
+            holder.thumbnail.setImageBitmap(bitmap);
         }
 
         ColorStateList titleColor = v.getResources().getColorStateList(R.color.list_title);



More information about the Android mailing list