diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ac3fe69..8350e0e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -55,6 +55,18 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasChooseBaseActivity.java b/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasChooseBaseActivity.java index 494ddb1..42687a7 100644 --- a/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasChooseBaseActivity.java +++ b/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasChooseBaseActivity.java @@ -62,6 +62,14 @@ protected void onCreate(Bundle savedInstanceState) { } protected void SetImageUriAndLastCropArea(Uri uri, Bundle savedInstanceState) { + final Rect crop = (Rect) ((savedInstanceState == null) + ? null + : savedInstanceState.getParcelable(CURRENT_CROP_AREA)); + + SetImageUriAndLastCropArea(uri, crop); + } + + protected void SetImageUriAndLastCropArea(Uri uri, Rect crop) { try { /* @@ -72,10 +80,6 @@ protected void SetImageUriAndLastCropArea(Uri uri, Bundle savedInstanceState) { */ uCropView.setImageUriAsync(uri); - final Rect crop = (Rect) ((savedInstanceState == null) - ? null - : savedInstanceState.getParcelable(CURRENT_CROP_AREA)); - setCropRect(crop); } catch (Exception e) { diff --git a/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasGetContentActivity.java b/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasGetContentActivity.java new file mode 100644 index 0000000..4d6a9d7 --- /dev/null +++ b/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasGetContentActivity.java @@ -0,0 +1,101 @@ +package de.k3b.android.lossless_jpg_crop; + +import android.app.Activity; +import android.content.ClipData; +import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.Rect; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; + +/** + * Handles ACTION_GET_CONTENT and ACTION_PICK to pick a cropped image + * + * #3: GET_CONTENT => llCrop => sourcePhoto.jpg=GET_CONTENT(mime=image/jpeg) => return crop(sourcePhoto.jpg) + */ +public class CropAreasGetContentActivity extends CropAreasChooseBaseActivity { + private static final String KEY_SOURCE_IMAGE_URI = "mSourceImageUri"; + private Uri mSourceImageUri = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (savedInstanceState != null) { + mSourceImageUri = savedInstanceState.getParcelable(KEY_SOURCE_IMAGE_URI); + } + + if (mSourceImageUri == null) { + pickFromGallery(REQUEST_GET_PICTURE); + } else { + SetImageUriAndLastCropArea(mSourceImageUri, savedInstanceState); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == REQUEST_GET_PICTURE) { + final Uri inUri = (data == null) ? null : data.getData(); + if ((resultCode == RESULT_OK) && (inUri != null)) { + SetImageUriAndLastCropArea(inUri, getCropRect()); + } else { + finish(); + } + return; + } + + super.onActivityResult(requestCode, resultCode, data); + } + + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putParcelable(KEY_SOURCE_IMAGE_URI, mSourceImageUri); + } + + @Override + public boolean onCreateOptionsMenu(final Menu menu) { + getMenuInflater().inflate(R.menu.menu_get_content, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_get_content: + return returnPrivateCroppedImage(); + default: + return super.onOptionsItemSelected(item); + } + // return true; + } + + /** get uri of image that will be cropped */ + @Override + protected Uri getSourceImageUri(Intent intent) { + return mSourceImageUri; + } + + @Override + protected void SetImageUriAndLastCropArea(Uri uri, Rect crop) { + this.mSourceImageUri = uri; + super.SetImageUriAndLastCropArea(uri, crop); + } + + private boolean returnPrivateCroppedImage() { + Uri outUri = cropToSharedUri(); + + if (outUri != null) { + Intent result = new Intent(); + result.setDataAndType(outUri, IMAGE_JPEG_MIME); + setResult(Activity.RESULT_OK, result); + finish(); + return true; + } + return false; + } +} diff --git a/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasSendActivity.java b/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasSendActivity.java index b669593..7703c13 100644 --- a/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasSendActivity.java +++ b/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasSendActivity.java @@ -9,9 +9,9 @@ import android.view.MenuItem; /** - * #2: SEND/SENDTO(uri=sourcePhoto.jpg) => crop => tempfile.jpg => SEND/SENDTO(uri=tempfile.jpg) + * Handles ACTION_SENDTO(uri=DATA) and ACTION_SEND(uri=EXTRA_STREAM) to re-send a cropped image * - * Handles ACTION_SENDTO(uri=DATA) and ACTION_SEND(uri=EXTRA_STREAM): + * #2: SEND/SENDTO(uri=sourcePhoto.jpg) => crop => tempfile.jpg => SEND/SENDTO(uri=tempfile.jpg) */ public class CropAreasSendActivity extends CropAreasChooseBaseActivity { @Override diff --git a/app/src/main/res/menu/menu_get_content.xml b/app/src/main/res/menu/menu_get_content.xml index 1fafd78..3b1da5f 100644 --- a/app/src/main/res/menu/menu_get_content.xml +++ b/app/src/main/res/menu/menu_get_content.xml @@ -5,7 +5,7 @@ diff --git a/fastlane/metadata/android/en-US/changelogs/4.txt b/fastlane/metadata/android/en-US/changelogs/4.txt new file mode 100644 index 0000000..b6bc3a5 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/4.txt @@ -0,0 +1,2 @@ +#2: Implemented Workflow: share/SEND/SENDTO to re-send a cropped photo +#3: Implemented Workflow: GET_CONTENT/PICK to pick a cropped photo