diff options
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java b/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java index 3a245d62..da5cbf09 100644 --- a/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java +++ b/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java @@ -23,6 +23,7 @@ import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.RectF; +import android.media.ExifInterface; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; @@ -30,6 +31,7 @@ import android.util.Base64; import android.util.Base64OutputStream; import android.util.Log; import android.webkit.MimeTypeMap; +import android.widget.ImageView; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.R; @@ -39,6 +41,7 @@ import de.thedevstack.conversationsplus.entities.Message; import de.thedevstack.conversationsplus.services.XmppConnectionService; import de.thedevstack.conversationsplus.utils.CryptoHelper; import de.thedevstack.conversationsplus.utils.ExifHelper; +import de.thedevstack.conversationsplus.utils.FileHelper; import de.thedevstack.conversationsplus.xmpp.pep.Avatar; public class FileBackend { @@ -95,7 +98,7 @@ public class FileBackend { public static String getConversationsImageDirectory() { return Environment.getExternalStoragePublicDirectory( - Environment.DIRECTORY_PICTURES).getAbsolutePath() + Environment.DIRECTORY_PICTURES).getAbsolutePath() + "/Conversations/"; } @@ -127,24 +130,7 @@ public class FileBackend { } public String getOriginalPath(Uri uri) { - String path = null; - if (uri.getScheme().equals("file")) { - return uri.getPath(); - } else if (uri.toString().startsWith("content://media/")) { - String[] projection = {MediaStore.MediaColumns.DATA}; - Cursor metaCursor = mXmppConnectionService.getContentResolver().query(uri, - projection, null, null, null); - if (metaCursor != null) { - try { - if (metaCursor.moveToFirst()) { - path = metaCursor.getString(0); - } - } finally { - metaCursor.close(); - } - } - } - return path; + return FileHelper.getRealPathFromUri(uri); } public DownloadableFile copyFileToPrivateStorage(Message message, Uri uri) throws FileCopyException { @@ -268,13 +254,43 @@ public class FileBackend { throw new FileNotFoundException(); } thumbnail = resize(fullsize, size); - this.mXmppConnectionService.getBitmapCache().put(message.getUuid(), + try { + thumbnail = rotate(thumbnail, file.getAbsolutePath()); + } catch (IOException e) { + throw new FileNotFoundException(); + } + this.mXmppConnectionService.getBitmapCache().put(message.getUuid(), thumbnail); } return thumbnail; } - public Uri getTakePhotoUri() { + private Bitmap rotate(Bitmap original, String srcPath) throws IOException { + try { + ExifInterface exif = new ExifInterface(srcPath); + int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); + int rotation = 0; + switch (orientation) { + case ExifInterface.ORIENTATION_ROTATE_90: + rotation = 90; + break; + case ExifInterface.ORIENTATION_ROTATE_180: + rotation = 180; + break; + case ExifInterface.ORIENTATION_ROTATE_270: + rotation = 270; + break; + } + if (rotation > 0) { + return rotate(original, rotation); + } + } catch (IOException e) { + Log.w("filebackend", "Error while rotating image, returning original"); + } + return original; + } + + public Uri getTakePhotoUri() { StringBuilder pathBuilder = new StringBuilder(); pathBuilder.append(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)); pathBuilder.append('/'); |