summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/WidgetPreviewLoader.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2017-03-17 18:41:31 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-03-17 18:41:31 +0000
commitafc3f09240abf904f0250aa7d3892ff41ec1ba6d (patch)
tree16197f015dfb3bf5e639c0a954b2955441896de1 /src/com/android/launcher3/WidgetPreviewLoader.java
parentf71bb700aa436d0e8c8c9056627e3999e1f667d6 (diff)
parentc65a0085d77edd8e8821254f081eb94e9dcc5e75 (diff)
downloadandroid_packages_apps_Trebuchet-afc3f09240abf904f0250aa7d3892ff41ec1ba6d.tar.gz
android_packages_apps_Trebuchet-afc3f09240abf904f0250aa7d3892ff41ec1ba6d.tar.bz2
android_packages_apps_Trebuchet-afc3f09240abf904f0250aa7d3892ff41ec1ba6d.zip
Adding support for showing the widget preview based on the provided RemoteViews
am: c65a0085d7 Change-Id: Iabea96bb74294e2775a08427c17e154020d9bc40
Diffstat (limited to 'src/com/android/launcher3/WidgetPreviewLoader.java')
-rw-r--r--src/com/android/launcher3/WidgetPreviewLoader.java68
1 files changed, 30 insertions, 38 deletions
diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java
index 6dc65d9a5..5e859c72a 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;
}
/**
@@ -511,42 +515,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;
@@ -662,6 +632,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 {