diff options
author | Chris Wren <cwren@android.com> | 2013-04-04 09:17:26 -0400 |
---|---|---|
committer | Chris Wren <cwren@android.com> | 2013-04-09 01:54:16 -0400 |
commit | 88d80f4471c900628e2cb6eef23029b99af48e09 (patch) | |
tree | 6829842f0dff21db530936037cd242853f43b416 /src/com/android/dreams/phototable/PicasaSource.java | |
parent | 1dc94b55d59f5c4dbf86788d0c32b7ac4449909a (diff) | |
download | android_packages_screensavers_PhotoTable-88d80f4471c900628e2cb6eef23029b99af48e09.tar.gz android_packages_screensavers_PhotoTable-88d80f4471c900628e2cb6eef23029b99af48e09.tar.bz2 android_packages_screensavers_PhotoTable-88d80f4471c900628e2cb6eef23029b99af48e09.zip |
story mode for PhotoTable.
also some cleanup and refactoring
also fix stuck alphas
Bug: 8399588
Change-Id: Id236b29701ede3696c8f1f0ccc6522eb8256ff25
Diffstat (limited to 'src/com/android/dreams/phototable/PicasaSource.java')
-rw-r--r-- | src/com/android/dreams/phototable/PicasaSource.java | 80 |
1 files changed, 62 insertions, 18 deletions
diff --git a/src/com/android/dreams/phototable/PicasaSource.java b/src/com/android/dreams/phototable/PicasaSource.java index ef4a7c4..eb8fd1f 100644 --- a/src/com/android/dreams/phototable/PicasaSource.java +++ b/src/com/android/dreams/phototable/PicasaSource.java @@ -26,7 +26,6 @@ import android.view.WindowManager; import java.io.FileNotFoundException; import java.io.InputStream; -import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -36,7 +35,7 @@ import java.util.Set; /** * Loads images from Picasa. */ -public class PicasaSource extends PhotoSource { +public class PicasaSource extends CursorPhotoSource { private static final String TAG = "PhotoTable.PicasaSource"; private static final String PICASA_AUTHORITY = @@ -61,7 +60,6 @@ public class PicasaSource extends PhotoSource { private static final String PICASA_TYPE_KEY = "type"; private static final String PICASA_TYPE_FULL_VALUE = "full"; private static final String PICASA_TYPE_SCREEN_VALUE = "screennail"; - private static final String PICASA_TYPE_THUMB_VALUE = "thumbnail"; private static final String PICASA_TYPE_IMAGE_VALUE = "image"; private static final String PICASA_POSTS_TYPE = "Buzz"; private static final String PICASA_UPLOAD_TYPE = "InstantUpload"; @@ -90,6 +88,7 @@ public class PicasaSource extends PhotoSource { mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); mRecycleBin = new LinkedList<ImageData>(); + fillQueue(); mDisplayLongSide = getDisplayLongSide(); } @@ -103,6 +102,65 @@ public class PicasaSource extends PhotoSource { } @Override + protected void openCursor(ImageData data) { + log(TAG, "opening single album"); + + String[] projection = {PICASA_ID, PICASA_URL, PICASA_ROTATION, PICASA_ALBUM_ID}; + String selection = PICASA_ALBUM_ID + " = '" + data.albumId + "'"; + + Uri.Builder picasaUriBuilder = new Uri.Builder() + .scheme("content") + .authority(PICASA_AUTHORITY) + .appendPath(PICASA_PHOTO_PATH); + data.cursor = mResolver.query(picasaUriBuilder.build(), + projection, selection, null, null); + } + + @Override + protected void findPosition(ImageData data) { + if (data.position == UNINITIALIZED) { + if (data.cursor == null) { + openCursor(data); + } + if (data.cursor != null) { + int idIndex = data.cursor.getColumnIndex(PICASA_ID); + data.cursor.moveToPosition(-1); + while (data.position == -1 && data.cursor.moveToNext()) { + String id = data.cursor.getString(idIndex); + if (id != null && id.equals(data.id)) { + data.position = data.cursor.getPosition(); + } + } + if (data.position == -1) { + // oops! The image isn't in this album. How did we get here? + data.position = INVALID; + } + } + } + } + + @Override + protected ImageData unpackImageData(Cursor cursor, ImageData data) { + if (data == null) { + data = new ImageData(); + } + int idIndex = cursor.getColumnIndex(PICASA_ID); + int urlIndex = cursor.getColumnIndex(PICASA_URL); + int bucketIndex = cursor.getColumnIndex(PICASA_ALBUM_ID); + + data.id = cursor.getString(idIndex); + if (bucketIndex >= 0) { + data.albumId = cursor.getString(bucketIndex); + } + if (urlIndex >= 0) { + data.url = cursor.getString(urlIndex); + } + data.position = UNINITIALIZED; + data.cursor = null; + return data; + } + + @Override protected Collection<ImageData> findImages(int howMany) { log(TAG, "finding images"); LinkedList<ImageData> foundImages = new LinkedList<ImageData>(); @@ -117,7 +175,6 @@ public class PicasaSource extends PhotoSource { } String[] projection = {PICASA_ID, PICASA_URL, PICASA_ROTATION, PICASA_ALBUM_ID}; - boolean usePosts = false; LinkedList<String> albumIds = new LinkedList<String>(); for (String id : getFoundAlbums()) { if (mSettings.isAlbumEnabled(id)) { @@ -170,22 +227,13 @@ public class PicasaSource extends PhotoSource { cursor.moveToPosition(mLastPosition); int idIndex = cursor.getColumnIndex(PICASA_ID); - int urlIndex = cursor.getColumnIndex(PICASA_URL); - int orientationIndex = cursor.getColumnIndex(PICASA_ROTATION); - int bucketIndex = cursor.getColumnIndex(PICASA_ALBUM_ID); if (idIndex < 0) { log(TAG, "can't find the ID column!"); } else { while (cursor.moveToNext()) { if (idIndex >= 0) { - ImageData data = new ImageData(); - data.id = cursor.getString(idIndex); - - if (urlIndex >= 0) { - data.url = cursor.getString(urlIndex); - } - + ImageData data = unpackImageData(cursor, null); foundImages.offer(data); } mLastPosition = cursor.getPosition(); @@ -255,7 +303,6 @@ public class PicasaSource extends PhotoSource { cursor.moveToPosition(-1); int idIndex = cursor.getColumnIndex(PICASA_ID); - int typeIndex = cursor.getColumnIndex(PICASA_ALBUM_TYPE); if (idIndex < 0) { log(TAG, "can't find the ID column!"); @@ -398,9 +445,6 @@ public class PicasaSource extends PhotoSource { } catch (FileNotFoundException fnf) { log(TAG, "file not found: " + fnf); is = null; - } catch (IOException ioe) { - log(TAG, "i/o exception: " + ioe); - is = null; } if (is != null) { |