| /* |
| * PhoneGap is available under *either* the terms of the modified BSD license *or* the |
| * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text. |
| * |
| * Copyright (c) 2005-2011, Nitobi Software Inc. |
| * Copyright (c) 2010-2011, IBM Corporation |
| * Copyright (c) 2011, Microsoft Corporation |
| */ |
| |
| if (!PhoneGap.hasResource("notification")) { |
| PhoneGap.addResource("notification"); |
| |
| /** |
| * This class provides access to notifications on the device. |
| * @constructor |
| */ |
| var Notification = function() { |
| }; |
| |
| /** |
| * 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) |
| */ |
| Notification.prototype.alert = function(message, completeCallback, title, buttonLabel) |
| { |
| var _title = (title || "Alert"); |
| var _buttonLabels = (buttonLabel || "OK"); |
| PhoneGap.exec(completeCallback, null, "Notification", "alert",{"message":message,"title":_title,"buttonLabels":_buttonLabels}); |
| }; |
| |
| /** |
| * Open a native confirm dialog, with a customizable title and button text. |
| * The result that the user selects is returned to the result callback. |
| * |
| * @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 {String} buttonLabels Comma separated list of the labels of the buttons (default: 'OK,Cancel') |
| */ |
| Notification.prototype.confirm = function(message, resultCallback, title, buttonLabels) |
| { |
| var _title = (title || "Confirm"); |
| var _buttonLabels = (buttonLabels || "OK,Cancel"); |
| PhoneGap.exec(resultCallback, null, "Notification", "confirm", {'message':message,"title":_title,"buttonLabels":_buttonLabels}); |
| }; |
| |
| /** |
| * Start spinning the activity indicator on the statusbar |
| */ |
| Notification.prototype.activityStart = function() { |
| PhoneGap.exec(null, null, "Notification", "activityStart", ["Busy","Please wait..."]); |
| }; |
| |
| /** |
| * Stop spinning the activity indicator on the statusbar, if it's currently spinning |
| */ |
| Notification.prototype.activityStop = function() { |
| PhoneGap.exec(null, null, "Notification", "activityStop", []); |
| }; |
| |
| /** |
| * Display a progress dialog with progress bar that goes from 0 to 100. |
| * |
| * @param {String} title Title of the progress dialog. |
| * @param {String} message Message to display in the dialog. |
| */ |
| Notification.prototype.progressStart = function(title, message) { |
| PhoneGap.exec(null, null, "Notification", "progressStart", [title, message]); |
| }; |
| |
| /** |
| * Set the progress dialog value. |
| * |
| * @param {Number} value 0-100 |
| */ |
| Notification.prototype.progressValue = function(value) { |
| PhoneGap.exec(null, null, "Notification", "progressValue", [value]); |
| }; |
| |
| /** |
| * Close the progress dialog. |
| */ |
| Notification.prototype.progressStop = function() { |
| PhoneGap.exec(null, null, "Notification", "progressStop", []); |
| }; |
| |
| /** |
| * Causes the device to blink a status LED. |
| * |
| * @param {Integer} count The number of blinks. |
| * @param {String} colour The colour of the light. |
| */ |
| Notification.prototype.blink = function(count, colour) { |
| // NOT IMPLEMENTED |
| }; |
| |
| /** |
| * Causes the device to vibrate. |
| * |
| * @param {Integer} mills The number of milliseconds to vibrate for. |
| */ |
| Notification.prototype.vibrate = function(mills) |
| { |
| PhoneGap.exec(null, null, "Notification", "vibrate", {duration:mills}); |
| }; |
| |
| /** |
| * Causes the device to beep. |
| * A packaged resource is played "repeatCount" times. |
| * |
| * @param {Integer} repeatCount The number of beeps. default 1 |
| */ |
| Notification.prototype.beep = function(repeatCount) |
| { |
| var count = repeatCount|| 1; |
| PhoneGap.exec(null, null, "Notification", "beep", count); |
| }; |
| |
| PhoneGap.addConstructor(function() { |
| if (typeof navigator.notification === "undefined") { |
| navigator.notification = new Notification(); |
| } |
| }); |
| } |