Added ARenzi`s Reachability fixes.

This commit is contained in:
filmaj
2010-02-23 11:07:30 -08:00
parent b0054aa1b4
commit 02c750134c
4 changed files with 126 additions and 184 deletions
+53 -86
View File
@@ -72,7 +72,7 @@ PhoneGap.addConstructor = function(func) {
e.initEvent('deviceready');
document.dispatchEvent(e);
}
}, 1);
}, 5);
})();
@@ -138,10 +138,11 @@ function Acceleration(x, y, z)
this.x = x;
this.y = y;
this.z = z;
this.timestamp = new Date().getTime();
}
// Need to define these for android
_accel = {}
_accel = {};
_accel.x = 0;
_accel.y = 0;
_accel.z = 0;
@@ -355,7 +356,7 @@ PhoneGap.addConstructor(function() {
if (typeof navigator.compass == "undefined") navigator.compass = new Compass();
});
var Contact = function(){
this.name = null;
this.name = new ContactName();
this.emails = [];
this.phones = [];
}
@@ -393,7 +394,18 @@ Contacts.prototype.find = function(obj, win, fail)
{
if(obj.name != null)
{
ContactHook.search(name, "", "");
// Build up the search term that we'll use in SQL, based on the structure/contents of the contact object passed into find.
var searchTerm = '';
if (obj.name.givenName && obj.name.givenName.length > 0) {
searchTerm = obj.name.givenName.split(' ').join('%');
}
if (obj.name.familyName && obj.name.familyName.length > 0) {
searchTerm += obj.name.familyName.split(' ').join('%');
}
if (!obj.name.familyName && !obj.name.givenName && obj.name.formatted) {
searchTerm = obj.name.formatted;
}
ContactHook.search(searchTerm, "", "");
}
this.win = win;
this.fail = fail;
@@ -578,46 +590,12 @@ function Geolocation() {
};
};
/**
* Asynchronously aquires the current position.
* @param {Function} successCallback The function to call when the position
* data is available
* @param {Function} errorCallback The function to call when there is an error
* getting the position data.
* @param {PositionOptions} options The options for getting the position data
* such as timeout.
*/
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
var referenceTime = 0;
if (this.lastPosition)
referenceTime = this.lastPosition.timeout;
else
this.start(options);
var timeout = 20000;
var interval = 500;
if (typeof(options) == 'object' && options.interval)
interval = options.interval;
if (typeof(successCallback) != 'function')
successCallback = function() {};
if (typeof(errorCallback) != 'function')
errorCallback = function() {};
var dis = this;
var delay = 0;
var timer = setInterval(function() {
delay += interval;
if (typeof(dis.lastPosition) == 'object' && dis.lastPosition.timestamp > referenceTime) {
successCallback(dis.lastPosition);
clearInterval(timer);
} else if (delay >= timeout) {
errorCallback();
clearInterval(timer);
}
}, interval);
};
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options)
{
var position = Geo.getCurrentLocation();
this.global_success = successCallback;
this.fail = errorCallback;
}
/**
* Asynchronously aquires the position repeatedly at a given interval.
@@ -675,23 +653,6 @@ Geolocation.prototype.setError = function(message) {
f(message);
}
};
PhoneGap.addConstructor(function() {
if (typeof navigator.geolocation == "undefined") navigator.geolocation = new Geolocation();
});
/*
* Since we can't guarantee that we will have the most recent, we just try our best!
*
* Also, the API doesn't specify which version is the best version of the API
*/
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options)
{
var position = Geo.getCurrentLocation();
this.global_success = successCallback;
this.fail = errorCallback;
}
// Run the global callback
Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head, vel, stamp)
@@ -704,6 +665,7 @@ Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head,
{
coords = new Coordinates(lat, lng, alt, altacc, head, vel);
loc = new Position(coords, stamp);
this.lastPosition = loc;
this.global_success(loc);
}
}
@@ -749,7 +711,19 @@ Geolocation.prototype.clearWatch = function(watchId)
{
Geo.stop(watchId);
}
function KeyEvent()
// Taken from Jesse's geo fix (similar problem) in PhoneGap iPhone. Go figure, same browser!
function __proxyObj(origObj, proxyObj, funkList) {
for (var v in funkList) {
origObj[funkList[v]] = proxyObj[funkList[v]];
}
}
PhoneGap.addConstructor(function() {
navigator._geo = new Geolocation();
__proxyObj(navigator.geolocation, navigator._geo,
["setLocation", "getCurrentPosition", "watchPosition",
"clearWatch", "setError", "start", "stop", "gotCurrentPosition"]
);
});function KeyEvent()
{
}
@@ -841,11 +815,9 @@ function NetworkStatus() {
this.code = null;
this.message = "";
}
NetworkStatus.NOT_REACHABLE = 0;
NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK = 1;
NetworkStatus.REACHABLE_VIA_WIFI_NETWORK = 2;
/**
* This class provides access to device Network data (reachability).
* @constructor
@@ -858,16 +830,6 @@ function Network() {
*/
this.lastReachability = null;
};
/**
*
* @param {Function} successCallback
* @param {Function} errorCallback
* @param {Object} options (isIpAddress:boolean)
*/
Network.prototype.isReachable = function(hostName, successCallback, options) {
}
/**
* Called by the geolocation framework when the reachability status has changed.
* @param {Reachibility} reachability The current reachability status.
@@ -875,25 +837,30 @@ Network.prototype.isReachable = function(hostName, successCallback, options) {
Network.prototype.updateReachability = function(reachability) {
this.lastReachability = reachability;
};
PhoneGap.addConstructor(function() {
if (typeof navigator.network == "undefined") navigator.network = new Network();
});
/**
*
* @param {Object} uri
* @param {Function} win
* @param {Object} options (isIpAddress:boolean)
*/
Network.prototype.isReachable = function(uri, win, options)
{
var status = new NetworkStatus();
if(NetworkManager.isReachable(uri))
{
if (NetworkManager.isWifiActive)
status.code = 2;
else
status.code = 1;
if (NetworkManager.isWifiActive()) {
status.code = NetworkStatus.REACHABLE_VIA_WIFI_NETWORK;
} else {
status.code = NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK;
}
} else {
status.code = NetworkStatus.NOT_REACHABLE;
}
else
status.code = 0;
win(status);
}
/**
};
PhoneGap.addConstructor(function() {
if (typeof navigator.network == "undefined") navigator.network = new Network();
});/**
* This class provides access to notifications on the device.
*/
function Notification() {