From 5ca50aeebed46905b07aa1dc7c1c9949a3f73ef4 Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Tue, 2 Feb 2016 15:28:25 +0100 Subject: [PATCH] Bind lru cache size to device memory --- src/ch/blinkenlights/android/vanilla/LazyCoverView.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ch/blinkenlights/android/vanilla/LazyCoverView.java b/src/ch/blinkenlights/android/vanilla/LazyCoverView.java index 78a85f9f..b5ddbc4e 100644 --- a/src/ch/blinkenlights/android/vanilla/LazyCoverView.java +++ b/src/ch/blinkenlights/android/vanilla/LazyCoverView.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Adrian Ulrich + * Copyright (C) 2015-2016 Adrian Ulrich * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,6 +17,7 @@ package ch.blinkenlights.android.vanilla; +import android.app.ActivityManager; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -97,7 +98,10 @@ public class LazyCoverView extends ImageView super(context, attributes); mContext = context; if (sBitmapLruCache == null) { - sBitmapLruCache = new BitmapLruCache(6*1024*1024); + ActivityManager am = (ActivityManager)context.getSystemService(context.ACTIVITY_SERVICE); + int lruSize = am.getMemoryClass() / 10; // use ~10% for LRU + lruSize = lruSize < 2 ? 2 : lruSize; // LRU will always be at least 2MiB + sBitmapLruCache = new BitmapLruCache(lruSize*1024*1024); } if (sFallbackBitmap == null) { sFallbackBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover); @@ -110,7 +114,6 @@ public class LazyCoverView extends ImageView thread.start(); sHandler = new Handler(thread.getLooper(), this); } - } /**