Return-Path: X-Original-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AC5FD92C9 for ; Wed, 28 Mar 2012 18:50:49 +0000 (UTC) Received: (qmail 7598 invoked by uid 500); 28 Mar 2012 18:50:49 -0000 Delivered-To: apmail-incubator-callback-commits-archive@incubator.apache.org Received: (qmail 7546 invoked by uid 500); 28 Mar 2012 18:50:49 -0000 Mailing-List: contact callback-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-commits@incubator.apache.org Received: (qmail 7453 invoked by uid 99); 28 Mar 2012 18:50:49 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Mar 2012 18:50:49 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 2DEFD9B9D; Wed, 28 Mar 2012 18:50:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: anis@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [2/3] more renaming Message-Id: <20120328185049.2DEFD9B9D@tyr.zones.apache.org> Date: Wed, 28 Mar 2012 18:50:49 +0000 (UTC) http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada/blob/d3ab5427/Res/cordova/notification.js ---------------------------------------------------------------------- diff --git a/Res/cordova/notification.js b/Res/cordova/notification.js new file mode 100644 index 0000000..26bd1d3 --- /dev/null +++ b/Res/cordova/notification.js @@ -0,0 +1,105 @@ + +/* + * Cordova 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 + */ + +MessageBox.MSGBOX_STYLE_NONE = 0; +MessageBox.MSGBOX_STYLE_OK = 1; +MessageBox.MSGBOX_STYLE_CANCEL = 2; +MessageBox.MSGBOX_STYLE_OKCANCEL = 3; +MessageBox.MSGBOX_STYLE_YESNO = 4; +MessageBox.MSGBOX_STYLE_YESNOCANCEL = 5; +MessageBox.MSGBOX_STYLE_ABORTRETRYIGNORE = 6; +MessageBox.MSGBOX_STYLE_CANCELTRYCONTINUE = 7; +MessageBox.MSGBOX_STYLE_RETRYCANCEL = 8; + +/** + * This class provides access to notifications on the device. + */ +function Notification() { + this.messageBox = new MessageBox("Test Alert", "This is an alert", "OK"); +} + +/* + * MessageBox: used by Bada to retrieve Dialog Information + */ + +function MessageBox(title, message, messageBoxStyle) { + this.title = title; + this.message = message; + this.messageBoxStyle = messageBoxStyle; +} + +labelsToBoxStyle = function(buttonLabels) { + if(!buttonLabels) + return MessageBox.MSGBOX_STYLE_NONE; + if(buttonLabels == "OK") + return MessageBox.MSGBOX_STYLE_OK; + if(buttonLabels == "Cancel") + return MessageBox.MSGBOX_STYLE_CANCEL; + if(buttonLabels == "OK,Cancel") + return MessageBox.MSGBOX_STYLE_OKCANCEL; + if(buttonLabels == "Yes,No") + return MessageBox.MSGBOX_STYLE_YESNO; + if(buttonLabels == "Yes,No,Cancel") + return MessageBox.MSGBOX_STYLE_YESNOCANCEL; + if(buttonLabels == "Abort,Retry,Ignore") + return MessageBox.MSGBOX_STYLE_ABORTRETRYIGNORE; + if(buttonLabels == "Cancel,Try,Continue") + return MessageBox.MSGBOX_STYLE_CANCELTRYCONTINUE; + if(buttonLabels == "Retry,Cancel") + return MessageBox.MSGBOX_STYLE_RETRYCANCEL; + + return MessageBox.MSGBOX_STYLE_NONE; +} + +/** + * 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 invoked when user clicks 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"); + this.messageBox = new MessageBox(_title, message, labelsToBoxStyle(buttonLabel)); + Cordova.exec(completeCallback, null, 'com.cordova.Notification', 'alert', []); +}; + +/** + * Open a custom confirmation dialog, with a customizable title and button text. + * @param {String} message Message to print in the body of the dialog + * @param {Function}resultCallback The callback that is invoked when a user clicks a button. + * @param {String} title Title of the alert dialog (default: 'Confirm') + * @param {String} buttonLabels Comma separated list of the button labels (default: 'OK,Cancel') + */ +Notification.prototype.confirm = function(message, resultCallback, title, buttonLabels) { + var _title = (title || "Confirm"); + var _buttonLabels = (buttonLabels || "OK,Cancel"); + this.messageBox = new MessageBox(_title, message, labelsToBoxStyle(buttonLabels)); + return Cordova.exec(resultCallback, null, 'com.cordova.Notification', 'confirm', []); +}; + +/** + * Causes the device to vibrate. + * @param {Integer} mills The number of milliseconds to vibrate for. + */ +Notification.prototype.vibrate = function(mills) { + Cordova.exec(null, null, 'com.cordova.Notification', 'vibrate', [mills]); +}; + +/** + * Causes the device to beep. + * @param {Integer} count The number of beeps. + */ +Notification.prototype.beep = function(count) { + Cordova.exec(null, null, 'com.cordova.Notification', 'beep', [count]); +}; + +Cordova.addConstructor(function() { + if (typeof navigator.notification == "undefined") navigator.notification = new Notification(); +}); http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada/blob/d3ab5427/Res/cordova/position.js ---------------------------------------------------------------------- diff --git a/Res/cordova/position.js b/Res/cordova/position.js new file mode 100644 index 0000000..94605ab --- /dev/null +++ b/Res/cordova/position.js @@ -0,0 +1,62 @@ + +/* + * Cordova 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 contains position information. + * @param {Object} lat + * @param {Object} lng + * @param {Object} acc + * @param {Object} alt + * @param {Object} altacc + * @param {Object} head + * @param {Object} vel + * @constructor + */ +function Position(coords, timestamp) { + this.coords = coords; + this.timestamp = timestamp; +} + +function PositionOptions(enableHighAccuracy, timeout, maximumAge, minimumAccuracy) { + this.enableHighAccuracy = enableHighAccuracy || false; + this.timeout = timeout || 10000000; + this.maximumAge = maximumAge || 0; + this.minimumAccuracy = minimumAccuracy || 10000000; +} + +function Coordinates(lat, lng, alt, acc, head, vel, altacc) { + /** + * The latitude of the position. + */ + this.latitude = lat || 0; + /** + * The longitude of the position, + */ + this.longitude = lng || 0; + /** + * The accuracy of the position. + */ + this.accuracy = acc || 0; + /** + * The altitude of the position. + */ + this.altitude = alt || 0; + /** + * The direction the device is moving at the position. + */ + this.heading = head || 0; + /** + * The velocity with which the device is moving at the position. + */ + this.speed = vel || 0; + /** + * The altitude accuracy of the position. + */ + this.altitudeAccuracy = (altacc != 'undefined') ? altacc : null; +} http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada/blob/d3ab5427/Res/phonegap/accelerometer.js ---------------------------------------------------------------------- diff --git a/Res/phonegap/accelerometer.js b/Res/phonegap/accelerometer.js deleted file mode 100644 index 6760258..0000000 --- a/Res/phonegap/accelerometer.js +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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 - */ -function Acceleration(x, y, z, timestamp) { - this.x = x; - this.y = y; - this.z = z; - this.timestamp = timestamp || new Date().getTime(); -}; - -/** - * Class provides access to device accelerometer data. - * @constructor - */ -function Accelerometer() { - - /** - * The last known acceleration. type=Acceleration() - */ - this.lastAcceleration = null; - this.id = null; -}; - -/** - * Asynchronously acquires the current acceleration. - * - * @param {Function} successCallback The function to call when the acceleration data is available - * @param {Function} errorCallback The function to call when there is an error getting the acceleration data. (OPTIONAL) - * @param {AccelerationOptions} options The options for getting the accelerometer data such as timeout. (OPTIONAL) - */ -Accelerometer.prototype.getCurrentAcceleration = function(successCallback, errorCallback, options) { - - // successCallback required - if (typeof successCallback != "function") { - console.log("Accelerometer Error: successCallback is not a function"); - return; - } - - // errorCallback optional - if (errorCallback && (typeof errorCallback != "function")) { - console.log("Accelerometer Error: errorCallback is not a function"); - return; - } - - // Get acceleration - PhoneGap.exec(successCallback, errorCallback, "com.phonegap.Accelerometer", "getCurrentAcceleration", []); -}; - -/** - * Asynchronously acquires the device acceleration at a given interval. - * - * @param {Function} successCallback The function to call each time the acceleration data is available - * @param {Function} errorCallback The function to call when there is an error getting the acceleration data. (OPTIONAL) - * @param {AccelerationOptions} options The options for getting the accelerometer data such as timeout. (OPTIONAL) - * @return String The watch id that must be passed to #clearWatch to stop watching. - */ -Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallback, options) { - - // Default interval (10 sec) - var frequency = (options != undefined) ? options.frequency : 10000; - - // successCallback required - if (typeof successCallback != "function") { - console.log("Accelerometer Error: successCallback is not a function"); - return; - } - - // errorCallback optional - if (errorCallback && (typeof errorCallback != "function")) { - console.log("Accelerometer Error: errorCallback is not a function"); - return; - } - // Start watch timer - this.id = PhoneGap.createUUID(); - PhoneGap.exec(successCallback, errorCallback, "com.phonegap.Accelerometer", "watchAcceleration", []); - return this.id; -}; - -/** - * Clears the specified accelerometer watch. - * - * @param {String} id The id of the watch returned from #watchAcceleration. - */ -Accelerometer.prototype.clearWatch = function(id) { - - // Stop javascript timer & remove from timer list - if (id == this.id) { - PhoneGap.exec(null, null, "com.phonegap.Accelerometer", "clearWatch", []); - } -}; - -/* - * Native callback when watchAcceleration has a new acceleration. - */ -Accelerometer.prototype.success = function(id, result) { - try { - var accel = new Acceleration(result.x, result.y, result.z, result.timestamp); - navigator.accelerometer.lastAcceleration = accel; - navigator.accelerometer.listeners[id].success(accel); - } - catch (e) { - debugPrint("Geolocation Error: "+e.message); - console.log("Geolocation Error: Error calling success callback function."); - } - - if (id == "global") { - delete navigator.accelerometer.listeners["global"]; - } -}; - -PhoneGap.addConstructor(function() { - if (typeof navigator.accelerometer == "undefined") navigator.accelerometer = new Accelerometer(); -}); http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada/blob/d3ab5427/Res/phonegap/camera.js ---------------------------------------------------------------------- diff --git a/Res/phonegap/camera.js b/Res/phonegap/camera.js deleted file mode 100644 index 1566a5e..0000000 --- a/Res/phonegap/camera.js +++ /dev/null @@ -1,90 +0,0 @@ - -/* - * 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 the device camera. - * - * @constructor - */ -Camera = function() { - this.options = null; -}; - -/** - * Format of image that returned from getPicture. - * - * Example: navigator.camera.getPicture(success, fail, - * { quality: 80, - * destinationType: Camera.DestinationType.DATA_URL, - * sourceType: Camera.PictureSourceType.PHOTOLIBRARY}) - */ -Camera.DestinationType = { - DATA_URL: 0, // Return base64 encoded string - FILE_URI: 1 // Return file URI -}; -Camera.prototype.DestinationType = Camera.DestinationType; - -/** - * Source to getPicture from. - * - * Example: navigator.camera.getPicture(success, fail, - * { quality: 80, - * destinationType: Camera.DestinationType.DATA_URL, - * sourceType: Camera.PictureSourceType.PHOTOLIBRARY}) - */ -Camera.PictureSourceType = { // Ignored on Blackberry - PHOTOLIBRARY : 0, // Choose image from picture library - CAMERA : 1, // Take picture from camera - SAVEDPHOTOALBUM : 2 // Choose image from picture library -}; -Camera.prototype.PictureSourceType = Camera.PictureSourceType; - -/** - * Gets a picture from source defined by "options.sourceType", and returns the - * image as defined by the "options.destinationType" option. - - * The defaults are sourceType=CAMERA and destinationType=DATA_URL. - * - * @param {Function} successCallback - * @param {Function} errorCallback - * @param {Object} options - */ -Camera.prototype.getPicture = function(successCallback, errorCallback, options) { - - // successCallback required - if (typeof successCallback != "function") { - console.log("Camera Error: successCallback is not a function"); - return; - } - - // errorCallback optional - if (errorCallback && (typeof errorCallback != "function")) { - console.log("Camera Error: errorCallback is not a function"); - return; - } - - this.options = options; - var quality = 80; - if (options.quality) { - quality = this.options.quality; - } - var destinationType = Camera.DestinationType.DATA_URL; - if (this.options.destinationType) { - destinationType = this.options.destinationType; - } - var sourceType = Camera.PictureSourceType.CAMERA; - if (typeof this.options.sourceType == "number") { - sourceType = this.options.sourceType; - } - PhoneGap.exec(successCallback, errorCallback, "com.phonegap.Camera", "getPicture", [quality, destinationType, sourceType]); -}; - -PhoneGap.addConstructor(function() { - if (typeof navigator.camera == "undefined") navigator.camera = new Camera(); -}); http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada/blob/d3ab5427/Res/phonegap/compass.js ---------------------------------------------------------------------- diff --git a/Res/phonegap/compass.js b/Res/phonegap/compass.js deleted file mode 100644 index d8c9653..0000000 --- a/Res/phonegap/compass.js +++ /dev/null @@ -1,56 +0,0 @@ -/** - * This class provides access to device Compass data. - * @constructor - */ -function Compass() { - /** - * The last known Compass position. - */ - this.uuid = null; -}; - -/** - * Asynchronously aquires the current heading. - * @param {Function} successCallback The function to call when the heading - * data is available - * @param {Function} errorCallback The function to call when there is an error - * getting the heading data. - * @param {PositionOptions} options The options for getting the heading data - * such as timeout. - */ -Compass.prototype.getCurrentHeading = function(successCallback, errorCallback, options) { - PhoneGap.exec(successCallback, errorCallback, "com.phonegap.Compass", "getCurrentHeading", options); -}; - -/** - * Asynchronously aquires the heading repeatedly at a given interval. - * @param {Function} successCallback The function to call each time the heading - * data is available - * @param {Function} errorCallback The function to call when there is an error - * getting the heading data. - * @param {HeadingOptions} options The options for getting the heading data - * such as timeout and the frequency of the watch. - */ -Compass.prototype.watchHeading= function(successCallback, errorCallback, options) { - this.uuid = PhoneGap.createUUID(); - PhoneGap.exec(successCallback, errorCallback, "com.phonegap.Compass", "watchHeading", [this.uuid, options.frequency || 3000]); - return this.uuid; -}; - - -/** - * Clears the specified heading watch. - * @param {String} watchId The ID of the watch returned from #watchHeading. - */ -Compass.prototype.clearWatch = function(watchId) { - if(this.uuid == watchId) { - PhoneGap.exec(null, null, "com.phonegap.Compass", "clearWatch", [this.uuid]); - this.uuid = null; - } else { - debugPrint('no clear watch'); - } -}; - -PhoneGap.addConstructor(function() { - if (typeof navigator.compass == "undefined") navigator.compass = new Compass(); -}); http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada/blob/d3ab5427/Res/phonegap/contact.js ---------------------------------------------------------------------- diff --git a/Res/phonegap/contact.js b/Res/phonegap/contact.js deleted file mode 100644 index d382ecc..0000000 --- a/Res/phonegap/contact.js +++ /dev/null @@ -1,342 +0,0 @@ -/* - * 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 - */ - -/** -* Contains information about a single contact. -* @param {DOMString} id unique identifier -* @param {DOMString} displayName -* @param {ContactName} name -* @param {DOMString} nickname -* @param {ContactField[]} phoneNumbers array of phone numbers -* @param {ContactField[]} emails array of email addresses -* @param {ContactAddress[]} addresses array of addresses -* @param {ContactField[]} ims instant messaging user ids -* @param {ContactOrganization[]} organizations -* @param {DOMString} revision date contact was last updated -* @param {DOMString} birthday contact's birthday -* @param {DOMString} gender contact's gender -* @param {DOMString} note user notes about contact -* @param {ContactField[]} photos -* @param {ContactField[]} urls contact's web sites -* @param {DOMString} timezone UTC time zone offset -*/ - -var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, addresses, - ims, organizations, revision, birthday, gender, note, photos, categories, urls, timezone) { - this.id = id || null; - this.displayName = displayName || null; - this.name = name || null; // ContactName - this.nickname = nickname || null; - this.phoneNumbers = phoneNumbers || null; // ContactField[] - this.emails = emails || null; // ContactField[] - this.addresses = addresses || null; // ContactAddress[] - this.ims = ims || null; // ContactField[] - this.organizations = organizations || null; // ContactOrganization[] - this.revision = revision || null; // JS Date - this.birthday = birthday || null; // JS Date - this.gender = gender || null; - this.note = note || null; - this.photos = photos || null; // ContactField[] - this.categories = categories || null; - this.urls = urls || null; // ContactField[] - this.timezone = timezone || null; -}; - -/** -* Removes contact from device storage. -* @param successCB success callback -* @param errorCB error callback (optional) -*/ -Contact.prototype.remove = function(successCB, errorCB) { - if (this.id == null) { - var errorObj = new ContactError(); - errorObj.code = ContactError.NOT_FOUND_ERROR; - errorCB(errorObj); - } - else { - PhoneGap.exec(successCB, errorCB, "com.phonegap.Contacts", "remove", [this.id]); - } -}; -/** -* Bada ONLY -* displays contact via Bada Contact UI -* -* @param errorCB error callback -*/ -Contact.prototype.display = function(successCB, errorCB, options) { - if (this.id == null) { - var errorObj = new ContactError(); - errorObj.code = ContactError.NOT_FOUND_ERROR; - errorCB(errorObj); - } - else { - PhoneGap.exec(successCB, errorCB, "com.phonegap.Contacts","displayContact", [this.id, options]); - } -}; - -/** -* Creates a deep copy of this Contact. -* With the contact ID set to null. -* @return copy of this Contact -*/ -Contact.prototype.clone = function() { - var clonedContact = PhoneGap.clone(this); - clonedContact.id = null; - // Loop through and clear out any id's in phones, emails, etc. - if (clonedContact.phoneNumbers) { - for (i=0; i - */ -function FileMgr() { -}; - -/** - * Returns the root file system paths. - * - * @return {String[]} array of root file system paths - */ -FileMgr.prototype.getRootPaths = function() { - return blackberry.io.dir.getRootDirs(); -}; - -/** - * Returns the available memory in bytes for the root file system of the specified file path. - * - * @param filePath A file system path - */ -FileMgr.prototype.getFreeDiskSpace = function(filePath) { - return blackberry.io.dir.getFreeSpaceForRoot(filePath); -}; - -/** - * Reads a file from the device and encodes the contents using the specified - * encoding. - * - * @param fileName The full path of the file to read - * @param encoding The encoding to use to encode the file's content - * @param successCallback Callback invoked with file contents - * @param errorCallback Callback invoked on error - */ -FileMgr.prototype.readAsText = function(fileName, encoding, successCallback, errorCallback) { - PhoneGap.exec(successCallback, errorCallback, "File", "readAsText", [fileName, encoding]); -}; - -/** - * Reads a file from the device and encodes the contents using BASE64 encoding. - * - * @param fileName The full path of the file to read. - * @param successCallback Callback invoked with file contents - * @param errorCallback Callback invoked on error - */ -FileMgr.prototype.readAsDataURL = function(fileName, successCallback, errorCallback) { - PhoneGap.exec(successCallback, errorCallback, "File", "readAsDataURL", [fileName]); -}; - -/** - * Writes data to the specified file. - * - * @param fileName The full path of the file to write - * @param data The data to be written - * @param position The position in the file to begin writing - * @param successCallback Callback invoked after successful write operation - * @param errorCallback Callback invoked on error - */ -FileMgr.prototype.write = function(fileName, data, position, successCallback, errorCallback) { - PhoneGap.exec(successCallback, errorCallback, "File", "write", [fileName, data, position]); -}; - -/** - * Tests whether file exists. Will return false if the path specifies a directory. - * - * @param fullPath The full path of the file - */ -FileMgr.prototype.testFileExists = function(fullPath) { - return blackberry.io.file.exists(fullPath); -}; - -/** - * Tests whether directory exists. Will return false if the path specifies a file. - * - * @param fullPath The full path of the directory - */ -FileMgr.prototype.testDirectoryExists = function(fullPath) { - return blackberry.io.dir.exists(fullPath); -}; - -/** - * Gets the properties of a file. Throws an exception if fileName is a directory. - * - * @param fileName The full path of the file - */ -FileMgr.prototype.getFileProperties = function(fileName) { - var fileProperties = new FileProperties(fileName); - // attempt to get file properties - if (blackberry.io.file.exists(fileName)) { - var props = blackberry.io.file.getFileProperties(fileName); - fileProperties.size = props.size; - fileProperties.lastModifiedDate = props.dateModified; - } - // fileName is a directory - else if (blackberry.io.dir.exists(fileName)) { - throw FileError.TYPE_MISMATCH_ERR; - } - return fileProperties; -}; - -/** - * Changes the length of the specified file. Data beyond new length is discarded. - * - * @param fileName The full path of the file to truncate - * @param size The size to which the length of the file is to be adjusted - * @param successCallback Callback invoked after successful write operation - * @param errorCallback Callback invoked on error - */ -FileMgr.prototype.truncate = function(fileName, size, successCallback, errorCallback) { - PhoneGap.exec(successCallback, errorCallback, "File", "truncate", [fileName, size]); -}; - -/** - * Removes a file from the file system. - * - * @param fileName The full path of the file to be deleted - */ -FileMgr.prototype.deleteFile = function(fileName) { - // delete file, if it exists - if (blackberry.io.file.exists(fileName)) { - blackberry.io.file.deleteFile(fileName); - } - // fileName is a directory - else if (blackberry.io.dir.exists(fileName)) { - throw FileError.TYPE_MISMATCH_ERR; - } - // fileName not found - else { - throw FileError.NOT_FOUND_ERR; - } -}; - -/** - * Creates a directory on device storage. - * - * @param dirName The full path of the directory to be created - */ -FileMgr.prototype.createDirectory = function(dirName) { - if (!blackberry.io.dir.exists(dirName)) { - // createNewDir API requires trailing slash - if (dirName.substr(-1) !== "/") { - dirName += "/"; - } - blackberry.io.dir.createNewDir(dirName); - } - // directory already exists - else { - throw FileError.PATH_EXISTS_ERR; - } -}; - -/** - * Deletes the specified directory from device storage. - * - * @param dirName The full path of the directory to be deleted - */ -FileMgr.prototype.deleteDirectory = function(dirName) { - blackberry.io.dir.deleteDirectory(dirName); -}; - -PhoneGap.addConstructor(function() { - if (typeof navigator.fileMgr == "undefined") navigator.fileMgr = new FileMgr(); -}); - -//----------------------------------------------------------------------------- -//File Reader -//----------------------------------------------------------------------------- - -/** - * This class reads the mobile device file system. - */ -function FileReader() { - this.fileName = ""; - - this.readyState = 0; - - // File data - this.result = null; - - // Error - this.error = null; - - // Event handlers - this.onloadstart = null; // When the read starts. - this.onprogress = null; // While reading (and decoding) file or fileBlob data, and reporting partial file data (progess.loaded/progress.total) - this.onload = null; // When the read has successfully completed. - this.onerror = null; // When the read has failed (see errors). - this.onloadend = null; // When the request has completed (either in success or failure). - this.onabort = null; // When the read has been aborted. For instance, by invoking the abort() method. -}; - -//States -FileReader.EMPTY = 0; -FileReader.LOADING = 1; -FileReader.DONE = 2; - -/** - * Abort read file operation. - */ -FileReader.prototype.abort = function() { - var event; - - // reset everything - this.readyState = FileReader.DONE; - this.result = null; - - // set error - var error = new FileError(); - error.code = error.ABORT_ERR; - this.error = error; - - // abort procedure - if (typeof this.onerror == "function") { - event = {"type":"error", "target":this}; - this.onerror(event); - } - if (typeof this.onabort == "function") { - event = {"type":"abort", "target":this}; - this.onabort(event); - } - if (typeof this.onloadend == "function") { - event = {"type":"loadend", "target":this}; - this.onloadend(event); - } -}; - -/** - * Reads and encodes text file. - * - * @param file The name of the file - * @param encoding [Optional] (see http://www.iana.org/assignments/character-sets) - */ -FileReader.prototype.readAsText = function(file, encoding) { - var event; - - // Use UTF-8 as default encoding - var enc = encoding ? encoding : "UTF-8"; - - // start - this.readyState = FileReader.LOADING; - if (typeof this.onloadstart == "function") { - event = {"type":"loadstart", "target":this}; - this.onloadstart(event); - } - - // read and encode file - this.fileName = file; - var me = this; - navigator.fileMgr.readAsText(file, enc, - - // success callback - function(result) { - // If DONE (canceled), then don't do anything - if (me.readyState === FileReader.DONE) { - return; - } - - // success procedure - me.result = result; - if (typeof me.onload == "function") { - event = {"type":"load", "target":me}; - me.onload(event); - } - me.readyState = FileReader.DONE; - if (typeof me.onloadend == "function") { - event = {"type":"loadend", "target":me}; - me.onloadend(event); - } - }, - - // error callback - function(error) { - // If DONE (canceled), then don't do anything - if (me.readyState === FileReader.DONE) { - return; - } - - // capture error - var err = new FileError(); - err.code = error; - me.error = err; - - // error procedure - me.result = null; - if (typeof me.onerror == "function") { - event = {"type":"error", "target":me}; - me.onerror(event); - } - me.readyState = FileReader.DONE; - if (typeof me.onloadend == "function") { - event = {"type":"loadend", "target":me}; - me.onloadend(event); - } - } - ); -}; - -/** - * Read file and return data as a base64 encoded data url. - * A data url is of the form: - * data:[][;base64], - * - * @param file The name of the file - */ -FileReader.prototype.readAsDataURL = function(file) { - var event; - - // start - this.readyState = FileReader.LOADING; - if (typeof this.onloadstart == "function") { - event = {"type":"loadstart", "target":this}; - this.onloadstart(event); - } - - // read and encode file - this.fileName = file; - var me = this; - navigator.fileMgr.readAsDataURL(file, - - // success callback - function(result) { - // If DONE (canceled), then don't do anything - if (me.readyState === FileReader.DONE) { - return; - } - - // success procedure - me.result = result; - if (typeof me.onload == "function") { - event = {"type":"load", "target":me}; - me.onload(event); - } - me.readyState = FileReader.DONE; - if (typeof me.onloadend == "function") { - event = {"type":"loadend", "target":me}; - me.onloadend(event); - } - }, - - // error callback - function(error) { - // If DONE (canceled), then don't do anything - if (me.readyState === FileReader.DONE) { - return; - } - - // capture error - var err = new FileError(); - err.code = error; - me.error = err; - - // error procedure - me.result = null; - if (typeof me.onerror == "function") { - event = {"type":"error", "target":me}; - me.onerror(event); - } - me.readyState = FileReader.DONE; - if (typeof me.onloadend == "function") { - event = {"type":"loadend", "target":me}; - me.onloadend(event); - } - } - ); -}; - -//----------------------------------------------------------------------------- -//File Writer -//----------------------------------------------------------------------------- - -/** -* This class writes to the mobile device file system. -* -* @param filePath The full path to the file to be written to -* @param append If true, then data will be written to the end of the file rather than the beginning -*/ -function FileWriter(filePath, append) { - this.fileName = filePath; - this.length = 0; - - // get the file properties - var fp = navigator.fileMgr.getFileProperties(filePath); - this.length = fp.size; - - // default is to write at the beginning of the file - this.position = (append !== true) ? 0 : this.length; - - this.readyState = 0; // EMPTY - - // Error - this.error = null; - - // Event handlers - this.onwritestart = null; // When writing starts - this.onprogress = null; // While writing the file, and reporting partial file data - this.onwrite = null; // When the write has successfully completed. - this.onwriteend = null; // When the request has completed (either in success or failure). - this.onabort = null; // When the write has been aborted. For instance, by invoking the abort() method. - this.onerror = null; // When the write has failed (see errors). -}; - -//States -FileWriter.INIT = 0; -FileWriter.WRITING = 1; -FileWriter.DONE = 2; - -/** - * Abort writing file. - */ -FileWriter.prototype.abort = function() { - var event; - // check for invalid state - if (this.readyState === FileWriter.DONE || this.readyState === FileWriter.INIT) { - throw FileError.INVALID_STATE_ERR; - } - - // set error - var error = new FileError(); - error.code = error.ABORT_ERR; - this.error = error; - - // dispatch progress events - if (typeof this.onerror == "function") { - event = {"type":"error", "target":this}; - this.onerror(event); - } - if (typeof this.onabort == "function") { - event = {"type":"abort", "target":this}; - this.onabort(event); - } - - // set state - this.readyState = FileWriter.DONE; - - // done - if (typeof this.writeend == "function") { - event = {"type":"writeend", "target":this}; - this.writeend(event); - } -}; - -/** - * Sets the file position at which the next write will occur. - * - * @param offset Absolute byte offset into the file - */ -FileWriter.prototype.seek = function(offset) { - // Throw an exception if we are already writing a file - if (this.readyState === FileWriter.WRITING) { - throw FileError.INVALID_STATE_ERR; - } - - if (!offset) { - return; - } - - // offset is bigger than file size, set to length of file - if (offset > this.length) { - this.position = this.length; - } - // seek back from end of file - else if (offset < 0) { - this.position = Math.max(offset + this.length, 0); - } - // offset in the middle of file - else { - this.position = offset; - } -}; - -/** - * Truncates the file to the specified size. - * - * @param size The size to which the file length is to be adjusted - */ -FileWriter.prototype.truncate = function(size) { - var event; - - // Throw an exception if we are already writing a file - if (this.readyState === FileWriter.WRITING) { - throw FileError.INVALID_STATE_ERR; - } - - // start - this.readyState = FileWriter.WRITING; - if (typeof this.onwritestart == "function") { - event = {"type":"writestart", "target":this}; - this.onwritestart(event); - } - - // truncate file - var me = this; - navigator.fileMgr.truncate(this.fileName, size, - // Success callback receives the new file size - function(result) { - // If DONE (canceled), then don't do anything - if (me.readyState === FileWriter.DONE) { - return; - } - - // new file size is returned - me.length = result; - // position is lesser of old position or new file size - me.position = Math.min(me.position, result); - - // success procedure - if (typeof me.onwrite == "function") { - event = {"type":"write", "target":me}; - me.onwrite(event); - } - me.readyState = FileWriter.DONE; - if (typeof me.onwriteend == "function") { - event = {"type":"writeend", "target":me}; - me.onwriteend(event); - } - }, - - // Error callback - function(error) { - // If DONE (canceled), then don't do anything - if (me.readyState === FileWriter.DONE) { - return; - } - - // Save error - var err = new FileError(); - err.code = error; - me.error = err; - - // error procedure - if (typeof me.onerror == "function") { - event = {"type":"error", "target":me}; - me.onerror(event); - } - me.readyState = FileWriter.DONE; - if (typeof me.onwriteend == "function") { - event = {"type":"writeend", "target":me}; - me.onwriteend(event); - } - } - ); -}; - -/** - * Writes the contents of a file to the device. - * - * @param data contents to be written - */ -FileWriter.prototype.write = function(data) { - var event; - - // Throw an exception if we are already writing a file - if (this.readyState === FileWriter.WRITING) { - throw FileError.INVALID_STATE_ERR; - } - - // WRITING state - this.readyState = FileWriter.WRITING; - if (typeof this.onwritestart == "function") { - event = {"type":"writestart", "target":this}; - this.onwritestart(event); - } - - // Write file - var me = this; - navigator.fileMgr.write(this.fileName, data, this.position, - - // Success callback receives bytes written - function(result) { - // If DONE (canceled), then don't do anything - if (me.readyState === FileWriter.DONE) { - return; - } - - // new length is maximum of old length, or position plus bytes written - me.length = Math.max(me.length, me.position + result); - // position always increases by bytes written because file would be extended - me.position += result; - - // success procedure - if (typeof me.onwrite == "function") { - event = {"type":"write", "target":me}; - me.onwrite(event); - } - me.readyState = FileWriter.DONE; - if (typeof me.onwriteend == "function") { - event = {"type":"writeend", "target":me}; - me.onwriteend(event); - } - }, - - // Error callback - function(error) { - // If DONE (canceled), then don't do anything - if (me.readyState === FileWriter.DONE) { - return; - } - - // Save error - var err = new FileError(); - err.code = error; - me.error = err; - - // error procedure - if (typeof me.onerror == "function") { - event = {"type":"error", "target":me}; - me.onerror(event); - } - me.readyState = FileWriter.DONE; - if (typeof me.onwriteend == "function") { - event = {"type":"writeend", "target":me}; - me.onwriteend(event); - } - } - ); -}; http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada/blob/d3ab5427/Res/phonegap/geolocation.js ---------------------------------------------------------------------- diff --git a/Res/phonegap/geolocation.js b/Res/phonegap/geolocation.js deleted file mode 100644 index f43a062..0000000 --- a/Res/phonegap/geolocation.js +++ /dev/null @@ -1,140 +0,0 @@ - -/* - * 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 device GPS data. - * @constructor - */ -function Geolocation() { - - // The last known GPS position. - this.lastPosition = null; - this.id = null; -}; - -/** - * Position error object - * - * @param code - * @param message - */ -function PositionError(code, message) { - this.code = code || 0; - this.message = message || ''; -}; - -PositionError.UNKNOWN_ERROR = 0; -PositionError.PERMISSION_DENIED = 1; -PositionError.POSITION_UNAVAILABLE = 2; -PositionError.TIMEOUT = 3; - -/** - * Asynchronously aquires the current position. - * - * @param {Function} successCallback The function to call when the position data is available - * @param {Function} errorCallback The function to call when there is an error getting the heading position. (OPTIONAL) - * @param {PositionOptions} options The options for getting the position data. (OPTIONAL) - */ -Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) { - this.id = PhoneGap.createUUID(); - // default maximumAge value should be 0, and set if positive - var maximumAge = 0; - - // default timeout value should be infinity, but that's a really long time - var timeout = 3600000; - - var enableHighAccuracy = false; - if (options) { - if (options.maximumAge && (options.maximumAge > 0)) { - maximumAge = options.maximumAge; - } - if (options.enableHighAccuracy) { - enableHighAccuracy = options.enableHighAccuracy; - } - if (options.timeout) { - timeout = (options.timeout < 0) ? 0 : options.timeout; - } - } - PhoneGap.exec(successCallback, errorCallback, "com.phonegap.Geolocation", "getCurrentPosition", [maximumAge, timeout, enableHighAccuracy]); -} - -/** - * Asynchronously watches the geolocation for changes to geolocation. When a change occurs, - * the successCallback is called with the new location. - * - * @param {Function} successCallback The function to call each time the location data is available - * @param {Function} errorCallback The function to call when there is an error getting the location data. (OPTIONAL) - * @param {PositionOptions} options The options for getting the location data such as frequency. (OPTIONAL) - * @return String The watch id that must be passed to #clearWatch to stop watching. - */ -Geolocation.prototype.watchPosition = function(successCallback, errorCallback, options) { - - // default maximumAge value should be 0, and set if positive - var maximumAge = 0; - - // DO NOT set timeout to a large value for watchPosition in BlackBerry. - // The interval used for updates is half the timeout value, so a large - // timeout value will mean a long wait for the first location. - var timeout = 10000; - - var enableHighAccuracy = false; - if (options) { - if (options.maximumAge && (options.maximumAge > 0)) { - maximumAge = options.maximumAge; - } - if (options.enableHighAccuracy) { - enableHighAccuracy = options.enableHighAccuracy; - } - if (options.timeout) { - timeout = (options.timeout < 0) ? 0 : options.timeout; - } - } - this.id = PhoneGap.createUUID(); - PhoneGap.exec(successCallback, errorCallback, "com.phonegap.Geolocation", "watchPosition", [maximumAge, timeout, enableHighAccuracy]); - return this.id; -}; - -/** - * Clears the specified position watch. - * - * @param {String} id The ID of the watch returned from #watchPosition - */ -Geolocation.prototype.clearWatch = function(id) { - PhoneGap.exec(null, null, "com.phonegap.Geolocation", "stop", []); - this.id = null; -}; - -/** - * Force the PhoneGap geolocation to be used instead of built-in. - */ -Geolocation.usingPhoneGap = false; -Geolocation.usePhoneGap = function() { - if (Geolocation.usingPhoneGap) { - return; - } - Geolocation.usingPhoneGap = true; - - // Set built-in geolocation methods to our own implementations - // (Cannot replace entire geolocation, but can replace individual methods) - navigator.geolocation.getCurrentPosition = navigator._geo.getCurrentPosition; - navigator.geolocation.watchPosition = navigator._geo.watchPosition; - navigator.geolocation.clearWatch = navigator._geo.clearWatch; - navigator.geolocation.success = navigator._geo.success; - navigator.geolocation.fail = navigator._geo.fail; -}; - -PhoneGap.addConstructor(function() { - navigator._geo = new Geolocation(); - - // if no native geolocation object, use PhoneGap geolocation - if (typeof navigator.geolocation == 'undefined') { - navigator.geolocation = navigator._geo; - Geolocation.usingPhoneGap = true; - } -}); http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada/blob/d3ab5427/Res/phonegap/network.js ---------------------------------------------------------------------- diff --git a/Res/phonegap/network.js b/Res/phonegap/network.js deleted file mode 100644 index e85291d..0000000 --- a/Res/phonegap/network.js +++ /dev/null @@ -1,58 +0,0 @@ - -/* - * 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 - */ - -/** - * Network status. - */ -NetworkStatus = { - NOT_REACHABLE: 0, - REACHABLE_VIA_CARRIER_DATA_NETWORK: 1, - REACHABLE_VIA_WIFI_NETWORK: 2 -}; - -/** - * This class provides access to device Network data (reachability). - * @constructor - */ -function Network() { - /** - * The last known Network status. - * { hostName: string, ipAddress: string, - remoteHostStatus: int(0/1/2), internetConnectionStatus: int(0/1/2), localWiFiConnectionStatus: int (0/2) } - */ - this.lastReachability = null; -}; - -/** - * Determine if a URI is reachable over the network. - - * @param {Object} uri - * @param {Function} callback - * @param {Object} options (isIpAddress:boolean) - */ -Network.prototype.isReachable = function(uri, callback, options) { - var isIpAddress = false; - if (options && options.isIpAddress) { - isIpAddress = options.isIpAddress; - } - PhoneGap.exec(callback, null, 'com.phonegap.Network', 'isReachable', [uri, isIpAddress]); -}; - -/** - * Called by the geolocation framework when the reachability status has changed. - * @param {Reachibility} reachability The current reachability status. - */ -// TODO: Callback from native code not implemented for Android -Network.prototype.updateReachability = function(reachability) { - this.lastReachability = reachability; -}; - -PhoneGap.addConstructor(function() { - if (typeof navigator.network == "undefined") navigator.network = new Network(); -}); http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada/blob/d3ab5427/Res/phonegap/notification.js ---------------------------------------------------------------------- diff --git a/Res/phonegap/notification.js b/Res/phonegap/notification.js deleted file mode 100644 index 0e39a73..0000000 --- a/Res/phonegap/notification.js +++ /dev/null @@ -1,105 +0,0 @@ - -/* - * 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 - */ - -MessageBox.MSGBOX_STYLE_NONE = 0; -MessageBox.MSGBOX_STYLE_OK = 1; -MessageBox.MSGBOX_STYLE_CANCEL = 2; -MessageBox.MSGBOX_STYLE_OKCANCEL = 3; -MessageBox.MSGBOX_STYLE_YESNO = 4; -MessageBox.MSGBOX_STYLE_YESNOCANCEL = 5; -MessageBox.MSGBOX_STYLE_ABORTRETRYIGNORE = 6; -MessageBox.MSGBOX_STYLE_CANCELTRYCONTINUE = 7; -MessageBox.MSGBOX_STYLE_RETRYCANCEL = 8; - -/** - * This class provides access to notifications on the device. - */ -function Notification() { - this.messageBox = new MessageBox("Test Alert", "This is an alert", "OK"); -} - -/* - * MessageBox: used by Bada to retrieve Dialog Information - */ - -function MessageBox(title, message, messageBoxStyle) { - this.title = title; - this.message = message; - this.messageBoxStyle = messageBoxStyle; -} - -labelsToBoxStyle = function(buttonLabels) { - if(!buttonLabels) - return MessageBox.MSGBOX_STYLE_NONE; - if(buttonLabels == "OK") - return MessageBox.MSGBOX_STYLE_OK; - if(buttonLabels == "Cancel") - return MessageBox.MSGBOX_STYLE_CANCEL; - if(buttonLabels == "OK,Cancel") - return MessageBox.MSGBOX_STYLE_OKCANCEL; - if(buttonLabels == "Yes,No") - return MessageBox.MSGBOX_STYLE_YESNO; - if(buttonLabels == "Yes,No,Cancel") - return MessageBox.MSGBOX_STYLE_YESNOCANCEL; - if(buttonLabels == "Abort,Retry,Ignore") - return MessageBox.MSGBOX_STYLE_ABORTRETRYIGNORE; - if(buttonLabels == "Cancel,Try,Continue") - return MessageBox.MSGBOX_STYLE_CANCELTRYCONTINUE; - if(buttonLabels == "Retry,Cancel") - return MessageBox.MSGBOX_STYLE_RETRYCANCEL; - - return MessageBox.MSGBOX_STYLE_NONE; -} - -/** - * 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 invoked when user clicks 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"); - this.messageBox = new MessageBox(_title, message, labelsToBoxStyle(buttonLabel)); - PhoneGap.exec(completeCallback, null, 'com.phonegap.Notification', 'alert', []); -}; - -/** - * Open a custom confirmation dialog, with a customizable title and button text. - * @param {String} message Message to print in the body of the dialog - * @param {Function}resultCallback The callback that is invoked when a user clicks a button. - * @param {String} title Title of the alert dialog (default: 'Confirm') - * @param {String} buttonLabels Comma separated list of the button labels (default: 'OK,Cancel') - */ -Notification.prototype.confirm = function(message, resultCallback, title, buttonLabels) { - var _title = (title || "Confirm"); - var _buttonLabels = (buttonLabels || "OK,Cancel"); - this.messageBox = new MessageBox(_title, message, labelsToBoxStyle(buttonLabels)); - return PhoneGap.exec(resultCallback, null, 'com.phonegap.Notification', 'confirm', []); -}; - -/** - * Causes the device to vibrate. - * @param {Integer} mills The number of milliseconds to vibrate for. - */ -Notification.prototype.vibrate = function(mills) { - PhoneGap.exec(null, null, 'com.phonegap.Notification', 'vibrate', [mills]); -}; - -/** - * Causes the device to beep. - * @param {Integer} count The number of beeps. - */ -Notification.prototype.beep = function(count) { - PhoneGap.exec(null, null, 'com.phonegap.Notification', 'beep', [count]); -}; - -PhoneGap.addConstructor(function() { - if (typeof navigator.notification == "undefined") navigator.notification = new Notification(); -}); http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada/blob/d3ab5427/Res/phonegap/phonegap.base.js ---------------------------------------------------------------------- diff --git a/Res/phonegap/phonegap.base.js b/Res/phonegap/phonegap.base.js deleted file mode 100644 index 2c21e1c..0000000 --- a/Res/phonegap/phonegap.base.js +++ /dev/null @@ -1,549 +0,0 @@ - -/* - * 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 - */ - -/** - * The order of events during page load and PhoneGap startup is as follows: - * - * onDOMContentLoaded Internal event that is received when the web page is loaded and parsed. - * window.onload Body onload event. - * onNativeReady Internal event that indicates the PhoneGap native side is ready. - * onPhoneGapInit Internal event that kicks off creation of all PhoneGap JavaScript objects (runs constructors). - * onPhoneGapReady Internal event fired when all PhoneGap JavaScript objects have been created - * onPhoneGapInfoReady Internal event fired when device properties are available - * onDeviceReady User event fired to indicate that PhoneGap is ready - * onResume User event fired to indicate a start/resume lifecycle event - * - * The only PhoneGap events that user code should register for are: - * onDeviceReady - * onResume - * - * Listeners can be registered as: - * document.addEventListener("deviceready", myDeviceReadyListener, false); - * document.addEventListener("resume", myResumeListener, false); - */ - -function debugPrint(body) { - var list = document.getElementById("debuglist"); - var item = document.createElement("li"); - item.appendChild(document.createTextNode(body)); - list.appendChild(item); -} -/** - * This represents the PhoneGap API itself, and provides a global namespace for accessing - * information about the state of PhoneGap. - * @class - */ -PhoneGap = { - queue: { - ready: true, - commands: [], - timer: null - }, - _constructors: [] -}; - -/** - * Boolean flag indicating if the PhoneGap API is available and initialized. - */ // TODO: Remove this, it is unused here ... -jm -PhoneGap.available = function() { - return window.device.uuid != undefined; -} - -/** - * Custom pub-sub channel that can have functions subscribed to it - */ -PhoneGap.Channel = function(type) -{ - this.type = type; - this.handlers = {}; - this.guid = 0; - this.fired = false; - this.enabled = true; -}; - -/** - * Subscribes the given function to the channel. Any time that - * Channel.fire is called so too will the function. - * Optionally specify an execution context for the function - * and a guid that can be used to stop subscribing to the channel. - * Returns the guid. - */ -PhoneGap.Channel.prototype.subscribe = function(f, c, g) { - // need a function to call - if (f == null) { return; } - - var func = f; - if (typeof c == "object" && f instanceof Function) { func = PhoneGap.close(c, f); } - - g = g || func.observer_guid || f.observer_guid || this.guid++; - func.observer_guid = g; - f.observer_guid = g; - this.handlers[g] = func; - return g; -}; - -/** - * Like subscribe but the function is only called once and then it - * auto-unsubscribes itself. - */ -PhoneGap.Channel.prototype.subscribeOnce = function(f, c) { - var g = null; - var _this = this; - var m = function() { - f.apply(c || null, arguments); - _this.unsubscribe(g); - } - if (this.fired) { - if (typeof c == "object" && f instanceof Function) { f = PhoneGap.close(c, f); } - f.apply(this, this.fireArgs); - } else { - g = this.subscribe(m); - } - return g; -}; - -/** - * Unsubscribes the function with the given guid from the channel. - */ -PhoneGap.Channel.prototype.unsubscribe = function(g) { - if (g instanceof Function) { g = g.observer_guid; } - this.handlers[g] = null; - delete this.handlers[g]; -}; - -/** - * Calls all functions subscribed to this channel. - */ -PhoneGap.Channel.prototype.fire = function(e) { - if (this.enabled) { - var fail = false; - for (var item in this.handlers) { - var handler = this.handlers[item]; - if (handler instanceof Function) { - var rv = (handler.apply(this, arguments)==false); - fail = fail || rv; - } - } - this.fired = true; - this.fireArgs = arguments; - return !fail; - } - return true; -}; - -/** - * Calls the provided function only after all of the channels specified - * have been fired. - */ -PhoneGap.Channel.join = function(h, c) { - var i = c.length; - var f = function() { - if (!(--i)) h(); - } - for (var j=0; j - * - * @param name The plugin name - * @param obj The plugin object - */ -PhoneGap.addPlugin = function(name, obj) { - if (!window.plugins[name]) { - window.plugins[name] = obj; - } - else { - console.log("Plugin " + name + " already exists."); - } -}; - -/** - * onDOMContentLoaded channel is fired when the DOM content - * of the page has been parsed. - */ -PhoneGap.onDOMContentLoaded = new PhoneGap.Channel('onDOMContentLoaded'); - -/** - * onNativeReady channel is fired when the PhoneGap native code - * has been initialized. - */ -PhoneGap.onNativeReady = new PhoneGap.Channel('onNativeReady'); - -/** - * onPhoneGapInit channel is fired when the web page is fully loaded and - * PhoneGap native code has been initialized. - */ -PhoneGap.onPhoneGapInit = new PhoneGap.Channel('onPhoneGapInit'); - -/** - * onPhoneGapReady channel is fired when the JS PhoneGap objects have been created. - */ -PhoneGap.onPhoneGapReady = new PhoneGap.Channel('onPhoneGapReady'); - -/** - * onPhoneGapInfoReady channel is fired when the PhoneGap device properties - * has been set. - */ -PhoneGap.onPhoneGapInfoReady = new PhoneGap.Channel('onPhoneGapInfoReady'); - -/** - * onResume channel is fired when the PhoneGap native code - * resumes. - */ -PhoneGap.onResume = new PhoneGap.Channel('onResume'); - -/** - * onPause channel is fired when the PhoneGap native code - * pauses. - */ -PhoneGap.onPause = new PhoneGap.Channel('onPause'); - -// _nativeReady is global variable that the native side can set -// to signify that the native code is ready. It is a global since -// it may be called before any PhoneGap JS is ready. -if (typeof _nativeReady !== 'undefined') { PhoneGap.onNativeReady.fire(); } - -/** - * onDeviceReady is fired only after all PhoneGap objects are created and - * the device properties are set. - */ -PhoneGap.onDeviceReady = new PhoneGap.Channel('onDeviceReady'); - -/** - * Create all PhoneGap objects once page has fully loaded and native side is ready. - */ -PhoneGap.Channel.join(function() { - - // Run PhoneGap constructors - PhoneGap.onPhoneGapInit.fire(); - - // Fire event to notify that all objects are created - PhoneGap.onPhoneGapReady.fire(); - -}, [ PhoneGap.onDOMContentLoaded, PhoneGap.onNativeReady ]); - -/** - * Fire onDeviceReady event once all constructors have run and PhoneGap info has been - * received from native side. - */ -PhoneGap.Channel.join(function() { - PhoneGap.onDeviceReady.fire(); - - // Fire the onresume event, since first one happens before JavaScript is loaded - PhoneGap.onResume.fire(); -}, [ PhoneGap.onPhoneGapReady, PhoneGap.onPhoneGapInfoReady]); - -// Listen for DOMContentLoaded and notify our channel subscribers -document.addEventListener('DOMContentLoaded', function() { - PhoneGap.onDOMContentLoaded.fire(); -}, false); - -// Intercept calls to document.addEventListener and watch for deviceready -PhoneGap.m_document_addEventListener = document.addEventListener; - -document.addEventListener = function(evt, handler, capture) { - var e = evt.toLowerCase(); - if (e == 'deviceready') { - PhoneGap.onDeviceReady.subscribeOnce(handler); - } else if (e == 'resume') { - PhoneGap.onResume.subscribe(handler); - // if subscribing listener after event has already fired, invoke the handler - if (PhoneGap.onResume.fired && handler instanceof Function) { - handler(); - } - } else if (e == 'pause') { - PhoneGap.onPause.subscribe(handler); - } else { - PhoneGap.m_document_addEventListener.call(document, evt, handler, capture); - } -}; - -PhoneGap.m_element_addEventListener = Element.prototype.addEventListener; - -/** - * For BlackBerry, the touchstart event does not work so we need to do click - * events when touchstart events are attached. - */ -Element.prototype.addEventListener = function(evt, handler, capture) { - if (evt === 'touchstart') { - evt = 'click'; - } - PhoneGap.m_element_addEventListener.call(this, evt, handler, capture); -}; - -/** - * Does a deep clone of the object. - * - * @param obj - * @return - */ -PhoneGap.clone = function(obj) { - if(!obj) { - return obj; - } - - if(obj instanceof Array){ - var retVal = new Array(); - for(var i = 0; i < obj.length; ++i){ - retVal.push(PhoneGap.clone(obj[i])); - } - return retVal; - } - - if (obj instanceof Function) { - return obj; - } - - if(!(obj instanceof Object)){ - return obj; - } - - if(obj instanceof Date){ - return obj; - } - - retVal = new Object(); - for(i in obj){ - if(!(i in retVal) || retVal[i] != obj[i]) { - retVal[i] = PhoneGap.clone(obj[i]); - } - } - return retVal; -}; - -PhoneGap.close = function(context, func, params) { - if (typeof params === 'undefined') { - return function() { - return func.apply(context, arguments); - } - } else { - return function() { - return func.apply(context, params); - } - } -}; - -PhoneGap.callbackId = 0; -PhoneGap.callbacks = {}; -PhoneGap.callbackStatus = { - NO_RESULT: 0, - OK: 1, - CLASS_NOT_FOUND_EXCEPTION: 2, - ILLEGAL_ACCESS_EXCEPTION: 3, - INSTANTIATION_EXCEPTION: 4, - MALFORMED_URL_EXCEPTION: 5, - IO_EXCEPTION: 6, - INVALID_ACTION: 7, - JSON_EXCEPTION: 8, - ERROR: 9 -}; - -/** - * Called by native code when returning successful result from an action. - * - * @param callbackId - * @param args - */ -PhoneGap.callbackSuccess = function(callbackId, args) { - if (PhoneGap.callbacks[callbackId]) { - - // If result is to be sent to callback - if (args.status == PhoneGap.callbackStatus.OK) { - try { - if (PhoneGap.callbacks[callbackId].success) { - PhoneGap.callbacks[callbackId].success(args.message); - } - } - catch (e) { - console.log("Error in success callback: "+callbackId+" = "+e); - } - } - - // Clear callback if not expecting any more results - if (!args.keepCallback) { - delete PhoneGap.callbacks[callbackId]; - } - } -}; - -/** - * Called by native code when returning error result from an action. - * - * @param callbackId - * @param args - */ -PhoneGap.callbackError = function(callbackId, args) { - if (PhoneGap.callbacks[callbackId]) { - try { - if (PhoneGap.callbacks[callbackId].fail) { - PhoneGap.callbacks[callbackId].fail(args.message); - } - } - catch (e) { - console.log("Error in error callback: "+callbackId+" = "+e); - } - - // Clear callback if not expecting any more results - if (!args.keepCallback) { - delete PhoneGap.callbacks[callbackId]; - } - } -}; - -/** - * Create a UUID - * - * @return - */ -PhoneGap.createUUID = function() { - return PhoneGap.UUIDcreatePart(4) + '-' + - PhoneGap.UUIDcreatePart(2) + '-' + - PhoneGap.UUIDcreatePart(2) + '-' + - PhoneGap.UUIDcreatePart(2) + '-' + - PhoneGap.UUIDcreatePart(6); -}; - -PhoneGap.UUIDcreatePart = function(length) { - var uuidpart = ""; - for (var i=0; i