Refactoring

This commit is contained in:
M66B
2019-06-22 14:41:02 +02:00
parent af5b3ba467
commit c55936b806
2 changed files with 41 additions and 40 deletions

View File

@@ -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 {