Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close function (Android only) #73

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
19 changes: 17 additions & 2 deletions src/android/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<AlertDialog> dialogs = new Vector<AlertDialog>();

public int confirmResult = -1;
public ProgressDialog spinnerDialog = null;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions www/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", []);
}
};