[Android] BitmapUtil: seperate bitmap getters
Thomas Guillem
git at videolan.org
Tue Oct 6 18:32:34 CEST 2015
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Oct 6 17:31:30 2015 +0200| [1a9d81618901987fa77e46b1e19673aff1ae5a8f] | committer: Thomas Guillem
BitmapUtil: seperate bitmap getters
getBitmapFromMemCache can be called from UI, but not getPicture or fetchPicture
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=1a9d81618901987fa77e46b1e19673aff1ae5a8f
---
vlc-android/src/org/videolan/vlc/MediaGroup.java | 2 +-
vlc-android/src/org/videolan/vlc/Thumbnailer.java | 2 +-
.../videolan/vlc/gui/SearchSuggestionsAdapter.java | 2 +-
.../src/org/videolan/vlc/util/BitmapUtil.java | 36 ++++++++++++--------
.../src/org/videolan/vlc/gui/tv/CardPresenter.java | 2 +-
.../vlc/gui/tv/RecommendationsService.java | 2 +-
6 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/MediaGroup.java b/vlc-android/src/org/videolan/vlc/MediaGroup.java
index 3453402..355f713 100644
--- a/vlc-android/src/org/videolan/vlc/MediaGroup.java
+++ b/vlc-android/src/org/videolan/vlc/MediaGroup.java
@@ -39,7 +39,7 @@ public class MediaGroup extends MediaWrapper {
media.getTime(),
media.getLength(),
MediaWrapper.TYPE_GROUP,
- BitmapUtil.getPictureFromCache(media),
+ BitmapUtil.getPicture(media),
media.getTitle(),
media.getArtist(),
media.getGenre(),
diff --git a/vlc-android/src/org/videolan/vlc/Thumbnailer.java b/vlc-android/src/org/videolan/vlc/Thumbnailer.java
index 57c7367..64c3db8 100644
--- a/vlc-android/src/org/videolan/vlc/Thumbnailer.java
+++ b/vlc-android/src/org/videolan/vlc/Thumbnailer.java
@@ -108,7 +108,7 @@ public class Thumbnailer implements Runnable {
* @param item media wrapper of the file browser item.
*/
public void addJob(MediaWrapper item) {
- if(BitmapUtil.getPictureFromCache(item) != null || item.isPictureParsed())
+ if(BitmapUtil.getPicture(item) != null || item.isPictureParsed())
return;
lock.lock();
try {
diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchSuggestionsAdapter.java b/vlc-android/src/org/videolan/vlc/gui/SearchSuggestionsAdapter.java
index 7d339ea..4c111be 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SearchSuggestionsAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SearchSuggestionsAdapter.java
@@ -91,7 +91,7 @@ public class SearchSuggestionsAdapter extends CursorAdapter {
if (mw.getType() == MediaWrapper.TYPE_AUDIO)
artwork = AudioUtil.getCover(context, mw, context.getResources().getDimensionPixelSize(R.dimen.audio_browser_item_size));
else if (mw.getType() == MediaWrapper.TYPE_VIDEO)
- artwork = BitmapUtil.getPictureFromCache(mw);
+ artwork = BitmapUtil.getPicture(mw);
else
artwork = null;
if (artwork != null) {
diff --git a/vlc-android/src/org/videolan/vlc/util/BitmapUtil.java b/vlc-android/src/org/videolan/vlc/util/BitmapUtil.java
index 8f2f8d2..89ef3c1 100644
--- a/vlc-android/src/org/videolan/vlc/util/BitmapUtil.java
+++ b/vlc-android/src/org/videolan/vlc/util/BitmapUtil.java
@@ -90,25 +90,33 @@ public class BitmapUtil {
// mPicture is not null only if passed through
// the ctor which is deprecated by now.
Bitmap b = media.getPicture();
- if(b == null) {
- BitmapCache cache = BitmapCache.getInstance();
- Bitmap picture = cache.getBitmapFromMemCache(media.getLocation());
- if(picture == null) {
- /* Not in memcache:
- * serving the file from the database and
- * adding it to the memcache for later use.
- */
- picture = readCoverBitmap(media.getArtworkURL());
- if (picture == null)
- picture = MediaDatabase.getInstance().getPicture(media.getUri());
- cache.addBitmapToMemCache(media.getLocation(), picture);
- }
- return picture;
+ if (b == null) {
+ final BitmapCache cache = BitmapCache.getInstance();
+ return cache.getBitmapFromMemCache(media.getLocation());
} else {
return b;
}
}
+ public static Bitmap fetchPicture(MediaWrapper media) {
+ final BitmapCache cache = BitmapCache.getInstance();
+
+ Bitmap picture = readCoverBitmap(media.getArtworkURL());
+ if (picture == null) {
+ picture = MediaDatabase.getInstance().getPicture(media.getUri());
+ }
+ cache.addBitmapToMemCache(media.getLocation(), picture);
+ return picture;
+ }
+
+ public static Bitmap getPicture(MediaWrapper media) {
+ final Bitmap picture = getPictureFromCache(media);
+ if (picture != null)
+ return picture;
+ else
+ return fetchPicture(media);
+ }
+
private static Bitmap readCoverBitmap(String path) {
if (path == null)
return null;
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/CardPresenter.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/CardPresenter.java
index 9b2e5fd..58149cf 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/CardPresenter.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/CardPresenter.java
@@ -183,7 +183,7 @@ public class CardPresenter extends Presenter {
if (picture == null)
picture = BitmapFactory.decodeResource(mRes, R.drawable.ic_browser_audio_big_normal);
} else if (mediaWrapper.getType() == mediaWrapper.TYPE_VIDEO) {
- picture = BitmapUtil.getPictureFromCache(mediaWrapper);
+ picture = BitmapUtil.getPicture(mediaWrapper);
if (picture == null)
picture = BitmapFactory.decodeResource(mRes, R.drawable.ic_browser_video_big_normal);
} else if (mediaWrapper.getType() == mediaWrapper.TYPE_DIR)
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/RecommendationsService.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/RecommendationsService.java
index 0a1924a..03a4b1b 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/RecommendationsService.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/RecommendationsService.java
@@ -96,7 +96,7 @@ public class RecommendationsService extends IntentService {
.setOngoing(true)
.setColor(mContext.getResources().getColor(R.color.orange800))
.setCategory("recommendation")
- .setLargeIcon(BitmapUtil.getPictureFromCache(movie))
+ .setLargeIcon(BitmapUtil.getPicture(movie))
.setSmallIcon(R.drawable.icon)
.setContentIntent(buildPendingIntent(movie, id))
).build();
More information about the Android
mailing list