diff options
author | George Mount <mount@google.com> | 2013-05-01 16:56:32 -0700 |
---|---|---|
committer | George Mount <mount@google.com> | 2013-05-02 09:23:45 -0700 |
commit | e4600fca519144d8d9b82a82fdfaabcc77182f40 (patch) | |
tree | d81f188be8d6dff51a625649a950c30b8d2febe1 /src | |
parent | 6cf36371a5888be8e137af1ede183bd592bb07b2 (diff) | |
download | android_packages_apps_Snap-e4600fca519144d8d9b82a82fdfaabcc77182f40.tar.gz android_packages_apps_Snap-e4600fca519144d8d9b82a82fdfaabcc77182f40.tar.bz2 android_packages_apps_Snap-e4600fca519144d8d9b82a82fdfaabcc77182f40.zip |
Allow prefetch for cache, reducing priority for prefetched images.
Bug 8446191
Required for I86cfa59f448daa4e7b9fd7ea9ada2d69357e1f63
Change-Id: I7cccfffc539988d26fc751e16726b05fb2ba21bd
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/photos/data/MediaCache.java | 30 |
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(); } } |