From 5b5c48652859e1ba79542f59f94398f18e76ca30 Mon Sep 17 00:00:00 2001 From: Adam Copp Date: Thu, 13 Sep 2012 13:45:29 +0100 Subject: 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 --- .../ex/photo/adapters/BaseCursorPagerAdapter.java | 2 +- .../android/ex/photo/adapters/PhotoPagerAdapter.java | 18 ++++++++++++++++-- .../android/ex/photo/fragments/PhotoViewFragment.java | 11 ++++++++++- .../com/android/ex/photo/provider/PhotoContract.java | 5 +++++ .../src/com/android/ex/photo/util/ImageUtils.java | 1 - 5 files changed, 32 insertions(+), 5 deletions(-) (limited to 'photoviewer') 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 mObjectRowMap = new HashMap(); + private final HashMap mObjectRowMap = new HashMap(); /** * 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 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 -- cgit v1.2.3