summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2013-04-09 15:58:31 -0400
committerChris Wren <cwren@android.com>2013-04-09 15:58:31 -0400
commita96a454c9084e98e20f263b435b536a194f25673 (patch)
treeb7766aedb08d8d14078c23006ec0da3f14e17eb1 /src
parenta924553fc2a5bf5ab88ac031adf154480b970bd9 (diff)
downloadandroid_packages_screensavers_PhotoTable-a96a454c9084e98e20f263b435b536a194f25673.tar.gz
android_packages_screensavers_PhotoTable-a96a454c9084e98e20f263b435b536a194f25673.tar.bz2
android_packages_screensavers_PhotoTable-a96a454c9084e98e20f263b435b536a194f25673.zip
manage obsolete threads.
Bug: 8574670 Change-Id: I79a9bdb8de2fec46de591acfe5a3cbcd30f0ecdf
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dreams/phototable/PhotoTable.java44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/com/android/dreams/phototable/PhotoTable.java b/src/com/android/dreams/phototable/PhotoTable.java
index ddf071f..7932bda 100644
--- a/src/com/android/dreams/phototable/PhotoTable.java
+++ b/src/com/android/dreams/phototable/PhotoTable.java
@@ -168,6 +168,11 @@ public class PhotoTable extends FrameLayout {
fadeAway(mOnDeck[slot], false);
mOnDeck[slot] = null;
}
+ if (mLoadOnDeckTasks[slot] != null &&
+ mLoadOnDeckTasks[slot].getStatus() != AsyncTask.Status.FINISHED) {
+ mLoadOnDeckTasks[slot].cancel(true);
+ mLoadOnDeckTasks[slot] = null;
+ }
}
mSelection = null;
}
@@ -446,6 +451,7 @@ public class PhotoTable extends FrameLayout {
private class LoadNaturalSiblingTask extends AsyncTask<View, Void, View> {
private final BitmapFactory.Options mOptions;
private final int mSlot;
+ private View mParent;
public LoadNaturalSiblingTask (int slot) {
mOptions = new BitmapFactory.Options();
@@ -457,7 +463,8 @@ public class PhotoTable extends FrameLayout {
public View doInBackground(View... views) {
log("load natural %s", (mSlot == NEXT ? "next" : "previous"));
final PhotoTable table = PhotoTable.this;
- final Bitmap current = getBitmap(views[0]);
+ mParent = views[0];
+ final Bitmap current = getBitmap(mParent);
Bitmap decodedPhoto;
if (mSlot == NEXT) {
decodedPhoto = table.mPhotoSource.naturalNext(current,
@@ -472,21 +479,26 @@ public class PhotoTable extends FrameLayout {
@Override
public void onPostExecute(View photo) {
if (photo != null) {
- log("natural %s being rendered", (mSlot == NEXT ? "next" : "previous"));
- PhotoTable.this.addView(photo, new LayoutParams(LayoutParams.WRAP_CONTENT,
- LayoutParams.WRAP_CONTENT));
- float width = (float) ((Integer) photo.getTag(R.id.photo_width)).intValue();
- float height = (float) ((Integer) photo.getTag(R.id.photo_height)).intValue();
- photo.setX(mSlot == PREV ? -2 * width : mWidth + 2 * width);
- photo.setY((mHeight - height) / 2);
- photo.addOnLayoutChangeListener(new OnLayoutChangeListener() {
- @Override
- public void onLayoutChange(View v, int left, int top, int right, int bottom,
- int oldLeft, int oldTop, int oldRight, int oldBottom) {
- PhotoTable.this.placeOnDeck(v, mSlot);
- v.removeOnLayoutChangeListener(this);
- }
- });
+ if (hasSelection() && getSelection() == mParent) {
+ log("natural %s being rendered", (mSlot == NEXT ? "next" : "previous"));
+ PhotoTable.this.addView(photo, new LayoutParams(LayoutParams.WRAP_CONTENT,
+ LayoutParams.WRAP_CONTENT));
+ PhotoTable.this.mOnDeck[mSlot] = photo;
+ float width = (float) ((Integer) photo.getTag(R.id.photo_width)).intValue();
+ float height = (float) ((Integer) photo.getTag(R.id.photo_height)).intValue();
+ photo.setX(mSlot == PREV ? -2 * width : mWidth + 2 * width);
+ photo.setY((mHeight - height) / 2);
+ photo.addOnLayoutChangeListener(new OnLayoutChangeListener() {
+ @Override
+ public void onLayoutChange(View v, int left, int top, int right, int bottom,
+ int oldLeft, int oldTop, int oldRight, int oldBottom) {
+ PhotoTable.this.placeOnDeck(v, mSlot);
+ v.removeOnLayoutChangeListener(this);
+ }
+ });
+ } else {
+ recycle(photo);
+ }
} else {
log("natural, %s was null!", (mSlot == NEXT ? "next" : "previous"));
}