Created
March 30, 2011 09:10
-
-
Save jos3000/894102 to your computer and use it in GitHub Desktop.
PhoneGap module suggestion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 | |
*/ | |
/** | |
* This class provides access to notifications on the device. | |
*/ | |
PhoneGap.addModule('notification', function(PhoneGap){ | |
function Notification() { | |
} | |
/** | |
* 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 _buttonLabel = (buttonLabel || "OK"); | |
PhoneGap.exec(completeCallback, null, "Notification", "alert", [message,_title,_buttonLabel]); | |
}; | |
/** | |
* 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,_title,_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", [mills]); | |
}; | |
/** | |
* Causes the device to beep. | |
* On Android, the default notification ringtone is played "count" times. | |
* | |
* @param {Integer} count The number of beeps. | |
*/ | |
Notification.prototype.beep = function(count) { | |
PhoneGap.exec(null, null, "Notification", "beep", [count]); | |
}; | |
PhoneGap.addConstructor(function() { | |
PhoneGap.attachToNavigator('notification', new Notification()); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PhoneGap.addModule = function(modulename, init){ | |
if(this.resources[modulename]) init(this); | |
this.resources[modulename] = true; | |
} | |
PhoneGap.attachToNavigator = function(name, object){ | |
navigator[name] = object; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment