summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2013-04-09 16:48:24 -0400
committerChris Wren <cwren@android.com>2013-04-10 14:15:32 -0400
commitbcfd4439d730a4d783a02596c8ab444796323aad (patch)
tree1ef262a15b2e2f260d4b159d0baae76778d6d825 /src
parenta96a454c9084e98e20f263b435b536a194f25673 (diff)
downloadandroid_packages_screensavers_PhotoTable-bcfd4439d730a4d783a02596c8ab444796323aad.tar.gz
android_packages_screensavers_PhotoTable-bcfd4439d730a4d783a02596c8ab444796323aad.tar.bz2
android_packages_screensavers_PhotoTable-bcfd4439d730a4d783a02596c8ab444796323aad.zip
better memory/cursor management for story mode.
Bug: 8578085 Change-Id: I11c44c64a9d4318a00f6db21369eba43b586f809
Diffstat (limited to 'src')
-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) {
+ }
}