Skip to content

Commit

Permalink
Got vibrate working
Browse files Browse the repository at this point in the history
  • Loading branch information
silentrob committed Feb 17, 2009
1 parent 8910e75 commit 914e0e2
Show file tree
Hide file tree
Showing 27 changed files with 1,309 additions and 731 deletions.
9 changes: 6 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def build
puts 'writing the full JS file to lib/phonegap.js'
final = "#{ LIBPATH }lib#{ File::SEPARATOR }phonegap.js"
js = ""

interfaces_to_build.each do |interface|
js << import("#{ LIBPATH }javascripts#{ File::SEPARATOR }#{ interface }.js")
end

platforms_to_build.each do |platform|
interfaces_to_build.each do |interface|
begin
Expand All @@ -37,9 +42,7 @@ def build
end
end
end
interfaces_to_build.each do |interface|
js << import("#{ LIBPATH }javascripts#{ File::SEPARATOR }#{ interface }.js")
end

FileUtils.mkdir_p "#{ LIBPATH }lib"
open(final,'w'){|f| f.puts( js )}

Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/GlassViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ - (void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOri
i = -90;
break;
}
// GlassAppDelegate *appDelegate = (GlassAppDelegate*)[[UIApplication sharedApplication] delegate];
jsCallBack = [[NSString alloc] initWithFormat:@"setOrientation(%f);", i];

jsCallBack = [[NSString alloc] initWithFormat:@"var _orientation=%f;", i];
[webView stringByEvaluatingJavaScriptFromString:jsCallBack];

[jsCallBack release];
Expand Down
270 changes: 77 additions & 193 deletions iphone/PhoneGap.xcodeproj/nitobi.mode1v3

Large diffs are not rendered by default.

59 changes: 31 additions & 28 deletions iphone/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,51 @@
</style>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8">


Accelerometer.prototype.getCurrentAcceleration = function(successCallback, errorCallback, options) {
if (typeof successCallback == "function") {
var accel = new Acceleration(_accel.x,_accel.y,_accel.z);
Accelerometer.lastAcceleration = accel;
successCallback(accel);
}

var getLocation = function() {
var suc = function(p){
alert(p.latitude + " " + p.longitude);
};

}


Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallback, options) {
this.getCurrentAccelerometer(successCallback, errorCallback, options);
// TODO: add the interval id to a list so we can clear all watches
return setInterval(function() {
navigator.accelerometer.getCurrentAcceleration(successCallback, errorCallback, options);
}, 10000);
var fail = function(){};
navigator.geolocation.getCurrentPosition(suc,fail);
}



var init = function() {
var g = new Accelerometer();
var getAccel = function() {
var suc = function(p){
alert(p.x);
alert(a.x + " " + a.y + " " + a.z);
};

var fail = function(er){console.log(er.message);};
g.watchAcceleration(suc, fail);
// var interval = g.watchPosition(suc,fail);

var fail = function(){};
navigator.accelerometer.getCurrentAcceleration(suc,fail);
}

var watchAccel = function() {
var suc = function(a){
document.getElementById('t').innerHTML = a.x + " " + a.y + " " + a.z;
};

var fail = function(){};

var opt = {};
opt.frequency = 100;
timer = navigator.accelerometer.watchAcceleration(suc,fail,opt);
}

var vibrate = function() {
navigator.notification.vibrate(0);
}

</script>

</head>
<body >
Welcome
<button onclick="init();">Get Geolocation</button>
<button onclick="getLocation();">Get Geolocation</button><br />
<button onclick="getAccel();">Get Accelerometer</button><br />
<button onclick="watchAccel();">Watch Accelerometer</button><br />
<button onclick="vibrate();">Vibrate</button><br />
<div id="t"></div>
<div id="p"></div>


</body>
Expand Down
234 changes: 129 additions & 105 deletions iphone/www/phonegap.js
Original file line number Diff line number Diff line change
@@ -1,105 +1,4 @@




File.prototype.read = function(fileName, successCallback, errorCallback) {
document.cookie = 'bb_command={command:8,args:{name:"'+fileName+'"}}';
navigator.file.successCallback = successCallback;
navigator.file.errorCallback = errorCallback;
navigator.file.readTimeout = window.setInterval('navigator.file._readReady()', 1000);
}

File.prototype._readReady = function() {
var cookies = document.cookie.split(';');
for (var i=0; i<cookies.length; i++) {
var cookie = cookies[i].split('=');
if (cookie[0] == 'bb_response') {
var obj = eval('('+cookie[1]+')');

// TODO: This needs to be in ONE cookie reading loop I think so that it can find
// various different data coming back from the phone at any time (poll piggy-backing)
var file = obj.readfile;
if (file != null)
{
window.clearTimeout(navigator.file.readTimeout);
if (file.length > 0)
{
successCallback(file);
}
}
}
}
}

File.prototype.write = function(fileName, data) {
document.cookie = 'bb_command={command:9,args:{name:"'+fileName+'",data:"'+data+'"}}';
}



Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
document.cookie = 'bb_command={command:'+phonegap.LOCATION+'}';
// Blackberry 4.5 does not let you use function pointers in setInterval. idiots.
geoSuccessCallback = successCallback;
geoErrorCallback = errorCallback;
geoOptions = options;
locationTimeout = window.setInterval('navigator.geolocation._getCurrentPosition()', 1000);
}

Geolocation.prototype._getCurrentPosition = function(successCallback, errorCallback, options) {
var cookies = document.cookie.split(';');
for (var i=0; i<cookies.length; i++) {
var cookie = cookies[i].split('=');
if (cookie[0] == 'bb_response') {
var obj = eval('('+cookie[1]+')');
var geo = obj.geolocation;
if (geo != null)
{
window.clearTimeout(locationTimeout);
if (geo.error != null) {
if (typeof geoErrorCallback == "function") {
geoErrorCallback(new PositionError(geo.error));
}
} else if (typeof geoSuccessCallback == "function") {
geoSuccessCallback(new Position(geo.lat, geo.lng));
}
break;
}
}
}
}

Geolocation.prototype.showMap = function(lat, lng) {
document.cookie = 'bb_command={command:1,args:{points:[{lat:'+lat+',lng:'+lng+',label:\'Nitobi\'}]}}';
}


Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
geoSuccessCallback = successCallback;
geoErrorCallback = errorCallback;
geoOptions = options;
// locationTimeout = window.setInterval("navigator.geolocation._getCurrentPosition();", 1000); // Works in Webkit
locationTimeout = window.setInterval("Geolocation.prototype._getCurrentPosition();", 1000); // Works in FireFox
}

Geolocation.prototype._getCurrentPosition = function() {
document.location = "gap://getloc/null";

if (geo.lng != 0) {
window.clearTimeout(locationTimeout);
if (geo.error != null) {
if (typeof geoErrorCallback == "function") {
geoErrorCallback(new PositionError(geo.error));
}
} else if (typeof geoSuccessCallback == "function") {
var position = new Position(geo.lat, geo.lng);
Geolocation.lastPosition = position;
geoSuccessCallback(position);
}
}
}


/**
* This class contains acceleration information
* @constructor
Expand Down Expand Up @@ -162,6 +61,13 @@
Accelerometer.prototype.getCurrentAcceleration = function(successCallback, errorCallback, options) {
// If the acceleration is available then call success
// If the acceleration is not available then call error

// Created for iPhone, Iphone passes back _accel obj litteral
if (typeof successCallback == "function") {
var accel = new Acceleration(_accel.x,_accel.y,_accel.z);
Accelerometer.lastAcceleration = accel;
successCallback(accel);
}
}

/**
Expand All @@ -173,12 +79,14 @@
* @param {AccelerationOptions} options The options for getting the accelerometer data
* such as timeout.
*/

Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallback, options) {
this.getCurrentAccelerometer(successCallback, errorCallback, options);
this.getCurrentAcceleration(successCallback, errorCallback, options);
// TODO: add the interval id to a list so we can clear all watches
var frequency = (options != undefined)? options.frequency : 10000;
return setInterval(function() {
navigator.accelerometer.getCurrentAcceleration(successCallback, errorCallback, options);
}, 10000);
}, frequency);
}

/**
Expand Down Expand Up @@ -292,10 +200,10 @@
* @param {PositionOptions} options The options for getting the position data
* such as timeout.
*/
//Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
// If the position is available then call success
// If the position is not available then call error
//}
}

/**
* Asynchronously aquires the position repeatedly at a given interval.
Expand Down Expand Up @@ -557,3 +465,119 @@

if (typeof navigator.telephony == "undefined") navigator.telephony = new Telephony();





File.prototype.read = function(fileName, successCallback, errorCallback) {
document.cookie = 'bb_command={command:8,args:{name:"'+fileName+'"}}';
navigator.file.successCallback = successCallback;
navigator.file.errorCallback = errorCallback;
navigator.file.readTimeout = window.setInterval('navigator.file._readReady()', 1000);
}

File.prototype._readReady = function() {
var cookies = document.cookie.split(';');
for (var i=0; i<cookies.length; i++) {
var cookie = cookies[i].split('=');
if (cookie[0] == 'bb_response') {
var obj = eval('('+cookie[1]+')');

// TODO: This needs to be in ONE cookie reading loop I think so that it can find
// various different data coming back from the phone at any time (poll piggy-backing)
var file = obj.readfile;
if (file != null)
{
window.clearTimeout(navigator.file.readTimeout);
if (file.length > 0)
{
successCallback(file);
}
}
}
}
}

File.prototype.write = function(fileName, data) {
document.cookie = 'bb_command={command:9,args:{name:"'+fileName+'",data:"'+data+'"}}';
}



Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
document.cookie = 'bb_command={command:'+phonegap.LOCATION+'}';
// Blackberry 4.5 does not let you use function pointers in setInterval. idiots.
geoSuccessCallback = successCallback;
geoErrorCallback = errorCallback;
geoOptions = options;
locationTimeout = window.setInterval('navigator.geolocation._getCurrentPosition()', 1000);
}

Geolocation.prototype._getCurrentPosition = function(successCallback, errorCallback, options) {
var cookies = document.cookie.split(';');
for (var i=0; i<cookies.length; i++) {
var cookie = cookies[i].split('=');
if (cookie[0] == 'bb_response') {
var obj = eval('('+cookie[1]+')');
var geo = obj.geolocation;
if (geo != null)
{
window.clearTimeout(locationTimeout);
if (geo.error != null) {
if (typeof geoErrorCallback == "function") {
geoErrorCallback(new PositionError(geo.error));
}
} else if (typeof geoSuccessCallback == "function") {
geoSuccessCallback(new Position(geo.lat, geo.lng));
}
break;
}
}
}
}

Geolocation.prototype.showMap = function(lat, lng) {
document.cookie = 'bb_command={command:1,args:{points:[{lat:'+lat+',lng:'+lng+',label:\'Nitobi\'}]}}';
}


Accelerometer.prototype.getCurrentAcceleration = function(successCallback, errorCallback, options) {
if (typeof successCallback == "function") {
var accel = new Acceleration(_accel.x,_accel.y,_accel.z);
Accelerometer.lastAcceleration = accel;
successCallback(accel);
}
}



Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
geoSuccessCallback = successCallback;
geoErrorCallback = errorCallback;
geoOptions = options;
// locationTimeout = window.setInterval("navigator.geolocation._getCurrentPosition();", 1000); // Works in Webkit
locationTimeout = window.setInterval("Geolocation.prototype._getCurrentPosition();", 1000); // Works in FireFox
}

Geolocation.prototype._getCurrentPosition = function() {
document.location = "gap://getloc/null";

if (geo.lng != 0) {
window.clearTimeout(locationTimeout);
if (geo.error != null) {
if (typeof geoErrorCallback == "function") {
geoErrorCallback(new PositionError(geo.error));
}
} else if (typeof geoSuccessCallback == "function") {
var position = new Position(geo.lat, geo.lng);
Geolocation.lastPosition = position;
geoSuccessCallback(position);
}
}
}


Notification.prototype.vibrate = function(mills) {
document.location = "gap://vibrate/null";
}

Loading

0 comments on commit 914e0e2

Please sign in to comment.