diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 91284a07e5..884a8a7398 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -98,7 +98,6 @@ import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.Group; import androidx.core.content.FileProvider; import androidx.cursoradapter.widget.SimpleCursorAdapter; -import androidx.exifinterface.media.ExifInterface; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Observer; import androidx.localbroadcastmanager.content.LocalBroadcastManager; @@ -1868,8 +1867,8 @@ public class FragmentCompose extends FragmentBase { options.outHeight / factor > resize) factor *= 2; - Log.i("Image type=" + attachment.type + " rotation=" + getImageRotation(file)); - Matrix rotation = ("image/jpeg".equals(attachment.type) ? getImageRotation(file) : null); + Matrix rotation = ("image/jpeg".equals(attachment.type) ? Helper.getImageRotation(file) : null); + Log.i("Image type=" + attachment.type + " rotation=" + rotation); if (factor > 1 || rotation != null) { options.inJustDecodeBounds = false; @@ -1910,43 +1909,6 @@ public class FragmentCompose extends FragmentBase { return attachment; } - private static Matrix getImageRotation(File file) throws IOException { - ExifInterface exif = new ExifInterface(file.getAbsolutePath()); - int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); - - Matrix matrix = new Matrix(); - switch (orientation) { - case ExifInterface.ORIENTATION_NORMAL: - return null; - case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: - matrix.setScale(-1, 1); - return matrix; - case ExifInterface.ORIENTATION_FLIP_VERTICAL: - matrix.setRotate(180); - matrix.postScale(-1, 1); - return matrix; - case ExifInterface.ORIENTATION_TRANSPOSE: - matrix.setRotate(90); - matrix.postScale(-1, 1); - return matrix; - case ExifInterface.ORIENTATION_TRANSVERSE: - matrix.setRotate(-90); - matrix.postScale(-1, 1); - return matrix; - case ExifInterface.ORIENTATION_ROTATE_90: - matrix.setRotate(90); - return matrix; - case ExifInterface.ORIENTATION_ROTATE_180: - matrix.setRotate(180); - return matrix; - case ExifInterface.ORIENTATION_ROTATE_270: - matrix.setRotate(-90); - return matrix; - default: - return null; - } - } - private SimpleTask draftLoader = new SimpleTask() { @Override protected EntityMessage onExecute(Context context, Bundle args) throws Throwable { diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index e71a4cc645..40a1679fac 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -29,6 +29,7 @@ import android.content.pm.ResolveInfo; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Matrix; import android.net.Uri; import android.os.Bundle; import android.os.Parcel; @@ -52,6 +53,7 @@ import androidx.annotation.NonNull; import androidx.browser.customtabs.CustomTabsIntent; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.content.ContextCompat; +import androidx.exifinterface.media.ExifInterface; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleOwner; import androidx.preference.PreferenceManager; @@ -523,6 +525,43 @@ public class Helper { return BitmapFactory.decodeFile(file.getAbsolutePath()); } + static Matrix getImageRotation(File file) throws IOException { + ExifInterface exif = new ExifInterface(file.getAbsolutePath()); + int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); + + Matrix matrix = new Matrix(); + switch (orientation) { + case ExifInterface.ORIENTATION_NORMAL: + return null; + case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: + matrix.setScale(-1, 1); + return matrix; + case ExifInterface.ORIENTATION_FLIP_VERTICAL: + matrix.setRotate(180); + matrix.postScale(-1, 1); + return matrix; + case ExifInterface.ORIENTATION_TRANSPOSE: + matrix.setRotate(90); + matrix.postScale(-1, 1); + return matrix; + case ExifInterface.ORIENTATION_TRANSVERSE: + matrix.setRotate(-90); + matrix.postScale(-1, 1); + return matrix; + case ExifInterface.ORIENTATION_ROTATE_90: + matrix.setRotate(90); + return matrix; + case ExifInterface.ORIENTATION_ROTATE_180: + matrix.setRotate(180); + return matrix; + case ExifInterface.ORIENTATION_ROTATE_270: + matrix.setRotate(-90); + return matrix; + default: + return null; + } + } + // Cryptography static String sha256(String data) throws NoSuchAlgorithmException {