2010-10-19 04:31:16 +08:00
|
|
|
/*
|
|
|
|
* 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-2010, Nitobi Software Inc.
|
|
|
|
* Copyright (c) 2010, IBM Corporation
|
|
|
|
*/
|
|
|
|
|
2009-11-18 02:38:49 +08:00
|
|
|
/**
|
|
|
|
* This class provides access to notifications on the device.
|
|
|
|
*/
|
|
|
|
function Notification() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a native alert dialog, with a customizable title and button text.
|
2010-10-08 22:18:10 +08:00
|
|
|
*
|
2010-10-26 00:20:41 +08:00
|
|
|
* @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)
|
2009-11-18 02:38:49 +08:00
|
|
|
*/
|
2010-10-26 00:20:41 +08:00
|
|
|
Notification.prototype.alert = function(message, completeCallback, title, buttonLabel) {
|
2010-10-08 22:18:10 +08:00
|
|
|
var _title = (title || "Alert");
|
|
|
|
var _buttonLabel = (buttonLabel || "OK");
|
2010-10-26 00:20:41 +08:00
|
|
|
PhoneGap.exec(completeCallback, null, "Notification", "alert", [message,_title,_buttonLabel]);
|
2009-11-18 02:38:49 +08:00
|
|
|
};
|
|
|
|
|
2010-10-08 22:18:10 +08:00
|
|
|
/**
|
|
|
|
* Open a native confirm dialog, with a customizable title and button text.
|
2010-10-26 00:20:41 +08:00
|
|
|
* The result that the user selects is returned to the result callback.
|
2010-10-08 22:18:10 +08:00
|
|
|
*
|
2010-10-26 00:20:41 +08:00
|
|
|
* @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')
|
2010-10-08 22:18:10 +08:00
|
|
|
*/
|
2010-10-26 00:20:41 +08:00
|
|
|
Notification.prototype.confirm = function(message, resultCallback, title, buttonLabels) {
|
2010-10-08 22:18:10 +08:00
|
|
|
var _title = (title || "Confirm");
|
|
|
|
var _buttonLabels = (buttonLabels || "OK,Cancel");
|
2010-10-26 00:20:41 +08:00
|
|
|
PhoneGap.exec(resultCallback, null, "Notification", "confirm", [message,_title,_buttonLabels]);
|
2010-10-08 22:18:10 +08:00
|
|
|
};
|
|
|
|
|
2009-11-18 02:38:49 +08:00
|
|
|
/**
|
|
|
|
* Start spinning the activity indicator on the statusbar
|
|
|
|
*/
|
|
|
|
Notification.prototype.activityStart = function() {
|
2010-10-21 12:53:33 +08:00
|
|
|
PhoneGap.exec(null, null, "Notification", "activityStart", ["Busy","Please wait..."]);
|
2009-11-18 02:38:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop spinning the activity indicator on the statusbar, if it's currently spinning
|
|
|
|
*/
|
|
|
|
Notification.prototype.activityStop = function() {
|
2010-10-21 12:53:33 +08:00
|
|
|
PhoneGap.exec(null, null, "Notification", "activityStop", []);
|
2010-10-08 22:18:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2010-10-21 12:53:33 +08:00
|
|
|
PhoneGap.exec(null, null, "Notification", "progressStart", [title, message]);
|
2010-10-08 22:18:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the progress dialog value.
|
|
|
|
*
|
|
|
|
* @param {Number} value 0-100
|
|
|
|
*/
|
|
|
|
Notification.prototype.progressValue = function(value) {
|
2010-10-21 12:53:33 +08:00
|
|
|
PhoneGap.exec(null, null, "Notification", "progressValue", [value]);
|
2010-10-08 22:18:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the progress dialog.
|
|
|
|
*/
|
|
|
|
Notification.prototype.progressStop = function() {
|
2010-10-21 12:53:33 +08:00
|
|
|
PhoneGap.exec(null, null, "Notification", "progressStop", []);
|
2009-11-18 02:38:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Causes the device to blink a status LED.
|
2010-10-08 22:18:10 +08:00
|
|
|
*
|
|
|
|
* @param {Integer} count The number of blinks.
|
|
|
|
* @param {String} colour The colour of the light.
|
2009-11-18 02:38:49 +08:00
|
|
|
*/
|
|
|
|
Notification.prototype.blink = function(count, colour) {
|
2010-10-08 22:18:10 +08:00
|
|
|
// NOT IMPLEMENTED
|
2009-11-18 02:38:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Causes the device to vibrate.
|
2010-10-08 22:18:10 +08:00
|
|
|
*
|
|
|
|
* @param {Integer} mills The number of milliseconds to vibrate for.
|
2009-11-18 02:38:49 +08:00
|
|
|
*/
|
|
|
|
Notification.prototype.vibrate = function(mills) {
|
2010-10-21 12:53:33 +08:00
|
|
|
PhoneGap.exec(null, null, "Notification", "vibrate", [mills]);
|
2009-11-18 02:38:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Causes the device to beep.
|
2010-10-08 22:18:10 +08:00
|
|
|
* On Android, the default notification ringtone is played "count" times.
|
2010-09-16 03:27:46 +08:00
|
|
|
*
|
2010-10-08 22:18:10 +08:00
|
|
|
* @param {Integer} count The number of beeps.
|
2009-11-18 02:38:49 +08:00
|
|
|
*/
|
2010-09-16 03:27:46 +08:00
|
|
|
Notification.prototype.beep = function(count) {
|
2010-10-21 12:53:33 +08:00
|
|
|
PhoneGap.exec(null, null, "Notification", "beep", [count]);
|
2009-11-18 02:38:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
PhoneGap.addConstructor(function() {
|
2011-02-03 00:46:19 +08:00
|
|
|
if (typeof navigator.notification === "undefined") {
|
|
|
|
navigator.notification = new Notification();
|
|
|
|
}
|
2009-11-18 02:38:49 +08:00
|
|
|
});
|
|
|
|
|