mirror of
https://github.com/apache/cordova-android.git
synced 2026-04-23 00:00:09 +08:00
Change to use Commands and CommandManager.
This commit is contained in:
Regular → Executable
+35
-16
@@ -1,14 +1,30 @@
|
||||
com.phonegap.NetworkManagerProxy = function() {
|
||||
this.className = "com.phonegap.NetworkManager";
|
||||
};
|
||||
com.phonegap.NetworkManagerProxy.prototype.isAvailable = function() {
|
||||
return PhoneGap.exec(this.className, "isAvailable", []);
|
||||
};
|
||||
com.phonegap.NetworkManagerProxy.prototype.isWifiActive = function() {
|
||||
return PhoneGap.exec(this.className, "isWifiActive", []);
|
||||
};
|
||||
com.phonegap.NetworkManagerProxy.prototype.isReachable = function(uri) {
|
||||
return PhoneGap.exec(this.className, "isReachable", [uri]);
|
||||
};
|
||||
com.phonegap.NetworkManager = new com.phonegap.NetworkManagerProxy();
|
||||
|
||||
/**
|
||||
* This class contains information about any NetworkStatus.
|
||||
* @constructor
|
||||
*/
|
||||
function NetworkStatus() {
|
||||
this.code = null;
|
||||
this.message = "";
|
||||
}
|
||||
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
|
||||
@@ -21,6 +37,7 @@ function Network() {
|
||||
*/
|
||||
this.lastReachability = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Called by the geolocation framework when the reachability status has changed.
|
||||
* @param {Reachibility} reachability The current reachability status.
|
||||
@@ -28,27 +45,29 @@ function Network() {
|
||||
Network.prototype.updateReachability = function(reachability) {
|
||||
this.lastReachability = reachability;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @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 = NetworkStatus.REACHABLE_VIA_WIFI_NETWORK;
|
||||
} else {
|
||||
status.code = NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK;
|
||||
}
|
||||
} else {
|
||||
status.code = NetworkStatus.NOT_REACHABLE;
|
||||
}
|
||||
Network.prototype.isReachable = function(uri, win, options) {
|
||||
var status = new NetworkStatus();
|
||||
if(com.phonegap.NetworkManager.isReachable(uri)) {
|
||||
if (com.phonegap.NetworkManager.isWifiActive()) {
|
||||
status.code = NetworkStatus.REACHABLE_VIA_WIFI_NETWORK;
|
||||
}
|
||||
else {
|
||||
status.code = NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK;
|
||||
}
|
||||
}
|
||||
else {
|
||||
status.code = NetworkStatus.NOT_REACHABLE;
|
||||
}
|
||||
win(status);
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
if (typeof navigator.network == "undefined") navigator.network = new Network();
|
||||
});
|
||||
Reference in New Issue
Block a user