You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by be...@apache.org on 2013/06/25 00:58:48 UTC
git commit: [CB-3730] first pass wp8 support
Updated Branches:
refs/heads/master 27a1eef5a -> f716a28b1
[CB-3730] first pass wp8 support
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/commit/f716a28b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/tree/f716a28b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/diff/f716a28b
Branch: refs/heads/master
Commit: f716a28b1c2b2eaa1e8696faa5864f2689d18028
Parents: 27a1eef
Author: Benn Mapes <be...@gmail.com>
Authored: Mon Jun 24 15:58:28 2013 -0700
Committer: Benn Mapes <be...@gmail.com>
Committed: Mon Jun 24 15:58:28 2013 -0700
----------------------------------------------------------------------
plugin.xml | 17 +++++-
src/wp8/NetworkStatus.cs | 129 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 145 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/blob/f716a28b/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 974998d..78dd358 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
+<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.apache.cordova.core.NetworkManager" version="0.1.0">
@@ -60,4 +60,19 @@ id="org.apache.cordova.core.NetworkManager" version="0.1.0">
<source-file src="src/wp7/NetworkStatus.cs" />
</platform>
+ <!-- wp8 -->
+ <platform name="wp8">
+ <config-file target="config.xml" parent="/*">
+ <feature name="NetworkStatus">
+ <param name="wp-package" value="NetworkStatus"/>
+ </feature>
+ </config-file>
+
+ <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
+ <Capability Name="ID_CAP_NETWORKING" />
+ </config-file>
+
+ <source-file src="src/wp8/NetworkStatus.cs" />
+ </platform>
+
</plugin>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/blob/f716a28b/src/wp8/NetworkStatus.cs
----------------------------------------------------------------------
diff --git a/src/wp8/NetworkStatus.cs b/src/wp8/NetworkStatus.cs
new file mode 100644
index 0000000..12eb061
--- /dev/null
+++ b/src/wp8/NetworkStatus.cs
@@ -0,0 +1,129 @@
+/*
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+using System;
+using System.Diagnostics;
+using System.Net;
+using System.Net.NetworkInformation;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Ink;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using Microsoft.Phone.Net.NetworkInformation;
+
+namespace WPCordovaClassLib.Cordova.Commands
+{
+
+ // http://msdn.microsoft.com/en-us/library/microsoft.phone.net.networkinformation(v=VS.92).aspx
+ // http://msdn.microsoft.com/en-us/library/microsoft.phone.net.networkinformation.devicenetworkinformation(v=VS.92).aspx
+
+ public class NetworkStatus : BaseCommand
+ {
+ const string UNKNOWN = "unknown";
+ const string ETHERNET = "ethernet";
+ const string WIFI = "wifi";
+ const string CELL_2G = "2g";
+ const string CELL_3G = "3g";
+ const string CELL_4G = "4g";
+ const string NONE = "none";
+ const string CELL = "cellular";
+
+ private bool HasCallback = false;
+
+ public NetworkStatus()
+ {
+ DeviceNetworkInformation.NetworkAvailabilityChanged += new EventHandler<NetworkNotificationEventArgs>(ChangeDetected);
+ }
+
+ public override void OnResume(object sender, Microsoft.Phone.Shell.ActivatedEventArgs e)
+ {
+ this.getConnectionInfo("");
+ }
+
+ public void getConnectionInfo(string empty)
+ {
+ HasCallback = true;
+ updateConnectionType(checkConnectionType());
+ }
+
+ private string checkConnectionType()
+ {
+ if (DeviceNetworkInformation.IsNetworkAvailable)
+ {
+ if (DeviceNetworkInformation.IsWiFiEnabled)
+ {
+ return WIFI;
+ }
+ else
+ {
+ return DeviceNetworkInformation.IsCellularDataEnabled ? CELL : UNKNOWN;
+ }
+ }
+ return NONE;
+ }
+
+ private string checkConnectionType(NetworkInterfaceSubType type)
+ {
+ switch (type)
+ {
+ case NetworkInterfaceSubType.Cellular_1XRTT: //cell
+ case NetworkInterfaceSubType.Cellular_GPRS: //cell
+ return CELL;
+ case NetworkInterfaceSubType.Cellular_EDGE: //2
+ return CELL_2G;
+ case NetworkInterfaceSubType.Cellular_3G:
+ case NetworkInterfaceSubType.Cellular_EVDO: //3
+ case NetworkInterfaceSubType.Cellular_EVDV: //3
+ case NetworkInterfaceSubType.Cellular_HSPA: //3
+ return CELL_3G;
+ case NetworkInterfaceSubType.WiFi:
+ return WIFI;
+ case NetworkInterfaceSubType.Unknown:
+ case NetworkInterfaceSubType.Desktop_PassThru:
+ default:
+ return UNKNOWN;
+ }
+ }
+
+ void ChangeDetected(object sender, NetworkNotificationEventArgs e)
+ {
+ switch (e.NotificationType)
+ {
+ case NetworkNotificationType.InterfaceConnected:
+ updateConnectionType(checkConnectionType(e.NetworkInterface.InterfaceSubtype));
+ break;
+ case NetworkNotificationType.InterfaceDisconnected:
+ updateConnectionType(NONE);
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void updateConnectionType(string type)
+ {
+ // This should also implicitly fire offline/online events as that is handled on the JS side
+ if (this.HasCallback)
+ {
+ PluginResult result = new PluginResult(PluginResult.Status.OK, type);
+ result.KeepCallback = true;
+ DispatchCommandResult(result);
+ }
+ }
+ }
+}