summaryrefslogtreecommitdiff
path: root/src/de/podfetcher/asynctask
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-07-06 15:55:20 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-07-06 15:55:20 +0200
commitac755c889975bdc28f5f6ddb121055f83ba556b6 (patch)
treea7fc6761dfef247b5142d197a01f3478b4572850 /src/de/podfetcher/asynctask
parent7b86821cd83d8051da0a1fd2777d33837b1fa325 (diff)
downloadAntennaPod-ac755c889975bdc28f5f6ddb121055f83ba556b6.zip
OutOfMemory Error seems to be fixed
Diffstat (limited to 'src/de/podfetcher/asynctask')
-rw-r--r--src/de/podfetcher/asynctask/FeedImageLoader.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/de/podfetcher/asynctask/FeedImageLoader.java b/src/de/podfetcher/asynctask/FeedImageLoader.java
index 9ffd2b9c9..8fcc5bdc6 100644
--- a/src/de/podfetcher/asynctask/FeedImageLoader.java
+++ b/src/de/podfetcher/asynctask/FeedImageLoader.java
@@ -1,8 +1,11 @@
package de.podfetcher.asynctask;
+import de.podfetcher.PodcastApp;
import de.podfetcher.R;
import de.podfetcher.feed.FeedImage;
import android.annotation.SuppressLint;
+import android.app.ActivityManager;
+import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
@@ -12,17 +15,24 @@ import android.widget.ImageView;
/** Caches and loads FeedImage bitmaps in the background */
public class FeedImageLoader {
+ private static final String TAG = "FeedImageLoader";
private static FeedImageLoader singleton;
/**
* Stores references to loaded bitmaps. Bitmaps can be accessed by the id of
* the FeedImage the bitmap belongs to.
*/
+
+ final int memClass = ((ActivityManager) PodcastApp.getInstance()
+ .getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
+
+ // Use 1/8th of the available memory for this memory cache.
+ final int cacheSize = 1024 * 1024 * memClass / 8;
private LruCache<Long, Bitmap> imageCache;
- private static final int CACHE_SIZE = 4 * 1024 * 1024;
private FeedImageLoader() {
- imageCache = new LruCache<Long, Bitmap>(CACHE_SIZE) {
+ Log.d(TAG, "Creating cache with size " + cacheSize);
+ imageCache = new LruCache<Long, Bitmap>(cacheSize) {
@SuppressLint("NewApi")
@Override
@@ -63,6 +73,14 @@ public class FeedImageLoader {
imageCache.put(id, bitmap);
}
+ public void wipeImageCache() {
+ imageCache.evictAll();
+ }
+
+ public boolean isInCache(FeedImage image) {
+ return imageCache.get(image.getId()) != null;
+ }
+
public Bitmap getBitmapFromCache(long id) {
return imageCache.get(id);
}