[Android] Add bitmap caching to AudioPlaylistAdapter
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:13:36 2012 +0200| [4f3487602b5a8cb3c41e6b5bb1c7b6762c612778] | committer: Ludovic Fauvet
Add bitmap caching to AudioPlaylistAdapter
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=4f3487602b5a8cb3c41e6b5bb1c7b6762c612778
---
.../vlc/gui/audio/AudioPlaylistAdapter.java | 27 +++++++++++++++++---
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java
index 5bd938d..59a92a5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java
@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+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 AudioPlaylistAdapter extends BaseExpandableListAdapter {
private ArrayList<String> mTitles;
private HashMap<String, ArrayList<String>> mSubTitles;
private HashMap<String, HashMap<String, ArrayList<Media>>> mGroups;
- private Bitmap mDefaultCover;
public AudioPlaylistAdapter(Context context, int groupTextId, int childTextId) {
mContext = context;
@@ -58,7 +58,6 @@ public class AudioPlaylistAdapter extends BaseExpandableListAdapter {
mTitles = new ArrayList<String>();
mSubTitles = new HashMap<String, ArrayList<String>>();
mGroups = new HashMap<String, HashMap<String, ArrayList<Media>>>();
- mDefaultCover = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);
}
public void add(String title, String subtitle, Media media) {
@@ -171,7 +170,17 @@ public class AudioPlaylistAdapter extends BaseExpandableListAdapter {
Resources res = mContext.getResources();
Bitmap cover = AudioUtil.getCover(v.getContext(), list.get(0), 64);
- holder.cover.setImageBitmap(cover != null ? cover : mDefaultCover);
+
+ if (cover == null) {
+ BitmapCache cache = BitmapCache.getInstance();
+ cover = cache.getBitmapFromMemCache(R.drawable.icon);
+ if (cover == null) {
+ cover = BitmapFactory.decodeResource(v.getResources(), R.drawable.icon);
+ cache.addBitmapToMemCache(R.drawable.icon, cover);
+ }
+ }
+
+ holder.cover.setImageBitmap(cover);
Util.setItemBackground(holder.layout, groupPosition);
holder.title.setText(name);
@@ -212,7 +221,17 @@ public class AudioPlaylistAdapter extends BaseExpandableListAdapter {
Resources res = mContext.getResources();
Bitmap cover = AudioUtil.getCover(v.getContext(), list.get(0), 64);
- holder.cover.setImageBitmap(cover != null ? cover : mDefaultCover);
+
+ if (cover == null) {
+ BitmapCache cache = BitmapCache.getInstance();
+ cover = cache.getBitmapFromMemCache(R.drawable.icon);
+ if (cover == null) {
+ cover = BitmapFactory.decodeResource(v.getResources(), R.drawable.icon);
+ cache.addBitmapToMemCache(R.drawable.icon, cover);
+ }
+ }
+
+ holder.cover.setImageBitmap(cover);
Util.setItemBackground(holder.layout, childPosition);
if (name != null)
More information about the Android
mailing list