diff --git a/src/android/Notification.java b/src/android/Notification.java index 8e34e540..ebee0153 100644 --- a/src/android/Notification.java +++ b/src/android/Notification.java @@ -61,6 +61,7 @@ public class Notification extends CordovaPlugin { private static final String ACTION_PROGRESS_START = "progressStart"; private static final String ACTION_PROGRESS_VALUE = "progressValue"; private static final String ACTION_PROGRESS_STOP = "progressStop"; + private static final String ACTION_SET_CANCELABLE = "setCancelable"; private static final long BEEP_TIMEOUT = 5000; private static final long BEEP_WAIT_TINE = 100; @@ -69,6 +70,8 @@ public class Notification extends CordovaPlugin { public ProgressDialog spinnerDialog = null; public ProgressDialog progressDialog = null; + private boolean isCancelable = true; + /** * Constructor. */ @@ -122,6 +125,9 @@ else if (action.equals(ACTION_PROGRESS_VALUE)) { else if (action.equals(ACTION_PROGRESS_STOP)) { this.progressStop(); } + else if (action.equals(ACTION_SET_CANCELABLE)) { + this.setCancelable(args.optBoolean(0, true)); + } else { return false; } @@ -174,6 +180,7 @@ public void run() { */ public synchronized void alert(final String message, final String title, final String buttonLabel, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; + final boolean isCancelable = this.isCancelable; Runnable runnable = new Runnable() { public void run() { @@ -181,7 +188,7 @@ public void run() { Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); - dlg.setCancelable(true); + dlg.setCancelable(isCancelable); dlg.setPositiveButton(buttonLabel, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { @@ -215,13 +222,14 @@ public void onCancel(DialogInterface dialog) */ public synchronized void confirm(final String message, final String title, final JSONArray buttonLabels, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; + final boolean isCancelable = this.isCancelable; Runnable runnable = new Runnable() { public void run() { Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); - dlg.setCancelable(true); + dlg.setCancelable(isCancelable); // First button if (buttonLabels.length() > 0) { @@ -296,6 +304,7 @@ public void onCancel(DialogInterface dialog) public synchronized void prompt(final String message, final String title, final JSONArray buttonLabels, final String defaultText, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; + final boolean isCancelable = this.isCancelable; Runnable runnable = new Runnable() { public void run() { @@ -311,7 +320,7 @@ But for some android versions is not visible (for example 5.1.1). Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); - dlg.setCancelable(true); + dlg.setCancelable(isCancelable); dlg.setView(promptInput); @@ -409,12 +418,13 @@ public synchronized void activityStart(final String title, final String message) } final Notification notification = this; final CordovaInterface cordova = this.cordova; + final boolean isCancelable = this.isCancelable; Runnable runnable = new Runnable() { public void run() { notification.spinnerDialog = createProgressDialog(cordova); // new ProgressDialog(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); notification.spinnerDialog.setTitle(title); notification.spinnerDialog.setMessage(message); - notification.spinnerDialog.setCancelable(true); + notification.spinnerDialog.setCancelable(isCancelable); notification.spinnerDialog.setIndeterminate(true); notification.spinnerDialog.setOnCancelListener( new DialogInterface.OnCancelListener() { @@ -451,13 +461,14 @@ public synchronized void progressStart(final String title, final String message) } final Notification notification = this; final CordovaInterface cordova = this.cordova; + final boolean isCancelable = this.isCancelable; Runnable runnable = new Runnable() { public void run() { notification.progressDialog = createProgressDialog(cordova); // new ProgressDialog(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); notification.progressDialog.setTitle(title); notification.progressDialog.setMessage(message); - notification.progressDialog.setCancelable(true); + notification.progressDialog.setCancelable(isCancelable); notification.progressDialog.setMax(100); notification.progressDialog.setProgress(0); notification.progressDialog.setOnCancelListener( @@ -493,6 +504,10 @@ public synchronized void progressStop() { } } + public void setCancelable(boolean enable) { + this.isCancelable = enable; + } + @SuppressLint("NewApi") private Builder createDialog(CordovaInterface cordova) { int currentapiVersion = android.os.Build.VERSION.SDK_INT; diff --git a/www/android/notification.js b/www/android/notification.js index 5562a9fe..c6ff0cc4 100644 --- a/www/android/notification.js +++ b/www/android/notification.js @@ -70,5 +70,13 @@ module.exports = { */ progressValue: function (value) { exec(null, null, 'Notification', 'progressValue', [ value ]); + }, + + /** + * Set whether the user can cancel the dialog + * @param {Boolean} enable Enable/Disable cancellable dialog + */ + setCancelable: function (enable) { + exec(null, null, 'Notification', 'setCancelable', [ enable ]); } };