summaryrefslogtreecommitdiff
path: root/src/com/android/dreams/phototable/PicasaSource.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/dreams/phototable/PicasaSource.java')
-rw-r--r--src/com/android/dreams/phototable/PicasaSource.java180
1 files changed, 162 insertions, 18 deletions
diff --git a/src/com/android/dreams/phototable/PicasaSource.java b/src/com/android/dreams/phototable/PicasaSource.java
index 061b66b..4d1c677 100644
--- a/src/com/android/dreams/phototable/PicasaSource.java
+++ b/src/com/android/dreams/phototable/PicasaSource.java
@@ -16,6 +16,7 @@
package com.android.dreams.phototable;
import android.content.Context;
+import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
@@ -23,6 +24,7 @@ import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;
import java.util.Collection;
+import java.util.HashMap;
import java.util.LinkedList;
/**
@@ -31,23 +33,39 @@ import java.util.LinkedList;
public class PicasaSource extends PhotoSource {
private static final String TAG = "PhotoTable.PicasaSource";
+ private static final String PICASA_AUTHORITY =
+ "com.google.android.gallery3d.GooglePhotoProvider";
+
+ private static final String PICASA_PHOTO_PATH = "photos";
+ private static final String PICASA_ALBUM_PATH = "albums";
+
private static final String PICASA_ID = "_id";
private static final String PICASA_URL = "content_url";
private static final String PICASA_ROTATION = "rotation";
private static final String PICASA_ALBUM_ID = "album_id";
+ private static final String PICASA_TITLE = "title";
+ private static final String PICASA_THUMB = "thumbnail_url";
+ private static final String PICASA_ALBUM_TYPE = "album_type";
+ private static final String PICASA_ALBUM_UPDATED = "date_updated";
private static final String PICASA_URL_KEY = "content_url";
private static final String PICASA_TYPE_KEY = "type";
- private static final String PICASA_TYPE_THUMB_VALUE = "full";
+ 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_BUZZ_TYPE = "Buzz";
- private int mNextPosition;
+ private final int mMaxPostAblums;
- public static final int TYPE = 3;
+ private int mNextPosition;
- public PicasaSource(Context context) {
- super(context);
+ public PicasaSource(Context context, SharedPreferences settings) {
+ super(context, settings);
mSourceName = TAG;
mNextPosition = -1;
+ mMaxPostAblums = mResources.getInteger(R.integer.max_post_albums);
+ log(TAG, "mSettings: " + mSettings);
fillQueue();
}
@@ -56,20 +74,45 @@ public class PicasaSource extends PhotoSource {
log(TAG, "finding images");
LinkedList<ImageData> foundImages = new LinkedList<ImageData>();
String[] projection = {PICASA_ID, PICASA_URL, PICASA_ROTATION, PICASA_ALBUM_ID};
- String[] selectionArgs = {}; // settings go here
- String selection = "";
- for (String arg : selectionArgs) {
- if (selection.length() > 0) {
- selection += " OR ";
+ StringBuilder selection = new StringBuilder();
+ boolean usePosts = false;
+ for (String id : AlbumSettings.getEnabledAlbums(mSettings)) {
+ if (id.startsWith(TAG)) {
+ String[] parts = id.split(":");
+ if (parts.length > 1) {
+ if (selection.length() > 0) {
+ selection.append(" OR ");
+ }
+ if (PICASA_BUZZ_TYPE.equals(parts[1])) {
+ usePosts = true;
+ } else {
+ log(TAG, "adding on: " + parts[1]);
+ selection.append(PICASA_ALBUM_ID + " = '" + parts[1] + "'");
+ }
+ }
}
- selection += PICASA_ALBUM_ID + " = '" + arg + "'";
}
+ if (usePosts) {
+ for (String id : findPostIds()) {
+ if (selection.length() > 0) {
+ selection.append(" OR ");
+ }
+ log(TAG, "adding on: " + id);
+ selection.append(PICASA_ALBUM_ID + " = '" + id + "'");
+ }
+ }
+
+ if (selection.length() == 0) {
+ return foundImages;
+ }
+ log(TAG, "selection is: " + selection.toString());
+
Uri.Builder picasaUriBuilder = new Uri.Builder()
.scheme("content")
- .authority("com.google.android.gallery3d.GooglePhotoProvider")
- .appendPath("photos");
+ .authority(PICASA_AUTHORITY)
+ .appendPath(PICASA_PHOTO_PATH);
Cursor cursor = mResolver.query(picasaUriBuilder.build(),
- projection, selection, null, null);
+ projection, selection.toString(), null, null);
if (cursor != null) {
if (cursor.getCount() > howMany && mNextPosition == -1) {
mNextPosition =
@@ -92,7 +135,6 @@ public class PicasaSource extends PhotoSource {
while (foundImages.size() < howMany && !cursor.isAfterLast()) {
if (idIndex >= 0) {
ImageData data = new ImageData();
- data.type = TYPE;
data.id = cursor.getString(idIndex);
if (urlIndex >= 0) {
@@ -116,16 +158,118 @@ public class PicasaSource extends PhotoSource {
return foundImages;
}
+ private Collection<String> findPostIds() {
+ LinkedList<String> postIds = new LinkedList<String>();
+ String[] projection = {PICASA_ID, PICASA_ALBUM_TYPE, PICASA_ALBUM_UPDATED};
+ String order = PICASA_ALBUM_UPDATED + " DESC";
+ Uri.Builder picasaUriBuilder = new Uri.Builder()
+ .scheme("content")
+ .authority(PICASA_AUTHORITY)
+ .appendPath(PICASA_ALBUM_PATH)
+ .appendQueryParameter(PICASA_TYPE_KEY, PICASA_TYPE_IMAGE_VALUE);
+ Cursor cursor = mResolver.query(picasaUriBuilder.build(),
+ projection, null, null, order);
+ if (cursor != null) {
+ cursor.moveToFirst();
+
+ int idIndex = cursor.getColumnIndex(PICASA_ID);
+ int typeIndex = cursor.getColumnIndex(PICASA_ALBUM_TYPE);
+
+ if (idIndex < 0) {
+ log(TAG, "can't find the ID column!");
+ } else {
+ while (postIds.size() < mMaxPostAblums && !cursor.isAfterLast()) {
+ if (typeIndex >= 0 && PICASA_BUZZ_TYPE.equals(cursor.getString(typeIndex))) {
+ postIds.add(cursor.getString(idIndex));
+ }
+ cursor.moveToNext();
+ }
+ }
+ cursor.close();
+ }
+ return postIds;
+ }
+
+ @Override
+ public Collection<AlbumData> findAlbums() {
+ log(TAG, "finding albums");
+ HashMap<String, AlbumData> foundAlbums = new HashMap<String, AlbumData>();
+ String[] projection = {PICASA_ID, PICASA_TITLE, PICASA_THUMB, PICASA_ALBUM_TYPE,
+ PICASA_ALBUM_UPDATED};
+ Uri.Builder picasaUriBuilder = new Uri.Builder()
+ .scheme("content")
+ .authority(PICASA_AUTHORITY)
+ .appendPath(PICASA_ALBUM_PATH)
+ .appendQueryParameter(PICASA_TYPE_KEY, PICASA_TYPE_IMAGE_VALUE);
+ Cursor cursor = mResolver.query(picasaUriBuilder.build(),
+ projection, null, null, null);
+ if (cursor != null) {
+ cursor.moveToFirst();
+
+ int idIndex = cursor.getColumnIndex(PICASA_ID);
+ int thumbIndex = cursor.getColumnIndex(PICASA_THUMB);
+ int titleIndex = cursor.getColumnIndex(PICASA_TITLE);
+ int typeIndex = cursor.getColumnIndex(PICASA_ALBUM_TYPE);
+ int updatedIndex = cursor.getColumnIndex(PICASA_ALBUM_UPDATED);
+
+ if (idIndex < 0) {
+ log(TAG, "can't find the ID column!");
+ } else {
+ while (!cursor.isAfterLast()) {
+ String id = TAG + ":" + cursor.getString(idIndex);
+ boolean isBuzz = (typeIndex >= 0 &&
+ PICASA_BUZZ_TYPE.equals(cursor.getString(typeIndex)));
+
+ if (isBuzz) {
+ id = TAG + ":" + PICASA_BUZZ_TYPE;
+ }
+
+ if (foundAlbums.get(id) == null) {
+ AlbumData data = new AlbumData();
+ data.id = id;
+
+ if (isBuzz) {
+ data.title =
+ mResources.getString(R.string.posts_album_name, "Posts");
+ } else if (titleIndex >= 0) {
+ data.title = cursor.getString(titleIndex);
+ } else {
+ data.title =
+ mResources.getString(R.string.unknown_album_name, "Unknown");
+ }
+
+ if (updatedIndex >= 0) {
+ data.updated = cursor.getLong(updatedIndex);
+ }
+
+ if (thumbIndex >= 0) {
+ data.thumbnailUrl = cursor.getString(thumbIndex);
+ }
+
+ log(TAG, "found " + data.title + "(" + data.id + ")");
+ foundAlbums.put(id, data);
+ }
+
+ cursor.moveToNext();
+ }
+ }
+ cursor.close();
+
+ }
+ log(TAG, "found " + foundAlbums.size() + " items.");
+ return foundAlbums.values();
+ }
+
@Override
protected InputStream getStream(ImageData data) {
InputStream is = null;
try {
Uri.Builder photoUriBuilder = new Uri.Builder()
.scheme("content")
- .authority("com.google.android.gallery3d.GooglePhotoProvider")
- .appendPath("photos")
+ .authority(PICASA_AUTHORITY)
+ .appendPath(PICASA_PHOTO_PATH)
.appendPath(data.id)
- .appendQueryParameter(PICASA_TYPE_KEY, PICASA_TYPE_THUMB_VALUE);
+ .appendQueryParameter(PICASA_TYPE_KEY, PICASA_TYPE_FULL_VALUE);
if (data.url != null) {
photoUriBuilder.appendQueryParameter(PICASA_URL_KEY, data.url);
}