-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3: implemendet ACTION_GET_CONTENT/ACTION_PICK to pick a cropped image
- Loading branch information
Showing
6 changed files
with
126 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasGetContentActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |