Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ public static class Options implements Serializable {

String settingsText = "Settings";
String rationaleDialogTitle = "Permissions Required";
String rationaleDialogNegativeButton = null;
String rationaleDialogPositiveButton = null;
String settingsDialogTitle = "Permissions Required";
String settingsDialogMessage = "Required permission(s) have been set" +
" not to ask again! Please provide them from settings.";
boolean rationaleDialogCancelable = true;
boolean sendBlockedToSettings = true;
boolean createNewTask = false;

Expand Down Expand Up @@ -193,6 +196,28 @@ public Options setRationaleDialogTitle(String rationaleDialogTitle) {
return this;
}

/**
* Sets a custom text for the rationale dialog's negative button.
*
* @param rationaleDialogNegativeButton cancel button text.
* @return same instance.
*/
public Options setRationaleDialogNegativeButton(String rationaleDialogNegativeButton) {
this.rationaleDialogNegativeButton = rationaleDialogNegativeButton;
return this;
}

/**
* Sets a custom text for the rationale dialog's positive button.
*
* @param rationaleDialogPositiveButton positive button text.
* @return same instance.
*/
public Options setRationaleDialogPositiveButton(String rationaleDialogPositiveButton) {
this.rationaleDialogPositiveButton = rationaleDialogPositiveButton;
return this;
}

/**
* Sets the title text of the dialog which asks user to go to settings, in the case when
* permission(s) have been set not to ask again.
Expand Down Expand Up @@ -230,6 +255,17 @@ public Options sendDontAskAgainToSettings(boolean send) {
sendBlockedToSettings = send;
return this;
}

/**
* Sets whether or not the rationale dialog should be cancelable.
*
* @param cancelable if true, the rationale dialog will be cancelable.
* @return same instance.
*/
public Options setRationaleDialogCancelable(boolean cancelable) {
rationaleDialogCancelable = cancelable;
return this;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,26 @@ public void onClick(DialogInterface dialog, int which) {
}
}
};
new AlertDialog.Builder(this).setTitle(options.rationaleDialogTitle)
.setMessage(rationale)
.setPositiveButton(android.R.string.ok, listener)
.setNegativeButton(android.R.string.cancel, listener)
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
deny();
}
}).create().show();

AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(options.rationaleDialogTitle);
builder.setMessage(rationale);

if (options.rationaleDialogCancelable) {
String negativeButtonText = options.rationaleDialogNegativeButton != null ? options.rationaleDialogNegativeButton : getString(android.R.string.cancel);
builder.setNegativeButton(negativeButtonText, listener)
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
deny();
}
});
} else {
builder.setCancelable(false);
}

String positiveButtonText = options.rationaleDialogPositiveButton != null ? options.rationaleDialogPositiveButton : getString(android.R.string.ok);
builder.setPositiveButton(positiveButtonText, listener)
.create().show();
}

@SuppressWarnings("NullableProblems")
Expand Down