Bind lru cache size to device memory
This commit is contained in:
parent
b8c4e73849
commit
5ca50aeebe
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015 Adrian Ulrich <adrian@blinkenlights.ch>
|
* Copyright (C) 2015-2016 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package ch.blinkenlights.android.vanilla;
|
package ch.blinkenlights.android.vanilla;
|
||||||
|
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
@ -97,7 +98,10 @@ public class LazyCoverView extends ImageView
|
|||||||
super(context, attributes);
|
super(context, attributes);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
if (sBitmapLruCache == null) {
|
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) {
|
if (sFallbackBitmap == null) {
|
||||||
sFallbackBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover);
|
sFallbackBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover);
|
||||||
@ -110,7 +114,6 @@ public class LazyCoverView extends ImageView
|
|||||||
thread.start();
|
thread.start();
|
||||||
sHandler = new Handler(thread.getLooper(), this);
|
sHandler = new Handler(thread.getLooper(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user