diff options
author | Hyunyoung Song <hyunyoungs@google.com> | 2015-06-16 18:08:13 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-06-16 18:08:14 +0000 |
commit | ed717bcd611628ff961e0e9a7e7e11015fca4a33 (patch) | |
tree | 3c6d46babd8eed9cc8aef63f39966d5a383057ef /src/com | |
parent | 383c507c47a5abf3258fc04220f37c366f983a97 (diff) | |
parent | e98f4a4d6dac0aa4fc6b35b46ab10aff06251ffc (diff) | |
download | android_packages_apps_Trebuchet-ed717bcd611628ff961e0e9a7e7e11015fca4a33.tar.gz android_packages_apps_Trebuchet-ed717bcd611628ff961e0e9a7e7e11015fca4a33.tar.bz2 android_packages_apps_Trebuchet-ed717bcd611628ff961e0e9a7e7e11015fca4a33.zip |
Merge "Fix last bit of WidgetTray jank issue b/21133230" into ub-launcher3-burnaby
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/launcher3/WidgetPreviewLoader.java | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java index c1cc42b2c..5ca0ac8d6 100644 --- a/src/com/android/launcher3/WidgetPreviewLoader.java +++ b/src/com/android/launcher3/WidgetPreviewLoader.java @@ -56,6 +56,8 @@ public class WidgetPreviewLoader { /** * Weak reference objects, do not prevent their referents from being made finalizable, * finalized, and then reclaimed. + * Note: synchronized block used for this variable is expensive and the block should always + * be posted to a background thread. */ @Thunk Set<Bitmap> mUnusedBitmaps = Collections.newSetFromMap(new WeakHashMap<Bitmap, Boolean>()); @@ -555,10 +557,15 @@ public class WidgetPreviewLoader { // in the tasks's onCancelled() call, and if cancelled while the task is writing to // disk, it will be cancelled in the task's onPostExecute() call. if (mTask.mBitmapToRecycle != null) { - synchronized (mUnusedBitmaps) { - mUnusedBitmaps.add(mTask.mBitmapToRecycle); - } - mTask.mBitmapToRecycle = null; + mWorkerHandler.post(new Runnable() { + @Override + public void run() { + synchronized (mUnusedBitmaps) { + mUnusedBitmaps.add(mTask.mBitmapToRecycle); + } + mTask.mBitmapToRecycle = null; + } + }); } } } @@ -661,14 +668,19 @@ public class WidgetPreviewLoader { } @Override - protected void onCancelled(Bitmap preview) { + protected void onCancelled(final Bitmap preview) { // If we've cancelled while the task is running, then can return the bitmap to the // recycled set immediately. Otherwise, it will be recycled after the preview is written // to disk. if (preview != null) { - synchronized (mUnusedBitmaps) { - mUnusedBitmaps.add(preview); - } + mWorkerHandler.post(new Runnable() { + @Override + public void run() { + synchronized (mUnusedBitmaps) { + mUnusedBitmaps.add(preview); + } + } + }); } } } |