aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/cyanogenmod/wallpapers/photophase/tasks
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2013-11-02 02:20:56 +0100
committerJorge Ruesga <jorge@ruesga.com>2013-11-02 02:20:56 +0100
commit4effddfe30fd045834232f6bb66070edf079578d (patch)
tree2e57f74d55685891a49b02ec069c118cf5b15110 /src/org/cyanogenmod/wallpapers/photophase/tasks
parentca2f0060cc367ac8174a27a3124cd0124e49c627 (diff)
downloadandroid_packages_wallpapers_PhotoPhase-4effddfe30fd045834232f6bb66070edf079578d.tar.gz
android_packages_wallpapers_PhotoPhase-4effddfe30fd045834232f6bb66070edf079578d.tar.bz2
android_packages_wallpapers_PhotoPhase-4effddfe30fd045834232f6bb66070edf079578d.zip
Multiples fixes
- Fully rewrite the album selection preference - Fix multiple style - Fix lints - Resources cleanup Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src/org/cyanogenmod/wallpapers/photophase/tasks')
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/tasks/AsyncPictureLoaderTask.java52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/org/cyanogenmod/wallpapers/photophase/tasks/AsyncPictureLoaderTask.java b/src/org/cyanogenmod/wallpapers/photophase/tasks/AsyncPictureLoaderTask.java
index bc07b17..3ea1885 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/tasks/AsyncPictureLoaderTask.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/tasks/AsyncPictureLoaderTask.java
@@ -32,8 +32,34 @@ import java.io.File;
*/
public class AsyncPictureLoaderTask extends AsyncTask<File, Void, Drawable> {
+ /**
+ * Notify whether the picture was loaded
+ */
+ public static abstract class OnPictureLoaded {
+ Object[] mRefs;
+
+ /**
+ * Constructor of <code>OnPictureLoaded</code>
+ *
+ * @param refs References to notify
+ */
+ public OnPictureLoaded(Object...refs) {
+ super();
+ mRefs = refs;
+ }
+
+ /**
+ * Invoked when a picture is loaded
+ *
+ * @param o The original object reference
+ * @param drawable The drawable
+ */
+ public abstract void onPictureLoaded(Object o, Drawable drawable);
+ }
+
private final Context mContext;
private final ImageView mView;
+ private final OnPictureLoaded mCallback;
/**
* Constructor of <code>AsyncPictureLoaderTask</code>
@@ -42,9 +68,21 @@ public class AsyncPictureLoaderTask extends AsyncTask<File, Void, Drawable> {
* @param v The associated view
*/
public AsyncPictureLoaderTask(Context context, ImageView v) {
+ this(context, v, null);
+ }
+
+ /**
+ * Constructor of <code>AsyncPictureLoaderTask</code>
+ *
+ * @param context The current context
+ * @param v The associated view
+ * @param callback A callback to notify when the picture was loaded
+ */
+ public AsyncPictureLoaderTask(Context context, ImageView v, OnPictureLoaded callback) {
super();
mContext = context;
mView = v;
+ mCallback = callback;
}
/**
@@ -56,7 +94,15 @@ public class AsyncPictureLoaderTask extends AsyncTask<File, Void, Drawable> {
int height = mView.getMeasuredHeight();
Bitmap bitmap = BitmapUtils.decodeBitmap(params[0], width, height);
if (bitmap != null) {
- return new BitmapDrawable(mContext.getResources(), bitmap);
+ Drawable dw = new BitmapDrawable(mContext.getResources(), bitmap);
+ if (mCallback != null) {
+ for (Object o : mCallback.mRefs) {
+ if (!isCancelled()) {
+ mCallback.onPictureLoaded(o, dw);
+ }
+ }
+ }
+ return dw;
}
return null;
}
@@ -66,6 +112,8 @@ public class AsyncPictureLoaderTask extends AsyncTask<File, Void, Drawable> {
*/
@Override
protected void onPostExecute(Drawable result) {
- mView.setImageDrawable(result);
+ if (!isCancelled()) {
+ mView.setImageDrawable(result);
+ }
}
}