diff --git a/src/android/Notification.java b/src/android/Notification.java index 9be56c06..e78b6c4f 100644 --- a/src/android/Notification.java +++ b/src/android/Notification.java @@ -18,6 +18,8 @@ Licensed to the Apache Software Foundation (ASF) under one */ package org.apache.cordova.dialogs; +import java.util.Vector; + import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaPlugin; @@ -50,6 +52,7 @@ Licensed to the Apache Software Foundation (ASF) under one public class Notification extends CordovaPlugin { private static final String LOG_TAG = "Notification"; + private Vector dialogs = new Vector(); public int confirmResult = -1; public ProgressDialog spinnerDialog = null; @@ -108,6 +111,9 @@ else if (action.equals("progressValue")) { else if (action.equals("progressStop")) { this.progressStop(); } + else if (action.equals("close")) { + this.closeDialogs(); + } else { return false; } @@ -472,6 +478,14 @@ public synchronized void progressStop() { } } + /** + * Close all dialogs. + */ + public void closeDialogs() { + for (AlertDialog dialog : dialogs) + if (dialog.isShowing()) dialog.dismiss(); + } + @SuppressLint("NewApi") private AlertDialog.Builder createDialog(CordovaInterface cordova) { int currentapiVersion = android.os.Build.VERSION.SDK_INT; @@ -495,8 +509,9 @@ private ProgressDialog createProgressDialog(CordovaInterface cordova) { @SuppressLint("NewApi") private void changeTextDirection(Builder dlg){ int currentapiVersion = android.os.Build.VERSION.SDK_INT; - dlg.create(); - AlertDialog dialog = dlg.show(); + AlertDialog dialog = dlg.create(); + this.dialogs.add(dialog); + dialog.show(); if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { TextView messageview = (TextView)dialog.findViewById(android.R.id.message); messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE); diff --git a/www/notification.js b/www/notification.js index 44f25c1a..3ff18017 100644 --- a/www/notification.js +++ b/www/notification.js @@ -108,5 +108,9 @@ module.exports = { beep: function(count) { var defaultedCount = count || 1; exec(null, null, "Notification", "beep", [ defaultedCount ]); + }, + + close: function() { + exec(null, null, "Notification", "close", []); } };