summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2013-04-10 11:31:34 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-04-10 11:31:34 -0700
commit6fc674aa76e56f9cc01a7df7059cc17eb16ac21b (patch)
tree450816e450f83889ec2c5139c846f2a01f770d76
parent8656984401488c6aa01a190f893b694115e722d5 (diff)
parentbcfd4439d730a4d783a02596c8ab444796323aad (diff)
downloadandroid_packages_screensavers_PhotoTable-6fc674aa76e56f9cc01a7df7059cc17eb16ac21b.tar.gz
android_packages_screensavers_PhotoTable-6fc674aa76e56f9cc01a7df7059cc17eb16ac21b.tar.bz2
android_packages_screensavers_PhotoTable-6fc674aa76e56f9cc01a7df7059cc17eb16ac21b.zip
am bcfd4439: better memory/cursor management for story mode.
* commit 'bcfd4439d730a4d783a02596c8ab444796323aad': better memory/cursor management for story mode.
-rw-r--r--src/com/android/dreams/phototable/CursorPhotoSource.java15
-rw-r--r--src/com/android/dreams/phototable/KeyboardInterpreter.java1
-rw-r--r--src/com/android/dreams/phototable/PhotoCarousel.java8
-rw-r--r--src/com/android/dreams/phototable/PhotoSource.java18
-rw-r--r--src/com/android/dreams/phototable/PhotoSourcePlexor.java5
-rw-r--r--src/com/android/dreams/phototable/PhotoTable.java10
-rw-r--r--src/com/android/dreams/phototable/StockSource.java6
7 files changed, 46 insertions, 17 deletions
diff --git a/src/com/android/dreams/phototable/CursorPhotoSource.java b/src/com/android/dreams/phototable/CursorPhotoSource.java
index cb4ce6b..f010a92 100644
--- a/src/com/android/dreams/phototable/CursorPhotoSource.java
+++ b/src/com/android/dreams/phototable/CursorPhotoSource.java
@@ -39,10 +39,10 @@ public abstract class CursorPhotoSource extends PhotoSource {
@Override
protected ImageData naturalNext(ImageData current) {
- if (current.cursor == null) {
+ if (current.cursor == null || current.cursor.isClosed()) {
openCursor(current);
- findPosition(current);
}
+ findPosition(current);
current.cursor.moveToPosition(current.position);
current.cursor.moveToNext();
ImageData data = null;
@@ -56,10 +56,10 @@ public abstract class CursorPhotoSource extends PhotoSource {
@Override
protected ImageData naturalPrevious(ImageData current) {
- if (current.cursor == null) {
+ if (current.cursor == null || current.cursor.isClosed()) {
openCursor(current);
- findPosition(current);
}
+ findPosition(current);
current.cursor.moveToPosition(current.position);
current.cursor.moveToPrevious();
ImageData data = null;
@@ -71,6 +71,13 @@ public abstract class CursorPhotoSource extends PhotoSource {
return data;
}
+ @Override
+ protected void donePaging(ImageData current) {
+ if (current.cursor != null && !current.cursor.isClosed()) {
+ current.cursor.close();
+ }
+ }
+
protected abstract void openCursor(ImageData data);
protected abstract void findPosition(ImageData data);
protected abstract ImageData unpackImageData(Cursor cursor, ImageData data);
diff --git a/src/com/android/dreams/phototable/KeyboardInterpreter.java b/src/com/android/dreams/phototable/KeyboardInterpreter.java
index 0b0d6bb..d7b55f4 100644
--- a/src/com/android/dreams/phototable/KeyboardInterpreter.java
+++ b/src/com/android/dreams/phototable/KeyboardInterpreter.java
@@ -37,7 +37,6 @@ public class KeyboardInterpreter {
public boolean onKeyDown(int keyCode, KeyEvent event) {
final View focus = mTable.getFocus();
boolean consumed = true;
- Log.d(TAG, "down: " + keyCode);
if (mTable.hasSelection()) {
switch (keyCode) {
case KeyEvent.KEYCODE_ENTER:
diff --git a/src/com/android/dreams/phototable/PhotoCarousel.java b/src/com/android/dreams/phototable/PhotoCarousel.java
index 9e77d06..23939c9 100644
--- a/src/com/android/dreams/phototable/PhotoCarousel.java
+++ b/src/com/android/dreams/phototable/PhotoCarousel.java
@@ -184,7 +184,6 @@ public class PhotoCarousel extends FrameLayout {
Bitmap photo = mBitmapQueue.poll();
if (photo != null) {
ImageView destination = getBackface();
- Bitmap old = mBitmapStore.get(destination);
int width = photo.getWidth();
int height = photo.getHeight();
int orientation = (width > height ? LANDSCAPE : PORTRAIT);
@@ -195,11 +194,8 @@ public class PhotoCarousel extends FrameLayout {
destination.setTag(R.id.photo_height, Integer.valueOf(height));
setScaleType(destination);
- mBitmapStore.put(destination, photo);
-
- if (old != null) {
- old.recycle();
- }
+ Bitmap old = mBitmapStore.put(destination, photo);
+ mPhotoSource.recycle(old);
return true;
} else {
diff --git a/src/com/android/dreams/phototable/PhotoSource.java b/src/com/android/dreams/phototable/PhotoSource.java
index d9d4ab9..fc4cf7b 100644
--- a/src/com/android/dreams/phototable/PhotoSource.java
+++ b/src/com/android/dreams/phototable/PhotoSource.java
@@ -64,6 +64,9 @@ public abstract class PhotoSource {
ImageData naturalPrevious() {
return PhotoSource.this.naturalPrevious(this);
}
+ public void donePaging() {
+ PhotoSource.this.donePaging(this);
+ }
}
public class AlbumData {
@@ -295,10 +298,25 @@ public abstract class PhotoSource {
return image;
}
+ public void donePaging(Bitmap current) {
+ ImageData data = mImageMap.get(current);
+ if (data != null) {
+ data.donePaging();
+ }
+ }
+
+ public void recycle(Bitmap trash) {
+ if (trash != null) {
+ mImageMap.remove(trash);
+ trash.recycle();
+ }
+ }
+
protected abstract InputStream getStream(ImageData data, int longSide);
protected abstract Collection<ImageData> findImages(int howMany);
protected abstract ImageData naturalNext(ImageData current);
protected abstract ImageData naturalPrevious(ImageData current);
+ protected abstract void donePaging(ImageData current);
public abstract Collection<AlbumData> findAlbums();
}
diff --git a/src/com/android/dreams/phototable/PhotoSourcePlexor.java b/src/com/android/dreams/phototable/PhotoSourcePlexor.java
index 93fdc9e..3733b02 100644
--- a/src/com/android/dreams/phototable/PhotoSourcePlexor.java
+++ b/src/com/android/dreams/phototable/PhotoSourcePlexor.java
@@ -80,4 +80,9 @@ public class PhotoSourcePlexor extends PhotoSource {
protected ImageData naturalPrevious(ImageData current) {
return current.naturalPrevious();
}
+
+ @Override
+ protected void donePaging(ImageData current) {
+ current.donePaging();
+ }
}
diff --git a/src/com/android/dreams/phototable/PhotoTable.java b/src/com/android/dreams/phototable/PhotoTable.java
index 7932bda..6fde1ed 100644
--- a/src/com/android/dreams/phototable/PhotoTable.java
+++ b/src/com/android/dreams/phototable/PhotoTable.java
@@ -161,7 +161,9 @@ public class PhotoTable extends FrameLayout {
public void clearSelection() {
if (hasSelection()) {
- dropOnTable(getSelection());
+ dropOnTable(mSelection);
+ mPhotoSource.donePaging(getBitmap(mSelection));
+ mSelection = null;
}
for (int slot = 0; slot < mOnDeck.length; slot++) {
if (mOnDeck[slot] != null) {
@@ -174,7 +176,6 @@ public class PhotoTable extends FrameLayout {
mLoadOnDeckTasks[slot] = null;
}
}
- mSelection = null;
}
public void setSelection(View selected) {
@@ -833,10 +834,7 @@ public class PhotoTable extends FrameLayout {
private void recycle(View photo) {
if (photo != null) {
removeView(photo);
- Bitmap bitmap = getBitmap(photo);
- if (bitmap != null) {
- bitmap.recycle();
- }
+ mPhotoSource.recycle(getBitmap(photo));
}
}
diff --git a/src/com/android/dreams/phototable/StockSource.java b/src/com/android/dreams/phototable/StockSource.java
index d7b3500..be2a860 100644
--- a/src/com/android/dreams/phototable/StockSource.java
+++ b/src/com/android/dreams/phototable/StockSource.java
@@ -94,16 +94,22 @@ public class StockSource extends PhotoSource {
return is;
}
+ @Override
public ImageData naturalNext(ImageData current) {
int idx = Integer.valueOf(current.id);
idx = (idx + 1) % PHOTOS.length;
return mImageCache.get(idx);
}
+ @Override
public ImageData naturalPrevious(ImageData current) {
int idx = Integer.valueOf(current.id);
idx = (PHOTOS.length + idx - 1) % PHOTOS.length;
return mImageCache.get(idx);
}
+
+ @Override
+ protected void donePaging(ImageData current) {
+ }
}