diff options
author | Jeff Sharkey <jsharkey@android.com> | 2013-08-23 23:18:11 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-08-23 23:18:11 +0000 |
commit | 365768fd3533343d6631875d7d46882907f7ab09 (patch) | |
tree | 2229069f7e5fdcd8006a97c4664e8466f82bda3e /packages/ExternalStorageProvider | |
parent | 98d6212327d1c483894b642d5e24c3aac9fca9cf (diff) | |
parent | 6398343e83b3fd11dd6536cf6f390a52c1e19d2e (diff) | |
download | frameworks_base-365768fd3533343d6631875d7d46882907f7ab09.zip frameworks_base-365768fd3533343d6631875d7d46882907f7ab09.tar.gz frameworks_base-365768fd3533343d6631875d7d46882907f7ab09.tar.bz2 |
Merge "Return EXIF thumbnails when available." into klp-dev
Diffstat (limited to 'packages/ExternalStorageProvider')
-rw-r--r-- | packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java index b4bf563..8843e19 100644 --- a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java +++ b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java @@ -20,10 +20,13 @@ import android.content.ContentProvider; import android.content.ContentResolver; import android.content.ContentValues; import android.content.UriMatcher; +import android.content.res.AssetFileDescriptor; import android.database.Cursor; import android.database.MatrixCursor; import android.database.MatrixCursor.RowBuilder; +import android.media.ExifInterface; import android.net.Uri; +import android.os.Bundle; import android.os.Environment; import android.os.ParcelFileDescriptor; import android.provider.DocumentsContract; @@ -296,7 +299,6 @@ public class ExternalStorageProvider extends ContentProvider { final Root root = mRoots.get(DocumentsContract.getRootId(uri)); final String docId = DocumentsContract.getDocId(uri); - // TODO: offer as thumbnail final File file = docIdToFile(root, docId); return ParcelFileDescriptor.open(file, ContentResolver.modeToMode(uri, mode)); } @@ -307,6 +309,39 @@ public class ExternalStorageProvider extends ContentProvider { } @Override + public AssetFileDescriptor openTypedAssetFile(Uri uri, String mimeTypeFilter, Bundle opts) + throws FileNotFoundException { + if (opts == null || !opts.containsKey(DocumentsContract.EXTRA_THUMBNAIL_SIZE)) { + return super.openTypedAssetFile(uri, mimeTypeFilter, opts); + } + + switch (sMatcher.match(uri)) { + case URI_DOCS_ID: { + final Root root = mRoots.get(DocumentsContract.getRootId(uri)); + final String docId = DocumentsContract.getDocId(uri); + + final File file = docIdToFile(root, docId); + final ParcelFileDescriptor pfd = ParcelFileDescriptor.open( + file, ParcelFileDescriptor.MODE_READ_ONLY); + + try { + final ExifInterface exif = new ExifInterface(file.getAbsolutePath()); + final long[] thumb = exif.getThumbnailRange(); + if (thumb != null) { + return new AssetFileDescriptor(pfd, thumb[0], thumb[1]); + } + } catch (IOException e) { + } + + return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH); + } + default: { + throw new UnsupportedOperationException("Unsupported Uri " + uri); + } + } + } + + @Override public Uri insert(Uri uri, ContentValues values) { switch (sMatcher.match(uri)) { case URI_DOCS_ID: { |