summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Koch <akoch@google.com>2013-11-12 19:45:22 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-11-12 19:47:46 +0000
commite95c167c98157c3b91847a969980c1f293eb1e3f (patch)
treefc0ce1e5f93062e7a5c0bcab3889edc5153e1deb
parent45d9321963a51470dc1aadf6ec9193cb881eed06 (diff)
parent67257655a3a1921fa0837f5de34e9f5d3babc938 (diff)
downloadframeworks_base-e95c167c98157c3b91847a969980c1f293eb1e3f.zip
frameworks_base-e95c167c98157c3b91847a969980c1f293eb1e3f.tar.gz
frameworks_base-e95c167c98157c3b91847a969980c1f293eb1e3f.tar.bz2
Merge "Bitmapfun Sample: Minor updates/fixes." into klp-docs
-rw-r--r--docs/downloads/training/BitmapFun.zipbin103825 -> 104008 bytes
-rw-r--r--docs/html/training/displaying-bitmaps/manage-memory.jd45
2 files changed, 24 insertions, 21 deletions
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 @@ 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&lt;SoftReference&lt;Bitmap&gt;&gt; mReusableBitmaps;
+<pre>Set&lt;SoftReference&lt;Bitmap&gt;&gt; mReusableBitmaps;
private LruCache&lt;String, BitmapDrawable&gt; 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&lt;SoftReference&lt;Bitmap&gt;&gt;();
+ mReusableBitmaps =
+ Collections.synchronizedSet(new HashSet&lt;SoftReference&lt;Bitmap&gt;&gt;());
}
mMemoryCache = new LruCache&lt;String, BitmapDrawable&gt;(mCacheParams.memCacheSize) {
@@ -243,25 +244,27 @@ protected Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) {
Bitmap bitmap = null;
if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
- final Iterator&lt;SoftReference&lt;Bitmap&gt;&gt; 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&lt;SoftReference&lt;Bitmap&gt;&gt; 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();
}
}
}