From 5fcd77231883b4af6707e635ba0dda952a454452 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 29 Jan 2015 14:52:32 -0800 Subject: Change to only keep small unknown images, otherwise we can get a full cache of only large unknown images which results in a stack overflow --- src/github/daneren2005/dsub/util/ImageLoader.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/util/ImageLoader.java b/src/github/daneren2005/dsub/util/ImageLoader.java index 9c87312a..e8201a33 100644 --- a/src/github/daneren2005/dsub/util/ImageLoader.java +++ b/src/github/daneren2005/dsub/util/ImageLoader.java @@ -73,6 +73,14 @@ public class ImageLoader { handler = new Handler(Looper.getMainLooper()); final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); final int cacheSize = maxMemory / 4; + + // Determine the density-dependent image sizes. + imageSizeDefault = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); + DisplayMetrics metrics = context.getResources().getDisplayMetrics(); + imageSizeLarge = Math.round(Math.min(metrics.widthPixels, metrics.heightPixels)); + avatarSizeDefault = context.getResources().getDrawable(R.drawable.ic_social_person).getIntrinsicHeight(); + + final String UNKOWN_KEEP_PART = getKey("unknown", imageSizeDefault); cache = new LruCache(cacheSize) { @Override protected int sizeOf(String key, Bitmap bitmap) { @@ -82,7 +90,7 @@ public class ImageLoader { @Override protected void entryRemoved(boolean evicted, String key, Bitmap oldBitmap, Bitmap newBitmap) { if(evicted) { - if(oldBitmap != nowPlaying && key.indexOf("unknown") == -1 || clearingCache) { + if(oldBitmap != nowPlaying && key.indexOf(UNKOWN_KEEP_PART) == -1 || clearingCache) { if(sizeOf("", oldBitmap) > 500) { oldBitmap.recycle(); } @@ -92,12 +100,6 @@ public class ImageLoader { } } }; - - // Determine the density-dependent image sizes. - imageSizeDefault = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); - DisplayMetrics metrics = context.getResources().getDisplayMetrics(); - imageSizeLarge = Math.round(Math.min(metrics.widthPixels, metrics.heightPixels)); - avatarSizeDefault = context.getResources().getDrawable(R.drawable.ic_social_person).getIntrinsicHeight(); } public void clearCache() { -- cgit v1.2.3