[Android] No need to pass View as param of getFromResource

Geoffrey Métais git at videolan.org
Mon Sep 7 14:29:23 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Sep  7 13:34:57 2015 +0200| [9b6be8c8a41e91fb6c006defeb50f3c72fa1a4f8] | committer: Geoffrey Métais

No need to pass View as param of getFromResource

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

 .../src/org/videolan/vlc/gui/video/VideoListAdapter.java      |    4 ++--
 vlc-android/src/org/videolan/vlc/util/BitmapCache.java        |    9 +++++----
 2 files changed, 7 insertions(+), 6 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 b5c5194..5046023 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -183,11 +183,11 @@ public class VideoListAdapter extends ArrayAdapter<MediaWrapper>
         if (thumbnail == null) {
             // missing thumbnail
             holder.binding.setVariable(BR.scaleType, ImageView.ScaleType.CENTER);
-            thumbnail = BitmapCache.getFromResource(v, R.drawable.ic_cone_o);
+            thumbnail = BitmapCache.getFromResource(v.getResources(), R.drawable.ic_cone_o);
         } else if (thumbnail.getWidth() == 1 && thumbnail.getHeight() == 1) {
             // dummy thumbnail
             holder.binding.setVariable(BR.scaleType, ImageView.ScaleType.CENTER);
-            thumbnail = BitmapCache.getFromResource(v, R.drawable.ic_cone_o);
+            thumbnail = BitmapCache.getFromResource(v.getResources(), R.drawable.ic_cone_o);
         } else
             holder.binding.setVariable(BR.scaleType, ImageView.ScaleType.FIT_CENTER);
 
diff --git a/vlc-android/src/org/videolan/vlc/util/BitmapCache.java b/vlc-android/src/org/videolan/vlc/util/BitmapCache.java
index 4fe0324..35bdbf8 100644
--- a/vlc-android/src/org/videolan/vlc/util/BitmapCache.java
+++ b/vlc-android/src/org/videolan/vlc/util/BitmapCache.java
@@ -23,12 +23,12 @@ package org.videolan.vlc.util;
 import android.annotation.TargetApi;
 import android.app.ActivityManager;
 import android.content.Context;
+import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.os.Build;
 import android.support.v4.util.LruCache;
 import android.util.Log;
-import android.view.View;
 
 import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.vlc.VLCApplication;
@@ -136,14 +136,15 @@ public class BitmapCache {
         mCachedBitmaps.clear();
     }
 
-    public static Bitmap getFromResource(View v, int resId) {
+    public static Bitmap getFromResource(Resources res, int resId) {
         BitmapCache cache = BitmapCache.getInstance();
         Bitmap bitmap = cache.getBitmapFromMemCache(resId);
         if (bitmap == null) {
             BitmapFactory.Options options = new BitmapFactory.Options();
             BitmapUtil.setInBitmap(options);
-            options.inMutable = true;
-            bitmap = BitmapFactory.decodeResource(v.getResources(), resId, options);
+            if (AndroidUtil.isHoneycombOrLater())
+                options.inMutable = true;
+            bitmap = BitmapFactory.decodeResource(res, resId, options);
             cache.addBitmapToMemCache(resId, bitmap);
         }
         return bitmap;



More information about the Android mailing list