diff options
Diffstat (limited to 'src/com/android/dreams/phototable/PhotoSource.java')
-rw-r--r-- | src/com/android/dreams/phototable/PhotoSource.java | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/src/com/android/dreams/phototable/PhotoSource.java b/src/com/android/dreams/phototable/PhotoSource.java index 32d41c7..d9d4ab9 100644 --- a/src/com/android/dreams/phototable/PhotoSource.java +++ b/src/com/android/dreams/phototable/PhotoSource.java @@ -23,16 +23,15 @@ import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; -import android.net.Uri; -import android.provider.MediaStore; import android.util.Log; +import java.io.BufferedInputStream; import java.io.FileNotFoundException; -import java.io.InputStream; import java.io.IOException; -import java.io.BufferedInputStream; +import java.io.InputStream; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.LinkedList; import java.util.Random; @@ -43,9 +42,6 @@ public abstract class PhotoSource { private static final String TAG = "PhotoTable.PhotoSource"; private static final boolean DEBUG = false; - // An invalid cursor position to represent the uninitialized state. - protected static final int INVALID = -2; - // This should be large enough for BitmapFactory to decode the header so // that we can mark and reset the input stream to avoid duplicate network i/o private static final int BUFFER_SIZE = 128 * 1024; @@ -55,9 +51,19 @@ public abstract class PhotoSource { public String url; public int orientation; + protected String albumId; + protected Cursor cursor; + protected int position; + InputStream getStream(int longSide) { return PhotoSource.this.getStream(this, longSide); } + ImageData naturalNext() { + return PhotoSource.this.naturalNext(this); + } + ImageData naturalPrevious() { + return PhotoSource.this.naturalPrevious(this); + } } public class AlbumData { @@ -79,6 +85,7 @@ public abstract class PhotoSource { private final float mMaxCropRatio; private final int mBadImageSkipLimit; private final PhotoSource mFallbackSource; + private final HashMap<Bitmap, ImageData> mImageMap; protected final Context mContext; protected final Resources mResources; @@ -102,6 +109,7 @@ public abstract class PhotoSource { mMaxQueueSize = mResources.getInteger(R.integer.image_queue_size); mMaxCropRatio = mResources.getInteger(R.integer.max_crop_ratio) / 1000000f; mBadImageSkipLimit = mResources.getInteger(R.integer.bad_image_skip_limit); + mImageMap = new HashMap<Bitmap, ImageData>(); mRNG = new Random(); mFallbackSource = fallbackSource; } @@ -124,11 +132,11 @@ public abstract class PhotoSource { if (mImageQueue.isEmpty()) { fillQueue(); } - imageData = mImageQueue.poll(); } if (imageData != null) { image = load(imageData, options, longSide, shortSide); + mImageMap.put(image, imageData); imageData = null; } @@ -259,7 +267,38 @@ public abstract class PhotoSource { } } + public Bitmap naturalNext(Bitmap current, BitmapFactory.Options options, + int longSide, int shortSide) { + Bitmap image = null; + ImageData data = mImageMap.get(current); + if (data != null) { + ImageData next = data.naturalNext(); + if (next != null) { + image = load(next, options, longSide, shortSide); + mImageMap.put(image, next); + } + } + return image; + } + + public Bitmap naturalPrevious(Bitmap current, BitmapFactory.Options options, + int longSide, int shortSide) { + Bitmap image = null; + ImageData data = mImageMap.get(current); + if (current != null) { + ImageData prev = data.naturalPrevious(); + if (prev != null) { + image = load(prev, options, longSide, shortSide); + mImageMap.put(image, prev); + } + } + return image; + } + 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); + public abstract Collection<AlbumData> findAlbums(); } |