diff options
| author | Shri Borde <shri@google.com> | 2014-08-19 10:42:00 -0700 |
|---|---|---|
| committer | Shri Borde <shri@google.com> | 2014-08-19 10:42:00 -0700 |
| commit | e36676cf09e0f48164831479a6427f4c9c26a40b (patch) | |
| tree | 1a5116a50c8249a7ea8e7e5a27cbb20b688957a3 | |
| parent | 0641890f68d850e17e8fbf2407e338a4bb18eec1 (diff) | |
| download | android_frameworks_opt_photoviewer-e36676cf09e0f48164831479a6427f4c9c26a40b.tar.gz android_frameworks_opt_photoviewer-e36676cf09e0f48164831479a6427f4c9c26a40b.tar.bz2 android_frameworks_opt_photoviewer-e36676cf09e0f48164831479a6427f4c9c26a40b.zip | |
Add PhotoPagerAdapter.getContentType api
All the columns are now exposed as an api
Change-Id: I8bdf4f00f8ee8ed9e2d535e49b13399599f74743
| -rw-r--r-- | src/com/android/ex/photo/adapters/PhotoPagerAdapter.java | 67 | ||||
| -rw-r--r-- | src/com/android/ex/photo/provider/PhotoContract.java | 4 |
2 files changed, 47 insertions, 24 deletions
diff --git a/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java b/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java index b937365..a09bb63 100644 --- a/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java +++ b/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java @@ -21,19 +21,20 @@ import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.support.v4.app.Fragment; +import android.support.v4.util.SimpleArrayMap; import com.android.ex.photo.Intents; import com.android.ex.photo.Intents.PhotoViewIntentBuilder; import com.android.ex.photo.fragments.PhotoViewFragment; -import com.android.ex.photo.provider.PhotoContract; +import com.android.ex.photo.provider.PhotoContract.PhotoViewColumns; +import com.android.ex.photo.provider.PhotoContract.PhotoQuery; /** * Pager adapter for the photo view */ public class PhotoPagerAdapter extends BaseCursorPagerAdapter { - protected int mContentUriIndex; - protected int mThumbnailUriIndex; - protected int mLoadingIndex; + protected SimpleArrayMap<String, Integer> mColumnIndices = + new SimpleArrayMap<String, Integer>(PhotoQuery.PROJECTION.length); protected final float mMaxScale; protected boolean mDisplayThumbsFullScreen; @@ -47,14 +48,9 @@ public class PhotoPagerAdapter extends BaseCursorPagerAdapter { @Override 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; - } + final String photoUri = getPhotoUri(cursor); + final String thumbnailUri = getThumbnailUri(cursor); + boolean loading = shouldShowLoadingIndicator(cursor); boolean onlyShowSpinner = false; if(photoUri == null && loading) { onlyShowSpinner = true; @@ -83,27 +79,50 @@ public class PhotoPagerAdapter extends BaseCursorPagerAdapter { @Override public Cursor swapCursor(Cursor newCursor) { + mColumnIndices.clear(); + if (newCursor != null) { - mContentUriIndex = - 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; + for(String column : PhotoQuery.PROJECTION) { + mColumnIndices.put(column, newCursor.getColumnIndexOrThrow(column)); + } + + for(String column : PhotoQuery.OPTIONAL_COLUMNS) { + int index = newCursor.getColumnIndex(column); + if (index != -1) { + mColumnIndices.put(column, index); + } + } } return super.swapCursor(newCursor); } public String getPhotoUri(Cursor cursor) { - return cursor.getString(mContentUriIndex); + return getString(cursor, PhotoViewColumns.CONTENT_URI); } public String getThumbnailUri(Cursor cursor) { - return cursor.getString(mThumbnailUriIndex); + return getString(cursor, PhotoViewColumns.THUMBNAIL_URI); + } + + public String getContentType(Cursor cursor) { + return getString(cursor, PhotoViewColumns.CONTENT_TYPE); + } + + public boolean shouldShowLoadingIndicator(Cursor cursor) { + String value = getString(cursor, PhotoViewColumns.LOADING_INDICATOR); + if (value == null) { + return false; + } else { + return Boolean.valueOf(value); + } + } + + private String getString(Cursor cursor, String column) { + if (mColumnIndices.containsKey(column)) { + return cursor.getString(mColumnIndices.get(column)); + } else { + return null; + } } } diff --git a/src/com/android/ex/photo/provider/PhotoContract.java b/src/com/android/ex/photo/provider/PhotoContract.java index c7e49fd..b79310e 100644 --- a/src/com/android/ex/photo/provider/PhotoContract.java +++ b/src/com/android/ex/photo/provider/PhotoContract.java @@ -64,6 +64,10 @@ public final class PhotoContract { PhotoViewColumns.THUMBNAIL_URI, PhotoViewColumns.CONTENT_TYPE }; + + public final static String[] OPTIONAL_COLUMNS = { + PhotoViewColumns.LOADING_INDICATOR + }; } public static final class ContentTypeParameters { |
