Skip to content

Commit

Permalink
Concatted JS, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
purplecabbage committed Sep 8, 2011
1 parent 15c94db commit bd1ae4b
Show file tree
Hide file tree
Showing 69 changed files with 3,538 additions and 6,969 deletions.
11 changes: 4 additions & 7 deletions framework/PGView.xaml.cs
Expand Up @@ -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")
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions framework/PhoneGap/PhoneGapCommandCall.cs
Expand Up @@ -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;
}

Expand Down
11 changes: 0 additions & 11 deletions framework/js/.disclaimer.js

This file was deleted.

16 changes: 0 additions & 16 deletions framework/js/acceleration.js

This file was deleted.

71 changes: 42 additions & 29 deletions framework/js/accelerometer.js
Expand Up @@ -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 */
Expand Down Expand Up @@ -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.
*
Expand All @@ -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") {
Expand All @@ -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);
};

/**
Expand All @@ -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();
}
});
Expand Down
86 changes: 0 additions & 86 deletions framework/js/app.js

This file was deleted.

4 changes: 2 additions & 2 deletions framework/js/build_phonegap.js.cmd
@@ -1,4 +1,4 @@

del phonegap.*.js
copy /b *.js phonegap._js
ren phonegap._js phonegap.%1.js
copy /b disclaimer.txt+phonegap.js.base+*.js phonegap._js
ren phonegap._js phonegap.1.0.js
90 changes: 46 additions & 44 deletions framework/js/camera.js
Expand Up @@ -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");
Expand All @@ -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() {
Expand Down

0 comments on commit bd1ae4b

Please sign in to comment.