Skip to content

Commit

Permalink
Added initial repository for Windows Mobile - only a couple of device…
Browse files Browse the repository at this point in the history
… functionalities work right now. Also updated JS for BlackBerry.
  • Loading branch information
Fil Maj committed Aug 21, 2009
1 parent 04e2e6c commit 1d9ce3e
Show file tree
Hide file tree
Showing 16 changed files with 730 additions and 0 deletions.
30 changes: 30 additions & 0 deletions javascripts/blackberry/camera.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* This class provides access to the device camera.
* @constructor
*/
function Camera() {
this.picture = null;
}

Camera.prototype.launch = function () {
if (device.hasCamera) device.exec("camera", ["obtain"], true);
else alert("Camera not supported on this device.");
}

/**
*
* @param {Function} successCallback
* @param {Function} errorCallback
* @param {Object} options
*/
Camera.prototype.getPicture = function(successCallback, errorCallback, options) {
if (device.hasCamera) {
if (successCallback) this.onSuccess = successCallback;
else this.onSuccess = null;
if (errorCallback) this.onError = errorCallback;
else this.onError = null;
device.exec("camera", ["picture"], true);
} else alert("Camera not supported");
}

if (typeof navigator.camera == "undefined") navigator.camera = new Camera();
56 changes: 56 additions & 0 deletions javascripts/blackberry/contacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* This class represents a Contact in the manager.
* @constructor
*/
function Contact() {
this.name = "";
this.phone = "";
this.address = "";
this.email = "";
}

function ContactManager() {
this.contacts = [];
this.timestamp = new Date().getTime();
// Options used when calling ContactManager functions.
this.options = {
'pageSize':0,
'pageNumber':0,
'nameFilter':''
};
}
ContactManager.prototype.formParams = function(options, startArray) {
var params = [];
if (startArray) params = startArray;
if (options.pageSize && options.pageSize > 0) params.push("pageSize:" + options.pageSize);
if (options.pageNumber) params.push("pageNumber:" + options.pageNumber);
if (options.nameFilter) params.push("nameFilter:" + options.nameFilter);
return params;
}
ContactManager.prototype.displayContact = function(successCallback, errorCallback, options) {
if (options.nameFilter && options.nameFilter.length > 0) {
var params = ["search"];
params = this.formParams(options,params);
this.search_onSuccess = successCallback;
this.search_onError = errorCallback;
device.exec("contacts", params, true);
} else {
ContactManager.getAllContacts(successCallback,errorCallback,options);
return;
}
}
ContactManager.prototype.getAllContacts = function(successCallback, errorCallback, options) {
this.global_onSuccess = successCallback;
this.global_onError = errorCallback;
var params = ["getall"];
params = this.formParams(options,params);
device.exec("contacts", params, true);
}
ContactManager.prototype.chooseContact = function(successCallback, options) {
this.choose_onSuccess = successCallback;
var params = ["choose"];
params = this.formParams(options,params);
device.exec("contacts", params, true);
}

if (typeof navigator.ContactManager == "undefined") navigator.ContactManager = new ContactManager();
31 changes: 31 additions & 0 deletions javascripts/blackberry/device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
window.device = {
isIPhone: false,
isIPod: false,
isBlackBerry: true,

init: function() {
this.exec("initialize");
this.poll(function() {
device.available = typeof device.name == "string";
});
},
exec: function(command, params, sync) {
if (device.available || command == "initialize") {
try {
var cookieCommand = "PhoneGap=" + command;
if (params) cookieCommand += "/" + params.join("/");
document.cookie = cookieCommand;
if (sync) this.poll();
} catch(e) {
console.log("Command '" + command + "' has not been executed, because of exception: " + e);
alert("Error executing command '" + command + "'.")
}
} else {
alert("Device not available YET - still loading.");
}
},
poll: function(callback) {
eval(document.cookie + (callback ? ";callback();" : ""));
}
};
window.device.init();
5 changes: 5 additions & 0 deletions javascripts/blackberry/media.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
navigator.media = {
playSound: function(media) {
window.device.exec("media",[media],true);
}
};
8 changes: 8 additions & 0 deletions javascripts/blackberry/notification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
navigator.notification = {
vibrate: function(secs) {
window.device.exec("notification/vibrate",[secs]);
},
beep: function(times) {
window.device.exec("notification/beep",[times]);
}
};
72 changes: 72 additions & 0 deletions javascripts/blackberry/position.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* This class contains position information.
* @param {Object} lat
* @param {Object} lng
* @param {Object} acc
* @param {Object} alt
* @param {Object} altacc
* @param {Object} head
* @param {Object} vel
* @constructor
*/
function Position(coords) {
this.coords = coords;
this.timestamp = new Date().getTime();
}

function Coordinates(lat, lng, alt, acc, head, vel) {
/**
* The latitude of the position.
*/
this.latitude = lat;
/**
* The longitude of the position,
*/
this.longitude = lng;
/**
* The accuracy of the position.
*/
this.accuracy = acc;
/**
* The altitude of the position.
*/
this.altitude = alt;
/**
* The direction the device is moving at the position.
*/
this.heading = head;
/**
* The velocity with which the device is moving at the position.
*/
this.speed = vel;
}

/**
* This class specifies the options for requesting position data.
* @constructor
*/
function PositionOptions() {
/**
* Specifies the desired position accuracy.
*/
this.enableHighAccuracy = true;
/**
* The timeout after which if position data cannot be obtained the errorCallback
* is called.
*/
this.timeout = 10000;
}

/**
* This class contains information about any GSP errors.
* @constructor
*/
function PositionError() {
this.code = null;
this.message = "";
}

PositionError.UNKNOWN_ERROR = 0;
PositionError.PERMISSION_DENIED = 1;
PositionError.POSITION_UNAVAILABLE = 2;
PositionError.TIMEOUT = 3;
18 changes: 18 additions & 0 deletions javascripts/blackberry/telephony.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* This class provides access to the telephony features of the device.
* @constructor
*/
function Telephony() {
this.number = null;
}

/**
* Calls the specifed number.
* @param {Integer} number The number to be called.
*/
Telephony.prototype.call = function(number) {
this.number = number;
device.exec("call", [this.number]);
}

if (typeof navigator.telephony == "undefined") navigator.telephony = new Telephony();
12 changes: 12 additions & 0 deletions winmo/Command.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace PhoneGap {

public interface Command {
String execute(String instruction);
Boolean accept(String instruction);
}

}
30 changes: 30 additions & 0 deletions winmo/CommandManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace PhoneGap {

class CommandManager {

private Command[] commands = new Command[1];

public CommandManager() {
commands[0] = new InitializationCommand();
//commands[1] = new MediaCommand();
}

public String processInstruction(String instruction) {
for (int index = 0; index < commands.Length; index++) {
Command command = (Command) commands[index];
if (command.accept(instruction))
try {
return command.execute(instruction);
} catch(Exception e) {

}
}
return null;
}
}

}
Loading

0 comments on commit 1d9ce3e

Please sign in to comment.