summaryrefslogtreecommitdiffstats
path: root/photoviewer
diff options
context:
space:
mode:
authorAdam Copp <adamcopp@google.com>2012-09-13 13:45:29 +0100
committerAdam Copp <adamcopp@google.com>2012-09-20 12:28:49 +0100
commit5b5c48652859e1ba79542f59f94398f18e76ca30 (patch)
tree789a75afaa7023a396c13d2e9b28978bfe75c529 /photoviewer
parent685658bb07dc786536e038060fdeec975aa62176 (diff)
downloadandroid_frameworks_ex-5b5c48652859e1ba79542f59f94398f18e76ca30.tar.gz
android_frameworks_ex-5b5c48652859e1ba79542f59f94398f18e76ca30.tar.bz2
android_frameworks_ex-5b5c48652859e1ba79542f59f94398f18e76ca30.zip
Add option to permenantly show ProgressBar
In order to indicate to the user that more content is loading, the provider can provide an image with the loading field set and null as it's url. In this case, we will not try loading any image, and will just show the ProgressBar. Something like this is nessecary in Velvet, where we wish to load infinite images. Change-Id: Ib26412a579abdbe7fbd338b99ff39f4d1c13f806
Diffstat (limited to 'photoviewer')
-rw-r--r--photoviewer/src/com/android/ex/photo/adapters/BaseCursorPagerAdapter.java2
-rw-r--r--photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java18
-rw-r--r--photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java11
-rw-r--r--photoviewer/src/com/android/ex/photo/provider/PhotoContract.java5
-rw-r--r--photoviewer/src/com/android/ex/photo/util/ImageUtils.java1
5 files changed, 32 insertions, 5 deletions
diff --git a/photoviewer/src/com/android/ex/photo/adapters/BaseCursorPagerAdapter.java b/photoviewer/src/com/android/ex/photo/adapters/BaseCursorPagerAdapter.java
index f827690..ae2c92e 100644
--- a/photoviewer/src/com/android/ex/photo/adapters/BaseCursorPagerAdapter.java
+++ b/photoviewer/src/com/android/ex/photo/adapters/BaseCursorPagerAdapter.java
@@ -43,7 +43,7 @@ public abstract class BaseCursorPagerAdapter extends BaseFragmentPagerAdapter {
/** Mapping of row ID to cursor position */
private SparseIntArray mItemPosition;
/** Mapping of instantiated object to row ID */
- private HashMap<Object, Integer> mObjectRowMap = new HashMap<Object, Integer>();
+ private final HashMap<Object, Integer> mObjectRowMap = new HashMap<Object, Integer>();
/**
* Constructor that always enables auto-requery.
diff --git a/photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java b/photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java
index d22a378..4536432 100644
--- a/photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java
+++ b/photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java
@@ -33,7 +33,8 @@ import com.android.ex.photo.provider.PhotoContract;
public class PhotoPagerAdapter extends BaseCursorPagerAdapter {
private int mContentUriIndex;
private int mThumbnailUriIndex;
- private float mMaxScale;
+ private int mLoadingIndex;
+ private final float mMaxScale;
public PhotoPagerAdapter(Context context, FragmentManager fm, Cursor c, float maxScale) {
super(context, fm, c);
@@ -44,6 +45,16 @@ public class PhotoPagerAdapter extends BaseCursorPagerAdapter {
public Fragment getItem(Context context, Cursor cursor, int position) {
final String photoUri = cursor.getString(mContentUriIndex);
final String thumbnailUri = cursor.getString(mThumbnailUriIndex);
+ boolean loading;
+ if(mLoadingIndex != -1) {
+ loading = Boolean.valueOf(cursor.getString(mLoadingIndex));
+ } else {
+ loading = false;
+ }
+ boolean onlyShowSpinner = false;
+ if(photoUri == null && loading) {
+ onlyShowSpinner = true;
+ }
// create new PhotoViewFragment
final PhotoViewIntentBuilder builder =
@@ -53,7 +64,7 @@ public class PhotoPagerAdapter extends BaseCursorPagerAdapter {
.setThumbnailUri(thumbnailUri)
.setMaxInitialScale(mMaxScale);
- return new PhotoViewFragment(builder.build(), position, this);
+ return new PhotoViewFragment(builder.build(), position, this, onlyShowSpinner);
}
@Override
@@ -63,9 +74,12 @@ public class PhotoPagerAdapter extends BaseCursorPagerAdapter {
newCursor.getColumnIndex(PhotoContract.PhotoViewColumns.CONTENT_URI);
mThumbnailUriIndex =
newCursor.getColumnIndex(PhotoContract.PhotoViewColumns.THUMBNAIL_URI);
+ mLoadingIndex =
+ newCursor.getColumnIndex(PhotoContract.PhotoViewColumns.LOADING_INDICATOR);
} else {
mContentUriIndex = -1;
mThumbnailUriIndex = -1;
+ mLoadingIndex = -1;
}
return super.swapCursor(newCursor);
diff --git a/photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java b/photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java
index c6c2e3b..2cb0d36 100644
--- a/photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java
+++ b/photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java
@@ -106,6 +106,9 @@ public class PhotoViewFragment extends Fragment implements
/** Whether or not the fragment should make the photo full-screen */
private boolean mFullScreen;
+ /** Whether or not this fragment will only show the loading spinner */
+ private final boolean mOnlyShowSpinner;
+
/** Whether or not the progress bar is showing valid information about the progress stated */
private boolean mProgressBarNeeded = true;
@@ -113,13 +116,16 @@ public class PhotoViewFragment extends Fragment implements
public PhotoViewFragment() {
mPosition = -1;
+ mOnlyShowSpinner = false;
mProgressBarNeeded = true;
}
- public PhotoViewFragment(Intent intent, int position, PhotoPagerAdapter adapter) {
+ public PhotoViewFragment(Intent intent, int position, PhotoPagerAdapter adapter,
+ boolean onlyShowSpinner) {
mIntent = intent;
mPosition = position;
mAdapter = adapter;
+ mOnlyShowSpinner = onlyShowSpinner;
mProgressBarNeeded = true;
}
@@ -241,6 +247,9 @@ public class PhotoViewFragment extends Fragment implements
@Override
public Loader<Bitmap> onCreateLoader(int id, Bundle args) {
+ if(mOnlyShowSpinner) {
+ return null;
+ }
switch (id) {
case LOADER_ID_PHOTO:
return new PhotoBitmapLoader(getActivity(), mResolvedPhotoUri);
diff --git a/photoviewer/src/com/android/ex/photo/provider/PhotoContract.java b/photoviewer/src/com/android/ex/photo/provider/PhotoContract.java
index 439b68b..8483620 100644
--- a/photoviewer/src/com/android/ex/photo/provider/PhotoContract.java
+++ b/photoviewer/src/com/android/ex/photo/provider/PhotoContract.java
@@ -48,6 +48,11 @@ public final class PhotoContract {
* This string column is the MIME type.
*/
public static final String CONTENT_TYPE = "contentType";
+ /**
+ * This boolean column indicates that a loading indicator should display permenantly
+ * if no image urls are provided.
+ */
+ public static final String LOADING_INDICATOR = "loadingIndicator";
}
diff --git a/photoviewer/src/com/android/ex/photo/util/ImageUtils.java b/photoviewer/src/com/android/ex/photo/util/ImageUtils.java
index 9c1636b..a9790eb 100644
--- a/photoviewer/src/com/android/ex/photo/util/ImageUtils.java
+++ b/photoviewer/src/com/android/ex/photo/util/ImageUtils.java
@@ -33,7 +33,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
-import java.net.URLConnection;
/**
* Image utilities