[Android] Save composed images in Bitmap Cache

Geoffrey Métais git at videolan.org
Wed Jun 7 13:55:50 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jun  7 13:39:46 2017 +0200| [97830784c4323ec699c39b392f2a90252bbc3018] | committer: Geoffrey Métais

Save composed images in Bitmap Cache

> https://code.videolan.org/videolan/vlc-android/commit/97830784c4323ec699c39b392f2a90252bbc3018
---

 .../src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java |  2 +-
 vlc-android/src/org/videolan/vlc/util/ImageComposer.java   | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java b/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java
index 2cffd5d2d..cbdc9a4b7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java
@@ -137,7 +137,7 @@ public class AsyncImageLoader {
                 return null;
             String artworkUrl = item.getArtworkMrl();
             if (item instanceof MediaGroup)
-                return ImageComposer.composeImage((MediaGroup) item);
+                return ImageComposer.getComposedImage((MediaGroup) item);
             if (!TextUtils.isEmpty(artworkUrl) && artworkUrl.startsWith("http"))
                 return HttpImageLoader.downloadBitmap(artworkUrl);
             return AudioUtil.readCoverBitmap(Uri.decode(item.getArtworkMrl()), width);
diff --git a/vlc-android/src/org/videolan/vlc/util/ImageComposer.java b/vlc-android/src/org/videolan/vlc/util/ImageComposer.java
index 00eb80098..cd032c3f4 100644
--- a/vlc-android/src/org/videolan/vlc/util/ImageComposer.java
+++ b/vlc-android/src/org/videolan/vlc/util/ImageComposer.java
@@ -28,6 +28,7 @@ import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.helpers.AudioUtil;
+import org.videolan.vlc.gui.helpers.BitmapCache;
 import org.videolan.vlc.media.MediaGroup;
 
 public class ImageComposer {
@@ -37,12 +38,23 @@ public class ImageComposer {
     private static final int sImageWidth = VLCApplication.getAppResources().getDimensionPixelSize(VLCApplication.showTvUi() ? R.dimen.tv_grid_card_thumb_width : R.dimen.grid_card_thumb_width);
     private static final int MAX_IMAGES = 4;
 
+    public static Bitmap getComposedImage(MediaGroup group) {
+        BitmapCache bmc = BitmapCache.getInstance();
+        String key = "group:"+group.getTitle();
+        Bitmap composedImage = bmc.getBitmapFromMemCache(key);
+        if (composedImage == null) {
+            composedImage = composeImage(group);
+            if (composedImage != null)
+                bmc.addBitmapToMemCache(key, composedImage);
+        }
+        return composedImage;
+    }
     /**
      * Compose 1 image from combined media thumbnails
      * @param group The MediaGroup instance
      * @return a Bitmap object
      */
-    public static Bitmap composeImage(MediaGroup group) {
+    private static Bitmap composeImage(MediaGroup group) {
         Bitmap[] sourcesImages = new Bitmap[MAX_IMAGES];
         int count = 0, minWidth = Integer.MAX_VALUE, minHeight = Integer.MAX_VALUE;
         for (MediaWrapper media : group.getAll()) {



More information about the Android mailing list