diff --git a/framework/assets/js/accelerometer.js b/framework/assets/js/accelerometer.js index e64a5cf1..54af21dc 100755 --- a/framework/assets/js/accelerometer.js +++ b/framework/assets/js/accelerometer.js @@ -3,25 +3,25 @@ * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text. * * Copyright (c) 2005-2010, Nitobi Software Inc. - * Copyright (c) 2010, IBM Corporation + * Copyright (c) 2010-2011, IBM Corporation */ if (!PhoneGap.hasResource("accelerometer")) { PhoneGap.addResource("accelerometer"); /** @constructor */ -function Acceleration(x, y, z) { +var Acceleration = function(x, y, z) { this.x = x; this.y = y; this.z = z; this.timestamp = new Date().getTime(); -} +}; /** * This class provides access to device accelerometer data. * @constructor */ -Accelerometer = function() { +var Accelerometer = function() { /** * The last known acceleration. type=Acceleration() @@ -32,7 +32,7 @@ Accelerometer = function() { * List of accelerometer watch timers */ this.timers = {}; -} +}; Accelerometer.ERROR_MSG = ["Not running", "Starting", "", "Failed to start"]; @@ -123,4 +123,4 @@ PhoneGap.addConstructor(function() { navigator.accelerometer = new Accelerometer(); } }); -}; +} diff --git a/framework/assets/js/app.js b/framework/assets/js/app.js index fe8a60b8..61ad3669 100755 --- a/framework/assets/js/app.js +++ b/framework/assets/js/app.js @@ -13,7 +13,7 @@ PhoneGap.addResource("app"); * Constructor * @constructor */ -App = function() {}; +var App = function() {}; /** * Clear the resource cache. @@ -91,4 +91,4 @@ App.prototype.exitApp = function() { PhoneGap.addConstructor(function() { navigator.app = window.app = new App(); }); -}; +} diff --git a/framework/assets/js/camera.js b/framework/assets/js/camera.js index c1ccc6e2..1c4be96d 100755 --- a/framework/assets/js/camera.js +++ b/framework/assets/js/camera.js @@ -3,7 +3,7 @@ * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text. * * Copyright (c) 2005-2010, Nitobi Software Inc. - * Copyright (c) 2010, IBM Corporation + * Copyright (c) 2010-2011, IBM Corporation */ if (!PhoneGap.hasResource("camera")) { @@ -14,7 +14,7 @@ PhoneGap.addResource("camera"); * * @constructor */ -Camera = function() { +var Camera = function() { this.successCallback = null; this.errorCallback = null; this.options = null; @@ -94,4 +94,4 @@ PhoneGap.addConstructor(function() { navigator.camera = new Camera(); } }); -}; +} diff --git a/framework/assets/js/capture.js b/framework/assets/js/capture.js index 14e6ad49..1c19357d 100644 --- a/framework/assets/js/capture.js +++ b/framework/assets/js/capture.js @@ -6,11 +6,58 @@ * Copyright (c) 2010-2011, IBM Corporation */ +if (!PhoneGap.hasResource("capture")) { +PhoneGap.addResource("capture"); + +/** + * Represents a single file. + * + * name {DOMString} name of the file, without path information + * fullPath {DOMString} the full path of the file, including the name + * type {DOMString} mime type + * lastModifiedDate {Date} last modified date + * size {Number} size of the file in bytes + */ +var MediaFile = function(name, fullPath, type, lastModifiedDate, size){ + this.name = name || null; + this.fullPath = fullPath || null; + this.type = type || null; + this.lastModifiedDate = lastModifiedDate || null; + this.size = size || 0; +}; + +/** + * Launch device camera application for recording video(s). + * + * @param {Function} successCB + * @param {Function} errorCB + */ +MediaFile.prototype.getFormatData = function(successCallback, errorCallback){ + PhoneGap.exec(successCallback, errorCallback, "Capture", "getFormatData", [this.fullPath, this.type]); +}; + +/** + * MediaFileData encapsulates format information of a media file. + * + * @param {DOMString} codecs + * @param {long} bitrate + * @param {long} height + * @param {long} width + * @param {float} duration + */ +var MediaFileData = function(codecs, bitrate, height, width, duration){ + this.codecs = codecs || null; + this.bitrate = bitrate || 0; + this.height = height || 0; + this.width = width || 0; + this.duration = duration || 0; +}; + /** * The CaptureError interface encapsulates all errors in the Capture API. */ -function CaptureError() { - this.code = null; +var CaptureError = function(){ + this.code = null; }; // Capture error codes @@ -23,7 +70,7 @@ CaptureError.CAPTURE_NOT_SUPPORTED = 20; /** * The Capture interface exposes an interface to the camera and microphone of the hosting device. */ -function Capture() { +var Capture = function(){ this.supportedAudioModes = []; this.supportedImageModes = []; this.supportedVideoModes = []; @@ -31,157 +78,114 @@ function Capture() { /** * Launch audio recorder application for recording audio clip(s). - * + * * @param {Function} successCB * @param {Function} errorCB * @param {CaptureAudioOptions} options */ -Capture.prototype.captureAudio = function(successCallback, errorCallback, options) { - PhoneGap.exec(successCallback, errorCallback, "Capture", "captureAudio", [options]); +Capture.prototype.captureAudio = function(successCallback, errorCallback, options){ + PhoneGap.exec(successCallback, errorCallback, "Capture", "captureAudio", [options]); }; /** * Launch camera application for taking image(s). - * + * * @param {Function} successCB * @param {Function} errorCB * @param {CaptureImageOptions} options */ -Capture.prototype.captureImage = function(successCallback, errorCallback, options) { - PhoneGap.exec(successCallback, errorCallback, "Capture", "captureImage", [options]); +Capture.prototype.captureImage = function(successCallback, errorCallback, options){ + PhoneGap.exec(successCallback, errorCallback, "Capture", "captureImage", [options]); }; /** * Launch camera application for taking image(s). - * + * * @param {Function} successCB * @param {Function} errorCB * @param {CaptureImageOptions} options */ -Capture.prototype._castMediaFile = function(pluginResult) { - var mediaFiles = []; - var i; - for (i=0; i 3) { - if (typeof errorCallback == "function") { - errorCallback({ - "code": FileError.SYNTAX_ERR - }); - } - } - else { - PhoneGap.exec(successCallback, errorCallback, "File", "requestFileSystem", [type, size]); - } -}; - -/** - * - * @param {DOMString} uri referring to a local file in a filesystem - * @param {Function} successCallback is called with the new entry - * @param {Function} errorCallback is called with a FileError - */ -LocalFileSystem.prototype.resolveLocalFileSystemURI = function(uri, successCallback, errorCallback) { - PhoneGap.exec(successCallback, errorCallback, "File", "resolveLocalFileSystemURI", [uri]); -}; - -/** -* This function returns and array of contacts. It is required as we need to convert raw -* JSON objects into concrete Contact objects. Currently this method is called after -* navigator.service.contacts.find but before the find methods success call back. -* -* @param a JSON Objects that need to be converted to DirectoryEntry or FileEntry objects. -* @returns an entry -*/ -LocalFileSystem.prototype._castFS = function(pluginResult) { - var entry = null; - entry = new DirectoryEntry(); - entry.isDirectory = pluginResult.message.root.isDirectory; - entry.isFile = pluginResult.message.root.isFile; - entry.name = pluginResult.message.root.name; - entry.fullPath = pluginResult.message.root.fullPath; - pluginResult.message.root = entry; - return pluginResult; -} - -LocalFileSystem.prototype._castEntry = function(pluginResult) { - var entry = null; - if (pluginResult.message.isDirectory) { - console.log("This is a dir"); - entry = new DirectoryEntry(); - } - else if (pluginResult.message.isFile) { - console.log("This is a file"); - entry = new FileEntry(); - } - entry.isDirectory = pluginResult.message.isDirectory; - entry.isFile = pluginResult.message.isFile; - entry.name = pluginResult.message.name; - entry.fullPath = pluginResult.message.fullPath; - pluginResult.message = entry; - return pluginResult; -} - -LocalFileSystem.prototype._castEntries = function(pluginResult) { - var entries = pluginResult.message; - var retVal = []; - for (i=0; i 3) { + if (typeof errorCallback == "function") { + errorCallback({ + "code": FileError.SYNTAX_ERR + }); + } + } + else { + PhoneGap.exec(successCallback, errorCallback, "File", "requestFileSystem", [type, size]); + } +}; + +/** + * + * @param {DOMString} uri referring to a local file in a filesystem + * @param {Function} successCallback is called with the new entry + * @param {Function} errorCallback is called with a FileError + */ +LocalFileSystem.prototype.resolveLocalFileSystemURI = function(uri, successCallback, errorCallback) { + PhoneGap.exec(successCallback, errorCallback, "File", "resolveLocalFileSystemURI", [uri]); +}; + +/** +* This function returns and array of contacts. It is required as we need to convert raw +* JSON objects into concrete Contact objects. Currently this method is called after +* navigator.service.contacts.find but before the find methods success call back. +* +* @param a JSON Objects that need to be converted to DirectoryEntry or FileEntry objects. +* @returns an entry +*/ +LocalFileSystem.prototype._castFS = function(pluginResult) { + var entry = null; + entry = new DirectoryEntry(); + entry.isDirectory = pluginResult.message.root.isDirectory; + entry.isFile = pluginResult.message.root.isFile; + entry.name = pluginResult.message.root.name; + entry.fullPath = pluginResult.message.root.fullPath; + pluginResult.message.root = entry; + return pluginResult; +}; + +LocalFileSystem.prototype._castEntry = function(pluginResult) { + var entry = null; + if (pluginResult.message.isDirectory) { + console.log("This is a dir"); + entry = new DirectoryEntry(); + } + else if (pluginResult.message.isFile) { + console.log("This is a file"); + entry = new FileEntry(); + } + entry.isDirectory = pluginResult.message.isDirectory; + entry.isFile = pluginResult.message.isFile; + entry.name = pluginResult.message.name; + entry.fullPath = pluginResult.message.fullPath; + pluginResult.message = entry; + return pluginResult; +}; + +LocalFileSystem.prototype._castEntries = function(pluginResult) { + var entries = pluginResult.message; + var retVal = []; + for (var i=0; i 0) { s = s + ","; } @@ -939,4 +939,4 @@ var PluginManager = { } }; -}; +} diff --git a/framework/assets/js/position.js b/framework/assets/js/position.js index 08d596db..d6b4e613 100755 --- a/framework/assets/js/position.js +++ b/framework/assets/js/position.js @@ -3,7 +3,7 @@ * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text. * * Copyright (c) 2005-2010, Nitobi Software Inc. - * Copyright (c) 2010, IBM Corporation + * Copyright (c) 2010-2011, IBM Corporation */ if (!PhoneGap.hasResource("position")) { @@ -20,13 +20,13 @@ PhoneGap.addResource("position"); * @param {Object} vel * @constructor */ -Position = function(coords, timestamp) { +var Position = function(coords, timestamp) { this.coords = coords; this.timestamp = (timestamp !== 'undefined') ? timestamp : new Date().getTime(); }; /** @constructor */ -function Coordinates(lat, lng, alt, acc, head, vel, altacc) { +var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) { /** * The latitude of the position. */ @@ -55,13 +55,13 @@ function Coordinates(lat, lng, alt, acc, head, vel, altacc) { * The altitude accuracy of the position. */ this.altitudeAccuracy = (altacc !== 'undefined') ? altacc : null; -} +}; /** * This class specifies the options for requesting position data. * @constructor */ -PositionOptions = function() { +var PositionOptions = function() { /** * Specifies the desired position accuracy. */ @@ -77,7 +77,7 @@ PositionOptions = function() { * This class contains information about any GSP errors. * @constructor */ -PositionError = function() { +var PositionError = function() { this.code = null; this.message = ""; }; @@ -86,4 +86,4 @@ PositionError.UNKNOWN_ERROR = 0; PositionError.PERMISSION_DENIED = 1; PositionError.POSITION_UNAVAILABLE = 2; PositionError.TIMEOUT = 3; -}; +} diff --git a/framework/assets/js/storage.js b/framework/assets/js/storage.js index 125c78c5..794aba11 100755 --- a/framework/assets/js/storage.js +++ b/framework/assets/js/storage.js @@ -3,7 +3,7 @@ * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text. * * Copyright (c) 2005-2010, Nitobi Software Inc. - * Copyright (c) 2010, IBM Corporation + * Copyright (c) 2010-2011, IBM Corporation */ /* @@ -15,6 +15,35 @@ if (!PhoneGap.hasResource("storage")) { PhoneGap.addResource("storage"); +/** + * SQL result set object + * PRIVATE METHOD + * @constructor + */ +var DroidDB_Rows = function() { + this.resultSet = []; // results array + this.length = 0; // number of rows +}; + +/** + * Get item from SQL result set + * + * @param row The row number to return + * @return The row object + */ +DroidDB_Rows.prototype.item = function(row) { + return this.resultSet[row]; +}; + +/** + * SQL result set that is returned to user. + * PRIVATE METHOD + * @constructor + */ +var DroidDB_Result = function() { + this.rows = new DroidDB_Rows(); +}; + /** * Storage object that is called by native code when performing queries. * PRIVATE METHOD @@ -103,6 +132,36 @@ DroidDB.prototype.fail = function(reason, id) { } }; +/** + * SQL query object + * PRIVATE METHOD + * + * @constructor + * @param tx The transaction object that this query belongs to + */ +var DroidDB_Query = function(tx) { + + // Set the id of the query + this.id = PhoneGap.createUUID(); + + // Add this query to the queue + droiddb.queryQueue[this.id] = this; + + // Init result + this.resultSet = []; + + // Set transaction that this query belongs to + this.tx = tx; + + // Add this query to transaction list + this.tx.queryList[this.id] = this; + + // Callbacks + this.successCallback = null; + this.errorCallback = null; + +}; + /** * Transaction object * PRIVATE METHOD @@ -121,37 +180,6 @@ var DroidDB_Tx = function() { this.queryList = {}; }; - -var DatabaseShell = function() { -}; - -/** - * Start a transaction. - * Does not support rollback in event of failure. - * - * @param process {Function} The transaction function - * @param successCallback {Function} - * @param errorCallback {Function} - */ -DatabaseShell.prototype.transaction = function(process, errorCallback, successCallback) { - var tx = new DroidDB_Tx(); - tx.successCallback = successCallback; - tx.errorCallback = errorCallback; - try { - process(tx); - } catch (e) { - console.log("Transaction error: "+e); - if (tx.errorCallback) { - try { - tx.errorCallback(e); - } catch (ex) { - console.log("Transaction error calling user error callback: "+e); - } - } - } -}; - - /** * Mark query in transaction as complete. * If all queries are complete, call the user's transaction success callback. @@ -203,36 +231,6 @@ DroidDB_Tx.prototype.queryFailed = function(id, reason) { } }; -/** - * SQL query object - * PRIVATE METHOD - * - * @constructor - * @param tx The transaction object that this query belongs to - */ -var DroidDB_Query = function(tx) { - - // Set the id of the query - this.id = PhoneGap.createUUID(); - - // Add this query to the queue - droiddb.queryQueue[this.id] = this; - - // Init result - this.resultSet = []; - - // Set transaction that this query belongs to - this.tx = tx; - - // Add this query to transaction list - this.tx.queryList[this.id] = this; - - // Callbacks - this.successCallback = null; - this.errorCallback = null; - -}; - /** * Execute SQL statement * @@ -260,33 +258,33 @@ DroidDB_Tx.prototype.executeSql = function(sql, params, successCallback, errorCa PhoneGap.exec(null, null, "Storage", "executeSql", [sql, params, query.id]); }; -/** - * SQL result set that is returned to user. - * PRIVATE METHOD - * @constructor - */ -DroidDB_Result = function() { - this.rows = new DroidDB_Rows(); +var DatabaseShell = function() { }; /** - * SQL result set object - * PRIVATE METHOD - * @constructor - */ -DroidDB_Rows = function() { - this.resultSet = []; // results array - this.length = 0; // number of rows -}; - -/** - * Get item from SQL result set + * Start a transaction. + * Does not support rollback in event of failure. * - * @param row The row number to return - * @return The row object + * @param process {Function} The transaction function + * @param successCallback {Function} + * @param errorCallback {Function} */ -DroidDB_Rows.prototype.item = function(row) { - return this.resultSet[row]; +DatabaseShell.prototype.transaction = function(process, errorCallback, successCallback) { + var tx = new DroidDB_Tx(); + tx.successCallback = successCallback; + tx.errorCallback = errorCallback; + try { + process(tx); + } catch (e) { + console.log("Transaction error: "+e); + if (tx.errorCallback) { + try { + tx.errorCallback(e); + } catch (ex) { + console.log("Transaction error calling user error callback: "+e); + } + } + } }; /** @@ -298,13 +296,12 @@ DroidDB_Rows.prototype.item = function(row) { * @param size Database size in bytes * @return Database object */ -DroidDB_openDatabase = function(name, version, display_name, size) { +var DroidDB_openDatabase = function(name, version, display_name, size) { PhoneGap.exec(null, null, "Storage", "openDatabase", [name, version, display_name, size]); var db = new DatabaseShell(); return db; }; - /** * For browsers with no localStorage we emulate it with SQLite. Follows the w3c api. * TODO: Do similar for sessionStorage. @@ -385,13 +382,14 @@ var CupcakeLocalStorage = function() { } } return null; - } + }; } catch(e) { alert("Database error "+e+"."); return; } }; + PhoneGap.addConstructor(function() { var setupDroidDB = function() { navigator.openDatabase = window.openDatabase = DroidDB_openDatabase; @@ -402,24 +400,24 @@ PhoneGap.addConstructor(function() { } else { window.openDatabase_orig = window.openDatabase; window.openDatabase = function(name, version, desc, size){ - // Some versions of Android will throw a SECURITY_ERR so we need - // to catch the exception and seutp our own DB handling. - var db = null; - try { - db = window.openDatabase_orig(name, version, desc, size); - } - catch (ex) { - db = null; - } - - if (db == null) { - setupDroidDB(); - return DroidDB_openDatabase(name, version, desc, size); - } - else { - return db; - } - } + // Some versions of Android will throw a SECURITY_ERR so we need + // to catch the exception and seutp our own DB handling. + var db = null; + try { + db = window.openDatabase_orig(name, version, desc, size); + } + catch (ex) { + db = null; + } + + if (db == null) { + setupDroidDB(); + return DroidDB_openDatabase(name, version, desc, size); + } + else { + return db; + } + } } if (typeof window.localStorage === "undefined") { @@ -427,4 +425,4 @@ PhoneGap.addConstructor(function() { PhoneGap.waitForInitialization("cupcakeStorage"); } }); -}; +}