From bd1ae4bf5b10bb66764436da4c81cc97e67ecb3b Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Thu, 8 Sep 2011 01:07:29 -0700 Subject: [PATCH] Concatted JS, cleanup --- framework/PGView.xaml.cs | 11 +- framework/PhoneGap/PhoneGapCommandCall.cs | 9 + framework/js/.disclaimer.js | 11 - framework/js/acceleration.js | 16 - framework/js/accelerometer.js | 71 +- framework/js/app.js | 86 - framework/js/build_phonegap.js.cmd | 4 +- framework/js/camera.js | 90 +- framework/js/capture.js | 35 +- framework/js/compass.js | 103 +- framework/js/contact.js | 109 +- framework/js/crypto.js | 43 - framework/js/debugconsole.js | 95 - framework/js/device.js | 39 +- framework/js/disclaimer.txt | 5 + framework/js/file.js | 68 +- framework/js/filetransfer.js | 85 - framework/js/geolocation.js | 198 -- framework/js/media.js | 214 -- framework/js/network.js | 16 +- framework/js/notification.js | 29 +- framework/js/orientation.js | 54 - framework/js/phonegap-base.js | 373 --- framework/js/phonegap.1.0.0.js | 2302 ++----------- .../js/phonegap.js.base | 9 - framework/js/position.js | 89 - framework/js/sms.js | 21 - framework/js/storage.js | 428 --- framework/js/telephony.js | 19 - js/acceleration.js | 16 - js/accelerometer.js | 38 - js/build_phonegap.js.cmd | 4 - js/camera.js | 26 - js/debugconsole.js | 83 - js/device.js | 12 - js/geolocation.js | 41 - js/network.js | 24 - js/notification.js | 26 - js/orientation.js | 54 - js/phonegap.js.base | 30 - js/position.js | 51 - js/sms.js | 21 - js/telephony.js | 19 - .../GapSourceDictionary.xml | 17 +- .../MobileSpecUnitTests.csproj | 16 +- .../www/accelerometer.html | 3 +- .../MobileSpecUnitTests/www/accelerometer.js | 139 - .../www/autotest/index.html | 33 +- tests/MobileSpecUnitTests/www/camera.html | 3 +- tests/MobileSpecUnitTests/www/camera.js | 145 - tests/MobileSpecUnitTests/www/capture.html | 4 +- tests/MobileSpecUnitTests/www/capture.js | 168 - tests/MobileSpecUnitTests/www/compass.html | 4 +- tests/MobileSpecUnitTests/www/compass.js | 148 - tests/MobileSpecUnitTests/www/contact.js | 311 -- tests/MobileSpecUnitTests/www/contacts.html | 4 +- tests/MobileSpecUnitTests/www/device.js | 72 - tests/MobileSpecUnitTests/www/events.html | 2 +- tests/MobileSpecUnitTests/www/file.js | 1065 ------ tests/MobileSpecUnitTests/www/index.html | 17 +- tests/MobileSpecUnitTests/www/location.html | 2 +- tests/MobileSpecUnitTests/www/main.js | 140 - tests/MobileSpecUnitTests/www/master.css | 14 +- tests/MobileSpecUnitTests/www/network.html | 3 +- tests/MobileSpecUnitTests/www/network.js | 88 - .../MobileSpecUnitTests/www/notification.html | 3 +- tests/MobileSpecUnitTests/www/notification.js | 127 - tests/MobileSpecUnitTests/www/phonegap.1.0.js | 2900 +++++++++++++++++ tests/MobileSpecUnitTests/www/storage.html | 2 +- 69 files changed, 3538 insertions(+), 6969 deletions(-) delete mode 100644 framework/js/.disclaimer.js delete mode 100644 framework/js/acceleration.js delete mode 100644 framework/js/app.js delete mode 100644 framework/js/crypto.js delete mode 100644 framework/js/debugconsole.js create mode 100644 framework/js/disclaimer.txt delete mode 100644 framework/js/filetransfer.js delete mode 100644 framework/js/geolocation.js delete mode 100644 framework/js/media.js delete mode 100644 framework/js/orientation.js delete mode 100644 framework/js/phonegap-base.js rename tests/MobileSpecUnitTests/www/phonegap.js => framework/js/phonegap.js.base (97%) delete mode 100644 framework/js/position.js delete mode 100644 framework/js/sms.js delete mode 100644 framework/js/storage.js delete mode 100644 framework/js/telephony.js delete mode 100644 js/acceleration.js delete mode 100644 js/accelerometer.js delete mode 100644 js/build_phonegap.js.cmd delete mode 100644 js/camera.js delete mode 100644 js/debugconsole.js delete mode 100644 js/device.js delete mode 100644 js/geolocation.js delete mode 100644 js/network.js delete mode 100644 js/notification.js delete mode 100644 js/orientation.js delete mode 100644 js/phonegap.js.base delete mode 100644 js/position.js delete mode 100644 js/sms.js delete mode 100644 js/telephony.js delete mode 100644 tests/MobileSpecUnitTests/www/accelerometer.js delete mode 100644 tests/MobileSpecUnitTests/www/camera.js delete mode 100644 tests/MobileSpecUnitTests/www/capture.js delete mode 100644 tests/MobileSpecUnitTests/www/compass.js delete mode 100644 tests/MobileSpecUnitTests/www/contact.js delete mode 100644 tests/MobileSpecUnitTests/www/device.js delete mode 100644 tests/MobileSpecUnitTests/www/file.js delete mode 100644 tests/MobileSpecUnitTests/www/main.js delete mode 100644 tests/MobileSpecUnitTests/www/network.js delete mode 100644 tests/MobileSpecUnitTests/www/notification.js create mode 100644 tests/MobileSpecUnitTests/www/phonegap.1.0.js diff --git a/framework/PGView.xaml.cs b/framework/PGView.xaml.cs index f7e34cb..d13fa76 100644 --- a/framework/PGView.xaml.cs +++ b/framework/PGView.xaml.cs @@ -267,15 +267,13 @@ void GapBrowser_Navigating(object sender, NavigatingEventArgs e) void GapBrowser_ScriptNotify(object sender, NotifyEventArgs e) { string commandStr = e.Value; - Debug.WriteLine("GapBrowser_ScriptNotify :: " + commandStr); + PhoneGapCommandCall commandCallParams = PhoneGapCommandCall.Parse(commandStr); if (commandCallParams == null) { // ERROR - - //Debug.WriteLine(commandStr); // this is the case of window.error messages - + Debug.WriteLine("ScriptNotify :: " + commandStr); return; } else if (commandCallParams.Service == "CoreEvents") @@ -312,9 +310,8 @@ void GapBrowser_ScriptNotify(object sender, NotifyEventArgs e) { bc.OnCommandResult -= delegate(object o, PluginResult res) { OnCommandResult(o, res, null); - } -; - // TODO log somehow + }; + Debug.WriteLine("failed to InvokeMethodNamed :: " + commandCallParams.Action + " on Object :: " + commandCallParams.Service); this.InvokeJSSCallback(commandCallParams.CallbackId, new PluginResult(PluginResult.Status.INVALID_ACTION)); return; } diff --git a/framework/PhoneGap/PhoneGapCommandCall.cs b/framework/PhoneGap/PhoneGapCommandCall.cs index 28c6aa5..13df7b0 100644 --- a/framework/PhoneGap/PhoneGapCommandCall.cs +++ b/framework/PhoneGap/PhoneGapCommandCall.cs @@ -47,6 +47,15 @@ public static PhoneGapCommandCall Parse(string commandStr) commandCallParameters.CallbackId = split[2]; commandCallParameters.Args = split.Length <= 3 ? String.Empty : String.Join("/", split.Skip(3)); + // sanity check for illegal names + // was failing with :: + // PhoneGapCommandResult :: 1, Device1, {"status":1,"message":"{\"name\":\"XD..... + if (commandCallParameters.Service.IndexOfAny(new char[] { '@', '.', ',', '!', ' ' }) > -1) + { + return null; + } + + return commandCallParameters; } diff --git a/framework/js/.disclaimer.js b/framework/js/.disclaimer.js deleted file mode 100644 index f99b436..0000000 --- a/framework/js/.disclaimer.js +++ /dev/null @@ -1,11 +0,0 @@ -/* - This is a machine generated file, do not edit directly. -jm -*/ - -/* - * 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-2011, IBM Corporation - */ diff --git a/framework/js/acceleration.js b/framework/js/acceleration.js deleted file mode 100644 index cc48941..0000000 --- a/framework/js/acceleration.js +++ /dev/null @@ -1,16 +0,0 @@ - -/****************************** ACCELERATION ******************************/ - -function Acceleration(x, y, z, timestamp) { - // The force applied by the device in the x-axis. - this.x = x; - - // The force applied by the device in the y-axis. - this.y = y; - - // The force applied by the device in the z-axis. - this.z = z; - - // The time that the acceleration was obtained. - this.timestamp = timestamp || new Date().getTime(); -} diff --git a/framework/js/accelerometer.js b/framework/js/accelerometer.js index 54af21d..87eb07f 100644 --- a/framework/js/accelerometer.js +++ b/framework/js/accelerometer.js @@ -2,11 +2,13 @@ * 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) 2005-2011, Nitobi Software Inc. * Copyright (c) 2010-2011, IBM Corporation + * Copyright (c) 2011, Microsoft Corporation */ -if (!PhoneGap.hasResource("accelerometer")) { +if (!PhoneGap.hasResource("accelerometer")) +{ PhoneGap.addResource("accelerometer"); /** @constructor */ @@ -56,11 +58,27 @@ Accelerometer.prototype.getCurrentAcceleration = function(successCallback, error console.log("Accelerometer Error: errorCallback is not a function"); return; } + + var self = this; + + var onSuccess = function(result) + { + var accResult = JSON.parse(result); + console.log("Accel x = " + accResult.x); + self.lastAcceleration = new Acceleration(accResult.x,accResult.y,accResult.z); + successCallback(self.lastAcceleration); + } + + var onError = function(err) + { + errorCallback(err); + } // Get acceleration - PhoneGap.exec(successCallback, errorCallback, "Accelerometer", "getAcceleration", []); + PhoneGap.exec(onSuccess, onError, "Accelerometer", "getAcceleration",options); }; + /** * Asynchronously aquires the acceleration repeatedly at a given interval. * @@ -69,10 +87,11 @@ Accelerometer.prototype.getCurrentAcceleration = function(successCallback, error * @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) { - +Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallback, options) +{ // Default interval (10 sec) - var frequency = (options !== undefined)? options.frequency : 10000; + var frequency = (options && options.frequency)? options.frequency : 10000; + var timeout = (options != options.timeout) ? options.timeout : 15000; // successCallback required if (typeof successCallback !== "function") { @@ -85,23 +104,17 @@ Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallb console.log("Accelerometer Error: errorCallback is not a function"); return; } + + var self = this; + + var onInterval = function() + { + self.getCurrentAcceleration(successCallback,errorCallback,options); + } - // Make sure accelerometer timeout > frequency + 10 sec - PhoneGap.exec( - function(timeout) { - if (timeout < (frequency + 10000)) { - PhoneGap.exec(null, null, "Accelerometer", "setTimeout", [frequency + 10000]); - } - }, - function(e) { }, "Accelerometer", "getTimeout", []); - - // Start watch timer - var id = PhoneGap.createUUID(); - navigator.accelerometer.timers[id] = setInterval(function() { - PhoneGap.exec(successCallback, errorCallback, "Accelerometer", "getAcceleration", []); - }, (frequency ? frequency : 1)); - - return id; + + + return window.setInterval(onInterval,frequency); }; /** @@ -111,15 +124,15 @@ Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallb */ Accelerometer.prototype.clearWatch = function(id) { - // Stop javascript timer & remove from timer list - if (id && navigator.accelerometer.timers[id] !== undefined) { - clearInterval(navigator.accelerometer.timers[id]); - delete navigator.accelerometer.timers[id]; - } + clearInterval(id); }; -PhoneGap.addConstructor(function() { - if (typeof navigator.accelerometer === "undefined") { +PhoneGap.addConstructor( +function() +{ + if (!navigator.accelerometer) + { + console.log("Installing accelerometer"); navigator.accelerometer = new Accelerometer(); } }); diff --git a/framework/js/app.js b/framework/js/app.js deleted file mode 100644 index 788e818..0000000 --- a/framework/js/app.js +++ /dev/null @@ -1,86 +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-2011, IBM Corporation - */ - -if (!PhoneGap.hasResource("app")) { -PhoneGap.addResource("app"); -(function() { - -/** - * Constructor - * @constructor - */ -var App = function() {}; - -/** - * Clear the resource cache. - */ -App.prototype.clearCache = function() { - PhoneGap.exec(null, null, "App", "clearCache", []); -}; - -/** - * Load the url into the webview. - * - * @param url The URL to load - * @param props Properties that can be passed in to the activity: - * wait: int => wait msec before loading URL - * loadingDialog: "Title,Message" => display a native loading dialog - * hideLoadingDialogOnPage: boolean => hide loadingDialog when page loaded instead of when deviceready event occurs. - * loadInWebView: boolean => cause all links on web page to be loaded into existing web view, instead of being loaded into new browser. - * loadUrlTimeoutValue: int => time in msec to wait before triggering a timeout error - * errorUrl: URL => URL to load if there's an error loading specified URL with loadUrl(). Should be a local URL such as file:///android_asset/www/error.html"); - * keepRunning: boolean => enable app to keep running in background - * - * Example: - * App app = new App(); - * app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000}); - */ -App.prototype.loadUrl = function(url, props) { - PhoneGap.exec(null, null, "App", "loadUrl", [url, props]); -}; - -/** - * Cancel loadUrl that is waiting to be loaded. - */ -App.prototype.cancelLoadUrl = function() { - PhoneGap.exec(null, null, "App", "cancelLoadUrl", []); -}; - -/** - * Clear web history in this web view. - * Instead of BACK button loading the previous web page, it will exit the app. - */ -App.prototype.clearHistory = function() { - PhoneGap.exec(null, null, "App", "clearHistory", []); -}; - -/** - * Override the default behavior of the Android back button. - * If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired. - * - * Note: The user should not have to call this method. Instead, when the user - * registers for the "backbutton" event, this is automatically done. - * - * @param override T=override, F=cancel override - */ -App.prototype.overrideBackbutton = function(override) { - PhoneGap.exec(null, null, "App", "overrideBackbutton", [override]); -}; - -/** - * Exit and terminate the application. - */ -App.prototype.exitApp = function() { - return PhoneGap.exec(null, null, "App", "exitApp", []); -}; - -PhoneGap.addConstructor(function() { - navigator.app = new App(); -}); -}()); -} diff --git a/framework/js/build_phonegap.js.cmd b/framework/js/build_phonegap.js.cmd index ba1dda2..53a9661 100644 --- a/framework/js/build_phonegap.js.cmd +++ b/framework/js/build_phonegap.js.cmd @@ -1,4 +1,4 @@ del phonegap.*.js -copy /b *.js phonegap._js -ren phonegap._js phonegap.%1.js \ No newline at end of file +copy /b disclaimer.txt+phonegap.js.base+*.js phonegap._js +ren phonegap._js phonegap.1.0.js \ No newline at end of file diff --git a/framework/js/camera.js b/framework/js/camera.js index 3971e1f..1f0e12f 100644 --- a/framework/js/camera.js +++ b/framework/js/camera.js @@ -75,7 +75,7 @@ Camera.prototype.PictureSourceType = Camera.PictureSourceType; * @param {Object} options */ Camera.prototype.getPicture = function(successCallback, errorCallback, options) { - + console.log("Camera.prototype.getPicture"); // successCallback required if (typeof successCallback !== "function") { console.log("Camera Error: successCallback is not a function"); @@ -89,50 +89,52 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options) } this.options = options; - var quality = 80; - if (options.quality) { - quality = this.options.quality; - } - - var maxResolution = 0; - if (options.maxResolution) { - maxResolution = this.options.maxResolution; - } - - 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; - } - var encodingType = Camera.EncodingType.JPEG; - if (typeof options.encodingType == "number") { - encodingType = this.options.encodingType; - } - - var targetWidth = -1; - if (typeof options.targetWidth == "number") { - targetWidth = options.targetWidth; - } else if (typeof options.targetWidth == "string") { - var width = new Number(options.targetWidth); - if (isNaN(width) === false) { - targetWidth = width.valueOf(); - } - } - var targetHeight = -1; - if (typeof options.targetHeight == "number") { - targetHeight = options.targetHeight; - } else if (typeof options.targetHeight == "string") { - var height = new Number(options.targetHeight); - if (isNaN(height) === false) { - targetHeight = height.valueOf(); - } - } - - PhoneGap.exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType]); +// TODO: This is duplicate - default values initialization exists in native C# code +// var quality = 80; +// if (options.quality) { +// quality = this.options.quality; +// } +// +// var maxResolution = 0; +// if (options.maxResolution) { +// maxResolution = this.options.maxResolution; +// } +// +// 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; +// } +// var encodingType = Camera.EncodingType.JPEG; +// if (typeof options.encodingType == "number") { +// encodingType = this.options.encodingType; +// } +// +// var targetWidth = -1; +// if (typeof options.targetWidth == "number") { +// targetWidth = options.targetWidth; +// } else if (typeof options.targetWidth == "string") { +// var width = new Number(options.targetWidth); +// if (isNaN(width) === false) { +// targetWidth = width.valueOf(); +// } +// } + +// var targetHeight = -1; +// if (typeof options.targetHeight == "number") { +// targetHeight = options.targetHeight; +// } else if (typeof options.targetHeight == "string") { +// var height = new Number(options.targetHeight); +// if (isNaN(height) === false) { +// targetHeight = height.valueOf(); +// } +// } + + PhoneGap.exec(successCallback, errorCallback, "Camera", "getPicture", this.options); }; PhoneGap.addConstructor(function() { diff --git a/framework/js/capture.js b/framework/js/capture.js index 1c19357..abcc25f 100644 --- a/framework/js/capture.js +++ b/framework/js/capture.js @@ -84,7 +84,7 @@ var Capture = function(){ * @param {CaptureAudioOptions} options */ Capture.prototype.captureAudio = function(successCallback, errorCallback, options){ - PhoneGap.exec(successCallback, errorCallback, "Capture", "captureAudio", [options]); + PhoneGap.exec(successCallback, errorCallback, "Capture", "captureAudio", options); }; /** @@ -94,31 +94,8 @@ Capture.prototype.captureAudio = function(successCallback, errorCallback, option * @param {Function} errorCB * @param {CaptureImageOptions} 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 < pluginResult.message.length; i++) { - var mediaFile = new MediaFile(); - mediaFile.name = pluginResult.message[i].name; - mediaFile.fullPath = pluginResult.message[i].fullPath; - mediaFile.type = pluginResult.message[i].type; - mediaFile.lastModifiedDate = pluginResult.message[i].lastModifiedDate; - mediaFile.size = pluginResult.message[i].size; - mediaFiles.push(mediaFile); - } - pluginResult.message = mediaFiles; - return pluginResult; +Capture.prototype.captureImage = function (successCallback, errorCallback, options) { + PhoneGap.exec(successCallback, errorCallback, "Capture", "captureImage", options); }; /** @@ -179,12 +156,12 @@ var CaptureAudioOptions = function(){ // The selected audio mode. Must match with one of the elements in supportedAudioModes array. this.mode = null; }; - -PhoneGap.addConstructor(function(){ +PhoneGap.addConstructor(function () { if (typeof navigator.device === "undefined") { navigator.device = window.device = new Device(); } - if (typeof navigator.device.capture === "undefined") { + if (typeof navigator.device.capture === "undefined") { + console.log("Installing capture"); navigator.device.capture = window.device.capture = new Capture(); } }); diff --git a/framework/js/compass.js b/framework/js/compass.js index 09a3115..4ac9b1e 100644 --- a/framework/js/compass.js +++ b/framework/js/compass.js @@ -18,14 +18,10 @@ var Compass = function() { * The last known Compass position. */ this.lastHeading = null; - - /** - * List of compass watch timers - */ - this.timers = {}; + this.isCompassSupported = true; // default assumption }; -Compass.ERROR_MSG = ["Not running", "Starting", "", "Failed to start"]; +Compass.ERROR_MSG = ["Not running", "Starting", "", "Failed to start", "Not Supported"]; /** * Asynchronously aquires the current heading. @@ -45,11 +41,42 @@ Compass.prototype.getCurrentHeading = function(successCallback, errorCallback, o // errorCallback optional if (errorCallback && (typeof errorCallback !== "function")) { console.log("Compass Error: errorCallback is not a function"); - return; + //return; + + errorCallback = function(){}; } - - // Get heading - PhoneGap.exec(successCallback, errorCallback, "Compass", "getHeading", []); + + if(this.isCompassSupported) + { + var self = this; + var onSuccess = function(result) + { + //var compassResult = JSON.parse(result); + console.log("compassResult = " + result); + self.lastHeading = result; + successCallback(self.lastHeading); + } + + var onError = function(err) + { + if(err == 4) + { + self.isCompassSupported = false; + } + errorCallback(err); + } + + // Get heading + PhoneGap.exec(onSuccess, onError, "Compass", "getHeading", []); + } + else + { + var funk = function() + { + errorCallback(4); + }; + window.setTimeout(funk,0); + } }; /** @@ -68,32 +95,33 @@ Compass.prototype.watchHeading= function(successCallback, errorCallback, options // successCallback required if (typeof successCallback !== "function") { console.log("Compass Error: successCallback is not a function"); - return; + return -1; // in case caller later calls clearWatch with this id } // errorCallback optional if (errorCallback && (typeof errorCallback !== "function")) { console.log("Compass Error: errorCallback is not a function"); - return; + return -1; // in case caller later calls clearWatch with this id } - - // Make sure compass timeout > frequency + 10 sec - PhoneGap.exec( - function(timeout) { - if (timeout < (frequency + 10000)) { - PhoneGap.exec(null, null, "Compass", "setTimeout", [frequency + 10000]); - } - }, - function(e) { }, "Compass", "getTimeout", []); - - // Start watch timer to get headings - var id = PhoneGap.createUUID(); - navigator.compass.timers[id] = setInterval( - function() { - PhoneGap.exec(successCallback, errorCallback, "Compass", "getHeading", []); - }, (frequency ? frequency : 1)); - - return id; + + if(this.isCompassSupported) + { + var self = this; + var onInterval = function() + { + self.getCurrentHeading(successCallback,errorCallback,options); + } + return window.setInterval(onInterval,frequency); + } + else + { + var funk = function() + { + errorCallback(4); + }; + window.setTimeout(funk,0); + return -1; + } }; @@ -104,15 +132,16 @@ Compass.prototype.watchHeading= function(successCallback, errorCallback, options */ Compass.prototype.clearWatch = function(id) { - // Stop javascript timer & remove from timer list - if (id && navigator.compass.timers[id]) { - clearInterval(navigator.compass.timers[id]); - delete navigator.compass.timers[id]; - } + // Stop javascript timer + clearInterval(id); + }; -PhoneGap.addConstructor(function() { - if (typeof navigator.compass === "undefined") { +PhoneGap.addConstructor( +function() +{ + if (!navigator.compass) + { navigator.compass = new Compass(); } }); diff --git a/framework/js/contact.js b/framework/js/contact.js index a0ddf8a..3310d0b 100644 --- a/framework/js/contact.js +++ b/framework/js/contact.js @@ -51,8 +51,8 @@ var Contact = function (id, displayName, name, nickname, phoneNumbers, emails, a * An error code assigned by an implementation when an error has occurreds * @constructor */ -var ContactError = function() { - this.code=null; +var ContactError = function(errCode) { + this.code=errCode; }; /** @@ -71,14 +71,19 @@ ContactError.PERMISSION_DENIED_ERROR = 20; * @param successCB success callback * @param errorCB error callback */ -Contact.prototype.remove = function(successCB, errorCB) { - if (this.id === null) { - var errorObj = new ContactError(); - errorObj.code = ContactError.UNKNOWN_ERROR; +Contact.prototype.remove = function(successCB, errorCB) +{ + if (!this.id) + { + var errorObj = new ContactError(ContactError.UNKNOWN_ERROR); + setTimeout(function(){ errorCB(errorObj); + },0); + return ContactError.UNKNOWN_ERROR; } - else { - PhoneGap.exec(successCB, errorCB, "Contacts", "remove", [this.id]); + else + { + PhoneGap.exec(successCB, errorCB, "Contacts", "remove",this.id); } }; @@ -88,51 +93,24 @@ Contact.prototype.remove = function(successCB, errorCB) { * @return copy of this Contact */ Contact.prototype.clone = function() { - var clonedContact = PhoneGap.clone(this); + var clonedContact = PhoneGap.safeClone(this); var i; clonedContact.id = null; clonedContact.rawId = null; // Loop through and clear out any id's in phones, emails, etc. - if (clonedContact.phoneNumbers) { - for (i = 0; i < clonedContact.phoneNumbers.length; i++) { - clonedContact.phoneNumbers[i].id = null; - } - } - if (clonedContact.emails) { - for (i = 0; i < clonedContact.emails.length; i++) { - clonedContact.emails[i].id = null; - } - } - if (clonedContact.addresses) { - for (i = 0; i < clonedContact.addresses.length; i++) { - clonedContact.addresses[i].id = null; - } - } - if (clonedContact.ims) { - for (i = 0; i < clonedContact.ims.length; i++) { - clonedContact.ims[i].id = null; - } - } - if (clonedContact.organizations) { - for (i = 0; i < clonedContact.organizations.length; i++) { - clonedContact.organizations[i].id = null; - } - } - if (clonedContact.tags) { - for (i = 0; i < clonedContact.tags.length; i++) { - clonedContact.tags[i].id = null; - } - } - if (clonedContact.photos) { - for (i = 0; i < clonedContact.photos.length; i++) { - clonedContact.photos[i].id = null; - } - } - if (clonedContact.urls) { - for (i = 0; i < clonedContact.urls.length; i++) { - clonedContact.urls[i].id = null; - } - } + var myArrayProps = ["phoneNumbers","emails","addresses","ims","organizations","tags","photos","urls"]; + + for(var n=0, pLen=myArrayProps.length;n < pLen; n++) + { + var arr = clonedContact[myArrayProps[n]]; + if (arr && arr.length) + { + for(var i=0,len=arr.length; i - * - * @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("Error: 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'); - -/** - * onPhoneGapConnectionReady channel is fired when the PhoneGap connection properties - * has been set. - */ -PhoneGap.onPhoneGapConnectionReady = new PhoneGap.Channel('onPhoneGapConnectionReady'); - -/** - * 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'); - -/** - * onDestroy channel is fired when the PhoneGap native code - * is destroyed. It is used internally. - * Window.onunload should be used by the user. - */ -PhoneGap.onDestroy = new PhoneGap.Channel('onDestroy'); -PhoneGap.onDestroy.subscribeOnce(function() { - PhoneGap.shuttingDown = true; -}); -PhoneGap.shuttingDown = false; - -// _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'); - - -// Array of channels that must fire before "deviceready" is fired -PhoneGap.deviceReadyChannelsArray = [ PhoneGap.onPhoneGapReady, PhoneGap.onPhoneGapInfoReady, PhoneGap.onPhoneGapConnectionReady]; - -// Hashtable of user defined channels that must also fire before "deviceready" is fired -PhoneGap.deviceReadyChannelsMap = {}; - -/** - * Indicate that a feature needs to be initialized before it is ready to be used. - * This holds up PhoneGap's "deviceready" event until the feature has been initialized - * and PhoneGap.initComplete(feature) is called. - * - * @param feature {String} The unique feature name - */ -PhoneGap.waitForInitialization = function(feature) { - if (feature) { - var channel = new PhoneGap.Channel(feature); - PhoneGap.deviceReadyChannelsMap[feature] = channel; - PhoneGap.deviceReadyChannelsArray.push(channel); - } -}; - -/** - * Indicate that initialization code has completed and the feature is ready to be used. - * - * @param feature {String} The unique feature name - */ -PhoneGap.initializationComplete = function(feature) { - var channel = PhoneGap.deviceReadyChannelsMap[feature]; - if (channel) { - channel.fire(); - } -}; - -/** - * Create all PhoneGap objects once page has fully loaded and native side is ready. - */ -PhoneGap.Channel.join( - function() - { - - setTimeout(function() - { - PhoneGap.UsePolling = false; - PhoneGap.JSCallback(); - },1); - - // Run PhoneGap constructors - PhoneGap.onPhoneGapInit.fire(); - - // Fire event to notify that all objects are created - PhoneGap.onPhoneGapReady.fire(); - - // Fire onDeviceReady event once all constructors have run and PhoneGap info has been - // received from native side, and any user defined initialization channels. - PhoneGap.Channel.join(function() { - PhoneGap.onDeviceReady.fire(); - - // Fire the onresume event, since first one happens before JavaScript is loaded - PhoneGap.onResume.fire(); - }, PhoneGap.deviceReadyChannelsArray); - - }, - [ PhoneGap.onDOMContentLoaded, PhoneGap.onNativeReady ]); - - - -// Listen for DOMContentLoaded and notify our channel subscribers -document.addEventListener('DOMContentLoaded', function() { - PhoneGap.onDOMContentLoaded.fire(); -}, false); - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////// - -function SetDeviceProperties(platform, version, name, uuid, gap) -{ - device.platform = platform; - device.version = version; - device.name = name; - device.uuid = uuid; - device.gap = gap; - - // in theory, everything is now set up and working so this is where we should fire the deviceready event - // unfortunately IE7 mobile doesn't seem to support a way of dynamically raising events - PhoneGap.available = true; -} - -// Load device info -//PhoneGap.exec("Device.GetAll;SetDeviceProperties"); - diff --git a/framework/js/phonegap.1.0.0.js b/framework/js/phonegap.1.0.0.js index ad96b79..b479063 100644 --- a/framework/js/phonegap.1.0.0.js +++ b/framework/js/phonegap.1.0.0.js @@ -1,39 +1,14 @@ -/* - This is a machine generated file, do not edit directly. -jm -*/ - -/* - * 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-2011, IBM Corporation - */ - -/****************************** ACCELERATION ******************************/ - -function Acceleration(x, y, z, timestamp) { - // The force applied by the device in the x-axis. - this.x = x; - - // The force applied by the device in the y-axis. - this.y = y; - - // The force applied by the device in the z-axis. - this.z = z; - - // The time that the acceleration was obtained. - this.timestamp = timestamp || new Date().getTime(); -} /* * 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) 2005-2011, Nitobi Software Inc. * Copyright (c) 2010-2011, IBM Corporation + * Copyright (c) 2011, Microsoft Corporation */ -if (!PhoneGap.hasResource("accelerometer")) { +if (!PhoneGap.hasResource("accelerometer")) +{ PhoneGap.addResource("accelerometer"); /** @constructor */ @@ -83,11 +58,27 @@ Accelerometer.prototype.getCurrentAcceleration = function(successCallback, error console.log("Accelerometer Error: errorCallback is not a function"); return; } + + var self = this; + + var onSuccess = function(result) + { + var accResult = JSON.parse(result); + console.log("Accel x = " + accResult.x); + self.lastAcceleration = new Acceleration(accResult.x,accResult.y,accResult.z); + successCallback(self.lastAcceleration); + } + + var onError = function(err) + { + errorCallback(err); + } // Get acceleration - PhoneGap.exec(successCallback, errorCallback, "Accelerometer", "getAcceleration", []); + PhoneGap.exec(onSuccess, onError, "Accelerometer", "getAcceleration",options); }; + /** * Asynchronously aquires the acceleration repeatedly at a given interval. * @@ -96,10 +87,11 @@ Accelerometer.prototype.getCurrentAcceleration = function(successCallback, error * @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) { - +Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallback, options) +{ // Default interval (10 sec) - var frequency = (options !== undefined)? options.frequency : 10000; + var frequency = (options && options.frequency)? options.frequency : 10000; + var timeout = (options != options.timeout) ? options.timeout : 15000; // successCallback required if (typeof successCallback !== "function") { @@ -112,23 +104,17 @@ Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallb console.log("Accelerometer Error: errorCallback is not a function"); return; } + + var self = this; + + var onInterval = function() + { + self.getCurrentAcceleration(successCallback,errorCallback,options); + } - // Make sure accelerometer timeout > frequency + 10 sec - PhoneGap.exec( - function(timeout) { - if (timeout < (frequency + 10000)) { - PhoneGap.exec(null, null, "Accelerometer", "setTimeout", [frequency + 10000]); - } - }, - function(e) { }, "Accelerometer", "getTimeout", []); - - // Start watch timer - var id = PhoneGap.createUUID(); - navigator.accelerometer.timers[id] = setInterval(function() { - PhoneGap.exec(successCallback, errorCallback, "Accelerometer", "getAcceleration", []); - }, (frequency ? frequency : 1)); + - return id; + return window.setInterval(onInterval,frequency); }; /** @@ -138,15 +124,15 @@ Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallb */ Accelerometer.prototype.clearWatch = function(id) { - // Stop javascript timer & remove from timer list - if (id && navigator.accelerometer.timers[id] !== undefined) { - clearInterval(navigator.accelerometer.timers[id]); - delete navigator.accelerometer.timers[id]; - } + clearInterval(id); }; -PhoneGap.addConstructor(function() { - if (typeof navigator.accelerometer === "undefined") { +PhoneGap.addConstructor( +function() +{ + if (!navigator.accelerometer) + { + console.log("Installing accelerometer"); navigator.accelerometer = new Accelerometer(); } }); @@ -159,92 +145,6 @@ PhoneGap.addConstructor(function() { * Copyright (c) 2010-2011, IBM Corporation */ -if (!PhoneGap.hasResource("app")) { -PhoneGap.addResource("app"); -(function() { - -/** - * Constructor - * @constructor - */ -var App = function() {}; - -/** - * Clear the resource cache. - */ -App.prototype.clearCache = function() { - PhoneGap.exec(null, null, "App", "clearCache", []); -}; - -/** - * Load the url into the webview. - * - * @param url The URL to load - * @param props Properties that can be passed in to the activity: - * wait: int => wait msec before loading URL - * loadingDialog: "Title,Message" => display a native loading dialog - * hideLoadingDialogOnPage: boolean => hide loadingDialog when page loaded instead of when deviceready event occurs. - * loadInWebView: boolean => cause all links on web page to be loaded into existing web view, instead of being loaded into new browser. - * loadUrlTimeoutValue: int => time in msec to wait before triggering a timeout error - * errorUrl: URL => URL to load if there's an error loading specified URL with loadUrl(). Should be a local URL such as file:///android_asset/www/error.html"); - * keepRunning: boolean => enable app to keep running in background - * - * Example: - * App app = new App(); - * app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000}); - */ -App.prototype.loadUrl = function(url, props) { - PhoneGap.exec(null, null, "App", "loadUrl", [url, props]); -}; - -/** - * Cancel loadUrl that is waiting to be loaded. - */ -App.prototype.cancelLoadUrl = function() { - PhoneGap.exec(null, null, "App", "cancelLoadUrl", []); -}; - -/** - * Clear web history in this web view. - * Instead of BACK button loading the previous web page, it will exit the app. - */ -App.prototype.clearHistory = function() { - PhoneGap.exec(null, null, "App", "clearHistory", []); -}; - -/** - * Override the default behavior of the Android back button. - * If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired. - * - * Note: The user should not have to call this method. Instead, when the user - * registers for the "backbutton" event, this is automatically done. - * - * @param override T=override, F=cancel override - */ -App.prototype.overrideBackbutton = function(override) { - PhoneGap.exec(null, null, "App", "overrideBackbutton", [override]); -}; - -/** - * Exit and terminate the application. - */ -App.prototype.exitApp = function() { - return PhoneGap.exec(null, null, "App", "exitApp", []); -}; - -PhoneGap.addConstructor(function() { - navigator.app = new App(); -}); -}()); -} -/* - * 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-2011, IBM Corporation - */ - if (!PhoneGap.hasResource("camera")) { PhoneGap.addResource("camera"); @@ -314,7 +214,7 @@ Camera.prototype.PictureSourceType = Camera.PictureSourceType; * @param {Object} options */ Camera.prototype.getPicture = function(successCallback, errorCallback, options) { - + console.log("Camera.prototype.getPicture"); // successCallback required if (typeof successCallback !== "function") { console.log("Camera Error: successCallback is not a function"); @@ -328,50 +228,52 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options) } this.options = options; - var quality = 80; - if (options.quality) { - quality = this.options.quality; - } - - var maxResolution = 0; - if (options.maxResolution) { - maxResolution = this.options.maxResolution; - } - - 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; - } - var encodingType = Camera.EncodingType.JPEG; - if (typeof options.encodingType == "number") { - encodingType = this.options.encodingType; - } - - var targetWidth = -1; - if (typeof options.targetWidth == "number") { - targetWidth = options.targetWidth; - } else if (typeof options.targetWidth == "string") { - var width = new Number(options.targetWidth); - if (isNaN(width) === false) { - targetWidth = width.valueOf(); - } - } - var targetHeight = -1; - if (typeof options.targetHeight == "number") { - targetHeight = options.targetHeight; - } else if (typeof options.targetHeight == "string") { - var height = new Number(options.targetHeight); - if (isNaN(height) === false) { - targetHeight = height.valueOf(); - } - } - - PhoneGap.exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType]); +// TODO: This is duplicate - default values initialization exists in native C# code +// var quality = 80; +// if (options.quality) { +// quality = this.options.quality; +// } +// +// var maxResolution = 0; +// if (options.maxResolution) { +// maxResolution = this.options.maxResolution; +// } +// +// 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; +// } +// var encodingType = Camera.EncodingType.JPEG; +// if (typeof options.encodingType == "number") { +// encodingType = this.options.encodingType; +// } +// +// var targetWidth = -1; +// if (typeof options.targetWidth == "number") { +// targetWidth = options.targetWidth; +// } else if (typeof options.targetWidth == "string") { +// var width = new Number(options.targetWidth); +// if (isNaN(width) === false) { +// targetWidth = width.valueOf(); +// } +// } + +// var targetHeight = -1; +// if (typeof options.targetHeight == "number") { +// targetHeight = options.targetHeight; +// } else if (typeof options.targetHeight == "string") { +// var height = new Number(options.targetHeight); +// if (isNaN(height) === false) { +// targetHeight = height.valueOf(); +// } +// } + + PhoneGap.exec(successCallback, errorCallback, "Camera", "getPicture", this.options); }; PhoneGap.addConstructor(function() { @@ -466,18 +368,7 @@ var Capture = function(){ * @param {CaptureAudioOptions} 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]); + PhoneGap.exec(successCallback, errorCallback, "Capture", "captureAudio", options); }; /** @@ -487,20 +378,8 @@ Capture.prototype.captureImage = function(successCallback, errorCallback, option * @param {Function} errorCB * @param {CaptureImageOptions} options */ -Capture.prototype._castMediaFile = function(pluginResult){ - var mediaFiles = []; - var i; - for (i = 0; i < pluginResult.message.length; i++) { - var mediaFile = new MediaFile(); - mediaFile.name = pluginResult.message[i].name; - mediaFile.fullPath = pluginResult.message[i].fullPath; - mediaFile.type = pluginResult.message[i].type; - mediaFile.lastModifiedDate = pluginResult.message[i].lastModifiedDate; - mediaFile.size = pluginResult.message[i].size; - mediaFiles.push(mediaFile); - } - pluginResult.message = mediaFiles; - return pluginResult; +Capture.prototype.captureImage = function (successCallback, errorCallback, options) { + PhoneGap.exec(successCallback, errorCallback, "Capture", "captureImage", options); }; /** @@ -561,12 +440,12 @@ var CaptureAudioOptions = function(){ // The selected audio mode. Must match with one of the elements in supportedAudioModes array. this.mode = null; }; - -PhoneGap.addConstructor(function(){ +PhoneGap.addConstructor(function () { if (typeof navigator.device === "undefined") { navigator.device = window.device = new Device(); } - if (typeof navigator.device.capture === "undefined") { + if (typeof navigator.device.capture === "undefined") { + console.log("Installing capture"); navigator.device.capture = window.device.capture = new Capture(); } }); @@ -590,14 +469,10 @@ var Compass = function() { * The last known Compass position. */ this.lastHeading = null; - - /** - * List of compass watch timers - */ - this.timers = {}; + this.isCompassSupported = true; // default assumption }; -Compass.ERROR_MSG = ["Not running", "Starting", "", "Failed to start"]; +Compass.ERROR_MSG = ["Not running", "Starting", "", "Failed to start", "Not Supported"]; /** * Asynchronously aquires the current heading. @@ -617,11 +492,42 @@ Compass.prototype.getCurrentHeading = function(successCallback, errorCallback, o // errorCallback optional if (errorCallback && (typeof errorCallback !== "function")) { console.log("Compass Error: errorCallback is not a function"); - return; + //return; + + errorCallback = function(){}; } - - // Get heading - PhoneGap.exec(successCallback, errorCallback, "Compass", "getHeading", []); + + if(this.isCompassSupported) + { + var self = this; + var onSuccess = function(result) + { + //var compassResult = JSON.parse(result); + console.log("compassResult = " + result); + self.lastHeading = result; + successCallback(self.lastHeading); + } + + var onError = function(err) + { + if(err == 4) + { + self.isCompassSupported = false; + } + errorCallback(err); + } + + // Get heading + PhoneGap.exec(onSuccess, onError, "Compass", "getHeading", []); + } + else + { + var funk = function() + { + errorCallback(4); + }; + window.setTimeout(funk,0); + } }; /** @@ -640,32 +546,33 @@ Compass.prototype.watchHeading= function(successCallback, errorCallback, options // successCallback required if (typeof successCallback !== "function") { console.log("Compass Error: successCallback is not a function"); - return; + return -1; // in case caller later calls clearWatch with this id } // errorCallback optional if (errorCallback && (typeof errorCallback !== "function")) { console.log("Compass Error: errorCallback is not a function"); - return; + return -1; // in case caller later calls clearWatch with this id } - - // Make sure compass timeout > frequency + 10 sec - PhoneGap.exec( - function(timeout) { - if (timeout < (frequency + 10000)) { - PhoneGap.exec(null, null, "Compass", "setTimeout", [frequency + 10000]); - } - }, - function(e) { }, "Compass", "getTimeout", []); - - // Start watch timer to get headings - var id = PhoneGap.createUUID(); - navigator.compass.timers[id] = setInterval( - function() { - PhoneGap.exec(successCallback, errorCallback, "Compass", "getHeading", []); - }, (frequency ? frequency : 1)); - - return id; + + if(this.isCompassSupported) + { + var self = this; + var onInterval = function() + { + self.getCurrentHeading(successCallback,errorCallback,options); + } + return window.setInterval(onInterval,frequency); + } + else + { + var funk = function() + { + errorCallback(4); + }; + window.setTimeout(funk,0); + return -1; + } }; @@ -676,15 +583,16 @@ Compass.prototype.watchHeading= function(successCallback, errorCallback, options */ Compass.prototype.clearWatch = function(id) { - // Stop javascript timer & remove from timer list - if (id && navigator.compass.timers[id]) { - clearInterval(navigator.compass.timers[id]); - delete navigator.compass.timers[id]; - } + // Stop javascript timer + clearInterval(id); + }; -PhoneGap.addConstructor(function() { - if (typeof navigator.compass === "undefined") { +PhoneGap.addConstructor( +function() +{ + if (!navigator.compass) + { navigator.compass = new Compass(); } }); @@ -742,8 +650,8 @@ var Contact = function (id, displayName, name, nickname, phoneNumbers, emails, a * An error code assigned by an implementation when an error has occurreds * @constructor */ -var ContactError = function() { - this.code=null; +var ContactError = function(errCode) { + this.code=errCode; }; /** @@ -762,14 +670,19 @@ ContactError.PERMISSION_DENIED_ERROR = 20; * @param successCB success callback * @param errorCB error callback */ -Contact.prototype.remove = function(successCB, errorCB) { - if (this.id === null) { - var errorObj = new ContactError(); - errorObj.code = ContactError.UNKNOWN_ERROR; +Contact.prototype.remove = function(successCB, errorCB) +{ + if (!this.id) + { + var errorObj = new ContactError(ContactError.UNKNOWN_ERROR); + setTimeout(function(){ errorCB(errorObj); + },0); + return ContactError.UNKNOWN_ERROR; } - else { - PhoneGap.exec(successCB, errorCB, "Contacts", "remove", [this.id]); + else + { + PhoneGap.exec(successCB, errorCB, "Contacts", "remove",this.id); } }; @@ -779,51 +692,24 @@ Contact.prototype.remove = function(successCB, errorCB) { * @return copy of this Contact */ Contact.prototype.clone = function() { - var clonedContact = PhoneGap.clone(this); + var clonedContact = PhoneGap.safeClone(this); var i; clonedContact.id = null; clonedContact.rawId = null; // Loop through and clear out any id's in phones, emails, etc. - if (clonedContact.phoneNumbers) { - for (i = 0; i < clonedContact.phoneNumbers.length; i++) { - clonedContact.phoneNumbers[i].id = null; - } - } - if (clonedContact.emails) { - for (i = 0; i < clonedContact.emails.length; i++) { - clonedContact.emails[i].id = null; - } - } - if (clonedContact.addresses) { - for (i = 0; i < clonedContact.addresses.length; i++) { - clonedContact.addresses[i].id = null; - } - } - if (clonedContact.ims) { - for (i = 0; i < clonedContact.ims.length; i++) { - clonedContact.ims[i].id = null; - } - } - if (clonedContact.organizations) { - for (i = 0; i < clonedContact.organizations.length; i++) { - clonedContact.organizations[i].id = null; - } - } - if (clonedContact.tags) { - for (i = 0; i < clonedContact.tags.length; i++) { - clonedContact.tags[i].id = null; - } - } - if (clonedContact.photos) { - for (i = 0; i < clonedContact.photos.length; i++) { - clonedContact.photos[i].id = null; - } - } - if (clonedContact.urls) { - for (i = 0; i < clonedContact.urls.length; i++) { - clonedContact.urls[i].id = null; - } - } + var myArrayProps = ["phoneNumbers","emails","addresses","ims","organizations","tags","photos","urls"]; + + for(var n=0, pLen=myArrayProps.length;n < pLen; n++) + { + var arr = clonedContact[myArrayProps[n]]; + if (arr && arr.length) + { + for(var i=0,len=arr.length; i - * - * @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("Error: 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'); - -/** - * onPhoneGapConnectionReady channel is fired when the PhoneGap connection properties - * has been set. - */ -PhoneGap.onPhoneGapConnectionReady = new PhoneGap.Channel('onPhoneGapConnectionReady'); - -/** - * 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'); - -/** - * onDestroy channel is fired when the PhoneGap native code - * is destroyed. It is used internally. - * Window.onunload should be used by the user. - */ -PhoneGap.onDestroy = new PhoneGap.Channel('onDestroy'); -PhoneGap.onDestroy.subscribeOnce(function() { - PhoneGap.shuttingDown = true; -}); -PhoneGap.shuttingDown = false; - -// _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'); - - -// Array of channels that must fire before "deviceready" is fired -PhoneGap.deviceReadyChannelsArray = [ PhoneGap.onPhoneGapReady, PhoneGap.onPhoneGapInfoReady, PhoneGap.onPhoneGapConnectionReady]; - -// Hashtable of user defined channels that must also fire before "deviceready" is fired -PhoneGap.deviceReadyChannelsMap = {}; - -/** - * Indicate that a feature needs to be initialized before it is ready to be used. - * This holds up PhoneGap's "deviceready" event until the feature has been initialized - * and PhoneGap.initComplete(feature) is called. - * - * @param feature {String} The unique feature name - */ -PhoneGap.waitForInitialization = function(feature) { - if (feature) { - var channel = new PhoneGap.Channel(feature); - PhoneGap.deviceReadyChannelsMap[feature] = channel; - PhoneGap.deviceReadyChannelsArray.push(channel); - } -}; - -/** - * Indicate that initialization code has completed and the feature is ready to be used. - * - * @param feature {String} The unique feature name - */ -PhoneGap.initializationComplete = function(feature) { - var channel = PhoneGap.deviceReadyChannelsMap[feature]; - if (channel) { - channel.fire(); - } -}; - -/** - * Create all PhoneGap objects once page has fully loaded and native side is ready. - */ -PhoneGap.Channel.join( - function() - { - - setTimeout(function() - { - PhoneGap.UsePolling = false; - PhoneGap.JSCallback(); - },1); - - // Run PhoneGap constructors - PhoneGap.onPhoneGapInit.fire(); - - // Fire event to notify that all objects are created - PhoneGap.onPhoneGapReady.fire(); - - // Fire onDeviceReady event once all constructors have run and PhoneGap info has been - // received from native side, and any user defined initialization channels. - PhoneGap.Channel.join(function() { - PhoneGap.onDeviceReady.fire(); - - // Fire the onresume event, since first one happens before JavaScript is loaded - PhoneGap.onResume.fire(); - }, PhoneGap.deviceReadyChannelsArray); - - }, - [ PhoneGap.onDOMContentLoaded, PhoneGap.onNativeReady ]); - - - -// Listen for DOMContentLoaded and notify our channel subscribers -document.addEventListener('DOMContentLoaded', function() { - PhoneGap.onDOMContentLoaded.fire(); -}, false); - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////// - -function SetDeviceProperties(platform, version, name, uuid, gap) -{ - device.platform = platform; - device.version = version; - device.name = name; - device.uuid = uuid; - device.gap = gap; - - // in theory, everything is now set up and working so this is where we should fire the deviceready event - // unfortunately IE7 mobile doesn't seem to support a way of dynamically raising events - PhoneGap.available = true; -} - -// Load device info -//PhoneGap.exec("Device.GetAll;SetDeviceProperties"); - -/* - * 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-2011, IBM Corporation - */ - -if (!PhoneGap.hasResource("position")) { -PhoneGap.addResource("position"); - -/** - * 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 - */ -var Position = function(coords, timestamp) { - this.coords = coords; - this.timestamp = (timestamp !== 'undefined') ? timestamp : new Date().getTime(); -}; - -/** @constructor */ -var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) { - /** - * The latitude of the position. - */ - this.latitude = lat; - /** - * The longitude of the position, - */ - this.longitude = lng; - /** - * The accuracy of the position. - */ - this.accuracy = acc; - /** - * The altitude of the position. - */ - this.altitude = alt; - /** - * The direction the device is moving at the position. - */ - this.heading = head; - /** - * The velocity with which the device is moving at the position. - */ - this.speed = vel; - /** - * The altitude accuracy of the position. - */ - this.altitudeAccuracy = (altacc !== 'undefined') ? altacc : null; -}; - -/** - * This class specifies the options for requesting position data. - * @constructor - */ -var PositionOptions = function() { - /** - * Specifies the desired position accuracy. - */ - this.enableHighAccuracy = true; - /** - * The timeout after which if position data cannot be obtained the errorCallback - * is called. - */ - this.timeout = 10000; -}; - -/** - * This class contains information about any GSP errors. - * @constructor - */ -var PositionError = function() { - this.code = null; - this.message = ""; -}; - -PositionError.UNKNOWN_ERROR = 0; -PositionError.PERMISSION_DENIED = 1; -PositionError.POSITION_UNAVAILABLE = 2; -PositionError.TIMEOUT = 3; -} - -/****************************** SMS ******************************/ - -function Sms() { - this._errorCallback = null; -} - -Sms.prototype.send = function (number, message, successCallback, errorCallback, options) { -// successCallback and options are not supported on WP7 - this._errorCallback = errorCallback; - PhoneGap.exec("Send.Sms;send_Error;" + number + ";" + message); -} - -function send_Error(errorMessage) { - navigator.sms._errorCallback(errorMessage); -} - -if (typeof navigator.sms == "undefined") { - navigator.sms = new Sms(); -} - -/* - * 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-2011, IBM Corporation - */ - -/* - * This is purely for the Android 1.5/1.6 HTML 5 Storage - * I was hoping that Android 2.0 would deprecate this, but given the fact that - * most manufacturers ship with Android 1.5 and do not do OTA Updates, this is required - */ - -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 - * @constructor - */ -var DroidDB = function() { - this.queryQueue = {}; -}; - -/** - * Callback from native code when query is complete. - * PRIVATE METHOD - * - * @param id Query id - */ -DroidDB.prototype.completeQuery = function(id, data) { - var query = this.queryQueue[id]; - if (query) { - try { - delete this.queryQueue[id]; - - // Get transaction - var tx = query.tx; - - // If transaction hasn't failed - // Note: We ignore all query results if previous query - // in the same transaction failed. - if (tx && tx.queryList[id]) { - - // Save query results - var r = new DroidDB_Result(); - r.rows.resultSet = data; - r.rows.length = data.length; - try { - if (typeof query.successCallback === 'function') { - query.successCallback(query.tx, r); - } - } catch (ex) { - console.log("executeSql error calling user success callback: "+ex); - } - - tx.queryComplete(id); - } - } catch (e) { - console.log("executeSql error: "+e); - } - } -}; - -/** - * Callback from native code when query fails - * PRIVATE METHOD - * - * @param reason Error message - * @param id Query id - */ -DroidDB.prototype.fail = function(reason, id) { - var query = this.queryQueue[id]; - if (query) { - try { - delete this.queryQueue[id]; - - // Get transaction - var tx = query.tx; - - // If transaction hasn't failed - // Note: We ignore all query results if previous query - // in the same transaction failed. - if (tx && tx.queryList[id]) { - tx.queryList = {}; - - try { - if (typeof query.errorCallback === 'function') { - query.errorCallback(query.tx, reason); - } - } catch (ex) { - console.log("executeSql error calling user error callback: "+ex); - } - - tx.queryFailed(id, reason); - } - - } catch (e) { - console.log("executeSql error: "+e); - } - } -}; - -/** - * 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 - * @constructor - */ -var DroidDB_Tx = function() { - - // Set the id of the transaction - this.id = PhoneGap.createUUID(); - - // Callbacks - this.successCallback = null; - this.errorCallback = null; - - // Query list - this.queryList = {}; -}; - -/** - * Mark query in transaction as complete. - * If all queries are complete, call the user's transaction success callback. - * - * @param id Query id - */ -DroidDB_Tx.prototype.queryComplete = function(id) { - delete this.queryList[id]; - - // If no more outstanding queries, then fire transaction success - if (this.successCallback) { - var count = 0; - var i; - for (i in this.queryList) { - if (this.queryList.hasOwnProperty(i)) { - count++; - } - } - if (count === 0) { - try { - this.successCallback(); - } catch(e) { - console.log("Transaction error calling user success callback: " + e); - } - } - } -}; - -/** - * Mark query in transaction as failed. - * - * @param id Query id - * @param reason Error message - */ -DroidDB_Tx.prototype.queryFailed = function(id, reason) { - - // The sql queries in this transaction have already been run, since - // we really don't have a real transaction implemented in native code. - // However, the user callbacks for the remaining sql queries in transaction - // will not be called. - this.queryList = {}; - - if (this.errorCallback) { - try { - this.errorCallback(reason); - } catch(e) { - console.log("Transaction error calling user error callback: " + e); - } - } -}; - -/** - * Execute SQL statement - * - * @param sql SQL statement to execute - * @param params Statement parameters - * @param successCallback Success callback - * @param errorCallback Error callback - */ -DroidDB_Tx.prototype.executeSql = function(sql, params, successCallback, errorCallback) { - - // Init params array - if (typeof params === 'undefined') { - params = []; - } - - // Create query and add to queue - var query = new DroidDB_Query(this); - droiddb.queryQueue[query.id] = query; - - // Save callbacks - query.successCallback = successCallback; - query.errorCallback = errorCallback; - - // Call native code - PhoneGap.exec(null, null, "Storage", "executeSql", [sql, params, query.id]); -}; - -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); - } - } - } -}; - -/** - * Open database - * - * @param name Database name - * @param version Database version - * @param display_name Database display name - * @param size Database size in bytes - * @return Database object - */ -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. - */ - -/** - * @constructor - */ -var CupcakeLocalStorage = function() { - try { - - this.db = openDatabase('localStorage', '1.0', 'localStorage', 2621440); - var storage = {}; - this.length = 0; - function setLength (length) { - this.length = length; - localStorage.length = length; - } - this.db.transaction( - function (transaction) { - var i; - transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))'); - transaction.executeSql('SELECT * FROM storage', [], function(tx, result) { - for(var i = 0; i < result.rows.length; i++) { - storage[result.rows.item(i)['id']] = result.rows.item(i)['body']; - } - setLength(result.rows.length); - PhoneGap.initializationComplete("cupcakeStorage"); - }); - - }, - function (err) { - alert(err.message); - } - ); - this.setItem = function(key, val) { - if (typeof(storage[key])=='undefined') { - this.length++; - } - storage[key] = val; - this.db.transaction( - function (transaction) { - transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))'); - transaction.executeSql('REPLACE INTO storage (id, body) values(?,?)', [key,val]); - } - ); - }; - this.getItem = function(key) { - return storage[key]; - }; - this.removeItem = function(key) { - delete storage[key]; - this.length--; - this.db.transaction( - function (transaction) { - transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))'); - transaction.executeSql('DELETE FROM storage where id=?', [key]); - } - ); - }; - this.clear = function() { - storage = {}; - this.length = 0; - this.db.transaction( - function (transaction) { - transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))'); - transaction.executeSql('DELETE FROM storage', []); - } - ); - }; - this.key = function(index) { - var i = 0; - for (var j in storage) { - if (i==index) { - return j; - } else { - i++; - } - } - return null; - }; - - } catch(e) { - alert("Database error "+e+"."); - return; - } -}; - -PhoneGap.addConstructor(function() { - var setupDroidDB = function() { - navigator.openDatabase = window.openDatabase = DroidDB_openDatabase; - window.droiddb = new DroidDB(); - } - if (typeof window.openDatabase === "undefined") { - setupDroidDB(); - } 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; - } - } - } - - if (typeof window.localStorage === "undefined") { - navigator.localStorage = window.localStorage = new CupcakeLocalStorage(); - PhoneGap.waitForInitialization("cupcakeStorage"); - } -}); -} - -/****************************** TELEPHONY ******************************/ - -function Telephony() { -} - -Telephony.prototype.call = function (number) { - PhoneGap.exec("Telephony.CallNumber;"+number); -}; - -// The spec say this, but the above makes more sense (to me at least) -Telephony.prototype.send = function (number) { - PhoneGap.exec("Telephony.CallNumber;"+number); -}; - -if (typeof navigator.telephony == "undefined") { - navigator.telephony = new Telephony(); -} - diff --git a/tests/MobileSpecUnitTests/www/phonegap.js b/framework/js/phonegap.js.base similarity index 97% rename from tests/MobileSpecUnitTests/www/phonegap.js rename to framework/js/phonegap.js.base index 343c7f0..8c86f8d 100644 --- a/tests/MobileSpecUnitTests/www/phonegap.js +++ b/framework/js/phonegap.js.base @@ -98,7 +98,6 @@ PhoneGap.exec = function(success, fail, service, action, args) PhoneGapCommandResult = function(status,callbackId,args,cast) { - console.log("PhoneGapCommandResult :: " + status + ", " + callbackId + ", " + args + ", " + cast); if(status === "backbutton") { PhoneGap.fireEvent(document,"backbutton"); @@ -133,7 +132,6 @@ PhoneGapCommandResult = function(status,callbackId,args,cast) */ PhoneGap.CallbackSuccess = function(callbackId, args, cast) { - console.log("PhoneGapCallbackSuccess::" + callbackId + "::" + args + "::" + cast); var commandResult; try @@ -183,8 +181,6 @@ PhoneGap.CallbackSuccess = function(callbackId, args, cast) */ PhoneGap.CallbackError = function (callbackId, args, cast) { - console.log("PhoneGap.CallbackError::" + callbackId + "::" + args); - var commandResult; try { @@ -565,12 +561,7 @@ PhoneGap.Channel.join( document.addEventListener('DOMContentLoaded', function() { PhoneGap.onDOMContentLoaded.fire(); }, false); - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////// PhoneGap.m_document_addEventListener = document.addEventListener; document.addEventListener = function(evt, handler, capture) { diff --git a/framework/js/position.js b/framework/js/position.js deleted file mode 100644 index d6b4e61..0000000 --- a/framework/js/position.js +++ /dev/null @@ -1,89 +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-2011, IBM Corporation - */ - -if (!PhoneGap.hasResource("position")) { -PhoneGap.addResource("position"); - -/** - * 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 - */ -var Position = function(coords, timestamp) { - this.coords = coords; - this.timestamp = (timestamp !== 'undefined') ? timestamp : new Date().getTime(); -}; - -/** @constructor */ -var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) { - /** - * The latitude of the position. - */ - this.latitude = lat; - /** - * The longitude of the position, - */ - this.longitude = lng; - /** - * The accuracy of the position. - */ - this.accuracy = acc; - /** - * The altitude of the position. - */ - this.altitude = alt; - /** - * The direction the device is moving at the position. - */ - this.heading = head; - /** - * The velocity with which the device is moving at the position. - */ - this.speed = vel; - /** - * The altitude accuracy of the position. - */ - this.altitudeAccuracy = (altacc !== 'undefined') ? altacc : null; -}; - -/** - * This class specifies the options for requesting position data. - * @constructor - */ -var PositionOptions = function() { - /** - * Specifies the desired position accuracy. - */ - this.enableHighAccuracy = true; - /** - * The timeout after which if position data cannot be obtained the errorCallback - * is called. - */ - this.timeout = 10000; -}; - -/** - * This class contains information about any GSP errors. - * @constructor - */ -var PositionError = function() { - this.code = null; - this.message = ""; -}; - -PositionError.UNKNOWN_ERROR = 0; -PositionError.PERMISSION_DENIED = 1; -PositionError.POSITION_UNAVAILABLE = 2; -PositionError.TIMEOUT = 3; -} diff --git a/framework/js/sms.js b/framework/js/sms.js deleted file mode 100644 index bf398ee..0000000 --- a/framework/js/sms.js +++ /dev/null @@ -1,21 +0,0 @@ - -/****************************** SMS ******************************/ - -function Sms() { - this._errorCallback = null; -} - -Sms.prototype.send = function (number, message, successCallback, errorCallback, options) { -// successCallback and options are not supported on WP7 - this._errorCallback = errorCallback; - PhoneGap.exec("Send.Sms;send_Error;" + number + ";" + message); -} - -function send_Error(errorMessage) { - navigator.sms._errorCallback(errorMessage); -} - -if (typeof navigator.sms == "undefined") { - navigator.sms = new Sms(); -} - diff --git a/framework/js/storage.js b/framework/js/storage.js deleted file mode 100644 index 794aba1..0000000 --- a/framework/js/storage.js +++ /dev/null @@ -1,428 +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-2011, IBM Corporation - */ - -/* - * This is purely for the Android 1.5/1.6 HTML 5 Storage - * I was hoping that Android 2.0 would deprecate this, but given the fact that - * most manufacturers ship with Android 1.5 and do not do OTA Updates, this is required - */ - -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 - * @constructor - */ -var DroidDB = function() { - this.queryQueue = {}; -}; - -/** - * Callback from native code when query is complete. - * PRIVATE METHOD - * - * @param id Query id - */ -DroidDB.prototype.completeQuery = function(id, data) { - var query = this.queryQueue[id]; - if (query) { - try { - delete this.queryQueue[id]; - - // Get transaction - var tx = query.tx; - - // If transaction hasn't failed - // Note: We ignore all query results if previous query - // in the same transaction failed. - if (tx && tx.queryList[id]) { - - // Save query results - var r = new DroidDB_Result(); - r.rows.resultSet = data; - r.rows.length = data.length; - try { - if (typeof query.successCallback === 'function') { - query.successCallback(query.tx, r); - } - } catch (ex) { - console.log("executeSql error calling user success callback: "+ex); - } - - tx.queryComplete(id); - } - } catch (e) { - console.log("executeSql error: "+e); - } - } -}; - -/** - * Callback from native code when query fails - * PRIVATE METHOD - * - * @param reason Error message - * @param id Query id - */ -DroidDB.prototype.fail = function(reason, id) { - var query = this.queryQueue[id]; - if (query) { - try { - delete this.queryQueue[id]; - - // Get transaction - var tx = query.tx; - - // If transaction hasn't failed - // Note: We ignore all query results if previous query - // in the same transaction failed. - if (tx && tx.queryList[id]) { - tx.queryList = {}; - - try { - if (typeof query.errorCallback === 'function') { - query.errorCallback(query.tx, reason); - } - } catch (ex) { - console.log("executeSql error calling user error callback: "+ex); - } - - tx.queryFailed(id, reason); - } - - } catch (e) { - console.log("executeSql error: "+e); - } - } -}; - -/** - * 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 - * @constructor - */ -var DroidDB_Tx = function() { - - // Set the id of the transaction - this.id = PhoneGap.createUUID(); - - // Callbacks - this.successCallback = null; - this.errorCallback = null; - - // Query list - this.queryList = {}; -}; - -/** - * Mark query in transaction as complete. - * If all queries are complete, call the user's transaction success callback. - * - * @param id Query id - */ -DroidDB_Tx.prototype.queryComplete = function(id) { - delete this.queryList[id]; - - // If no more outstanding queries, then fire transaction success - if (this.successCallback) { - var count = 0; - var i; - for (i in this.queryList) { - if (this.queryList.hasOwnProperty(i)) { - count++; - } - } - if (count === 0) { - try { - this.successCallback(); - } catch(e) { - console.log("Transaction error calling user success callback: " + e); - } - } - } -}; - -/** - * Mark query in transaction as failed. - * - * @param id Query id - * @param reason Error message - */ -DroidDB_Tx.prototype.queryFailed = function(id, reason) { - - // The sql queries in this transaction have already been run, since - // we really don't have a real transaction implemented in native code. - // However, the user callbacks for the remaining sql queries in transaction - // will not be called. - this.queryList = {}; - - if (this.errorCallback) { - try { - this.errorCallback(reason); - } catch(e) { - console.log("Transaction error calling user error callback: " + e); - } - } -}; - -/** - * Execute SQL statement - * - * @param sql SQL statement to execute - * @param params Statement parameters - * @param successCallback Success callback - * @param errorCallback Error callback - */ -DroidDB_Tx.prototype.executeSql = function(sql, params, successCallback, errorCallback) { - - // Init params array - if (typeof params === 'undefined') { - params = []; - } - - // Create query and add to queue - var query = new DroidDB_Query(this); - droiddb.queryQueue[query.id] = query; - - // Save callbacks - query.successCallback = successCallback; - query.errorCallback = errorCallback; - - // Call native code - PhoneGap.exec(null, null, "Storage", "executeSql", [sql, params, query.id]); -}; - -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); - } - } - } -}; - -/** - * Open database - * - * @param name Database name - * @param version Database version - * @param display_name Database display name - * @param size Database size in bytes - * @return Database object - */ -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. - */ - -/** - * @constructor - */ -var CupcakeLocalStorage = function() { - try { - - this.db = openDatabase('localStorage', '1.0', 'localStorage', 2621440); - var storage = {}; - this.length = 0; - function setLength (length) { - this.length = length; - localStorage.length = length; - } - this.db.transaction( - function (transaction) { - var i; - transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))'); - transaction.executeSql('SELECT * FROM storage', [], function(tx, result) { - for(var i = 0; i < result.rows.length; i++) { - storage[result.rows.item(i)['id']] = result.rows.item(i)['body']; - } - setLength(result.rows.length); - PhoneGap.initializationComplete("cupcakeStorage"); - }); - - }, - function (err) { - alert(err.message); - } - ); - this.setItem = function(key, val) { - if (typeof(storage[key])=='undefined') { - this.length++; - } - storage[key] = val; - this.db.transaction( - function (transaction) { - transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))'); - transaction.executeSql('REPLACE INTO storage (id, body) values(?,?)', [key,val]); - } - ); - }; - this.getItem = function(key) { - return storage[key]; - }; - this.removeItem = function(key) { - delete storage[key]; - this.length--; - this.db.transaction( - function (transaction) { - transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))'); - transaction.executeSql('DELETE FROM storage where id=?', [key]); - } - ); - }; - this.clear = function() { - storage = {}; - this.length = 0; - this.db.transaction( - function (transaction) { - transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))'); - transaction.executeSql('DELETE FROM storage', []); - } - ); - }; - this.key = function(index) { - var i = 0; - for (var j in storage) { - if (i==index) { - return j; - } else { - i++; - } - } - return null; - }; - - } catch(e) { - alert("Database error "+e+"."); - return; - } -}; - -PhoneGap.addConstructor(function() { - var setupDroidDB = function() { - navigator.openDatabase = window.openDatabase = DroidDB_openDatabase; - window.droiddb = new DroidDB(); - } - if (typeof window.openDatabase === "undefined") { - setupDroidDB(); - } 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; - } - } - } - - if (typeof window.localStorage === "undefined") { - navigator.localStorage = window.localStorage = new CupcakeLocalStorage(); - PhoneGap.waitForInitialization("cupcakeStorage"); - } -}); -} diff --git a/framework/js/telephony.js b/framework/js/telephony.js deleted file mode 100644 index 3a391c2..0000000 --- a/framework/js/telephony.js +++ /dev/null @@ -1,19 +0,0 @@ - -/****************************** TELEPHONY ******************************/ - -function Telephony() { -} - -Telephony.prototype.call = function (number) { - PhoneGap.exec("Telephony.CallNumber;"+number); -}; - -// The spec say this, but the above makes more sense (to me at least) -Telephony.prototype.send = function (number) { - PhoneGap.exec("Telephony.CallNumber;"+number); -}; - -if (typeof navigator.telephony == "undefined") { - navigator.telephony = new Telephony(); -} - diff --git a/js/acceleration.js b/js/acceleration.js deleted file mode 100644 index cc48941..0000000 --- a/js/acceleration.js +++ /dev/null @@ -1,16 +0,0 @@ - -/****************************** ACCELERATION ******************************/ - -function Acceleration(x, y, z, timestamp) { - // The force applied by the device in the x-axis. - this.x = x; - - // The force applied by the device in the y-axis. - this.y = y; - - // The force applied by the device in the z-axis. - this.z = z; - - // The time that the acceleration was obtained. - this.timestamp = timestamp || new Date().getTime(); -} diff --git a/js/accelerometer.js b/js/accelerometer.js deleted file mode 100644 index b1b4622..0000000 --- a/js/accelerometer.js +++ /dev/null @@ -1,38 +0,0 @@ - -/****************************** ACCELEROMETER ******************************/ - -function Accelerometer() { - this._succssCallback = null; - this._errorCallback = null; - - this.watchAcceleration = function (win, fail, opts) { - // TODO - // return watchId - } - - this.clearWatch = function (watchId) { - // TODO - } -} - -Accelerometer.prototype.getCurrentAcceleration = function (successCallback, errorCallback, options) { - // We don't support any options so if anything is passed just ignore it - this._succssCallback = successCallback; - this._errorCallback = errorCallback; - - PhoneGap.exec("Accelerometer.GetCurrentAcceleration;getCurrentAcceleration_Success;getCurrentAcceleration_Error"); -}; - -function getCurrentAcceleration_Success(x, y, z, changedTime) { - acceleration = new Acceleration(x, y, z, changedTime); - - navigator.accelerometer._succssCallback(acceleration); -}; - -function getCurrentAcceleration_Error(errorMessage) { - navigator.accelerometer._errorCallback(errorMessage); -}; - -if (typeof navigator.accelerometer == "undefined") { - navigator.accelerometer = new Accelerometer(); -} diff --git a/js/build_phonegap.js.cmd b/js/build_phonegap.js.cmd deleted file mode 100644 index c706bc0..0000000 --- a/js/build_phonegap.js.cmd +++ /dev/null @@ -1,4 +0,0 @@ - -del phonegap.*.js -copy /b *.js phonegap._js -ren phonegap._js phonegap.%1.js \ No newline at end of file diff --git a/js/camera.js b/js/camera.js deleted file mode 100644 index acd7349..0000000 --- a/js/camera.js +++ /dev/null @@ -1,26 +0,0 @@ - -/****************************** CAMERA ******************************/ - -function Camera() { - this._succssCallback = null; - this._errorCallback = null; -} - -Camera.prototype.getPicture = function (successCallback, errorCallback, options) { - this._succssCallback = successCallback; - this._errorCallback = errorCallback; - PhoneGap.exec("Camera.GetPicture;getPicture_Success;getPicture_Error;" + options); -} - -function getPicture_Success(imageData) { - navigator.camera._succssCallback(imageData); -} - -function getPicture_Error(errorMessage) { - navigator.camera._errorCallback(errorMessage); -} - -if (typeof navigator.camera == "undefined") { - navigator.camera = new Camera(); -} - diff --git a/js/debugconsole.js b/js/debugconsole.js deleted file mode 100644 index 8eae70a..0000000 --- a/js/debugconsole.js +++ /dev/null @@ -1,83 +0,0 @@ - -/****************************** DEBUGCONSOLE ******************************/ - -/** - * This class provides access to the debugging console. - * @constructor - */ -function DebugConsole() { -} - -/** - * Utility function for rendering and indenting strings, or serializing - * objects to a string capable of being printed to the console. - * @param {Object|String} message The string or object to convert to an indented string - * @private - */ -DebugConsole.prototype.processMessage = function(message) { - if (typeof(message) != 'object') { - return message; - } else { - /** - * @function - * @ignore - */ - function indent(str) { - return str.replace(/^/mg, " "); - } - /** - * @function - * @ignore - */ - function makeStructured(obj) { - var str = ""; - for (var i in obj) { - try { - if (typeof(obj[i]) == 'object') { - str += i + ":\n" + indent(makeStructured(obj[i])) + "\n"; - } else { - str += i + " = " + indent(String(obj[i])).replace(/^ /, "") + "\n"; - } - } catch(e) { - str += i + " = EXCEPTION: " + e.message + "\n"; - } - } - return str; - } - return "Object:\n" + makeStructured(message); - } -}; - -/** - * Print a normal log message to the console - * @param {Object|String} message Message or object to print to the console - */ -DebugConsole.prototype.log = function(message) { - if (PhoneGap.available) { - PhoneGap.exec('DebugConsole;INFO;' + this.processMessage(message)); - } -}; - -/** - * Print a warning message to the console - * @param {Object|String} message Message or object to print to the console - */ -DebugConsole.prototype.warn = function(message) { - if (PhoneGap.available) { - PhoneGap.exec('DebugConsole;WARN;' + this.processMessage(message)); - } -}; - -/** - * Print an error message to the console - * @param {Object|String} message Message or object to print to the console - */ -DebugConsole.prototype.error = function(message) { - if (PhoneGap.available) { - PhoneGap.exec('DebugConsole;ERROR;' + this.processMessage(message)); - } -}; - -if (typeof window.debug == "undefined") { - window.debug = new DebugConsole(); -} diff --git a/js/device.js b/js/device.js deleted file mode 100644 index 18b7aa8..0000000 --- a/js/device.js +++ /dev/null @@ -1,12 +0,0 @@ - -/****************************** DEVICE ******************************/ - -function Device() { - this.platform = null; - this.version = null; - this.name = null; - this.uuid = null; - this.gap = null; -} - -navigator.device = window.device = new Device(); diff --git a/js/geolocation.js b/js/geolocation.js deleted file mode 100644 index 1d98ced..0000000 --- a/js/geolocation.js +++ /dev/null @@ -1,41 +0,0 @@ - -/****************************** GEOLOCATION ******************************/ - -function Geolocation() { - this._succssCallback = null; - this._errorCallback = null; - this.lastPosition = null; - - this.watchPosition = function(successCallback, errorCallback, options) { - // TODO - // return watchId - } - - this.clearWatch = function(watchId) { - // TODO - } -} - -Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) { - this._succssCallback = successCallback; - this._errorCallback = errorCallback; - - PhoneGap.exec("Geolocation.GetCurrentPosition;getCurrentPosition_Success;getCurrentPosition_Error;" + options); -}; - -function getCurrentPosition_Success(lat, lng, altitude, horizontalaccuracy, verticalaccuracy, heading, velocity, time) { - accuracy = new Accuracy(horizontalaccuracy, verticalaccuracy); - coords = new Coordinates(lat, lng, altitude, accuracy, heading, velocity); - position = new Position(coords, time); - - navigator.lastPosition = position; - navigator.geolocation._succssCallback(position); -} - -function getCurrentPosition_Error(errorMessage) { - navigator.geolocation._errorCallback(errorMessage); -} - -if (typeof navigator.geolocation == "undefined") { - navigator.geolocation = new Geolocation(); -} diff --git a/js/network.js b/js/network.js deleted file mode 100644 index bc178f7..0000000 --- a/js/network.js +++ /dev/null @@ -1,24 +0,0 @@ - -/****************************** NETWORK ******************************/ - -function Network() { - this._callback = null; -} - -Network.prototype.isReachable = function (hostName, successCallback, options) { - this._callback = successCallback; - PhoneGap.exec("Network.IsReachable;"+hostName+";networkIsReachable_Success;"+options); -}; - -function networkIsReachable_Success(reachability) { - navigator.network._callback(reachability); -} - -if (typeof navigator.network == "undefined") { - navigator.network = new Network(); -} - -function NetworkStatus() { } -NetworkStatus.NOT_REACHABLE = 0; -NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK = 1; -NetworkStatus.REACHABLE_VIA_WIFI_NETWORK = 2; diff --git a/js/notification.js b/js/notification.js deleted file mode 100644 index 3aefa98..0000000 --- a/js/notification.js +++ /dev/null @@ -1,26 +0,0 @@ - -/****************************** NOTIFICATION ******************************/ - -function Notification() { -} - -//// @title is optional -//// @button is ignored as this can't be specified in WP7 -Notification.prototype.alert = function (message, title, button) { - PhoneGap.exec("Notification.Alert;" + message + ";" + title + ";" + button); -}; - -//// The docs specify this signature -//// but all other implementations use: function(count, volume) -Notification.prototype.beep = function (times) { - PhoneGap.exec("Notification.Beep;" + times); -}; - -Notification.prototype.vibrate = function (duration) { - PhoneGap.exec("Notification.Vibrate;" + duration); -}; - -if (typeof navigator.notification == "undefined") { - navigator.notification = new Notification(); -} - diff --git a/js/orientation.js b/js/orientation.js deleted file mode 100644 index 4417c0b..0000000 --- a/js/orientation.js +++ /dev/null @@ -1,54 +0,0 @@ - -/****************************** ORIENTATION ******************************/ - -function Orientation() { - this._succssCallback = null; - this._errorCallback = null; - this._watches = new Object; - this._baseWatchId = 1; - this.currentOrientation = null; -} - -function getCurrentOrientation_Success(newOrientation) { - navigator.orientation.currentOrientation = newOrientation; - navigator.orientation._succssCallback(newOrientation); -} - -function getCurrentOrientation_Error(errorMessage) { - navigator.orientation._errorCallback(errorMessage); -} - -Orientation.prototype.getCurrentOrientation = function (successCallback, errorCallback) { - this._succssCallback = successCallback; - this._errorCallback = errorCallback; - - PhoneGap.exec("Orientation.GetCurrentOrientation;getCurrentOrientation_Success;getCurrentOrientation_Error"); -} - -Orientation.prototype.watchOrientation = function (successCallback, errorCallback) { - var newId = this._baseWatchId; - this._baseWatchId = this._baseWatchId + 1; - - // Not currently doing anything with errorCallBack - this._watches[newId] = successCallback; - PhoneGap.exec("Orientation.WatchOrientation;watchOrientation_Changed;" + newId); - - return newId; -} - -Orientation.prototype.clearWatch = function (watchId) { - this._watches[watchId] = null; - PhoneGap.exec("Orientation.ClearWatch;"+watchId); -} - -function watchOrientation_Changed(watchId, newOrientation) { - navigator.orientation.currentOrientation = newOrientation; - - if (navigator.orientation._watches[watchId] != null) { - navigator.orientation._watches[watchId](newOrientation); - } -} - -if (typeof navigator.orientation == "undefined") { - navigator.orientation = new Orientation(); -} diff --git a/js/phonegap.js.base b/js/phonegap.js.base deleted file mode 100644 index 0ba2b5d..0000000 --- a/js/phonegap.js.base +++ /dev/null @@ -1,30 +0,0 @@ - -/****************************** PHONEGAP-BASE ******************************/ - -/** - * This represents the PhoneGap API itself. - * It is dramatically simplified from other implementations as I couldn't get the queued processing of constructors working - */ -PhoneGap = { -}; - -PhoneGap.exec = function(nativeMethodAndArgs) { - window.external.Notify(nativeMethodAndArgs); -}; - -PhoneGap.available = false; - -function SetDeviceProperties(platform, version, name, uuid, gap) { - device.platform = platform; - device.version = version; - device.name = name; - device.uuid = uuid; - device.gap = gap; - - // in theory, everything is now set up and working so this is where we should fire the deviceready event - // unfortunately IE7 mobile doesn't seem to support a way of dynamically raising events - PhoneGap.available = true; -} - -// Load device info -PhoneGap.exec("Device.GetAll;SetDeviceProperties"); diff --git a/js/position.js b/js/position.js deleted file mode 100644 index 7d41e43..0000000 --- a/js/position.js +++ /dev/null @@ -1,51 +0,0 @@ - -/****************************** POSITION ******************************/ - -function Position(coords, timestamp) { - this.coords = coords; - this.timestamp = new Date().getTime(); -} - -function Accuracy(horizontal, vertical) { - this.horizontal = horizontal; - this.vertical = vertical; -} - -function Coordinates(lat, lng, alt, acc, head, vel) { - // The latitude of the position. - this.latitude = lat; - - // The longitude of the position. - this.longitude = lng; - - // The accuracy of the position. - this.accuracy = acc; - - // The altitude of the position. - this.altitude = alt; - - // The direction the device is moving at the position. - this.heading = head; - - // The velocity with which the device is moving at the position. - this.speed = vel; -} - -function PositionOptions() { - // Specifies the desired position accuracy. - this.enableHighAccuracy = false; - - // The timeout after which if position data cannot be obtained the errorCallback is called. - this.timeout = 10000; -} - -function PositionError() { - this.code = null; - this.message = ""; -} - -PositionError.UNKNOWN_ERROR = 0; -PositionError.PERMISSION_DENIED = 1; -PositionError.POSITION_UNAVAILABLE = 2; -PositionError.TIMEOUT = 3; - diff --git a/js/sms.js b/js/sms.js deleted file mode 100644 index bf398ee..0000000 --- a/js/sms.js +++ /dev/null @@ -1,21 +0,0 @@ - -/****************************** SMS ******************************/ - -function Sms() { - this._errorCallback = null; -} - -Sms.prototype.send = function (number, message, successCallback, errorCallback, options) { -// successCallback and options are not supported on WP7 - this._errorCallback = errorCallback; - PhoneGap.exec("Send.Sms;send_Error;" + number + ";" + message); -} - -function send_Error(errorMessage) { - navigator.sms._errorCallback(errorMessage); -} - -if (typeof navigator.sms == "undefined") { - navigator.sms = new Sms(); -} - diff --git a/js/telephony.js b/js/telephony.js deleted file mode 100644 index 3a391c2..0000000 --- a/js/telephony.js +++ /dev/null @@ -1,19 +0,0 @@ - -/****************************** TELEPHONY ******************************/ - -function Telephony() { -} - -Telephony.prototype.call = function (number) { - PhoneGap.exec("Telephony.CallNumber;"+number); -}; - -// The spec say this, but the above makes more sense (to me at least) -Telephony.prototype.send = function (number) { - PhoneGap.exec("Telephony.CallNumber;"+number); -}; - -if (typeof navigator.telephony == "undefined") { - navigator.telephony = new Telephony(); -} - diff --git a/tests/MobileSpecUnitTests/GapSourceDictionary.xml b/tests/MobileSpecUnitTests/GapSourceDictionary.xml index 18c5770..89220a1 100644 --- a/tests/MobileSpecUnitTests/GapSourceDictionary.xml +++ b/tests/MobileSpecUnitTests/GapSourceDictionary.xml @@ -4,26 +4,13 @@ - - - - - - - - - - - - + - - - + diff --git a/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj b/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj index f839066..f69f2e0 100644 --- a/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj +++ b/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj @@ -77,7 +77,9 @@ - + + Designer + @@ -94,7 +96,6 @@ Designer - Designer @@ -117,29 +118,20 @@ - - - - - - - - Designer - - + Designer diff --git a/tests/MobileSpecUnitTests/www/accelerometer.html b/tests/MobileSpecUnitTests/www/accelerometer.html index df2ad2d..b4e3d6c 100644 --- a/tests/MobileSpecUnitTests/www/accelerometer.html +++ b/tests/MobileSpecUnitTests/www/accelerometer.html @@ -24,8 +24,7 @@ - - + - - - - - - - - - - - + + @@ -61,9 +63,14 @@ + + + - +

PhoneGap API Spec

diff --git a/tests/MobileSpecUnitTests/www/camera.html b/tests/MobileSpecUnitTests/www/camera.html index 131a97d..4772e70 100644 --- a/tests/MobileSpecUnitTests/www/camera.html +++ b/tests/MobileSpecUnitTests/www/camera.html @@ -21,8 +21,7 @@ console.log("Installed console ! "); - - + - - - + - - + + - - + + - + - - - + - + diff --git a/tests/MobileSpecUnitTests/www/main.js b/tests/MobileSpecUnitTests/www/main.js deleted file mode 100644 index ae447aa..0000000 --- a/tests/MobileSpecUnitTests/www/main.js +++ /dev/null @@ -1,140 +0,0 @@ -var deviceInfo = function() { - document.getElementById("platform").innerHTML = device.platform; - document.getElementById("version").innerHTML = device.version; - document.getElementById("uuid").innerHTML = device.uuid; - document.getElementById("name").innerHTML = device.name; - document.getElementById("width").innerHTML = screen.width; - document.getElementById("height").innerHTML = screen.height; - document.getElementById("colorDepth").innerHTML = screen.colorDepth; -}; - -var getLocation = function() { - var suc = function(p) { - alert(p.coords.latitude + " " + p.coords.longitude); - }; - var locFail = function() { - }; - navigator.geolocation.getCurrentPosition(suc, locFail); -}; - -var beep = function() { - navigator.notification.beep(2); -}; - -var vibrate = function() { - navigator.notification.vibrate(0); -}; - -function roundNumber(num) { - var dec = 3; - var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec); - return result; -} - -var accelerationWatch = null; - -function updateAcceleration(a) { - document.getElementById('x').innerHTML = roundNumber(a.x); - document.getElementById('y').innerHTML = roundNumber(a.y); - document.getElementById('z').innerHTML = roundNumber(a.z); -} - -var toggleAccel = function() { - if (accelerationWatch !== null) { - navigator.accelerometer.clearWatch(accelerationWatch); - updateAcceleration({ - x : "", - y : "", - z : "" - }); - accelerationWatch = null; - } else { - var options = {}; - options.frequency = 1000; - accelerationWatch = navigator.accelerometer.watchAcceleration( - updateAcceleration, function(ex) { - alert("accel fail (" + ex.name + ": " + ex.message + ")"); - }, options); - } -}; - -var preventBehavior = function(e) { - e.preventDefault(); -}; - -function dump_pic(data) { - var viewport = document.getElementById('viewport'); - console.log(data); - viewport.style.display = ""; - viewport.style.position = "absolute"; - viewport.style.top = "10px"; - viewport.style.left = "10px"; - document.getElementById("test_img").src = "data:image/jpeg;base64," + data; -} - -function fail(msg) { - alert(msg); -} - -function show_pic() { - navigator.camera.getPicture(dump_pic, fail, { - quality : 50 - }); -} - -function close() { - var viewport = document.getElementById('viewport'); - viewport.style.position = "relative"; - viewport.style.display = "none"; -} - -// This is just to do this. -function readFile() { - navigator.file.read('/sdcard/phonegap.txt', fail, fail); -} - -function writeFile() { - navigator.file.write('foo.txt', "This is a test of writing to a file", - fail, fail); -} - -function contacts_success(contacts) { - alert(contacts.length - + ' contacts returned.' - + (contacts[2] && contacts[2].name ? (' Third contact is ' + contacts[2].name.formatted) - : '')); -} - -function get_contacts() { - var obj = new ContactFindOptions(); - obj.filter = ""; - obj.multiple = true; - obj.limit = 5; - navigator.service.contacts.find( - [ "displayName", "name" ], contacts_success, - fail, obj); -} - -var networkReachableCallback = function(reachability) { - // There is no consistency on the format of reachability - var networkState = reachability.code || reachability; - - var currentState = {}; - currentState[NetworkStatus.NOT_REACHABLE] = 'No network connection'; - currentState[NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK] = 'Carrier data connection'; - currentState[NetworkStatus.REACHABLE_VIA_WIFI_NETWORK] = 'WiFi connection'; - - confirm("Connection type:\n" + currentState[networkState]); -}; - -function check_network() { - navigator.network.isReachable("www.mobiledevelopersolutions.com", - networkReachableCallback, {}); -} - -function init() { - // the next line makes it impossible to see Contacts on the HTC Evo since it - // doesn't have a scroll button - // document.addEventListener("touchmove", preventBehavior, false); - document.addEventListener("deviceready", deviceInfo, true); -} diff --git a/tests/MobileSpecUnitTests/www/master.css b/tests/MobileSpecUnitTests/www/master.css index d377072..0335319 100644 --- a/tests/MobileSpecUnitTests/www/master.css +++ b/tests/MobileSpecUnitTests/www/master.css @@ -1,11 +1,11 @@ body { - background:#222 none repeat scroll 0 0; - color:#666; - font-family:Helvetica, Verdana, Geneva, sans-serif; - font-size:72%; - line-height:1.5em; - margin:0; - border-top:1px solid #393939; + background:#222 none repeat scroll 0 0; + color:#FFC312; + font-family:Helvetica, Verdana, Geneva, sans-serif; + font-size:72%; + line-height:1.5em; + margin:0; + border-top:1px solid #393939; } #info{ diff --git a/tests/MobileSpecUnitTests/www/network.html b/tests/MobileSpecUnitTests/www/network.html index 404a1e3..dc14464 100644 --- a/tests/MobileSpecUnitTests/www/network.html +++ b/tests/MobileSpecUnitTests/www/network.html @@ -22,8 +22,7 @@ console.log("Installed console ! "); - - + - - + - +