-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
170 additions
and
24 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
73 changes: 73 additions & 0 deletions
73
app/src/main/java/de/k3b/android/lossless_jpg_crop/BaseActivity.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,73 @@ | ||
package de.k3b.android.lossless_jpg_crop; | ||
|
||
import android.app.Activity; | ||
import android.app.AlertDialog; | ||
import android.content.DialogInterface; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.ActivityCompat; | ||
|
||
/** | ||
* Created by Oleksii Shliama (https://github.com/shliama). | ||
*/ | ||
public class BaseActivity extends Activity { | ||
|
||
private AlertDialog mAlertDialog; | ||
|
||
/** | ||
* Hide alert dialog if any. | ||
*/ | ||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
if (mAlertDialog != null && mAlertDialog.isShowing()) { | ||
mAlertDialog.dismiss(); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Requests given permission. | ||
* If the permission has been denied previously, a Dialog will prompt the user to grant the | ||
* permission, otherwise it is requested directly. | ||
*/ | ||
protected void requestPermission(final String permission, String rationale, final int requestCode) { | ||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) { | ||
showAlertDialog(getString(R.string.permission_title_rationale), rationale, | ||
new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
ActivityCompat.requestPermissions(BaseActivity.this, | ||
new String[]{permission}, requestCode); | ||
} | ||
}, getString(android.R.string.ok), null, getString(android.R.string.cancel)); | ||
} else { | ||
ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode); | ||
} | ||
} | ||
|
||
/** | ||
* This method shows dialog with given title & message. | ||
* Also there is an option to pass onClickListener for positive & negative button. | ||
* | ||
* @param title - dialog title | ||
* @param message - dialog message | ||
* @param onPositiveButtonClickListener - listener for positive button | ||
* @param positiveText - positive button text | ||
* @param onNegativeButtonClickListener - listener for negative button | ||
* @param negativeText - negative button text | ||
*/ | ||
protected void showAlertDialog(@Nullable String title, @Nullable String message, | ||
@Nullable DialogInterface.OnClickListener onPositiveButtonClickListener, | ||
@NonNull String positiveText, | ||
@Nullable DialogInterface.OnClickListener onNegativeButtonClickListener, | ||
@NonNull String negativeText) { | ||
AlertDialog.Builder builder = new AlertDialog.Builder(this); | ||
builder.setTitle(title); | ||
builder.setMessage(message); | ||
builder.setPositiveButton(positiveText, onPositiveButtonClickListener); | ||
builder.setNegativeButton(negativeText, onNegativeButtonClickListener); | ||
mAlertDialog = builder.show(); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,3 +1,14 @@ | ||
<resources> | ||
<string name="app_name">Loss-Less-Crop</string> | ||
|
||
<string name="label_select_picture">Select Picture</string> | ||
|
||
<string name="permission_title_rationale">Permission needed</string> | ||
<string name="permission_read_storage_rationale">Storage read permission is needed to pick files.</string> | ||
<string name="permission_write_storage_rationale">Storage write permission is needed to save the image.</string> | ||
|
||
<string name="toast_cannot_retrieve_selected_image">Cannot retrieve selected image</string> | ||
<string name="toast_cannot_retrieve_cropped_image">Cannot retrieve cropped image</string> | ||
<string name="toast_unexpected_error">Unexpected error</string> | ||
|
||
</resources> |
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