diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-11-08 12:37:03 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-11-08 12:37:03 -0500 |
| commit | ef4f212fc1482136dba1e690ec589b315b4a377f (patch) | |
| tree | 0b7e16d72567fafcfd3e08d7c5c591ad07a63458 /StoneIsland/plugins/cordova-plugin-dialogs/src | |
| parent | 5fa81da81260d65113f57a293b6256d334fe8e2d (diff) | |
build 0.7.0
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-dialogs/src')
14 files changed, 164 insertions, 84 deletions
diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/android/Notification.java b/StoneIsland/plugins/cordova-plugin-dialogs/src/android/Notification.java index 3bc3cee6..f19bc888 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/android/Notification.java +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/android/Notification.java @@ -21,6 +21,7 @@ package org.apache.cordova.dialogs; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.LOG; import org.apache.cordova.PluginResult; import org.json.JSONArray; import org.json.JSONException; @@ -31,6 +32,7 @@ import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.ProgressDialog; import android.content.DialogInterface; +import android.content.res.Resources; import android.media.Ringtone; import android.media.RingtoneManager; import android.net.Uri; @@ -48,6 +50,8 @@ import android.widget.TextView; */ public class Notification extends CordovaPlugin { + private static final String LOG_TAG = "Notification"; + public int confirmResult = -1; public ProgressDialog spinnerDialog = null; public ProgressDialog progressDialog = null; @@ -139,6 +143,7 @@ public class Notification extends CordovaPlugin { try { Thread.sleep(100); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } } } @@ -215,7 +220,9 @@ public class Notification extends CordovaPlugin { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 1)); } }); - } catch (JSONException e) { } + } catch (JSONException e) { + LOG.d(LOG_TAG,"JSONException on first button."); + } } // Second button @@ -228,7 +235,9 @@ public class Notification extends CordovaPlugin { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 2)); } }); - } catch (JSONException e) { } + } catch (JSONException e) { + LOG.d(LOG_TAG,"JSONException on second button."); + } } // Third button @@ -241,7 +250,9 @@ public class Notification extends CordovaPlugin { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 3)); } }); - } catch (JSONException e) { } + } catch (JSONException e) { + LOG.d(LOG_TAG,"JSONException on third button."); + } } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) @@ -276,7 +287,14 @@ public class Notification extends CordovaPlugin { Runnable runnable = new Runnable() { public void run() { final EditText promptInput = new EditText(cordova.getActivity()); - promptInput.setHint(defaultText); + + /* CB-11677 - By default, prompt input text color is set according current theme. + But for some android versions is not visible (for example 5.1.1). + android.R.color.primary_text_light will make text visible on all versions. */ + Resources resources = cordova.getActivity().getResources(); + int promptInputTextColor = resources.getColor(android.R.color.primary_text_light); + promptInput.setTextColor(promptInputTextColor); + promptInput.setText(defaultText); AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); @@ -296,11 +314,15 @@ public class Notification extends CordovaPlugin { try { result.put("buttonIndex",1); result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText()); - } catch (JSONException e) { e.printStackTrace(); } + } catch (JSONException e) { + LOG.d(LOG_TAG,"JSONException on first button.", e); + } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); - } catch (JSONException e) { } + } catch (JSONException e) { + LOG.d(LOG_TAG,"JSONException on first button."); + } } // Second button @@ -313,11 +335,15 @@ public class Notification extends CordovaPlugin { try { result.put("buttonIndex",2); result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText()); - } catch (JSONException e) { e.printStackTrace(); } + } catch (JSONException e) { + LOG.d(LOG_TAG,"JSONException on second button.", e); + } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); - } catch (JSONException e) { } + } catch (JSONException e) { + LOG.d(LOG_TAG,"JSONException on second button."); + } } // Third button @@ -330,11 +356,15 @@ public class Notification extends CordovaPlugin { try { result.put("buttonIndex",3); result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText()); - } catch (JSONException e) { e.printStackTrace(); } + } catch (JSONException e) { + LOG.d(LOG_TAG,"JSONException on third button.", e); + } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); - } catch (JSONException e) { } + } catch (JSONException e) { + LOG.d(LOG_TAG,"JSONException on third button."); + } } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog){ diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/blackberry10/index.js b/StoneIsland/plugins/cordova-plugin-dialogs/src/blackberry10/index.js index 3660f667..4969a770 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/blackberry10/index.js +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/blackberry10/index.js @@ -14,6 +14,8 @@ * limitations under the License. */ +/* global qnx, PluginResult */ + function showDialog(args, dialogType, result) { //Unpack and map the args var msg = JSON.parse(decodeURIComponent(args[0])), diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/firefoxos/notification.js b/StoneIsland/plugins/cordova-plugin-dialogs/src/firefoxos/notification.js index b6986fd0..aea562d0 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/firefoxos/notification.js +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/firefoxos/notification.js @@ -60,7 +60,8 @@ function modal(message, callback, title, buttonLabels, domObjects) { var menu = modalDocument.createElement('menu'); box.appendChild(menu); for (var index = 0; index < buttonLabels.length; index++) { - addButton(buttonLabels[index], index, (index === 0)); + // TODO: last button listens to the cancel key + addButton(buttonLabels[index], (index+1), (index === 0)); } modalDocument.body.appendChild(box); @@ -83,12 +84,12 @@ function modal(message, callback, title, buttonLabels, domObjects) { result = { input1: '', buttonIndex: 0 - } + }; } mainWindow.setTimeout(function() { callback(result); }, 10); - }; + } modalWindow.addEventListener('unload', onUnload, false); // call callback and destroy modal @@ -109,7 +110,7 @@ function modal(message, callback, title, buttonLabels, domObjects) { } response = response || labelIndex; callback(response); - } + }; } } diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/ios/CDVNotification.bundle/beep.wav b/StoneIsland/plugins/cordova-plugin-dialogs/src/ios/CDVNotification.bundle/beep.wav Binary files differindex 05f5997f..05f5997f 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/ios/CDVNotification.bundle/beep.wav +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/ios/CDVNotification.bundle/beep.wav diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/ios/CDVNotification.h b/StoneIsland/plugins/cordova-plugin-dialogs/src/ios/CDVNotification.h index 9253f6a9..9253f6a9 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/ios/CDVNotification.h +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/ios/CDVNotification.h diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/ios/CDVNotification.m b/StoneIsland/plugins/cordova-plugin-dialogs/src/ios/CDVNotification.m index 1581ad3c..0dd3d2cb 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/ios/CDVNotification.m +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/ios/CDVNotification.m @@ -23,6 +23,7 @@ #define DIALOG_TYPE_PROMPT @"prompt" static void soundCompletionCallback(SystemSoundID ssid, void* data); +static NSMutableArray *alertList = nil; @implementation CDVNotification @@ -39,7 +40,7 @@ static void soundCompletionCallback(SystemSoundID ssid, void* data); - (void)showDialogWithMessage:(NSString*)message title:(NSString*)title buttons:(NSArray*)buttons defaultText:(NSString*)defaultText callbackId:(NSString*)callbackId dialogType:(NSString*)dialogType { - NSUInteger count = [buttons count]; + int count = (int)[buttons count]; #ifdef __IPHONE_8_0 if (NSClassFromString(@"UIAlertController")) { @@ -58,33 +59,32 @@ static void soundCompletionCallback(SystemSoundID ssid, void* data); alertController.view.frame = alertFrame; } - + + __weak CDVNotification* weakNotif = self; + for (int n = 0; n < count; n++) { - - UIAlertAction* action = [UIAlertAction actionWithTitle:[buttons objectAtIndex:n] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) - { - CDVPluginResult* result; - - if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT]) { - - NSString* value0 = [[alertController.textFields objectAtIndex:0] text]; - NSDictionary* info = @{ - @"buttonIndex":@(n + 1), - @"input1":(value0 ? value0 : [NSNull null]) - }; - result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info]; - - } else { - - result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:(int)(n + 1)]; - - } - - [self.commandDelegate sendPluginResult:result callbackId:callbackId]; - - }]; - [alertController addAction:action]; - + [alertController addAction:[UIAlertAction actionWithTitle:[buttons objectAtIndex:n] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) + { + CDVPluginResult* result; + + if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT]) + { + NSString* value0 = [[alertController.textFields objectAtIndex:0] text]; + NSDictionary* info = @{ + @"buttonIndex":@(n + 1), + @"input1":(value0 ? value0 : [NSNull null]) + }; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info]; + } + else + { + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:(int)(n + 1)]; + } + + [weakNotif.commandDelegate sendPluginResult:result callbackId:callbackId]; + }]]; } if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT]) { @@ -94,12 +94,19 @@ static void soundCompletionCallback(SystemSoundID ssid, void* data); }]; } + if(!alertList) + alertList = [[NSMutableArray alloc] init]; + [alertList addObject:alertController]; + if ([alertList count]==1) { + [self presentAlertcontroller]; + } - [self.viewController presentViewController:alertController animated:YES completion:nil]; - - } else { + } + else + { #endif + CDVAlertView* alertView = [[CDVAlertView alloc] initWithTitle:title message:message @@ -183,6 +190,14 @@ static void soundCompletionCallback(SystemSoundID ssid, void* data); [self.commandDelegate sendPluginResult:result callbackId:cdvAlertView.callbackId]; } +- (void)didPresentAlertView:(UIAlertView*)alertView +{ + //show keyboard on iOS 8 + if (alertView.alertViewStyle == UIAlertViewStylePlainTextInput){ + [[alertView textFieldAtIndex:0] selectAll:nil]; + } +} + static void playBeep(int count) { SystemSoundID completeSound; NSInteger cbDataCount = count; @@ -211,6 +226,26 @@ static void soundCompletionCallback(SystemSoundID ssid, void* data) { playBeep([count intValue]); } +-(UIViewController *)getTopPresentedViewController { + UIViewController *presentingViewController = self.viewController; + while(presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]) + { + presentingViewController = presentingViewController.presentedViewController; + } + return presentingViewController; +} + +-(void)presentAlertcontroller { + + __weak CDVNotification* weakNotif = self; + [self.getTopPresentedViewController presentViewController:[alertList firstObject] animated:YES completion:^{ + [alertList removeObject:[alertList firstObject]]; + if ([alertList count]>0) { + [weakNotif presentAlertcontroller]; + } + }]; + +} @end diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/ubuntu/notification.cpp b/StoneIsland/plugins/cordova-plugin-dialogs/src/ubuntu/notification.cpp index d0adf892..d0adf892 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/ubuntu/notification.cpp +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/ubuntu/notification.cpp diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/ubuntu/notification.h b/StoneIsland/plugins/cordova-plugin-dialogs/src/ubuntu/notification.h index 53430738..53430738 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/ubuntu/notification.h +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/ubuntu/notification.h diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/ubuntu/notification.qml b/StoneIsland/plugins/cordova-plugin-dialogs/src/ubuntu/notification.qml index 5fdc7d31..5fdc7d31 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/ubuntu/notification.qml +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/ubuntu/notification.qml diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js b/StoneIsland/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js index d1eb3448..2d32f836 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js @@ -17,17 +17,36 @@ * specific language governing permissions and limitations * under the License. * -*/ + */ -/*global Windows:true */ +/*global Windows:true, WinJS, toStaticHTML */ var cordova = require('cordova'); +var urlutil = require('cordova/urlutil'); var isAlertShowing = false; var alertStack = []; +function createCSSElem(fileName) { + var elemId = fileName.substr(0, fileName.lastIndexOf(".")) + "-plugin-style"; + // If the CSS element exists, don't recreate it. + if (document.getElementById(elemId)) { + return false; + } + + // Create CSS and append it to DOM. + var $elem = document.createElement('link'); + $elem.id = elemId; + $elem.rel = "stylesheet"; + $elem.type = "text/css"; + $elem.href = urlutil.makeAbsolute("/www/css/" + fileName); + + document.head.appendChild($elem); + return true; +} + // CB-8928: When toStaticHTML is undefined, prompt fails to run -function _cleanHtml(html) { return html; } +var _cleanHtml = function(html) { return html; }; if (typeof toStaticHTML !== 'undefined') { _cleanHtml = toStaticHTML; } @@ -36,66 +55,53 @@ if (typeof toStaticHTML !== 'undefined') { // simple html-based implementation until it is available function createPromptDialog(title, message, buttons, defaultText, callback) { - var isPhone = cordova.platformId == "windows" && WinJS.Utilities.isPhone;; + var isPhone = cordova.platformId === "windows" && WinJS.Utilities.isPhone; + var isWindows = !!cordova.platformId.match(/windows/); + + createCSSElem("notification.css"); var dlgWrap = document.createElement("div"); - dlgWrap.style.position = "absolute"; - dlgWrap.style.width = "100%"; - dlgWrap.style.height = "100%"; - dlgWrap.style.backgroundColor = "rgba(0,0,0,0.25)"; - dlgWrap.style.zIndex = "100000"; + dlgWrap.className = "dlgWrap"; var dlg = document.createElement("div"); - dlg.style.width = "100%"; - dlg.style.minHeight = "180px"; - dlg.style.height = "auto"; - dlg.style.overflow = "auto"; - dlg.style.backgroundColor = "white"; - dlg.style.position = "relative"; - dlg.style.lineHeight = "2"; + dlg.className = "dlgContainer"; - if (isPhone) { - dlg.style.padding = "0px 5%"; - } else { - dlg.style.top = "50%"; // center vertically - dlg.style.transform = "translateY(-50%)"; - dlg.style.padding = "0px 30%"; + if (isWindows) { + dlg.className += " dlgContainer-windows"; + } else if (isPhone) { + dlg.className += " dlgContainer-phone"; } + // dialog layout template - dlg.innerHTML = _cleanHtml("<span id='lbl-title' style='font-size: 24pt'></span><br/>" // title - + "<span id='lbl-message'></span><br/>" // message - + "<input id='prompt-input' style='width: 100%'/><br/>"); // input fields + dlg.innerHTML = _cleanHtml("<span id='lbl-title'></span><br/>" + // title + "<span id='lbl-message'></span><br/>" + // message + "<input id='prompt-input'/><br/>"); // input fields dlg.querySelector('#lbl-title').appendChild(document.createTextNode(title)); dlg.querySelector('#lbl-message').appendChild(document.createTextNode(message)); dlg.querySelector('#prompt-input').setAttribute('placeholder', defaultText); + dlg.querySelector('#prompt-input').setAttribute('value', defaultText); function makeButtonCallback(idx) { return function () { - var value = promptInput = dlg.querySelector('#prompt-input').value; + var value = dlg.querySelector('#prompt-input').value || defaultText; dlgWrap.parentNode.removeChild(dlgWrap); if (callback) { callback({ input1: value, buttonIndex: idx }); } - } + }; } function addButton(idx, label) { var button = document.createElement('button'); - button.style.margin = "8px 0 8px 16px"; - button.style.float = "right"; - button.style.fontSize = "12pt"; + button.className = "dlgButton"; button.tabIndex = idx; button.onclick = makeButtonCallback(idx + 1); - if (idx == 0) { - button.style.color = "white"; - button.style.backgroundColor = "#464646"; - } else { - button.style.backgroundColor = "#cccccc"; + if (idx === 0) { + button.className += " dlgButtonFirst"; } - button.style.border = "none"; button.appendChild(document.createTextNode(label)); dlg.appendChild(button); } @@ -109,7 +115,7 @@ function createPromptDialog(title, message, buttons, defaultText, callback) { document.body.appendChild(dlgWrap); // make sure input field is under focus - dlg.querySelector('#prompt-input').focus(); + dlg.querySelector('#prompt-input').select(); return dlgWrap; } @@ -134,7 +140,9 @@ module.exports = { md.commands.append(new Windows.UI.Popups.UICommand(_buttonLabel)); md.showAsync().then(function() { isAlertShowing = false; - win && win(); + if (win) { + win(); + } if (alertStack.length) { setTimeout(alertStack.shift(), 0); @@ -204,7 +212,9 @@ module.exports = { md.showAsync().then(function(res) { isAlertShowing = false; var result = res ? buttons.indexOf(res.label) + 1 : 0; - win && win(result); + if (win) { + win(result); + } if (alertStack.length) { setTimeout(alertStack.shift(), 0); } @@ -236,7 +246,9 @@ module.exports = { } else { snd.removeEventListener("ended", onEvent); snd = null; - winX && winX(); // notification.js just sends null, but this is future friendly + if (winX) { + winX(); // notification.js just sends null, but this is future friendly + } } count--; }; diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/Notification.cs b/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/Notification.cs index b6216848..b6216848 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/Notification.cs +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/Notification.cs diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/NotificationBox.xaml b/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/NotificationBox.xaml index 2d564fba..2d564fba 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/NotificationBox.xaml +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/NotificationBox.xaml diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/NotificationBox.xaml.cs b/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/NotificationBox.xaml.cs index 50b2f2a8..50b2f2a8 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/NotificationBox.xaml.cs +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/NotificationBox.xaml.cs diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/notification-beep.wav b/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/notification-beep.wav Binary files differindex d0ad085f..d0ad085f 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/notification-beep.wav +++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/wp/notification-beep.wav |
