diff options
| author | 2013-11-12 12:01:09 -0800 | |
|---|---|---|
| committer | 2013-11-12 12:01:09 -0800 | |
| commit | dec9cdad734476c8cdbe5948d42e5d9534a5aaf2 (patch) | |
| tree | 5a03a89f583e971d9e2d3ba2aab9df5917ec3079 | |
| parent | d9ef5006ff20275e3ed5048230ed35e7f6a3d93c (diff) | |
| parent | 1d64812a35350692e0a770dcf278fab45ff855c8 (diff) | |
am 1d64812a: am c6a6539c: am e95c167c: Merge "Bitmapfun Sample: Minor updates/fixes." into klp-docs
* commit '1d64812a35350692e0a770dcf278fab45ff855c8':
Bitmapfun Sample: Minor updates/fixes.
| -rw-r--r-- | docs/downloads/training/BitmapFun.zip | bin | 103825 -> 104008 bytes | |||
| -rw-r--r-- | docs/html/training/displaying-bitmaps/manage-memory.jd | 45 |
2 files changed, 24 insertions, 21 deletions
diff --git a/docs/downloads/training/BitmapFun.zip b/docs/downloads/training/BitmapFun.zip Binary files differindex 8668897f9901..d3dd02a5e08f 100644 --- a/docs/downloads/training/BitmapFun.zip +++ b/docs/downloads/training/BitmapFun.zip diff --git a/docs/html/training/displaying-bitmaps/manage-memory.jd b/docs/html/training/displaying-bitmaps/manage-memory.jd index 0e1279e97043..7f2b4c5d2a09 100644 --- a/docs/html/training/displaying-bitmaps/manage-memory.jd +++ b/docs/html/training/displaying-bitmaps/manage-memory.jd @@ -160,13 +160,14 @@ a soft reference to the bitmap is placed 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 @@ protected Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) { Bitmap bitmap = null; if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) { - final Iterator<SoftReference<Bitmap>> iterator - = mReusableBitmaps.iterator(); - Bitmap item; - - 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; - - // Remove from reusable set so it can't be used again. + synchronized (mReusableBitmaps) { + final Iterator<SoftReference<Bitmap>> iterator + = mReusableBitmaps.iterator(); + Bitmap item; + + 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; + + // 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(); } } } |