Merge "Bitmapfun Sample: Minor updates/fixes." into klp-docs
diff --git a/docs/downloads/training/BitmapFun.zip b/docs/downloads/training/BitmapFun.zip
index 8668897..d3dd02a 100644
--- a/docs/downloads/training/BitmapFun.zip
+++ b/docs/downloads/training/BitmapFun.zip
Binary files differ
diff --git a/docs/html/training/displaying-bitmaps/manage-memory.jd b/docs/html/training/displaying-bitmaps/manage-memory.jd
index 0e1279e..7f2b4c5 100644
--- a/docs/html/training/displaying-bitmaps/manage-memory.jd
+++ b/docs/html/training/displaying-bitmaps/manage-memory.jd
@@ -160,13 +160,14 @@
in a {@link java.util.HashSet}, for possible reuse later with
{@link android.graphics.BitmapFactory.Options#inBitmap}:
-<pre>HashSet<SoftReference<Bitmap>> mReusableBitmaps;
+<pre>Set<SoftReference<Bitmap>> mReusableBitmaps;
private LruCache<String, BitmapDrawable> mMemoryCache;
-// If you're running on Honeycomb or newer, create
-// a HashSet of references to reusable bitmaps.
+// If you're running on Honeycomb or newer, create a
+// synchronized HashSet of references to reusable bitmaps.
if (Utils.hasHoneycomb()) {
- mReusableBitmaps = new HashSet<SoftReference<Bitmap>>();
+ mReusableBitmaps =
+ Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>());
}
mMemoryCache = new LruCache<String, BitmapDrawable>(mCacheParams.memCacheSize) {
@@ -243,25 +244,27 @@
Bitmap bitmap = null;
if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
- final Iterator<SoftReference<Bitmap>> iterator
- = mReusableBitmaps.iterator();
- Bitmap item;
+ synchronized (mReusableBitmaps) {
+ final Iterator<SoftReference<Bitmap>> iterator
+ = mReusableBitmaps.iterator();
+ Bitmap item;
- while (iterator.hasNext()) {
- item = iterator.next().get();
+ while (iterator.hasNext()) {
+ item = iterator.next().get();
- if (null != item && item.isMutable()) {
- // Check to see it the item can be used for inBitmap.
- if (canUseForInBitmap(item, options)) {
- bitmap = item;
+ if (null != item && item.isMutable()) {
+ // Check to see it the item can be used for inBitmap.
+ if (canUseForInBitmap(item, options)) {
+ 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();
- break;
}
- } else {
- // Remove from the set if the reference has been cleared.
- iterator.remove();
}
}
}