summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d
diff options
context:
space:
mode:
authorRuben Brunk <rubenbrunk@google.com>2013-06-11 13:21:02 -0700
committerRuben Brunk <rubenbrunk@google.com>2013-06-11 13:25:33 -0700
commit1e2b3f8be10ca20f6807ed71f160d6f6a8ab1c81 (patch)
tree553c7b12d2d0fadd6925fa8624d1ccdf7a2a2467 /src/com/android/gallery3d
parentc76547793270371785f9b928e173e1dbc238ef37 (diff)
downloadandroid_packages_apps_Snap-1e2b3f8be10ca20f6807ed71f160d6f6a8ab1c81.tar.gz
android_packages_apps_Snap-1e2b3f8be10ca20f6807ed71f160d6f6a8ab1c81.tar.bz2
android_packages_apps_Snap-1e2b3f8be10ca20f6807ed71f160d6f6a8ab1c81.zip
Mirror CL 319301 in Bryce.
Change-Id: If84a08aa1969415a0d5d9ad3b9153743b1951108
Diffstat (limited to 'src/com/android/gallery3d')
-rw-r--r--src/com/android/gallery3d/filtershow/crop/CropLoader.java56
1 files changed, 36 insertions, 20 deletions
diff --git a/src/com/android/gallery3d/filtershow/crop/CropLoader.java b/src/com/android/gallery3d/filtershow/crop/CropLoader.java
index fc461f5d0..53a9ebc14 100644
--- a/src/com/android/gallery3d/filtershow/crop/CropLoader.java
+++ b/src/com/android/gallery3d/filtershow/crop/CropLoader.java
@@ -30,6 +30,7 @@ import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Images.ImageColumns;
import android.util.Log;
+import android.webkit.MimeTypeMap;
import com.android.gallery3d.common.Utils;
import com.android.gallery3d.exif.ExifInterface;
@@ -64,39 +65,45 @@ public abstract class CropLoader {
if (uri == null || context == null) {
throw new IllegalArgumentException("bad argument to getScaledBitmap");
}
- if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
- String mimeType = context.getContentResolver().getType(uri);
- if (mimeType != JPEG_MIME_TYPE) {
- return 0;
- }
- String path = uri.getPath();
- int orientation = 0;
- ExifInterface exif = new ExifInterface();
- try {
- exif.readExif(path);
- orientation = ExifInterface.getRotationForOrientationValue(
- exif.getTagIntValue(ExifInterface.TAG_ORIENTATION).shortValue());
- } catch (IOException e) {
- Log.w(LOGTAG, "Failed to read EXIF orientation", e);
- }
- return orientation;
- }
+
+ // First try to find orientation data in Gallery's ContentProvider.
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri,
new String[] { MediaStore.Images.ImageColumns.ORIENTATION },
null, null, null);
- if (cursor.moveToNext()) {
+ if (cursor != null && cursor.moveToNext()) {
int ori = cursor.getInt(0);
return (ori < 0) ? 0 : ori;
}
} catch (SQLiteException e) {
- return 0;
+ // Do nothing
} catch (IllegalArgumentException e) {
- return 0;
+ // Do nothing
} finally {
Utils.closeSilently(cursor);
}
+
+ // Fall back to checking EXIF tags in file.
+ if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
+ String mimeType = getMimeType(uri);
+ if (!JPEG_MIME_TYPE.equals(mimeType)) {
+ return 0;
+ }
+ String path = uri.getPath();
+ int orientation = 0;
+ ExifInterface exif = new ExifInterface();
+ try {
+ exif.readExif(path);
+ Integer tagval = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION);
+ if (tagval != null) {
+ orientation = ExifInterface.getRotationForOrientationValue(tagval.shortValue());
+ }
+ } catch (IOException e) {
+ Log.w(LOGTAG, "Failed to read EXIF orientation", e);
+ }
+ return orientation;
+ }
return 0;
}
@@ -252,6 +259,15 @@ public abstract class CropLoader {
return dir[0];
}
+ private static String getMimeType(Uri src) {
+ String postfix = MimeTypeMap.getFileExtensionFromUrl(src.toString());
+ String ret = null;
+ if (postfix != null) {
+ ret = MimeTypeMap.getSingleton().getMimeTypeFromExtension(postfix);
+ }
+ return ret;
+ }
+
public static Uri insertContent(Context context, Uri sourceUri, File file, String saveFileName,
long time) {
time /= 1000;