From 7ebab3412b1c46d6eb2c594c774b457d70e9ecf5 Mon Sep 17 00:00:00 2001 From: Andro Delrue Date: Fri, 29 Jan 2016 14:32:20 +0100 Subject: [PATCH 1/9] Update Notification.java added a separate function to dismiss dialogs --- src/android/Notification.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/android/Notification.java b/src/android/Notification.java index 9be56c06..441ad45d 100644 --- a/src/android/Notification.java +++ b/src/android/Notification.java @@ -50,6 +50,7 @@ Licensed to the Apache Software Foundation (ASF) under one public class Notification extends CordovaPlugin { private static final String LOG_TAG = "Notification"; + private AlertDialog.Builder dlg; public int confirmResult = -1; public ProgressDialog spinnerDialog = null; @@ -108,6 +109,9 @@ else if (action.equals("progressValue")) { else if (action.equals("progressStop")) { this.progressStop(); } + else if (action.equals("dismiss")) { + this.dismissAll(); + } else { return false; } @@ -204,7 +208,7 @@ public synchronized void confirm(final String message, final String title, final Runnable runnable = new Runnable() { public void run() { - AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); + dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(true); @@ -472,6 +476,13 @@ public synchronized void progressStop() { } } + /** + * Dismiss all dialogs. + */ + public void dismissAll() { + dlg.dismiss(); + } + @SuppressLint("NewApi") private AlertDialog.Builder createDialog(CordovaInterface cordova) { int currentapiVersion = android.os.Build.VERSION.SDK_INT; From fadb689974094658e4f890e3730fb3bc785dbada Mon Sep 17 00:00:00 2001 From: Andro Delrue Date: Fri, 29 Jan 2016 14:33:32 +0100 Subject: [PATCH 2/9] Update notification.js make dismiss function accessable for js --- www/notification.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/www/notification.js b/www/notification.js index 44f25c1a..0f7235cb 100644 --- a/www/notification.js +++ b/www/notification.js @@ -109,4 +109,8 @@ module.exports = { var defaultedCount = count || 1; exec(null, null, "Notification", "beep", [ defaultedCount ]); } + + dismiss: function() { + exec(null, null, "Notification", "dismiss", []); + } }; From 931e9f594c93746ce4470ce22815b689876a59b2 Mon Sep 17 00:00:00 2001 From: Andro Delrue Date: Fri, 29 Jan 2016 14:39:32 +0100 Subject: [PATCH 3/9] Update notification.js added missing comma --- www/notification.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/notification.js b/www/notification.js index 0f7235cb..84331c5e 100644 --- a/www/notification.js +++ b/www/notification.js @@ -108,7 +108,7 @@ module.exports = { beep: function(count) { var defaultedCount = count || 1; exec(null, null, "Notification", "beep", [ defaultedCount ]); - } + }, dismiss: function() { exec(null, null, "Notification", "dismiss", []); From 239363d28b12e7ee469b12155ff1e8b2e34db5d8 Mon Sep 17 00:00:00 2001 From: Andro Delrue Date: Wed, 3 Feb 2016 09:23:33 +0100 Subject: [PATCH 4/9] Update Notification.java replaced dlg with this.dlg where needed --- src/android/Notification.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/android/Notification.java b/src/android/Notification.java index 441ad45d..be59536f 100644 --- a/src/android/Notification.java +++ b/src/android/Notification.java @@ -208,15 +208,15 @@ public synchronized void confirm(final String message, final String title, final Runnable runnable = new Runnable() { public void run() { - dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); - dlg.setMessage(message); - dlg.setTitle(title); - dlg.setCancelable(true); + this.dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); + this.dlg.setMessage(message); + this.dlg.setTitle(title); + this.dlg.setCancelable(true); // First button if (buttonLabels.length() > 0) { try { - dlg.setNegativeButton(buttonLabels.getString(0), + this.dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); @@ -231,7 +231,7 @@ public void onClick(DialogInterface dialog, int which) { // Second button if (buttonLabels.length() > 1) { try { - dlg.setNeutralButton(buttonLabels.getString(1), + this.dlg.setNeutralButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); @@ -246,7 +246,7 @@ public void onClick(DialogInterface dialog, int which) { // Third button if (buttonLabels.length() > 2) { try { - dlg.setPositiveButton(buttonLabels.getString(2), + this.dlg.setPositiveButton(buttonLabels.getString(2), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); @@ -257,7 +257,7 @@ public void onClick(DialogInterface dialog, int which) { LOG.d(LOG_TAG,"JSONException on third button."); } } - dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { + this.dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); @@ -265,7 +265,7 @@ public void onCancel(DialogInterface dialog) } }); - changeTextDirection(dlg); + changeTextDirection(this.dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); @@ -480,7 +480,7 @@ public synchronized void progressStop() { * Dismiss all dialogs. */ public void dismissAll() { - dlg.dismiss(); + this.dlg.dismiss(); } @SuppressLint("NewApi") From 98d5d6a9f80e31b4d28a44b6546d39f0ed21f4b9 Mon Sep 17 00:00:00 2001 From: Andro Delrue Date: Wed, 3 Feb 2016 09:33:21 +0100 Subject: [PATCH 5/9] Update Notification.java --- src/android/Notification.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/android/Notification.java b/src/android/Notification.java index be59536f..f51b193b 100644 --- a/src/android/Notification.java +++ b/src/android/Notification.java @@ -50,7 +50,7 @@ Licensed to the Apache Software Foundation (ASF) under one public class Notification extends CordovaPlugin { private static final String LOG_TAG = "Notification"; - private AlertDialog.Builder dlg; + private Builder dlg = null; public int confirmResult = -1; public ProgressDialog spinnerDialog = null; @@ -480,7 +480,10 @@ public synchronized void progressStop() { * Dismiss all dialogs. */ public void dismissAll() { - this.dlg.dismiss(); + if (this.dlg != null) { + this.dlg.dismiss(); + this.dlg = null; + } } @SuppressLint("NewApi") From f6df68d54e03d9e9867c5031ef2cb28eba50b3e5 Mon Sep 17 00:00:00 2001 From: Andro Delrue Date: Wed, 3 Feb 2016 09:44:18 +0100 Subject: [PATCH 6/9] Update Notification.java --- src/android/Notification.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/android/Notification.java b/src/android/Notification.java index f51b193b..56c18469 100644 --- a/src/android/Notification.java +++ b/src/android/Notification.java @@ -50,11 +50,11 @@ Licensed to the Apache Software Foundation (ASF) under one public class Notification extends CordovaPlugin { private static final String LOG_TAG = "Notification"; - private Builder dlg = null; public int confirmResult = -1; public ProgressDialog spinnerDialog = null; public ProgressDialog progressDialog = null; + public AlertDialog.Builder dlg = null; /** * Constructor. @@ -479,7 +479,7 @@ public synchronized void progressStop() { /** * Dismiss all dialogs. */ - public void dismissAll() { + public synchronized void dismissAll() { if (this.dlg != null) { this.dlg.dismiss(); this.dlg = null; From 258ca82735985ca5b840b962a4c96e823bb954bd Mon Sep 17 00:00:00 2001 From: Andro Delrue Date: Wed, 3 Feb 2016 10:38:54 +0100 Subject: [PATCH 7/9] Update Notification.java Implemented new way to close dialogs --- src/android/Notification.java | 39 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/android/Notification.java b/src/android/Notification.java index 56c18469..347007c1 100644 --- a/src/android/Notification.java +++ b/src/android/Notification.java @@ -50,11 +50,11 @@ 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; public ProgressDialog progressDialog = null; - public AlertDialog.Builder dlg = null; /** * Constructor. @@ -109,8 +109,8 @@ else if (action.equals("progressValue")) { else if (action.equals("progressStop")) { this.progressStop(); } - else if (action.equals("dismiss")) { - this.dismissAll(); + else if (action.equals("close")) { + this.closeDialogs(); } else { return false; @@ -208,15 +208,15 @@ public synchronized void confirm(final String message, final String title, final Runnable runnable = new Runnable() { public void run() { - this.dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); - this.dlg.setMessage(message); - this.dlg.setTitle(title); - this.dlg.setCancelable(true); + AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); + dlg.setMessage(message); + dlg.setTitle(title); + dlg.setCancelable(true); // First button if (buttonLabels.length() > 0) { try { - this.dlg.setNegativeButton(buttonLabels.getString(0), + dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); @@ -231,7 +231,7 @@ public void onClick(DialogInterface dialog, int which) { // Second button if (buttonLabels.length() > 1) { try { - this.dlg.setNeutralButton(buttonLabels.getString(1), + dlg.setNeutralButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); @@ -246,7 +246,7 @@ public void onClick(DialogInterface dialog, int which) { // Third button if (buttonLabels.length() > 2) { try { - this.dlg.setPositiveButton(buttonLabels.getString(2), + dlg.setPositiveButton(buttonLabels.getString(2), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); @@ -257,7 +257,7 @@ public void onClick(DialogInterface dialog, int which) { LOG.d(LOG_TAG,"JSONException on third button."); } } - this.dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { + dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); @@ -265,7 +265,7 @@ public void onCancel(DialogInterface dialog) } }); - changeTextDirection(this.dlg); + changeTextDirection(dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); @@ -477,13 +477,11 @@ public synchronized void progressStop() { } /** - * Dismiss all dialogs. + * Close all dialogs. */ - public synchronized void dismissAll() { - if (this.dlg != null) { - this.dlg.dismiss(); - this.dlg = null; - } + public void closeDialogs() { + for (AlertDialog dialog : dialogs) + if (dialog.isShowing()) dialog.dismiss(); } @SuppressLint("NewApi") @@ -509,8 +507,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); From 38b2e64548c82dbb33b6497b5bdbeb775ef639df Mon Sep 17 00:00:00 2001 From: Andro Delrue Date: Wed, 3 Feb 2016 10:47:53 +0100 Subject: [PATCH 8/9] Update Notification.java added Vector class import --- src/android/Notification.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/android/Notification.java b/src/android/Notification.java index 347007c1..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; From cbfe3beec13b595dd566b41017644f7f0decc6f7 Mon Sep 17 00:00:00 2001 From: Andro Delrue Date: Wed, 3 Feb 2016 10:53:24 +0100 Subject: [PATCH 9/9] Update notification.js --- www/notification.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/notification.js b/www/notification.js index 84331c5e..3ff18017 100644 --- a/www/notification.js +++ b/www/notification.js @@ -110,7 +110,7 @@ module.exports = { exec(null, null, "Notification", "beep", [ defaultedCount ]); }, - dismiss: function() { - exec(null, null, "Notification", "dismiss", []); + close: function() { + exec(null, null, "Notification", "close", []); } };