summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2013-03-08 11:19:27 -0800
committerJohn Reck <jreck@google.com>2013-03-08 11:22:33 -0800
commit0d84f476ed24922864f39d54e09274f6feac085e (patch)
treee2f869a31eb1499a87d2517ae03e6ba6d0204406
parent75f1d6c7f6d9cb32187ff7d1bc443916c496e38a (diff)
downloadandroid_packages_apps_Snap-0d84f476ed24922864f39d54e09274f6feac085e.zip
android_packages_apps_Snap-0d84f476ed24922864f39d54e09274f6feac085e.tar.gz
android_packages_apps_Snap-0d84f476ed24922864f39d54e09274f6feac085e.tar.bz2
Support clicking on photos to view them
Change-Id: I511af0cbe46c833d81cbbd563b9c2b4feec2bffe
-rw-r--r--src/com/android/photos/AlbumSetFragment.java6
-rw-r--r--src/com/android/photos/PhotoSetFragment.java37
-rw-r--r--src/com/android/photos/data/PhotoSetLoader.java9
-rw-r--r--src/com/android/photos/shims/LoaderCompatShim.java (renamed from src/com/android/photos/drawables/DrawableFactory.java)6
-rw-r--r--src/com/android/photos/shims/MediaItemsLoader.java11
-rw-r--r--src/com/android/photos/shims/MediaSetLoader.java11
6 files changed, 64 insertions, 16 deletions
diff --git a/src/com/android/photos/AlbumSetFragment.java b/src/com/android/photos/AlbumSetFragment.java
index 6a37607..0d4fcc0 100644
--- a/src/com/android/photos/AlbumSetFragment.java
+++ b/src/com/android/photos/AlbumSetFragment.java
@@ -38,7 +38,7 @@ import android.widget.Toast;
import com.android.gallery3d.R;
import com.android.photos.data.AlbumSetLoader;
-import com.android.photos.drawables.DrawableFactory;
+import com.android.photos.shims.LoaderCompatShim;
import com.android.photos.shims.MediaSetLoader;
import java.util.Date;
@@ -108,9 +108,9 @@ public class AlbumSetFragment extends Fragment implements OnItemClickListener,
private static class AlbumSetCursorAdapter extends CursorAdapter {
- private DrawableFactory<Cursor> mDrawableFactory;
+ private LoaderCompatShim<Cursor> mDrawableFactory;
- public void setDrawableFactory(DrawableFactory<Cursor> factory) {
+ public void setDrawableFactory(LoaderCompatShim<Cursor> factory) {
mDrawableFactory = factory;
}
private Date mDate = new Date(); // Used for converting timestamps for display
diff --git a/src/com/android/photos/PhotoSetFragment.java b/src/com/android/photos/PhotoSetFragment.java
index 5911ad0..18587fc 100644
--- a/src/com/android/photos/PhotoSetFragment.java
+++ b/src/com/android/photos/PhotoSetFragment.java
@@ -19,32 +19,40 @@ package com.android.photos;
import android.app.Fragment;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.Context;
+import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
import android.widget.CursorAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import com.android.gallery3d.R;
+import com.android.gallery3d.app.Gallery;
import com.android.photos.data.PhotoSetLoader;
-import com.android.photos.drawables.DrawableFactory;
+import com.android.photos.shims.LoaderCompatShim;
import com.android.photos.shims.MediaItemsLoader;
import com.android.photos.views.GalleryThumbnailView.GalleryThumbnailAdapter;
-public class PhotoSetFragment extends Fragment implements LoaderCallbacks<Cursor> {
+public class PhotoSetFragment extends Fragment implements LoaderCallbacks<Cursor>,
+ OnItemClickListener {
private static final int LOADER_PHOTOSET = 1;
private GridView mPhotoSetView;
private View mEmptyView;
private ThumbnailAdapter mAdapter;
+ private boolean mInitialLoadComplete = false;
+ private LoaderCompatShim<Cursor> mLoaderCompatShim;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -59,6 +67,7 @@ public class PhotoSetFragment extends Fragment implements LoaderCallbacks<Cursor
mPhotoSetView = (GridView) root.findViewById(android.R.id.list);
// TODO: Remove once UI stabilizes
mPhotoSetView.setColumnWidth(MediaItemsLoader.getThumbnailSize());
+ mPhotoSetView.setOnItemClickListener(this);
mEmptyView = root.findViewById(android.R.id.empty);
mEmptyView.setVisibility(View.GONE);
mPhotoSetView.setAdapter(mAdapter);
@@ -70,7 +79,22 @@ public class PhotoSetFragment extends Fragment implements LoaderCallbacks<Cursor
private void updateEmptyStatus() {
boolean empty = (mAdapter == null || mAdapter.getCount() == 0);
mPhotoSetView.setVisibility(empty ? View.GONE : View.VISIBLE);
- mEmptyView.setVisibility(empty ? View.VISIBLE : View.GONE);
+ mEmptyView.setVisibility(empty && mInitialLoadComplete
+ ? View.VISIBLE : View.GONE);
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position,
+ long id) {
+ if (mLoaderCompatShim == null) {
+ // Not fully initialized yet, discard
+ return;
+ }
+ Cursor item = mAdapter.getItem(position);
+ Uri uri = mLoaderCompatShim.uriForItem(item);
+ Intent intent = new Intent(Intent.ACTION_VIEW, uri);
+ intent.setClass(getActivity(), Gallery.class);
+ startActivity(intent);
}
@Override
@@ -78,6 +102,8 @@ public class PhotoSetFragment extends Fragment implements LoaderCallbacks<Cursor
// TODO: Switch to PhotoSetLoader
MediaItemsLoader loader = new MediaItemsLoader(getActivity());
mAdapter.setDrawableFactory(loader);
+ mInitialLoadComplete = false;
+ mLoaderCompatShim = loader;
return loader;
}
@@ -85,6 +111,7 @@ public class PhotoSetFragment extends Fragment implements LoaderCallbacks<Cursor
public void onLoadFinished(Loader<Cursor> loader,
Cursor data) {
mAdapter.swapCursor(data);
+ mInitialLoadComplete = true;
updateEmptyStatus();
}
@@ -94,14 +121,14 @@ public class PhotoSetFragment extends Fragment implements LoaderCallbacks<Cursor
private static class ThumbnailAdapter extends CursorAdapter implements GalleryThumbnailAdapter {
private LayoutInflater mInflater;
- private DrawableFactory<Cursor> mDrawableFactory;
+ private LoaderCompatShim<Cursor> mDrawableFactory;
public ThumbnailAdapter(Context context) {
super(context, null, false);
mInflater = LayoutInflater.from(context);
}
- public void setDrawableFactory(DrawableFactory<Cursor> factory) {
+ public void setDrawableFactory(LoaderCompatShim<Cursor> factory) {
mDrawableFactory = factory;
}
diff --git a/src/com/android/photos/data/PhotoSetLoader.java b/src/com/android/photos/data/PhotoSetLoader.java
index 21da906..78662cd 100644
--- a/src/com/android/photos/data/PhotoSetLoader.java
+++ b/src/com/android/photos/data/PhotoSetLoader.java
@@ -27,9 +27,9 @@ import android.provider.MediaStore.Files;
import android.provider.MediaStore.Files.FileColumns;
import com.android.photos.drawables.DataUriThumbnailDrawable;
-import com.android.photos.drawables.DrawableFactory;
+import com.android.photos.shims.LoaderCompatShim;
-public class PhotoSetLoader extends CursorLoader implements DrawableFactory<Cursor> {
+public class PhotoSetLoader extends CursorLoader implements LoaderCompatShim<Cursor> {
private static final Uri CONTENT_URI = Files.getContentUri("external");
public static final String[] PROJECTION = new String[] {
@@ -85,4 +85,9 @@ public class PhotoSetLoader extends CursorLoader implements DrawableFactory<Curs
item.getInt(INDEX_WIDTH), item.getInt(INDEX_HEIGHT));
return drawable;
}
+
+ @Override
+ public Uri uriForItem(Cursor item) {
+ return null;
+ }
}
diff --git a/src/com/android/photos/drawables/DrawableFactory.java b/src/com/android/photos/shims/LoaderCompatShim.java
index ad046c8..9da4436 100644
--- a/src/com/android/photos/drawables/DrawableFactory.java
+++ b/src/com/android/photos/shims/LoaderCompatShim.java
@@ -14,11 +14,13 @@
* limitations under the License.
*/
-package com.android.photos.drawables;
+package com.android.photos.shims;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
-public interface DrawableFactory<T> {
+public interface LoaderCompatShim<T> {
Drawable drawableForItem(T item, Drawable recycle);
+ Uri uriForItem(T item);
}
diff --git a/src/com/android/photos/shims/MediaItemsLoader.java b/src/com/android/photos/shims/MediaItemsLoader.java
index 2907eaf..9c270a5 100644
--- a/src/com/android/photos/shims/MediaItemsLoader.java
+++ b/src/com/android/photos/shims/MediaItemsLoader.java
@@ -21,6 +21,7 @@ import android.content.Context;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
import android.provider.MediaStore.Files.FileColumns;
import android.util.SparseArray;
@@ -32,13 +33,12 @@ import com.android.gallery3d.data.MediaSet.ItemConsumer;
import com.android.gallery3d.data.MediaSet.SyncListener;
import com.android.gallery3d.util.Future;
import com.android.photos.data.PhotoSetLoader;
-import com.android.photos.drawables.DrawableFactory;
/**
* Returns all MediaItems in a MediaSet, wrapping them in a cursor to appear
* like a PhotoSetLoader
*/
-public class MediaItemsLoader extends AsyncTaskLoader<Cursor> implements DrawableFactory<Cursor> {
+public class MediaItemsLoader extends AsyncTaskLoader<Cursor> implements LoaderCompatShim<Cursor> {
private static final SyncListener sNullListener = new SyncListener() {
@Override
@@ -148,4 +148,11 @@ public class MediaItemsLoader extends AsyncTaskLoader<Cursor> implements Drawabl
return MediaItem.getTargetSize(MediaItem.TYPE_MICROTHUMBNAIL);
}
+ @Override
+ public Uri uriForItem(Cursor item) {
+ int index = item.getInt(PhotoSetLoader.INDEX_ID);
+ MediaItem mi = mMediaItems.get(index);
+ return mi == null ? null : mi.getContentUri();
+ }
+
}
diff --git a/src/com/android/photos/shims/MediaSetLoader.java b/src/com/android/photos/shims/MediaSetLoader.java
index 87039c2..96c7485 100644
--- a/src/com/android/photos/shims/MediaSetLoader.java
+++ b/src/com/android/photos/shims/MediaSetLoader.java
@@ -21,6 +21,7 @@ import android.content.Context;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
import com.android.gallery3d.data.ContentListener;
import com.android.gallery3d.data.DataManager;
@@ -29,7 +30,6 @@ import com.android.gallery3d.data.MediaSet;
import com.android.gallery3d.data.MediaSet.SyncListener;
import com.android.gallery3d.util.Future;
import com.android.photos.data.AlbumSetLoader;
-import com.android.photos.drawables.DrawableFactory;
import java.util.ArrayList;
@@ -37,7 +37,7 @@ import java.util.ArrayList;
* Returns all MediaSets in a MediaSet, wrapping them in a cursor to appear
* like a AlbumSetLoader.
*/
-public class MediaSetLoader extends AsyncTaskLoader<Cursor> implements DrawableFactory<Cursor>{
+public class MediaSetLoader extends AsyncTaskLoader<Cursor> implements LoaderCompatShim<Cursor>{
private static final SyncListener sNullListener = new SyncListener() {
@Override
@@ -140,4 +140,11 @@ public class MediaSetLoader extends AsyncTaskLoader<Cursor> implements DrawableF
public static int getThumbnailSize() {
return MediaItem.getTargetSize(MediaItem.TYPE_MICROTHUMBNAIL);
}
+
+ @Override
+ public Uri uriForItem(Cursor item) {
+ int index = item.getInt(AlbumSetLoader.INDEX_ID);
+ MediaSet ms = mMediaSet.getSubMediaSet(index);
+ return ms == null ? null : ms.getContentUri();
+ }
}