From 143ec63f8ff661621e01a618ae0fb62cef36b5a1 Mon Sep 17 00:00:00 2001 From: Kevin <468561207@qq.com> Date: Wed, 4 Jul 2018 19:27:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=81=B5=E5=BE=AA=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/notification.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/www/notification.js b/www/notification.js index 4a428d7d..5fdbe5c2 100644 --- a/www/notification.js +++ b/www/notification.js @@ -78,8 +78,9 @@ module.exports = { * @param {String} title Title of the dialog (default: "Prompt") * @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"]) * @param {String} defaultText Textbox input value (default: empty string) + * @param {Object} options Other Options */ - prompt: function (message, resultCallback, title, buttonLabels, defaultText) { + prompt: function (message, resultCallback, title, buttonLabels, defaultText, options) { var _message = (typeof message === 'string' ? message : JSON.stringify(message)); var _title = (typeof title === 'string' ? title : 'Prompt'); var _buttonLabels = (buttonLabels || ['OK', 'Cancel']); @@ -92,7 +93,7 @@ module.exports = { _buttonLabels = convertButtonLabels(_buttonLabels); var _defaultText = (defaultText || ''); - exec(resultCallback, null, 'Notification', 'prompt', [_message, _title, _buttonLabels, _defaultText]); + exec(resultCallback, null, 'Notification', 'prompt', [_message, _title, _buttonLabels, _defaultText, options]); }, /** From 6e9778812b6683afed5e21b4bccb29d23c2548b6 Mon Sep 17 00:00:00 2001 From: Kevin <468561207@qq.com> Date: Wed, 4 Jul 2018 19:56:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=BF=98=E5=8E=9F=E4=BA=86=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E9=94=99=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/android/notification.js | 114 +++++++++--------------------------- 1 file changed, 29 insertions(+), 85 deletions(-) diff --git a/www/android/notification.js b/www/android/notification.js index ae571eb5..5562a9fe 100644 --- a/www/android/notification.js +++ b/www/android/notification.js @@ -20,111 +20,55 @@ */ var exec = require('cordova/exec'); -var platform = require('cordova/platform'); /** - * Provides access to notifications on the device. + * Provides Android enhanced notification API. */ - module.exports = { + activityStart: function (title, message) { + // If title and message not specified then mimic Android behavior of + // using default strings. + if (typeof title === 'undefined' && typeof message === 'undefined') { + title = 'Busy'; + message = 'Please wait...'; + } + + exec(null, null, 'Notification', 'activityStart', [ title, message ]); + }, /** - * Open a native alert dialog, with a customizable title and button text. - * - * @param {String} message Message to print in the body of the alert - * @param {Function} completeCallback The callback that is called when user clicks on a button. - * @param {String} title Title of the alert dialog (default: Alert) - * @param {String} buttonLabel Label of the close button (default: OK) + * Close an activity dialog */ - alert: function (message, completeCallback, title, buttonLabel,options) { - var _message = (typeof message === 'string' ? message : JSON.stringify(message)); - var _title = (typeof title === 'string' ? title : 'Alert'); - var _buttonLabel = (buttonLabel && typeof buttonLabel === 'string' ? buttonLabel : 'OK'); - exec(completeCallback, null, 'Notification', 'alert', [_message, _title, _buttonLabel,options]); + activityStop: function () { + exec(null, null, 'Notification', 'activityStop', []); }, /** - * Open a native confirm dialog, with a customizable title and button text. - * The result that the user selects is returned to the result callback. + * Display a progress dialog with progress bar that goes from 0 to 100. * - * @param {String} message Message to print in the body of the alert - * @param {Function} resultCallback The callback that is called when user clicks on a button. - * @param {String} title Title of the alert dialog (default: Confirm) - * @param {Array} buttonLabels Array of the labels of the buttons (default: ['OK', 'Cancel']) + * @param {String} + * title Title of the progress dialog. + * @param {String} + * message Message to display in the dialog. */ - confirm: function (message, resultCallback, title, buttonLabels,options) { - var _message = (typeof message === 'string' ? message : JSON.stringify(message)); - var _title = (typeof title === 'string' ? title : 'Confirm'); - var _buttonLabels = (buttonLabels || ['OK', 'Cancel']); - - // Strings are deprecated! - if (typeof _buttonLabels === 'string') { - console.log('Notification.confirm(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array).'); - } - - _buttonLabels = convertButtonLabels(_buttonLabels); - - exec(resultCallback, null, 'Notification', 'confirm', [_message, _title, _buttonLabels,options]); + progressStart: function (title, message) { + exec(null, null, 'Notification', 'progressStart', [ title, message ]); }, /** - * Open a native prompt dialog, with a customizable title and button text. - * The following results are returned to the result callback: - * buttonIndex Index number of the button selected. - * input1 The text entered in the prompt dialog box. - * - * @param {String} message Dialog message to display (default: "Prompt message") - * @param {Function} resultCallback The callback that is called when user clicks on a button. - * @param {String} title Title of the dialog (default: "Prompt") - * @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"]) - * @param {String} defaultText Textbox input value (default: empty string) + * Close the progress dialog. */ - prompt: function (message, resultCallback, title, buttonLabels, defaultText,options) { - var _message = (typeof message === 'string' ? message : JSON.stringify(message)); - var _title = (typeof title === 'string' ? title : 'Prompt'); - var _buttonLabels = (buttonLabels || ['OK', 'Cancel']); - - // Strings are deprecated! - if (typeof _buttonLabels === 'string') { - console.log('Notification.prompt(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array).'); - } - - _buttonLabels = convertButtonLabels(_buttonLabels); - - var _defaultText = (defaultText || ''); - exec(resultCallback, null, 'Notification', 'prompt', [_message, _title, _buttonLabels, _defaultText,options]); + progressStop: function () { + exec(null, null, 'Notification', 'progressStop', []); }, /** - * Causes the device to beep. - * On Android, the default notification ringtone is played "count" times. + * Set the progress dialog value. * - * @param {Integer} count The number of beeps. + * @param {Number} + * value 0-100 */ - beep: function (count) { - var defaultedCount = count || 1; - exec(null, null, 'Notification', 'beep', [ defaultedCount ]); + progressValue: function (value) { + exec(null, null, 'Notification', 'progressValue', [ value ]); } }; - -function convertButtonLabels (buttonLabels) { - - // Some platforms take an array of button label names. - // Other platforms take a comma separated list. - // For compatibility, we convert to the desired type based on the platform. - if (platform.id === 'amazon-fireos' || platform.id === 'android' || platform.id === 'ios' || - platform.id === 'windowsphone' || platform.id === 'firefoxos' || platform.id === 'ubuntu' || - platform.id === 'windows8' || platform.id === 'windows') { - - if (typeof buttonLabels === 'string') { - buttonLabels = buttonLabels.split(','); // not crazy about changing the var type here - } - } else { - if (Array.isArray(buttonLabels)) { - var buttonLabelArray = buttonLabels; - buttonLabels = buttonLabelArray.toString(); - } - } - - return buttonLabels; -}