summaryrefslogtreecommitdiffstats
path: root/src/com/android/photos/data/MediaCache.java
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2013-05-02 17:19:24 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-05-02 17:19:25 +0000
commit7b96023121ebeac1d7b48e573a24acfd8964e2d1 (patch)
treecf64c13a1b6e2271d4298975a94ac3cffc0fb0dd /src/com/android/photos/data/MediaCache.java
parentf6c71858b1a6d39eab259bc593e3b4dd096daeef (diff)
parent7b4502110166210cf7bbb0740544a0daf1c4d258 (diff)
downloadandroid_packages_apps_Snap-7b96023121ebeac1d7b48e573a24acfd8964e2d1.tar.gz
android_packages_apps_Snap-7b96023121ebeac1d7b48e573a24acfd8964e2d1.tar.bz2
android_packages_apps_Snap-7b96023121ebeac1d7b48e573a24acfd8964e2d1.zip
Merge changes Ia9b2ced0,I7cccfffc into gb-ub-photos-bryce
* changes: Class to simplify use of GalleryBitmapPool for decoding Bitmaps. Allow prefetch for cache, reducing priority for prefetched images.
Diffstat (limited to 'src/com/android/photos/data/MediaCache.java')
-rw-r--r--src/com/android/photos/data/MediaCache.java30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/com/android/photos/data/MediaCache.java b/src/com/android/photos/data/MediaCache.java
index 9cf69d643..0952a4017 100644
--- a/src/com/android/photos/data/MediaCache.java
+++ b/src/com/android/photos/data/MediaCache.java
@@ -107,6 +107,8 @@ public class MediaCache {
void notifyReady();
void setFile(File file) throws FileNotFoundException;
+
+ boolean isPrefetch();
}
private static class NotifyOriginalReady implements NotifyReady {
@@ -119,13 +121,20 @@ public class MediaCache {
@Override
public void notifyReady() {
- mCallback.originalReady(mFile);
+ if (mCallback != null) {
+ mCallback.originalReady(mFile);
+ }
}
@Override
public void setFile(File file) {
mFile = file;
}
+
+ @Override
+ public boolean isPrefetch() {
+ return mCallback == null;
+ }
}
private static class NotifyImageReady implements NotifyReady {
@@ -138,7 +147,9 @@ public class MediaCache {
@Override
public void notifyReady() {
- mCallback.imageReady(mInputStream);
+ if (mCallback != null) {
+ mCallback.imageReady(mInputStream);
+ }
}
@Override
@@ -149,6 +160,11 @@ public class MediaCache {
public void setBytes(byte[] bytes) {
mInputStream = new ByteArrayInputStream(bytes);
}
+
+ @Override
+ public boolean isPrefetch() {
+ return mCallback == null;
+ }
}
/** A media item to be retrieved and its notifications. */
@@ -496,7 +512,15 @@ public class MediaCache {
}
synchronized (tasks) {
ProcessingJob job = new ProcessingJob(uri, size, complete, lowResolution);
- tasks.add(job);
+ if (complete.isPrefetch()) {
+ tasks.add(job);
+ } else {
+ int index = tasks.size() - 1;
+ while (index >= 0 && tasks.get(index).complete.isPrefetch()) {
+ index--;
+ }
+ tasks.add(index + 1, job);
+ }
tasks.notifyAll();
}
}