framework/www/phonegap.js
author Ryan Willoughby <ryan.willoughby@nitobi.com>
Tue, 06 Jul 2010 11:31:19 -0700
changeset 0 54063d8b0412
permissions -rwxr-xr-x
initial commit of PhoneGap WRT framework, licensing and test code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
     1
if (typeof(DeviceInfo) != 'object')
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
     2
    DeviceInfo = {};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
     3
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
     4
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
     5
 * This represents the PhoneGap API itself, and provides a global namespace for accessing
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
     6
 * information about the state of PhoneGap.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
     7
 * @class
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
     8
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
     9
PhoneGap = {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    10
    queue: {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    11
        ready: true,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    12
        commands: [],
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    13
        timer: null
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    14
    },
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    15
    _constructors: []
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    16
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    17
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    18
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    19
 * Boolean flag indicating if the PhoneGap API is available and initialized.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    20
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    21
PhoneGap.available = DeviceInfo.uuid != undefined;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    22
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    23
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    24
 * Execute a PhoneGap command in a queued fashion, to ensure commands do not
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    25
 * execute with any race conditions, and only run when PhoneGap is ready to
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    26
 * recieve them.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    27
 * @param {String} command Command to be run in PhoneGap, e.g. "ClassName.method"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    28
 * @param {String[]} [args] Zero or more arguments to pass to the method
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    29
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    30
PhoneGap.exec = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    31
    PhoneGap.queue.commands.push(arguments);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    32
    if (PhoneGap.queue.timer == null)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    33
        PhoneGap.queue.timer = setInterval(PhoneGap.run_command, 10);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    34
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    35
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    36
 * Internal function used to dispatch the request to PhoneGap.  This needs to be implemented per-platform to
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    37
 * ensure that methods are called on the phone in a way appropriate for that device.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    38
 * @private
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    39
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    40
PhoneGap.run_command = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    41
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    42
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    43
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    44
 * This class contains acceleration information
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    45
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    46
 * @param {Number} x The force applied by the device in the x-axis.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    47
 * @param {Number} y The force applied by the device in the y-axis.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    48
 * @param {Number} z The force applied by the device in the z-axis.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    49
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    50
function Acceleration(x, y, z) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    51
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    52
	 * The force applied by the device in the x-axis.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    53
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    54
	this.x = x;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    55
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    56
	 * The force applied by the device in the y-axis.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    57
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    58
	this.y = y;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    59
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    60
	 * The force applied by the device in the z-axis.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    61
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    62
	this.z = z;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    63
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    64
	 * The time that the acceleration was obtained.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    65
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    66
	this.timestamp = new Date().getTime();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    67
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    68
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    69
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    70
 * This class specifies the options for requesting acceleration data.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    71
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    72
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    73
function AccelerationOptions() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    74
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    75
	 * The timeout after which if acceleration data cannot be obtained the errorCallback
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    76
	 * is called.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    77
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    78
	this.timeout = 10000;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    79
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    80
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    81
 * This class provides access to device accelerometer data.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    82
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    83
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    84
function Accelerometer() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    85
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    86
	 * The last known acceleration.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    87
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    88
	this.lastAcceleration = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    89
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    90
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    91
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    92
 * Asynchronously aquires the current acceleration.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    93
 * @param {Function} successCallback The function to call when the acceleration
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    94
 * data is available
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    95
 * @param {Function} errorCallback The function to call when there is an error 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    96
 * getting the acceleration data.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    97
 * @param {AccelerationOptions} options The options for getting the accelerometer data
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    98
 * such as timeout.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
    99
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   100
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   101
Accelerometer.prototype.getCurrentAcceleration = function(successCallback, errorCallback, options) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   102
	// If the acceleration is available then call success
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   103
	// If the acceleration is not available then call error
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   104
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   105
	try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   106
		if (!this.serviceObj) 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   107
			this.serviceObj = this.getServiceObj();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   108
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   109
		if (this.serviceObj == null) 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   110
			throw {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   111
				name: "DeviceErr",
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   112
				message: "Could not initialize service object"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   113
			};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   114
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   115
		//get the sensor channel
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   116
		var SensorParams = {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   117
			SearchCriterion: "AccelerometerAxis"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   118
		};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   119
		var returnvalue = this.serviceObj.ISensor.FindSensorChannel(SensorParams);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   120
		var error = returnvalue["ErrorCode"];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   121
		var errmsg = returnvalue["ErrorMessage"];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   122
		if (!(error == 0 || error == 1012)) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   123
			var ex = {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   124
				name: "Unable to find Sensor Channel: " + error,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   125
				message: errmsg
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   126
			};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   127
			throw ex;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   128
		}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   129
		var channelInfoMap = returnvalue["ReturnValue"][0];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   130
		var criteria = {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   131
			ChannelInfoMap: channelInfoMap,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   132
			ListeningType: "ChannelData"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   133
		};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   134
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   135
		if (typeof(successCallback) != 'function') 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   136
			successCallback = function(){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   137
			};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   138
		if (typeof(errorCallback) != 'function') 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   139
			errorCallback = function(){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   140
			};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   141
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   142
		this.success_callback = successCallback;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   143
		this.error_callback = errorCallback;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   144
		//create a closure to persist this instance of Accelerometer into the RegisterForNofication callback
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   145
		var obj = this;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   146
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   147
		// TODO: this call crashes WRT, but there is no other way to read the accel sensor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   148
		// http://discussion.forum.nokia.com/forum/showthread.php?t=182151&highlight=memory+leak
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   149
		this.serviceObj.ISensor.RegisterForNotification(criteria, function(transId, eventCode, result){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   150
			try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   151
				var criteria = {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   152
					TransactionID: transId
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   153
				};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   154
				obj.serviceObj.ISensor.Cancel(criteria);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   155
				
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   156
				var accel = new Acceleration(result.ReturnValue.XAxisData, result.ReturnValue.YAxisData, result.ReturnValue.ZAxisData);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   157
				Accelerometer.lastAcceleration = accel;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   158
				
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   159
				obj.success_callback(accel);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   160
				
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   161
			} 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   162
			catch (ex) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   163
				obj.serviceObj.ISensor.Cancel(criteria);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   164
				obj.error_callback(ex);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   165
			}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   166
			
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   167
		});
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   168
	} catch (ex) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   169
		errorCallback(ex);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   170
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   171
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   172
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   173
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   174
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   175
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   176
 * Asynchronously aquires the acceleration repeatedly at a given interval.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   177
 * @param {Function} successCallback The function to call each time the acceleration
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   178
 * data is available
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   179
 * @param {Function} errorCallback The function to call when there is an error 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   180
 * getting the acceleration data.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   181
 * @param {AccelerationOptions} options The options for getting the accelerometer data
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   182
 * such as timeout.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   183
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   184
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   185
Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallback, options) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   186
	this.getCurrentAcceleration(successCallback, errorCallback, options);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   187
	// TODO: add the interval id to a list so we can clear all watches
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   188
 	var frequency = (options != undefined)? options.frequency : 10000;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   189
	return setInterval(function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   190
		navigator.accelerometer.getCurrentAcceleration(successCallback, errorCallback, options);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   191
	}, frequency);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   192
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   193
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   194
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   195
 * Clears the specified accelerometer watch.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   196
 * @param {String} watchId The ID of the watch returned from #watchAcceleration.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   197
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   198
Accelerometer.prototype.clearWatch = function(watchId) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   199
	clearInterval(watchId);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   200
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   201
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   202
//gets the Acceleration Service Object from WRT
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   203
Accelerometer.prototype.getServiceObj = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   204
	var so;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   205
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   206
    try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   207
        so = device.getServiceObject("Service.Sensor", "ISensor");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   208
    } catch (ex) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   209
		throw {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   210
			name: "DeviceError",
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   211
			message: "Could not initialize accel service object (" + ex.name + ": " + ex.message + ")"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   212
		};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   213
    }		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   214
	return so;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   215
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   216
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   217
if (typeof navigator.accelerometer == "undefined") navigator.accelerometer = new Accelerometer();/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   218
 * This class provides access to the device media, interfaces to both sound and video
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   219
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   220
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   221
function Audio(src, successCallback, errorCallback) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   222
	this.src = src;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   223
	this.successCallback = successCallback;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   224
	this.errorCallback = errorCallback;												
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   225
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   226
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   227
Audio.prototype.record = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   228
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   229
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   230
Audio.prototype.play = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   231
try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   232
	if (document.getElementById('gapsound'))
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   233
		document.body.removeChild(document.getElementById('gapsound'));
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   234
	var obj;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   235
	obj = document.createElement("embed");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   236
	obj.setAttribute("id", "gapsound");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   237
	obj.setAttribute("type", "audio/x-mpeg");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   238
	obj.setAttribute("width", "0");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   239
	obj.setAttribute("width", "0");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   240
	obj.setAttribute("hidden", "true");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   241
	obj.setAttribute("autostart", "true");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   242
	obj.setAttribute("src", this.src);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   243
	document.body.appendChild(obj);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   244
} catch (ex) { debug.log(ex.name + ": " + ex.message); }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   245
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   246
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   247
Audio.prototype.pause = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   248
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   249
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   250
Audio.prototype.stop = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   251
	document.body.removeChild(document.getElementById('gapsound'));
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   252
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   253
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   254
 * This class provides access to the device camera.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   255
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   256
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   257
function Camera() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   258
	this.success_callback = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   259
	this.error_callback = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   260
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   261
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   262
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   263
 * We use the Platform Services 2.0 API here. So we must include a portion of the
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   264
 * PS 2.0 source code (camera API). 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   265
 * @param {Function} successCallback
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   266
 * @param {Function} errorCallback
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   267
 * @param {Object} options
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   268
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   269
Camera.prototype.getPicture = function(successCallback, errorCallback, options){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   270
	try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   271
		if (!this.serviceObj) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   272
			this.serviceObj = com.nokia.device.load("", "com.nokia.device.camera", "");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   273
		}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   274
		if (!this.serviceObj) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   275
			throw {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   276
				name: "CameraError",
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   277
				message: "could not load camera service"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   278
			};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   279
		}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   280
		var obj = this;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   281
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   282
		obj.success_callback = successCallback;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   283
		obj.error_callback = errorCallback;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   284
		this.serviceObj.startCamera( function(transactionID, errorCode, outPut) { 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   285
			//outPut should be an array of image urls (local), or an error code
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   286
			if (errorCode == 0) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   287
				obj.success_callback(outPut);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   288
			}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   289
			else {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   290
				obj.error_callback({
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   291
					name: "CameraError",
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   292
					message: errorCode
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   293
				});
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   294
			}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   295
		});
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   296
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   297
	} catch (ex) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   298
		errorCallback.call(ex);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   299
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   300
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   301
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   302
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   303
if (typeof navigator.camera == "undefined") navigator.camera = new Camera();/*
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   304
Copyright © 2009 Nokia. All rights reserved.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   305
Code licensed under the BSD License:
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   306
Software License Agreement (BSD License) Copyright © 2009 Nokia.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   307
All rights reserved.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   308
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   309
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   310
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   311
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   312
Neither the name of Nokia Corporation. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Nokia Corporation. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   313
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   314
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   315
version: 1.0
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   316
*/
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   317
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   318
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   319
// utility.js
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   320
//
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   321
// This file contains some utility functions for S60 providers
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   322
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   323
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   324
// Start an application and wait for it to exit
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   325
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   326
//TBD: Get rid of this global, use closures instead
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   327
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   328
DeviceError.prototype = new Error(); //inheritance occurs here
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   329
DeviceError.prototype.constructor = DeviceError; //If this not present then, it uses default constructor of Error
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   330
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   331
//constructor for DeviceError.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   332
function DeviceError(message,code) 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   333
{
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   334
	this.toString = concatenate;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   335
	this.code = code;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   336
	this.name = "DeviceException";//we can even overwrite default name "Error"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   337
	this.message=message; 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   338
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   339
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   340
function concatenate()
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   341
{
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   342
	return (this.name+":"+" "+this.message+" "+this.code);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   343
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   344
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   345
function splitErrorMessage(errmessage)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   346
{
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   347
	if(errmessage.search(/:/)!=-1)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   348
	{
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   349
		if((errmessage.split(":").length)==2)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   350
		{
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   351
			return errmessage.split(":")[1];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   352
		}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   353
		if((errmessage.split(":").length)>2)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   354
		{
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   355
			return errmessage.split(":")[2];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   356
		}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   357
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   358
	return errmessage;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   359
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   360
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   361
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   362
var __s60_start_and_wait_cb;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   363
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   364
function __s60_on_app_exit(){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   365
  widget.onshow = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   366
  if(__s60_start_and_wait_cb != null){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   367
    __s60_start_and_wait_cb();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   368
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   369
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   370
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   371
function __s60_on_app_start(){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   372
  widget.onhide = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   373
  widget.onshow = __s60_on_app_exit;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   374
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   375
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   376
// This function cannot actually force JS to wait,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   377
// but it does supply a callback the apps can use
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   378
// to continue processing on return from the app.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   379
// Apps should take care not to reinvoke this and
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   380
// should be careful about any other processing
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   381
// that might happen while the app is running.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   382
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   383
function __s60_start_and_wait(id, args, app_exit_cb){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   384
  __s60_start_and_wait_cb = app_exit_cb;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   385
  widget.onhide = __s60_on_app_start;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   386
  widget.openApplication(id, args);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   387
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   388
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   389
function __s60_api_not_supported(){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   390
  throw(err_ServiceNotSupported);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   391
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   392
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   393
function __s60_enumerate_object(object, namespace, func, param){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   394
    var key;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   395
    for(key in object){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   396
       
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   397
        var propname;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   398
       	if(namespace){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   399
	    propname = namespace + "." + key;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   400
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   401
	else{
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   402
	    propname = key;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   403
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   404
        var value = object[key];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   405
        if(typeof value == "object"){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   406
	  __s60_enumerate_object(value, propname, func, param);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   407
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   408
	else {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   409
	  func(propname,value, param);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   410
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   411
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   412
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   413
/*
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   414
Copyright © 2009 Nokia. All rights reserved.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   415
Code licensed under the BSD License:
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   416
Software License Agreement (BSD License) Copyright © 2009 Nokia.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   417
All rights reserved.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   418
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   419
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   420
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   421
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   422
Neither the name of Nokia Corporation. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Nokia Corporation. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   423
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   424
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   425
version: 1.0
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   426
*/
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   427
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   428
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   429
var __device_debug_on__ = true;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   430
var err_missing_argument = 1003;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   431
var event_cancelled = 3;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   432
var err_bad_argument = 1002;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   433
var err_InvalidService_Argument = 1000;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   434
var err_ServiceNotReady = 1006;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   435
var err_ServiceNotSupported = 1004;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   436
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   437
function __device_debug(text){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   438
  //if(__device_debug_on__) alert(text);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   439
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   440
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   441
function __device_handle_exception(e, text){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   442
	__device_debug(text);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   443
	throw(e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   444
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   445
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   446
function __device_typeof(value)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   447
{
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   448
	// First check to see if the value is undefined.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   449
	if (value == undefined) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   450
        return "undefined";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   451
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   452
	// Check for objects created with the "new" keyword.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   453
	if (value instanceof Object) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   454
		// Check whether it's a string object.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   455
		if (value instanceof String) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   456
			return "String";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   457
		}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   458
		// Check whether it's an array object/array literal.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   459
		else 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   460
			if (value instanceof Array) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   461
				return "Array";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   462
			}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   463
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   464
	// dealing with a literal.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   465
		if (typeof value) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   466
			if (typeof value == "object") {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   467
				if (typeof value == "object" && !value) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   468
					return "null";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   469
				}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   470
			}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   471
           // if not null check for other types
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   472
			
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   473
				// Check if it's a string literal.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   474
			else if (typeof value == "string") {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   475
					return "string";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   476
				}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   477
		}	 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   478
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   479
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   480
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   481
// The top-level service object. It would be nice to use a namespace here 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   482
// (com.nokia.device.service), but emulating namespaces still allows name clashes.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   483
/*
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   484
var sp_device = {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   485
        //services: null; // TBD: Make the services list a member of this object?
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   486
	load: __device_service_load,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   487
        listServices: __device_service_list,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   488
        listInterfaces: __device_service_interfaces,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   489
        version: "0.1",
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   490
        info: "device prototype"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   491
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   492
*/
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   493
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   494
if(undefined == com)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   495
    var com={};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   496
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   497
if( typeof com != "object")
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   498
    throw("com defined as non object");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   499
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   500
if(undefined == com.nokia)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   501
    com.nokia = {};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   502
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   503
if( typeof com.nokia != "object")
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   504
    throw("com.nokia defined as non object");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   505
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   506
if(undefined == com.nokia.device)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   507
    com.nokia.device = {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   508
        load: __device_service_load,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   509
        listServices: __device_service_list,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   510
        listInterfaces: __device_service_interfaces,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   511
        version: "0.1",
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   512
        info: "device prototype"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   513
        };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   514
else
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   515
    throw("com.nokia.device already defined");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   516
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   517
com.nokia.device.SORT_ASCENDING = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   518
com.nokia.device.SORT_DESCENDING = 1;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   519
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   520
com.nokia.device.SORT_BY_DATE = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   521
com.nokia.device.SORT_BY_SENDER = 1;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   522
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   523
com.nokia.device.STATUS_READ = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   524
com.nokia.device.STATUS_UNREAD = 1;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   525
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   526
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   527
// Configure the services offered.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   528
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   529
var __device_services_inited = false;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   530
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   531
var __device_services = [
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   532
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   533
  // For now, the only service is the base "device"" service
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   534
  {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   535
    "name":"com.nokia.device",
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   536
    "version": 0.1, 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   537
    "interfaces": []
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   538
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   539
];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   540
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   541
// Initialize the configured services.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   542
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   543
function __device_services_init(){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   544
  if(__device_services_inited){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   545
    return;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   546
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   547
  __device_services_inited = true;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   548
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   549
  // Get the service-specific service entries. Note that these
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   550
  // need to be individually wrapped by try/catch blocks so that the
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   551
  // interpreter gracefully handles missing services. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   552
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   553
  try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   554
    __device_services[0].interfaces.push(__device_geolocation_service_entry);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   555
  }catch (e){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   556
    __device_debug("Missing library implementation: " + e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   557
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   558
  try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   559
    __device_services[0].interfaces.push(__device_camera_service_entry);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   560
  }catch (e){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   561
    __device_debug("Missing library implementation: " + e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   562
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   563
  try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   564
    __device_services[0].interfaces.push(__device_media_service_entry);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   565
  }catch (e){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   566
//    __device_debug("Missing library implementation: " + e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   567
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   568
  try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   569
    __device_services[0].interfaces.push(__device_contacts_service_entry);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   570
  }catch (e){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   571
//    __device_debug("Missing library implementation: " + e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   572
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   573
 try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   574
    __device_services[0].interfaces.push(__device_messaging_service_entry);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   575
  }catch (e){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   576
      __device_debug("Missing library implementation: " + e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   577
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   578
  try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   579
    __device_services[0].interfaces.push(__device_calendar_service_entry);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   580
  }catch (e){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   581
      __device_debug("Missing library implementation: " + e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   582
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   583
  try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   584
    __device_services[0].interfaces.push(__device_landmarks_service_entry);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   585
  }catch (e){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   586
      __device_debug("Missing library implementation: " + e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   587
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   588
  try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   589
    __device_services[0].interfaces.push(__device_event_service_entry);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   590
  }catch (e){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   591
      __device_debug("Missing library implementation: " + e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   592
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   593
  try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   594
    __device_services[0].interfaces.push(__device_sysinfo_service_entry);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   595
  }catch (e){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   596
      __device_debug("Missing library implementation: " + e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   597
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   598
  try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   599
    __device_services[0].interfaces.push(__device_sensors_service_entry);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   600
  }catch (e){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   601
      __device_debug("Missing library implementation: " + e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   602
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   603
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   604
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   605
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   606
function __device_get_implementation(i){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   607
  //__device_debug("get_implementation: " + i);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   608
  return  new i.proto(new(i.providers[0].instance));
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   609
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   610
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   611
function __device_get_descriptor(i){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   612
  //__device_debug("get_descriptor: " + i);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   613
  return new i.descriptor(new(i.providers[0].descriptor));
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   614
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   615
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   616
function __device_get_interface(s, interfaceName, version){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   617
  //__device_debug("get_interface: " + s + " " + interfaceName);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   618
  var i = s.interfaces;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   619
  if((interfaceName == null) || (interfaceName == '')){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   620
    // Interface name not specified, get first interface, ignoring version
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   621
    return __device_get_implementation(i[0]);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   622
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   623
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   624
  // Find first match of name and version
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   625
  for (var d in i){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   626
  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   627
    if(i[d].name == null){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   628
      __device_update_descriptor(i[d]);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   629
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   630
    if(i[d].name == undefined){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   631
      continue;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   632
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   633
    if (i[d].name == interfaceName){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   634
      // Match version if specified
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   635
      if ((version == null) || (version == '') || (i[d].version >= version)){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   636
	return __device_get_implementation(i[d]);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   637
      }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   638
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   639
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   640
  return null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   641
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   642
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   643
// Implemention of the load method
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   644
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   645
function __device_service_load(serviceName, interfaceName, version){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   646
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   647
  __device_services_init();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   648
  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   649
  // Service name is specified
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   650
   if ((serviceName != null) && (serviceName != '') &&(serviceName != "*")){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   651
    for(var s in __device_services){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   652
      if (serviceName == __device_services[s].name){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   653
	return __device_get_interface(__device_services[s], interfaceName, version);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   654
      }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   655
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   656
  // Service name not specified, get first implementation 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   657
  } else {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   658
    //__device_debug("Trying to get interface implementations: ");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   659
    for(var s in __device_services){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   660
      //__device_debug("service_load: " + s + ":" +  __device_services[s].name + ": " + interfaceName);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   661
      var i = __device_get_interface(__device_services[s], interfaceName, version);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   662
      if (i != null){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   663
	return i;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   664
      }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   665
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   666
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   667
  return null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   668
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   669
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   670
// Lazily fill in the descriptor table
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   671
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   672
function __device_update_descriptor(i){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   673
  var d = __device_get_descriptor(i);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   674
  i.name = d.interfaceName;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   675
  i.version = d.version;  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   676
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   677
// Get an array of interface descriptors for a service
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   678
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   679
function __device_interface_list(s){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   680
  var retval = new Array();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   681
  for(var i in s.interfaces){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   682
    if(s.interfaces[i].name == null){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   683
      __device_update_descriptor(s.interfaces[i]);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   684
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   685
    if(s.interfaces[i].name == undefined){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   686
      continue;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   687
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   688
    retval[i] = new Object();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   689
    retval[i].name = s.interfaces[i].name;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   690
    retval[i].version = s.interfaces[i].version;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   691
  }  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   692
  return retval;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   693
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   694
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   695
// Get a service description
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   696
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   697
function __device_service_descriptor(s){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   698
  this.name = s.name;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   699
  this.version = s.version;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   700
  this.interfaces = __device_interface_list(s);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   701
  this.toString = __device_service_descriptor_to_string;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   702
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   703
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   704
function __device_service_descriptor_to_string(){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   705
  var is = "\nInterfaces(s): ";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   706
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   707
  for (i in this.interfaces){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   708
    is += "\n" + this.interfaces[i].name + " " + this.interfaces[0].version;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   709
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   710
  return ("Service: " + this.name + is);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   711
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   712
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   713
// Implement the listServices method 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   714
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   715
function __device_service_list(serviceName, interfaceName, version){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   716
  //__device_debug("__device_service_list: " + serviceName + " " + interfaceName);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   717
  __device_services_init();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   718
  var retval = new Array();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   719
  var n = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   720
  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   721
  //Treat empty service and interface names as wildcards
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   722
  if ((serviceName == null)|| (serviceName == '')/* || (serviceName == undefined)*/){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   723
    serviceName = ".*"; 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   724
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   725
  if ((interfaceName == null) || (interfaceName == '') /*|| (serviceName == undefined)*/){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   726
    interfaceName = ".*";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   727
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   728
 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   729
  if ((typeof serviceName != "string") || (typeof interfaceName != "string")) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   730
  	return retval;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   731
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   732
  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   733
  // This method does regular expression matching of service and interface
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   734
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   735
  var sregx = new RegExp(serviceName);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   736
  var iregx = new RegExp(interfaceName);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   737
 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   738
  for(var s in __device_services){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   739
   //__device_debug (serviceName + "==" + __device_services[s].name + "?:" + sregx.test(__device_services[s].name));
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   740
    if (sregx.test(__device_services[s].name)){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   741
      // Find the first matching interface 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   742
        
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   743
      for(var i in __device_services[s].interfaces){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   744
        if(__device_services[s].interfaces[i].name == null){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   745
          __device_update_descriptor(__device_services[s].interfaces[i]);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   746
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   747
        if(__device_services[s].interfaces[i].name == undefined){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   748
	  continue;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   749
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   750
	//__device_debug (interfaceName + "==" + __device_services[s].interfaces[i].name + "?:" + iregx.test(__device_services[s].interfaces[i].name));
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   751
	if (iregx.test(__device_services[s].interfaces[i].name)){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   752
	  if ((version == null) || (version == '') || (__device_services[s].interfaces[i].version >= version)){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   753
            // An interface matched, we're done.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   754
            retval[n] = new __device_service_descriptor(__device_services[s]);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   755
            break; 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   756
	  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   757
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   758
      }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   759
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   760
    ++n;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   761
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   762
  return retval;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   763
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   764
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   765
// Implement the listInterfaces method
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   766
    
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   767
function __device_service_interfaces(serviceName){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   768
  __device_services_init();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   769
  if(serviceName==null||serviceName==undefined||serviceName==''){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   770
  	throw new DeviceError("Framework: listInterfaces: serviceName is missing", err_missing_argument);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   771
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   772
  for (var s in __device_services){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   773
    if(__device_services[s].name == serviceName){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   774
      return __device_interface_list(__device_services[s]);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   775
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   776
  }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   777
  return null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   778
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   779
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   780
function modifyObjectBaseProp(obj){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   781
  for (pro in obj) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   782
    if(typeof obj[pro] == "function" )
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   783
      obj[pro] = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   784
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   785
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   786
/*
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   787
Copyright © 2009 Nokia. All rights reserved.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   788
Code licensed under the BSD License:
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   789
Software License Agreement (BSD License) Copyright © 2009 Nokia.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   790
All rights reserved.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   791
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   792
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   793
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   794
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   795
Neither the name of Nokia Corporation. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Nokia Corporation. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   796
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   797
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   798
version: 1.0
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   799
*/
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   800
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   801
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   802
// S60 sp-based camera provider
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   803
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   804
function __sp_camera_descriptor(){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   805
  //__device_debug("sp_camera_descriptor");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   806
  //Read-only properties
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   807
  this.interfaceName = "com.nokia.device.camera";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   808
  this.version = "0.1";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   809
  //Class-static properties 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   810
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   811
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   812
// TBD make local to closure funcs
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   813
var __sp_camera_start_date;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   814
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   815
function __sp_camera_instance(){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   816
  //__device_debug("sp_camera_instance");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   817
  //Descriptor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   818
  this.descriptor = new __sp_camera_descriptor();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   819
  //Core methods
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   820
  this.startCamera = __sp_startCamera;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   821
  this.stopViewfinder = __s60_api_not_supported;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   822
  //Extended methods
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   823
  this.takePicture = __s60_api_not_supported;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   824
  //Private data
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   825
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   826
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   827
var CAMERA_APP_ID = 0x101f857a;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   828
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   829
//Apps should take care that this is not reinvoked
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   830
//while the viewfinder is running. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   831
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   832
function __sp_startCamera(camera_cb){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   833
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   834
	//If callback is null , then return missing argument error
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   835
    if( camera_cb == null )
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   836
        throw new DeviceError("Camera:startCamera:callback is missing", err_missing_argument);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   837
        
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   838
	//If the callback is not a function, then return bad type error
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   839
	if( typeof(camera_cb) != "function" )
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   840
	    throw new DeviceError("Camera:startCamera:callback is a non-function", err_bad_argument);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   841
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   842
  var finished = function (){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   843
    var invoker = function (arg1, arg2, arg3){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   844
      //__device_debug("invoker with: " + camera_cb);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   845
      var it = arg3.ReturnValue;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   846
      var item;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   847
      var items = new Array();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   848
      while (( item = it.getNext()) != undefined){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   849
          var d = new Date(Date.parse(item.FileDate));
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   850
          //__device_debug(item.FileName + " " + d );
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   851
          // Items returned in reverse date order, so stop iterating before
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   852
          // reaching initial date. (Should be able to do this more efficiently
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   853
          // with sp filter, but that doesn't seem to work right now.)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   854
          if (d > __sp_camera_start_date) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   855
              var pathname = item.FileNameAndPath.replace(/\\/g, "/");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   856
              var fileScheme = "file:///";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   857
              //Non-patched builds don't allow file scheme TBD: change this for patched builds
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   858
              items.unshift(fileScheme + pathname);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   859
          }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   860
      }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   861
      var dummyTransID = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   862
      var dummyStatusCode = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   863
      camera_cb(dummyTransID, dummyStatusCode, items);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   864
    };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   865
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   866
    
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   867
    //When camera returns, get the image(s) created
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   868
    try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   869
      var mso = device.getServiceObject("Service.MediaManagement", "IDataSource");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   870
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   871
    catch(e) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   872
      __device_handle_exception (e, "media service not available : " + e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   873
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   874
    
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   875
    var criteria = new Object();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   876
	modifyObjectBaseProp(criteria);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   877
    criteria.Type = 'FileInfo';
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   878
    criteria.Filter = new Object();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   879
	modifyObjectBaseProp(criteria.Filter);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   880
    criteria.Filter.FileType = 'Image';
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   881
    //criteria.Filter.Key = 'FileDate';
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   882
    //criteria.Filter.StartRange = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   883
    //criteria.Filter.EndRange = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   884
    criteria.Sort = new Object();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   885
	modifyObjectBaseProp(criteria.Sort);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   886
    criteria.Sort.Key = 'FileDate';
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   887
    criteria.Sort.Order = 'Descending';
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   888
    
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   889
    try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   890
      var rval = mso.IDataSource.GetList(criteria, invoker);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   891
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   892
    catch (e) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   893
      __device_handle_exception (e, "media service GetList failed: " + e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   894
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   895
  };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   896
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   897
  __sp_camera_start_date = new Date();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   898
  __s60_start_and_wait(CAMERA_APP_ID, "", finished);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   899
  var dummyTid = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   900
  return dummyTid;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   901
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   902
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   903
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   904
/*
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   905
Copyright © 2009 Nokia. All rights reserved.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   906
Code licensed under the BSD License:
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   907
Software License Agreement (BSD License) Copyright © 2009 Nokia.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   908
All rights reserved.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   909
Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   910
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   911
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   912
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   913
Neither the name of Nokia Corporation. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Nokia Corporation. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   914
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   915
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   916
version: 1.0
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   917
*/
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   918
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   919
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   920
// Camera service interface
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   921
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   922
var __device_camera_service_entry =  {"name": null, 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   923
					 "version": null,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   924
					 "proto": __device_camera,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   925
					 "descriptor": __device_camera_descriptor,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   926
					 "providers": [{"descriptor": __sp_camera_descriptor, "instance": __sp_camera_instance}]
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   927
					};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   928
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   929
function __device_camera_descriptor(provider){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   930
  this.interfaceName = provider.interfaceName;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   931
  this.version = provider.version;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   932
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   933
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   934
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   935
// Private camera  prototype: called from service factory
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   936
function __device_camera(provider){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   937
  //Private properties
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   938
  this.provider = provider;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   939
  //Read-only properties
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   940
  this.interfaceName = provider.descriptor.interfaceName;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   941
  this.version = provider.descriptor.version;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   942
 // this.supportedMediaTypes = provider.supportedMediaTypes;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   943
 // this.supportedSizes = provider.supportedSizes;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   944
  //Core methods
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   945
  this.startCamera = __device_camera_startCamera;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   946
  this.stopViewfinder = __device_camera_stopViewfinder;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   947
  //Extended methods
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   948
  this.takePicture = __device_camera_takePicture;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   949
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   950
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   951
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   952
//Why bother to define these methods? Because the camera
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   953
//object defines the contract for providers!
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   954
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   955
function __device_camera_startCamera(camera_cb){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   956
  return this.provider.startCamera(camera_cb);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   957
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   958
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   959
function __device_camera_stopViewfinder(){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   960
  this.provider.stopViewfinder();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   961
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   962
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   963
function __device_camera_takePicture(format){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   964
  this.provider.takePicture(format);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   965
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   966
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   967
 * This class provides access to the device contacts.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   968
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   969
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   970
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   971
function Contacts() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   972
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   973
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   974
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   975
function Contact() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   976
	this.id = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   977
	this.name = { 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   978
		formatted: "",
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   979
		givenName: "",
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   980
		familyName: ""
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   981
	};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   982
    this.phones = [];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   983
    this.emails = [];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   984
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   985
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   986
Contact.prototype.displayName = function()
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   987
{
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   988
    // TODO: can be tuned according to prefs
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   989
	return this.givenName + " " + this.familyName;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   990
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   991
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   992
/*
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   993
 * @param {ContactsFilter} filter Object with filter properties. filter.name only for now.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   994
 * @param {function} successCallback Callback function on success
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   995
 * @param {function} errorCallback Callback function on failure
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   996
 * @param {object} options Object with properties .page and .limit for paging
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   997
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   998
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
   999
Contacts.prototype.find = function(filter, successCallback, errorCallback, options) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1000
	try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1001
		this.contactsService = device.getServiceObject("Service.Contact", "IDataSource");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1002
		if (typeof options == 'object')
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1003
			this.options = options;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1004
		else
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1005
			this.options = {};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1006
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1007
		var criteria = new Object();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1008
		criteria.Type = "Contact";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1009
		if (filter && filter.name) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1010
			var searchTerm = '';
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1011
			if (filter.name.givenName && filter.name.givenName.length > 0) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1012
				searchTerm += filter.name.givenName;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1013
			}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1014
			if (filter.name.familyName && filter.name.familyName.length > 0) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1015
				searchTerm += searchTerm.length > 0 ? ' ' + filter.name.familyName : filter.name.familyName;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1016
			}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1017
			if (!filter.name.familyName && !filter.name.givenName && filter.name.formatted) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1018
				searchTerm = filter.name.formatted;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1019
			}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1020
			criteria.Filter = { SearchVal: searchTerm };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1021
		}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1022
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1023
		if (typeof(successCallback) != 'function') 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1024
			successCallback = function(){};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1025
		if (typeof(errorCallback) != 'function') 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1026
			errorCallback = function(){};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1027
		if (isNaN(this.options.limit))
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1028
			this.options.limit = 200;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1029
		if (isNaN(this.options.page))
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1030
			this.options.page = 1;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1031
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1032
		//need a closure here to bind this method to this instance of the Contacts object
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1033
		this.global_success = successCallback;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1034
		var obj = this;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1035
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1036
		//WRT: result.ReturnValue is an iterator of contacts
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1037
		this.contactsService.IDataSource.GetList(criteria, function(transId, eventCode, result){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1038
			obj.success_callback(result.ReturnValue);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1039
		});
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1040
	} 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1041
	catch (ex) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1042
		alert(ex.name + ": " + ex.message);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1043
		errorCallback(ex);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1044
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1045
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1046
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1047
Contacts.prototype.success_callback = function(contacts_iterator) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1048
	try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1049
	var gapContacts = new Array();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1050
	contacts_iterator.reset();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1051
    var contact;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1052
	var i = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1053
	var end = this.options.page * this.options.limit;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1054
	var start = end - this.options.limit;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1055
	while ((contact = contacts_iterator.getNext()) != undefined && i < end) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1056
		try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1057
			if (i >= start) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1058
				var gapContact = new Contact();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1059
				gapContact.name.givenName = Contacts.GetValue(contact, "FirstName");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1060
				gapContact.name.familyName = Contacts.GetValue(contact, "LastName");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1061
				gapContact.name.formatted = gapContact.name.givenName + " " + gapContact.name.familyName;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1062
				gapContact.emails = Contacts.getEmailsList(contact);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1063
				gapContact.phones = Contacts.getPhonesList(contact);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1064
				gapContact.address = Contacts.getAddress(contact);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1065
				gapContact.id = Contacts.GetValue(contact, "id");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1066
				gapContacts.push(gapContact);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1067
			}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1068
			i++;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1069
		} catch (e) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1070
			alert("ContactsError (" + e.name + ": " + e.message + ")");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1071
		}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1072
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1073
	this.contacts = gapContacts;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1074
	this.global_success(gapContacts);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1075
	} catch (ex) { alert(ex.name + ": " + ex.message); }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1076
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1077
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1078
Contacts.getEmailsList = function(contact) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1079
	var emails = new Array();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1080
	try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1081
			emails[0] = { type:"General", address: Contacts.GetValue(contact, "EmailGen") };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1082
			emails[1] = { type:"Work", address: Contacts.GetValue(contact, "EmailWork") };		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1083
			emails[2] = { type:"Home", address: Contacts.GetValue(contact, "EmailHome") };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1084
	} catch (e) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1085
		emails = [];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1086
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1087
	return emails;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1088
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1089
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1090
Contacts.getPhonesList = function(contact) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1091
	var phones = new Array();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1092
	try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1093
			phones[0] = { type:"Mobile", number: Contacts.GetValue(contact, "MobilePhoneGen") };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1094
			phones[1] = { type:"Home", number: Contacts.GetValue(contact, "LandPhoneGen") };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1095
			phones[2] = { type:"Fax", number: Contacts.GetValue(contact, "FaxNumberGen") };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1096
			phones[3] = { type:"Work", number: Contacts.GetValue(contact, "LandPhoneWork") };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1097
			phones[4] = { type:"WorkMobile", number: Contacts.GetValue(contact, "MobilePhoneWork") };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1098
	} catch (e) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1099
		phones = [];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1100
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1101
	return phones;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1102
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1103
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1104
Contacts.getAddress = function(contact) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1105
	var address = "";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1106
	try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1107
		address = Contacts.GetValue(contact, "AddrLabelHome") + ", " + Contacts.GetValue(contact, "AddrStreetHome") + ", " +
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1108
				Contacts.GetValue(contact, "AddrLocalHome") + ", " + Contacts.GetValue(contact, "AddrRegionHome") + ", " + 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1109
				Contacts.GetValue(contact, "AddrPostCodeHome") + ", " + Contacts.GetValue(contact, "AddrCountryHome");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1110
	} catch (e) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1111
		address = "";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1112
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1113
	return address;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1114
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1115
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1116
Contacts.GetValue = function(contactObj, key) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1117
	try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1118
		return contactObj[key]["Value"];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1119
	} catch (e) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1120
		return "";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1121
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1122
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1123
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1124
if (typeof navigator.contacts == "undefined") navigator.contacts = new Contacts();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1125
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1126
 * This class provides access to the debugging console.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1127
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1128
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1129
function DebugConsole() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1130
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1131
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1132
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1133
 * Print a normal log message to the console
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1134
 * @param {Object|String} message Message or object to print to the console
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1135
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1136
DebugConsole.prototype.log = function(message) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1137
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1138
	//This ends up in C:\jslog_widget.log on the device
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1139
	console.log(message);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1140
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1141
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1142
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1143
 * Print a warning message to the console
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1144
 * @param {Object|String} message Message or object to print to the console
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1145
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1146
DebugConsole.prototype.warn = function(message) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1147
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1148
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1149
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1150
 * Print an error message to the console
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1151
 * @param {Object|String} message Message or object to print to the console
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1152
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1153
DebugConsole.prototype.error = function(message) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1154
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1155
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1156
if (typeof window.debug == "undefined") window.debug = new DebugConsole();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1157
PhoneGap.ExtendWrtDeviceObj = function(){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1158
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1159
	if (!window.device)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1160
		window.device = {};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1161
	navigator.device = window.device;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1162
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1163
	try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1164
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1165
		if (window.menu)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1166
	    	window.menu.hideSoftkeys();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1167
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1168
		device.available = PhoneGap.available;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1169
		device.platform = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1170
		device.version = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1171
		device.name = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1172
		device.uuid = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1173
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1174
		var so = device.getServiceObject("Service.SysInfo", "ISysInfo");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1175
		var pf = PhoneGap.GetWrtPlatformVersion(so);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1176
		device.platform = pf.platform;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1177
		device.version = pf.version;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1178
		device.uuid = PhoneGap.GetWrtDeviceProperty(so, "IMEI");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1179
		device.name = PhoneGap.GetWrtDeviceProperty(so, "PhoneModel");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1180
	} 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1181
	catch (e) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1182
		device.available = false;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1183
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1184
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1185
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1186
PhoneGap.GetWrtDeviceProperty = function(serviceObj, key) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1187
	var criteria = { "Entity": "Device", "Key": key };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1188
	var result = serviceObj.ISysInfo.GetInfo(criteria);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1189
	if (result.ErrorCode == 0) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1190
		return result.ReturnValue.StringData;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1191
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1192
	else {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1193
		return null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1194
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1195
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1196
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1197
PhoneGap.GetWrtPlatformVersion = function(serviceObj) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1198
	var criteria = { "Entity": "Device", "Key": "PlatformVersion" };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1199
	var result = serviceObj.ISysInfo.GetInfo(criteria);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1200
	if (result.ErrorCode == 0) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1201
		var version = {};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1202
		version.platform = result.ReturnValue.MajorVersion;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1203
		version.version = result.ReturnValue.MinorVersion;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1204
		return version;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1205
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1206
	else {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1207
		return null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1208
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1209
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1210
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1211
PhoneGap.ExtendWrtDeviceObj();/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1212
 * This class provides access to device GPS data.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1213
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1214
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1215
function Geolocation() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1216
    /**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1217
     * The last known GPS position.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1218
     */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1219
    this.lastPosition = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1220
    this.lastError = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1221
    this.callbacks = {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1222
        onLocationChanged: [],
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1223
        onError:           []
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1224
    };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1225
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1226
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1227
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1228
 * Asynchronously aquires the current position.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1229
 * @param {Function} successCallback The function to call when the position
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1230
 * data is available
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1231
 * @param {Function} errorCallback The function to call when there is an error 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1232
 * getting the position data.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1233
 * @param {PositionOptions} options The options for getting the position data
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1234
 * such as timeout.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1235
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1236
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1237
    var referenceTime = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1238
    if (this.lastPosition)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1239
        referenceTime = this.lastPosition.timestamp;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1240
    else
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1241
        this.start(options);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1242
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1243
    var timeout = 20000;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1244
    var interval = 500;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1245
    if (typeof(options) == 'object' && options.interval)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1246
        interval = options.interval;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1247
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1248
    if (typeof(successCallback) != 'function')
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1249
        successCallback = function() {};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1250
    if (typeof(errorCallback) != 'function')
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1251
        errorCallback = function() {};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1252
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1253
    var dis = this;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1254
    var delay = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1255
    var timer = setInterval(function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1256
        delay += interval;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1257
		//if we have a new position, call success and cancel the timer
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1258
        if (dis.lastPosition && dis.lastPosition.timestamp > referenceTime) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1259
            successCallback(dis.lastPosition);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1260
            clearInterval(timer);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1261
        } else if (delay >= timeout) { //else if timeout has occured then call error and cancel the timer
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1262
            errorCallback();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1263
            clearInterval(timer);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1264
        }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1265
		//else the interval gets called again
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1266
    }, interval);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1267
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1268
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1269
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1270
 * Asynchronously aquires the position repeatedly at a given interval.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1271
 * @param {Function} successCallback The function to call each time the position
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1272
 * data is available
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1273
 * @param {Function} errorCallback The function to call when there is an error 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1274
 * getting the position data.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1275
 * @param {PositionOptions} options The options for getting the position data
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1276
 * such as timeout and the frequency of the watch.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1277
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1278
Geolocation.prototype.watchPosition = function(successCallback, errorCallback, options) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1279
	// Invoke the appropriate callback with a new Position object every time the implementation 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1280
	// determines that the position of the hosting device has changed. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1281
	this.getCurrentPosition(successCallback, errorCallback, options);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1282
	var frequency = 10000;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1283
        if (typeof options == 'object' && options.frequency)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1284
            frequency = options.frequency;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1285
	var that = this;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1286
	return setInterval(function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1287
		that.getCurrentPosition(successCallback, errorCallback, options);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1288
	}, frequency);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1289
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1290
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1291
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1292
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1293
 * Clears the specified position watch.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1294
 * @param {String} watchId The ID of the watch returned from #watchPosition.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1295
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1296
Geolocation.prototype.clearWatch = function(watchId) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1297
	clearInterval(watchId);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1298
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1299
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1300
Geolocation.prototype.start = function(options) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1301
	var so = device.getServiceObject("Service.Location", "ILocation");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1302
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1303
	//construct the criteria for our location request
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1304
	var updateOptions = new Object();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1305
	// Specify that location information need not be guaranteed. This helps in
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1306
	// that the widget doesn't need to wait for that information possibly indefinitely.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1307
	updateOptions.PartialUpdates = true;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1308
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1309
	//default 15 seconds
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1310
	if (typeof(options) == 'object' && options.timeout) 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1311
		//options.timeout in in ms, updateOptions.UpdateTimeout in microsecs
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1312
		updateOptions.UpdateTimeOut = options.timeout * 1000;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1313
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1314
	//default 1 second
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1315
	if (typeof(options) == 'object' && options.interval) 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1316
		//options.timeout in in ms, updateOptions.UpdateTimeout in microsecs
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1317
		updateOptions.UpdateInterval = options.interval * 1000;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1318
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1319
	// Initialize the criteria for the GetLocation call
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1320
	var trackCriteria = new Object();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1321
	// could use "BasicLocationInformation" or "GenericLocationInfo"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1322
	trackCriteria.LocationInformationClass = "GenericLocationInfo";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1323
	trackCriteria.Updateoptions = updateOptions;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1324
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1325
	var dis = this;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1326
	so.ILocation.Trace(trackCriteria, function(transId, eventCode, result) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1327
		var retVal = result.ReturnValue;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1328
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1329
		if (result.ErrorCode != 0 || isNaN(retVal.Latitude))
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1330
			return;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1331
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1332
		// heading options: retVal.TrueCourse, retVal.MagneticHeading, retVal.Heading, retVal.MagneticCourse
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1333
		// but retVal.Heading was the only field being returned with data on the test device (Nokia 5800)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1334
		// WRT does not provide accuracy
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1335
		var newCoords = new Coordinates(retVal.Latitude, retVal.Longitude, retVal.Altitude, null, retVal.Heading, retVal.HorizontalSpeed);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1336
		var positionObj = { coords: newCoords, timestamp: (new Date()).getTime() };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1337
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1338
		dis.lastPosition = positionObj;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1339
	});
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1340
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1341
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1342
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1343
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1344
if (typeof navigator.geolocation == "undefined") navigator.geolocation = new Geolocation();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1345
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1346
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1347
 * This class provides access to native mapping applications on the device.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1348
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1349
function Map() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1350
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1351
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1352
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1353
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1354
 * Shows a native map on the device with pins at the given positions.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1355
 * @param {Array} positions
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1356
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1357
Map.prototype.show = function(positions) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1358
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1359
	var err = "map api is unimplemented on symbian.wrt";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1360
	debug.log(err);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1361
	return { name: "MapError", message: err };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1362
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1363
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1364
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1365
if (typeof navigator.map == "undefined") navigator.map = new Map();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1366
function Network() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1367
    /**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1368
     * The last known Network status.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1369
     */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1370
	this.lastReachability = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1371
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1372
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1373
Network.prototype.isReachable = function(hostName, successCallback, options) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1374
	var req = new XMLHttpRequest();  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1375
   	req.open('GET', hostName, true);  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1376
   	req.onreadystatechange = function (aEvt) {  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1377
     	if (req.readyState == 4) {  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1378
        	if(req.status == 200)  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1379
        		successCallback(NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1380
         	else  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1381
          		successCallback(NetworkStatus.NOT_REACHABLE);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1382
 		}  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1383
  	};  
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1384
  	req.send(null);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1385
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1386
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1387
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1388
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1389
 * This class contains information about any NetworkStatus.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1390
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1391
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1392
function NetworkStatus() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1393
	this.code = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1394
	this.message = "";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1395
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1396
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1397
NetworkStatus.NOT_REACHABLE = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1398
NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK = 1;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1399
NetworkStatus.REACHABLE_VIA_WIFI_NETWORK = 2;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1400
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1401
if (typeof navigator.network == "undefined") navigator.network = new Network();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1402
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1403
 * This class provides access to notifications on the device.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1404
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1405
function Notification() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1406
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1407
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1408
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1409
Notification.prototype.vibrate = function(mills)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1410
{
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1411
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1412
	if (!Notification.getSysinfoObject())
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1413
		Notification.embedSysinfoObject();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1414
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1415
	this.sysinfo = Notification.getSysinfoObject();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1416
	this.sysinfo.startvibra(mills, 100);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1417
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1418
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1419
//TODO: this is not beeping
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1420
Notification.prototype.beep = function(count, volume)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1421
{
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1422
	if (!Notification.getSysinfoObject())
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1423
		Notification.embedSysinfoObject();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1424
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1425
	this.sysinfo = Notification.getSysinfoObject();	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1426
	this.sysinfo.beep(220,2000);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1427
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1428
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1429
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1430
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1431
 * Open a native alert dialog, with a customizable title and button text.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1432
 * @param {String} message Message to print in the body of the alert
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1433
 * @param {String} [title="Alert"] Title of the alert dialog (default: Alert)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1434
 * @param {String} [buttonLabel="OK"] Label of the close button (default: OK)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1435
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1436
Notification.prototype.alert = function(message, title, buttonLabel) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1437
    // Default is to use a browser alert; this will use "index.html" as the title though
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1438
    alert(message);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1439
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1440
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1441
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1442
 * Start spinning the activity indicator on the statusbar
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1443
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1444
Notification.prototype.activityStart = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1445
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1446
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1447
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1448
 * Stop spinning the activity indicator on the statusbar, if it's currently spinning
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1449
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1450
Notification.prototype.activityStop = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1451
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1452
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1453
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1454
 * Causes the device to blink a status LED.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1455
 * @param {Integer} count The number of blinks.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1456
 * @param {String} colour The colour of the light.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1457
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1458
Notification.prototype.blink = function(count, colour) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1459
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1460
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1461
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1462
Notification.embedSysinfoObject = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1463
	var el = document.createElement("embed");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1464
	el.setAttribute("type", "application/x-systeminfo-widget");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1465
	el.setAttribute("hidden", "yes");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1466
	document.getElementsByTagName("body")[0].appendChild(el);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1467
	return;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1468
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1469
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1470
Notification.getSysinfoObject = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1471
	return document.embeds[0];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1472
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1473
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1474
if (typeof navigator.notification == "undefined") navigator.notification = new Notification();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1475
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1476
 * This class provides access to the device orientation.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1477
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1478
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1479
function Orientation() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1480
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1481
	 * The current orientation, or null if the orientation hasn't changed yet.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1482
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1483
	this.currentOrientation = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1484
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1485
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1486
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1487
 * Set the current orientation of the phone.  This is called from the device automatically.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1488
 * 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1489
 * When the orientation is changed, the DOMEvent \c orientationChanged is dispatched against
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1490
 * the document element.  The event has the property \c orientation which can be used to retrieve
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1491
 * the device's current orientation, in addition to the \c Orientation.currentOrientation class property.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1492
 *
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1493
 * @param {Number} orientation The orientation to be set
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1494
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1495
Orientation.prototype.setOrientation = function(orientation) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1496
		if (orientation == this.currentOrientation) 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1497
			return;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1498
		var old = this.currentOrientation;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1499
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1500
		this.currentOrientation = orientation;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1501
		var e = document.createEvent('Events');
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1502
		e.initEvent('orientationChanged', 'false', 'false');
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1503
		e.orientation = orientation;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1504
		e.oldOrientation = old;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1505
		document.dispatchEvent(e);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1506
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1507
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1508
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1509
 * Asynchronously aquires the current orientation.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1510
 * @param {Function} successCallback The function to call when the orientation
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1511
 * is known.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1512
 * @param {Function} errorCallback The function to call when there is an error 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1513
 * getting the orientation.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1514
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1515
Orientation.prototype.getCurrentOrientation = function(successCallback, errorCallback) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1516
	// If the orientation is available then call success
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1517
	// If the orientation is not available then call error
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1518
	try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1519
		if (!this.serviceObj) 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1520
			this.serviceObj = this.getServiceObj();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1521
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1522
		if (this.serviceObj == null) 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1523
			errorCallback({
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1524
				name: "DeviceErr",
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1525
				message: "Could not initialize service object"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1526
			});
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1527
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1528
		//get the sensor channel
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1529
		var SensorParams = {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1530
			SearchCriterion: "Orientation"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1531
		};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1532
		var returnvalue = this.serviceObj.ISensor.FindSensorChannel(SensorParams);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1533
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1534
		var error = returnvalue["ErrorCode"];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1535
		var errmsg = returnvalue["ErrorMessage"];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1536
		if (!(error == 0 || error == 1012)) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1537
			var ex = {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1538
				name: "Unable to find Sensor Channel: " + error,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1539
				message: errmsg
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1540
			};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1541
			errorCallback(ex);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1542
		}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1543
		var channelInfoMap = returnvalue["ReturnValue"][0];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1544
		var criteria = {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1545
			ChannelInfoMap: channelInfoMap,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1546
			ListeningType: "ChannelData"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1547
		};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1548
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1549
		if (typeof(successCallback) != 'function') 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1550
			successCallback = function(){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1551
			};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1552
		if (typeof(errorCallback) != 'function') 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1553
			errorCallback = function(){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1554
			};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1555
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1556
		this.success_callback = successCallback;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1557
		this.error_callback = errorCallback;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1558
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1559
		//create a closure to persist this instance of orientation object into the RegisterForNofication callback
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1560
		var obj = this;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1561
		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1562
		// TODO: this call crashes WRT, but there is no other way to read the orientation sensor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1563
		// http://discussion.forum.nokia.com/forum/showthread.php?t=182151&highlight=memory+leak
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1564
		this.serviceObj.ISensor.RegisterForNotification(criteria, function(transId, eventCode, result){
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1565
			var criteria = {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1566
				TransactionID: transId
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1567
			};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1568
			try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1569
				//var orientation = result.ReturnValue.DeviceOrientation;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1570
				obj.serviceObj.ISensor.Cancel(criteria);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1571
				
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1572
				var orientation = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1573
				switch (result.ReturnValue.DeviceOrientation) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1574
					case "DisplayUpwards": orientation = DisplayOrientation.FACE_UP; break;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1575
					case "DisplayDownwards": orientation = DisplayOrientation.FACE_DOWN; break;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1576
					case "DisplayUp": orientation = DisplayOrientation.PORTRAIT; break;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1577
					case "DisplayDown": orientation = DisplayOrientation.REVERSE_PORTRAIT; break;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1578
					case "DisplayRightUp": orientation = DisplayOrientation.LANDSCAPE_RIGHT_UP; break;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1579
					case "DisplayLeftUp": orientation = DisplayOrientation.LANDSCAPE_LEFT_UP; break;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1580
					
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1581
				}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1582
				
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1583
				obj.setOrientation(orientation);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1584
				
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1585
				obj.success_callback(orientation);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1586
				
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1587
			} 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1588
			catch (ex) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1589
				obj.serviceObj.ISensor.Cancel(criteria);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1590
				obj.error_callback(ex);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1591
			}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1592
			
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1593
		});
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1594
	} catch (ex) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1595
		errorCallback({ name: "OrientationError", message: ex.name + ": " + ex.message });
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1596
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1597
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1598
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1599
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1600
 * Asynchronously aquires the orientation repeatedly at a given interval.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1601
 * @param {Function} successCallback The function to call each time the orientation
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1602
 * data is available.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1603
 * @param {Function} errorCallback The function to call when there is an error 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1604
 * getting the orientation data.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1605
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1606
Orientation.prototype.watchOrientation = function(successCallback, errorCallback, options) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1607
	// Invoke the appropriate callback with a new Position object every time the implementation 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1608
	// determines that the position of the hosting device has changed. 
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1609
	this.getCurrentOrientation(successCallback, errorCallback);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1610
	var frequency = (options != undefined)? options.frequency : 1000;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1611
	return setInterval(function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1612
		navigator.orientation.getCurrentOrientation(successCallback, errorCallback);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1613
	}, frequency);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1614
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1615
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1616
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1617
 * Clears the specified orientation watch.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1618
 * @param {String} watchId The ID of the watch returned from #watchOrientation.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1619
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1620
Orientation.prototype.clearWatch = function(watchId) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1621
	clearInterval(watchId);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1622
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1623
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1624
//gets the Acceleration Service Object from WRT
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1625
Orientation.prototype.getServiceObj = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1626
	var so;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1627
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1628
    try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1629
        so = device.getServiceObject("Service.Sensor", "ISensor");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1630
    } catch (ex) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1631
		throw {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1632
			name: "DeviceError",
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1633
			message: ex.name + ": " + ex.message
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1634
		};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1635
    }		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1636
	return so;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1637
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1638
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1639
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1640
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1641
 * This class encapsulates the possible orientation values.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1642
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1643
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1644
function DisplayOrientation() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1645
	this.code = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1646
	this.message = "";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1647
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1648
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1649
DisplayOrientation.PORTRAIT = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1650
DisplayOrientation.REVERSE_PORTRAIT = 1;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1651
DisplayOrientation.LANDSCAPE_LEFT_UP = 2;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1652
DisplayOrientation.LANDSCAPE_RIGHT_UP = 3;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1653
DisplayOrientation.FACE_UP = 4;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1654
DisplayOrientation.FACE_DOWN = 5;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1655
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1656
if (typeof navigator.orientation == "undefined") navigator.orientation = new Orientation();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1657
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1658
 * This class contains position information.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1659
 * @param {Object} lat
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1660
 * @param {Object} lng
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1661
 * @param {Object} acc
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1662
 * @param {Object} alt
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1663
 * @param {Object} altacc
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1664
 * @param {Object} head
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1665
 * @param {Object} vel
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1666
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1667
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1668
function Position(coords, timestamp) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1669
	this.coords = coords;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1670
        this.timestamp = new Date().getTime();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1671
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1672
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1673
function Coordinates(lat, lng, alt, acc, head, vel) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1674
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1675
	 * The latitude of the position.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1676
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1677
	this.latitude = lat;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1678
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1679
	 * The longitude of the position,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1680
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1681
	this.longitude = lng;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1682
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1683
	 * The accuracy of the position.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1684
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1685
	this.accuracy = acc;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1686
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1687
	 * The altitude of the position.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1688
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1689
	this.altitude = alt;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1690
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1691
	 * The direction the device is moving at the position.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1692
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1693
	this.heading = head;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1694
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1695
	 * The velocity with which the device is moving at the position.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1696
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1697
	this.speed = vel;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1698
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1699
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1700
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1701
 * This class specifies the options for requesting position data.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1702
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1703
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1704
function PositionOptions() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1705
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1706
	 * Specifies the desired position accuracy.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1707
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1708
	this.enableHighAccuracy = true;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1709
	/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1710
	 * The timeout after which if position data cannot be obtained the errorCallback
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1711
	 * is called.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1712
	 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1713
	this.timeout = 10000;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1714
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1715
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1716
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1717
 * This class contains information about any GSP errors.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1718
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1719
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1720
function PositionError() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1721
	this.code = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1722
	this.message = "";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1723
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1724
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1725
PositionError.UNKNOWN_ERROR = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1726
PositionError.PERMISSION_DENIED = 1;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1727
PositionError.POSITION_UNAVAILABLE = 2;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1728
PositionError.TIMEOUT = 3;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1729
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1730
 * This class provides access to the device SMS functionality.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1731
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1732
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1733
function Sms() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1734
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1735
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1736
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1737
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1738
 * Sends an SMS message.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1739
 * @param {Integer} number The phone number to send the message to.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1740
 * @param {String} message The contents of the SMS message to send.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1741
 * @param {Function} successCallback The function to call when the SMS message is sent.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1742
 * @param {Function} errorCallback The function to call when there is an error sending the SMS message.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1743
 * @param {PositionOptions} options The options for accessing the GPS location such as timeout and accuracy.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1744
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1745
Sms.prototype.send = function(number, message, successCallback, errorCallback, options) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1746
    try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1747
		if (!this.serviceObj)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1748
			this.serviceObj = this.getServiceObj();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1749
			
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1750
	    // Setup input params using dot syntax
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1751
	    var criteria = new Object();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1752
	    criteria.MessageType = 'SMS';
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1753
	    criteria.To = number;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1754
	    criteria.BodyText = message;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1755
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1756
      	var result = this.serviceObj.IMessaging.Send(criteria);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1757
    	if (result.ErrorCode != 0 && result.ErrorCode != "0")
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1758
		{
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1759
			var exception = { name: "SMSError", message: result.ErrorMessage };
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1760
			throw exception;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1761
		} else {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1762
			successCallback.call();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1763
		}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1764
    }
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1765
  	catch(ex)
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1766
  	{
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1767
		errorCallback.call({ name: "SmsError", message: ex.name + ": " + ex.message });
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1768
  	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1769
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1770
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1771
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1772
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1773
//gets the Sms Service Object from WRT
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1774
Sms.prototype.getServiceObj = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1775
	var so;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1776
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1777
    try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1778
        so = device.getServiceObject("Service.Messaging", "IMessaging");
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1779
    } catch (ex) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1780
		throw {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1781
			name: "SmsError",
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1782
			message: "Failed to load sms service (" + ex.name + ": " + ex.message + ")"
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1783
		};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1784
    }		
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1785
	return so;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1786
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1787
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1788
if (typeof navigator.sms == "undefined") navigator.sms = new Sms();/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1789
 * @author ryan
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1790
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1791
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1792
function Storage() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1793
	this.available = true;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1794
	this.serialized = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1795
	this.items = null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1796
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1797
	if (!window.widget) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1798
		this.available = false;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1799
		return;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1800
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1801
	var pref = window.widget.preferenceForKey(Storage.PREFERENCE_KEY);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1802
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1803
	//storage not yet created
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1804
	if (pref == "undefined" || pref == undefined) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1805
		this.length = 0;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1806
		this.serialized = "({})";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1807
		this.items = {};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1808
		window.widget.setPreferenceForKey(this.serialized, Storage.PREFERENCE_KEY);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1809
	} else {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1810
		this.serialized = pref;'({"store_test": { "key": "store_test", "data": "asdfasdfs" },})';
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1811
		this.items = eval(this.serialized);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1812
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1813
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1814
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1815
Storage.PREFERENCE_KEY = "phonegap_storage_pref_key";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1816
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1817
Storage.prototype.index = function (key) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1818
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1819
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1820
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1821
Storage.prototype.getItem = function (key) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1822
	try {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1823
		return this.items[key].data;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1824
	} catch (ex) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1825
		return null;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1826
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1827
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1828
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1829
Storage.prototype.setItem = function (key, data) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1830
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1831
	this.items[key] = {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1832
		"key": key,
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1833
		"data": data
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1834
	};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1835
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1836
	this.serialize();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1837
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1838
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1839
Storage.prototype.removeItem = function (key) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1840
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1841
	if (this.items[key]) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1842
		this.items[key] = undefined;
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1843
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1844
	this.serialize();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1845
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1846
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1847
Storage.prototype.clear = function () {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1848
	this.serialized = "({})";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1849
	this.items = {};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1850
	this.serialize();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1851
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1852
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1853
Storage.prototype.serialize = function() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1854
	var json = "";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1855
	
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1856
	for (key in this.items) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1857
		var item = this.items[key];
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1858
		if (typeof item != "undefined") {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1859
			json += "\"" + item.key + "\": { \"key\": \"" + item.key + "\", \"data\": \"" + item.data + "\" }, ";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1860
		}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1861
	}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1862
	this.serialized = "({" + json + "})";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1863
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1864
	window.widget.setPreferenceForKey( this.serialized, Storage.PREFERENCE_KEY);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1865
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1866
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1867
if (typeof navigator.storage == "undefined" ) navigator.storage = new Storage();
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1868
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1869
 * This class provides access to the telephony features of the device.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1870
 * @constructor
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1871
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1872
function Telephony() {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1873
	this.number = "";
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1874
}
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1875
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1876
/**
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1877
 * Calls the specifed number.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1878
 * @param {Integer} number The number to be called.
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1879
 */
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1880
Telephony.prototype.send = function(number) {
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1881
	widget.openURL('tel:+' + number);
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1882
};
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1883
54063d8b0412 initial commit of PhoneGap WRT framework, licensing and test code
Ryan Willoughby <ryan.willoughby@nitobi.com>
parents:
diff changeset
  1884
if (typeof navigator.telephony == "undefined") navigator.telephony = new Telephony();