diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2017-03-08 14:49:55 -0800 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2017-03-17 11:25:29 -0700 |
commit | c65a0085d77edd8e8821254f081eb94e9dcc5e75 (patch) | |
tree | 9b5828af69bd8c6fb34d47e121202cfe86123b8f /src/com/android/launcher3/WidgetPreviewLoader.java | |
parent | efd5cbf55c45185230d56799e67b31e96d8d7029 (diff) | |
download | android_packages_apps_Trebuchet-c65a0085d77edd8e8821254f081eb94e9dcc5e75.tar.gz android_packages_apps_Trebuchet-c65a0085d77edd8e8821254f081eb94e9dcc5e75.tar.bz2 android_packages_apps_Trebuchet-c65a0085d77edd8e8821254f081eb94e9dcc5e75.zip |
Adding support for showing the widget preview based on the provided RemoteViews
Bug: 35811129
Change-Id: I336e48cd00cfec2e617ac73bd8a81419b0944aa7
Diffstat (limited to 'src/com/android/launcher3/WidgetPreviewLoader.java')
-rw-r--r-- | src/com/android/launcher3/WidgetPreviewLoader.java | 68 |
1 files changed, 30 insertions, 38 deletions
diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java index 689cc9b3e..0e9106201 100644 --- a/src/com/android/launcher3/WidgetPreviewLoader.java +++ b/src/com/android/launcher3/WidgetPreviewLoader.java @@ -22,6 +22,7 @@ import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.os.AsyncTask; +import android.os.CancellationSignal; import android.os.Handler; import android.os.UserHandle; import android.support.v4.graphics.ColorUtils; @@ -89,14 +90,17 @@ public class WidgetPreviewLoader { * * @return a request id which can be used to cancel the request. */ - public PreviewLoadRequest getPreview(WidgetItem item, int previewWidth, + public CancellationSignal getPreview(WidgetItem item, int previewWidth, int previewHeight, WidgetCell caller) { String size = previewWidth + "x" + previewHeight; WidgetCacheKey key = new WidgetCacheKey(item.componentName, item.user, size); PreviewLoadTask task = new PreviewLoadTask(key, item, previewWidth, previewHeight, caller); task.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR); - return new PreviewLoadRequest(task); + + CancellationSignal signal = new CancellationSignal(); + signal.setOnCancelListener(task); + return signal; } /** @@ -510,42 +514,8 @@ public class WidgetPreviewLoader { } } - /** - * A request Id which can be used by the client to cancel any request. - */ - public class PreviewLoadRequest { - - @Thunk final PreviewLoadTask mTask; - - public PreviewLoadRequest(PreviewLoadTask task) { - mTask = task; - } - - public void cleanup() { - if (mTask != null) { - mTask.cancel(true); - } - - // This only handles the case where the PreviewLoadTask is cancelled after the task has - // successfully completed (including having written to disk when necessary). In the - // other cases where it is cancelled while the task is running, it will be cleaned up - // 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) { - mWorkerHandler.post(new Runnable() { - @Override - public void run() { - synchronized (mUnusedBitmaps) { - mUnusedBitmaps.add(mTask.mBitmapToRecycle); - } - mTask.mBitmapToRecycle = null; - } - }); - } - } - } - - public class PreviewLoadTask extends AsyncTask<Void, Void, Bitmap> { + public class PreviewLoadTask extends AsyncTask<Void, Void, Bitmap> + implements CancellationSignal.OnCancelListener { @Thunk final WidgetCacheKey mKey; private final WidgetItem mInfo; private final int mPreviewHeight; @@ -661,6 +631,28 @@ public class WidgetPreviewLoader { }); } } + + @Override + public void onCancel() { + cancel(true); + + // This only handles the case where the PreviewLoadTask is cancelled after the task has + // successfully completed (including having written to disk when necessary). In the + // other cases where it is cancelled while the task is running, it will be cleaned up + // 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 (mBitmapToRecycle != null) { + mWorkerHandler.post(new Runnable() { + @Override + public void run() { + synchronized (mUnusedBitmaps) { + mUnusedBitmaps.add(mBitmapToRecycle); + } + mBitmapToRecycle = null; + } + }); + } + } } private static final class WidgetCacheKey extends ComponentKey { |