Merge "Bitmapfun Sample: Minor updates/fixes." into klp-docs
This commit is contained in:
Binary file not shown.
@ -160,13 +160,14 @@ a soft reference to the bitmap is placed
|
|||||||
in a {@link java.util.HashSet}, for possible reuse later with
|
in a {@link java.util.HashSet}, for possible reuse later with
|
||||||
{@link android.graphics.BitmapFactory.Options#inBitmap}:
|
{@link android.graphics.BitmapFactory.Options#inBitmap}:
|
||||||
|
|
||||||
<pre>HashSet<SoftReference<Bitmap>> mReusableBitmaps;
|
<pre>Set<SoftReference<Bitmap>> mReusableBitmaps;
|
||||||
private LruCache<String, BitmapDrawable> mMemoryCache;
|
private LruCache<String, BitmapDrawable> mMemoryCache;
|
||||||
|
|
||||||
// If you're running on Honeycomb or newer, create
|
// If you're running on Honeycomb or newer, create a
|
||||||
// a HashSet of references to reusable bitmaps.
|
// synchronized HashSet of references to reusable bitmaps.
|
||||||
if (Utils.hasHoneycomb()) {
|
if (Utils.hasHoneycomb()) {
|
||||||
mReusableBitmaps = new HashSet<SoftReference<Bitmap>>();
|
mReusableBitmaps =
|
||||||
|
Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
mMemoryCache = new LruCache<String, BitmapDrawable>(mCacheParams.memCacheSize) {
|
mMemoryCache = new LruCache<String, BitmapDrawable>(mCacheParams.memCacheSize) {
|
||||||
@ -243,25 +244,27 @@ protected Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) {
|
|||||||
Bitmap bitmap = null;
|
Bitmap bitmap = null;
|
||||||
|
|
||||||
if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
|
if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
|
||||||
final Iterator<SoftReference<Bitmap>> iterator
|
synchronized (mReusableBitmaps) {
|
||||||
= mReusableBitmaps.iterator();
|
final Iterator<SoftReference<Bitmap>> iterator
|
||||||
Bitmap item;
|
= mReusableBitmaps.iterator();
|
||||||
|
Bitmap item;
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
item = iterator.next().get();
|
item = iterator.next().get();
|
||||||
|
|
||||||
if (null != item && item.isMutable()) {
|
if (null != item && item.isMutable()) {
|
||||||
// Check to see it the item can be used for inBitmap.
|
// Check to see it the item can be used for inBitmap.
|
||||||
if (canUseForInBitmap(item, options)) {
|
if (canUseForInBitmap(item, options)) {
|
||||||
bitmap = item;
|
bitmap = item;
|
||||||
|
|
||||||
// Remove from reusable set so it can't be used again.
|
// Remove from reusable set so it can't be used again.
|
||||||
|
iterator.remove();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Remove from the set if the reference has been cleared.
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Remove from the set if the reference has been cleared.
|
|
||||||
iterator.remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user