Skip to content

Commit

Permalink
Fixed missing permission; Added "done" message as toast
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed May 7, 2019
1 parent 4d2ad9e commit 5d1ce61
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
// implementation "com.android.support:appcompat-v7:$support"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.annotation:annotation:1.0.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

public class CropAreasChooseActivity extends BaseActivity {
private static final String TAG = "llCrop";
Expand Down Expand Up @@ -161,9 +164,6 @@ private void pickFromGallery() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT)
.setType(IMAGE_JPEG_MIME)
.addCategory(Intent.CATEGORY_OPENABLE)
// Fix: after pressing "back" return to caller off this app and not to previous-instance
// without parameters
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_GRANT_READ_URI_PERMISSION)
;

startActivityForResult(Intent.createChooser(intent, getString(R.string.label_select_picture)), REQUEST_GET_PICTURE);
Expand All @@ -176,6 +176,8 @@ private void onGetPictureResult(int resultCode, Intent data) {
Log.d(TAG, "Restarting with uri '" + selectedUri + "'");

Intent intent = new Intent(Intent.ACTION_VIEW, selectedUri, this, CropAreasChooseActivity.class);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

this.startActivity(intent);
finish();
return;
Expand Down Expand Up @@ -228,13 +230,19 @@ private void onOpenPublicOutputUriPickerResult(int resultCode, Uri outUri) {
InputStream inStream = null;
OutputStream outStream = null;

final String context_message = "Cropping '" + inUri + "'(" + rect + ") => '" + outUri + "'";
final String context_message = "Cropping '" + inUri + "'(" + rect + ") => '"
+ outUri + "' ('" + toString(outUri) + "')";
Log.i(TAG, context_message);

try {
outStream = getContentResolver().openOutputStream(outUri, "w");
inStream = getContentResolver().openInputStream(inUri);
outStream = getContentResolver().openOutputStream(outUri, "w");
this.mSpectrum.crop(inStream, outStream, rect, 0);

String message = getString(R.string.toast_saved_as,
toString(outUri));
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();

finish();
return;
} catch (Exception e) {
Expand All @@ -249,6 +257,15 @@ private void onOpenPublicOutputUriPickerResult(int resultCode, Uri outUri) {
}
}

private String toString(Uri outUri) {
if (outUri == null) return "";
try {
return URLDecoder.decode(outUri.toString(), StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
return outUri.toString();
}
}

private static void close(Closeable stream, Object source) {
if (stream != null) {
try {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<string name="permission_write_storage_rationale">Benötige Datei-Schreibrechte um ein Photo zu speichern.</string>

<string name="toast_cannot_retrieve_selected_image">Beende app: Kein Quell Photo ausgewählt</string>
<string name="toast_saved_as">Gespeichert als \'%1$s\'</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<string name="permission_write_storage_rationale">Storage write permission is needed to save the image.</string>

<string name="toast_cannot_retrieve_selected_image">Quitting: No source image selected</string>
<string name="toast_saved_as">Saved as \'%1$s\'</string>
</resources>

0 comments on commit 5d1ce61

Please sign in to comment.