This commit is contained in:
tom79 2019-08-04 11:22:49 +02:00
parent 27447a8ad3
commit 34629f6d35
2 changed files with 39 additions and 5 deletions

View File

@ -104,7 +104,7 @@ dependencies {
implementation 'com.github.stom79:horizontalbargraph:1.5' implementation 'com.github.stom79:horizontalbargraph:1.5'
implementation 'jp.wasabeef:glide-transformations:4.0.0' implementation 'jp.wasabeef:glide-transformations:4.0.0'
playstoreImplementation "io.github.kobakei:ratethisapp:$ratethisappLibraryVersion" playstoreImplementation "io.github.kobakei:ratethisapp:$ratethisappLibraryVersion"
implementation 'ja.burhanrashid52:photoeditor:0.3.3' implementation 'ja.burhanrashid52:photoeditor:0.4.0'
implementation 'com.github.yalantis:ucrop:2.2.3' implementation 'com.github.yalantis:ucrop:2.2.3'
implementation "net.gotev:uploadservice:$uploadServiceVersion" implementation "net.gotev:uploadservice:$uploadServiceVersion"

View File

@ -18,9 +18,10 @@ import android.annotation.SuppressLint;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.exifinterface.media.ExifInterface;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import android.view.Window; import android.view.Window;
@ -63,6 +64,7 @@ import com.yalantis.ucrop.UCrop;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
@ -170,6 +172,18 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
mPhotoEditorView.getSource().setImageURI(uri); mPhotoEditorView.getSource().setImageURI(uri);
if( uri != null ) {
try (InputStream inputStream = getContentResolver().openInputStream(uri)) {
assert inputStream != null;
ExifInterface exif = new ExifInterface(inputStream);
int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
int rotationInDegrees = exifToDegrees(rotation);
mPhotoEditorView.getSource().setRotation(rotationInDegrees);
} catch (Exception e) {
e.printStackTrace();
}
}
Button send = findViewById(R.id.send); Button send = findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener() { send.setOnClickListener(new View.OnClickListener() {
@ -181,6 +195,13 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
}); });
} }
private static int exifToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; }
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { return 180; }
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { return 270; }
return 0;
}
private void initViews() { private void initViews() {
ImageView imgUndo; ImageView imgUndo;
ImageView imgRedo; ImageView imgRedo;
@ -232,9 +253,6 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
public void onAddViewListener(ViewType viewType, int numberOfAddedViews) { public void onAddViewListener(ViewType viewType, int numberOfAddedViews) {
} }
@Override
public void onRemoveViewListener(int numberOfAddedViews) {
}
@Override @Override
public void onRemoveViewListener(ViewType viewType, int numberOfAddedViews) { public void onRemoveViewListener(ViewType viewType, int numberOfAddedViews) {
@ -331,11 +349,25 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
ExifInterface exif = null;
int rotation = 0;
int rotationInDegrees = 0;
if( data != null && data.getData() != null) {
try (InputStream inputStream = getContentResolver().openInputStream(data.getData())) {
assert inputStream != null;
exif = new androidx.exifinterface.media.ExifInterface(inputStream);
rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
rotationInDegrees = exifToDegrees(rotation);
} catch (Exception e) {
e.printStackTrace();
}
}
switch (requestCode) { switch (requestCode) {
case CAMERA_REQUEST: case CAMERA_REQUEST:
mPhotoEditor.clearAllViews(); mPhotoEditor.clearAllViews();
Bitmap photo = (Bitmap) data.getExtras().get("data"); Bitmap photo = (Bitmap) data.getExtras().get("data");
mPhotoEditorView.getSource().setImageBitmap(photo); mPhotoEditorView.getSource().setImageBitmap(photo);
mPhotoEditorView.getSource().setRotation(rotationInDegrees);
break; break;
case PICK_REQUEST: case PICK_REQUEST:
try { try {
@ -343,6 +375,7 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
Uri uri = data.getData(); Uri uri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri); Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
mPhotoEditorView.getSource().setImageBitmap(bitmap); mPhotoEditorView.getSource().setImageBitmap(bitmap);
mPhotoEditorView.getSource().setRotation(rotationInDegrees);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -351,6 +384,7 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorL
final Uri resultUri = UCrop.getOutput(data); final Uri resultUri = UCrop.getOutput(data);
if( resultUri != null) { if( resultUri != null) {
mPhotoEditorView.getSource().setImageURI(resultUri); mPhotoEditorView.getSource().setImageURI(resultUri);
mPhotoEditorView.getSource().setRotation(rotationInDegrees);
File fdelete = new File(uri.getPath()); File fdelete = new File(uri.getPath());
if (fdelete.exists()) { if (fdelete.exists()) {
fdelete.delete(); fdelete.delete();