Skip to content

Commit

Permalink
#3: implemendet ACTION_GET_CONTENT/ACTION_PICK to pick a cropped image
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed May 17, 2019
1 parent ffc9e3e commit 1e73389
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 7 deletions.
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@
</intent-filter>

</activity>

<activity android:name=".CropAreasGetContentActivity">
<intent-filter>
<action android:name="android.intent.action.PICK" />
<action android:name="android.intent.action.GET_CONTENT" />

<category android:name="android.intent.category.OPENABLE"/>
<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="image/jpeg" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/*
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/menu/menu_get_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<item android:id="@+id/menu_get_content"

android:showAsAction="always"
android:icon="@android:drawable/checkbox_on_background"
android:icon="@android:drawable/ic_menu_send"
android:title="@android:string/ok"
tools:ignore="AppCompatResource" />

Expand Down
2 changes: 2 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/4.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1e73389

Please sign in to comment.