diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-01-29 14:52:32 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-01-29 14:52:32 -0800 |
commit | 5fcd77231883b4af6707e635ba0dda952a454452 (patch) | |
tree | 9f2d32dbb58da5db71c328ee519038d5d719f2fa /src | |
parent | 1b19d2ca62f49ee94b4790584d9fe6b44fb86db4 (diff) | |
download | dsub-5fcd77231883b4af6707e635ba0dda952a454452.tar.gz dsub-5fcd77231883b4af6707e635ba0dda952a454452.tar.bz2 dsub-5fcd77231883b4af6707e635ba0dda952a454452.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/github/daneren2005/dsub/util/ImageLoader.java | 16 |
1 files changed, 9 insertions, 7 deletions
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<String, Bitmap>(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() { |