diff options
author | Hyunyoung Song <hyunyoungs@google.com> | 2015-06-16 10:45:24 -0700 |
---|---|---|
committer | Hyunyoung Song <hyunyoungs@google.com> | 2015-06-16 10:45:24 -0700 |
commit | e98f4a4d6dac0aa4fc6b35b46ab10aff06251ffc (patch) | |
tree | e06245d2a79e6c4a2f2b93f6db983a181e0e23d5 /src/com | |
parent | 0fc56db04fa7dde3150b02862d6a3ab3374d89bc (diff) | |
download | android_packages_apps_Trebuchet-e98f4a4d6dac0aa4fc6b35b46ab10aff06251ffc.tar.gz android_packages_apps_Trebuchet-e98f4a4d6dac0aa4fc6b35b46ab10aff06251ffc.tar.bz2 android_packages_apps_Trebuchet-e98f4a4d6dac0aa4fc6b35b46ab10aff06251ffc.zip |
Fix last bit of WidgetTray jank issue
b/21133230
Change-Id: Ic198b8d21be1b0f3465cd4efc30a240e3ec4304a
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 75952d1a6..46405ada7 100644 --- a/src/com/android/launcher3/WidgetPreviewLoader.java +++ b/src/com/android/launcher3/WidgetPreviewLoader.java @@ -55,6 +55,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>()); @@ -554,10 +556,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; + } + }); } } } @@ -660,14 +667,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); + } + } + }); } } } |