You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/04/10 00:40:30 UTC

[34/34] wp7 commit: Changes for use with commoner cordova-js

Changes for use with commoner cordova-js


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/commit/f123d4d3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/tree/f123d4d3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/diff/f123d4d3

Branch: refs/heads/master
Commit: f123d4d3344a76e4de29092478fce986448b1607
Parents: 012625d
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Mar 30 12:48:44 2012 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri Mar 30 12:48:44 2012 -0700

----------------------------------------------------------------------
 framework/Cordova/Commands/Device.cs        |    5 +-
 framework/Cordova/Commands/NetworkStatus.cs |   89 ++++++++++++++++++++++
 framework/Cordova/NativeExecution.cs        |    1 +
 framework/CordovaView.xaml.cs               |   11 +++-
 framework/WP7CordovaClassLib.csproj         |    2 +-
 framework/js/network.js                     |    4 +-
 6 files changed, 107 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/f123d4d3/framework/Cordova/Commands/Device.cs
----------------------------------------------------------------------
diff --git a/framework/Cordova/Commands/Device.cs b/framework/Cordova/Commands/Device.cs
index 9429f52..d5ebe0d 100644
--- a/framework/Cordova/Commands/Device.cs
+++ b/framework/Cordova/Commands/Device.cs
@@ -32,7 +32,7 @@ namespace WP7CordovaClassLib.Cordova.Commands
 {
     public class Device : BaseCommand
     {
-        public void Get(string notused)
+        public void getDeviceInfo(string notused)
         {
 
             string res = String.Format("\"name\":\"{0}\",\"cordova\":\"{1}\",\"platform\":\"{2}\",\"uuid\":\"{3}\",\"version\":\"{4}\"",
@@ -43,8 +43,9 @@ namespace WP7CordovaClassLib.Cordova.Commands
                                         this.version);
 
 
+            
             res = "{" + res + "}";
-
+            //Debug.WriteLine("Result::" + res);
             DispatchCommandResult(new PluginResult(PluginResult.Status.OK, res));
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/f123d4d3/framework/Cordova/Commands/NetworkStatus.cs
----------------------------------------------------------------------
diff --git a/framework/Cordova/Commands/NetworkStatus.cs b/framework/Cordova/Commands/NetworkStatus.cs
new file mode 100644
index 0000000..4718c7b
--- /dev/null
+++ b/framework/Cordova/Commands/NetworkStatus.cs
@@ -0,0 +1,89 @@
+/*  
+	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.Net;
+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 WP7CordovaClassLib.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";
+
+
+        public void getConnectionInfo(string empty)
+        {
+
+            //DeviceNetworkInformation.NetworkAvailabilityChanged += new EventHandler<NetworkNotificationEventArgs>(DeviceNetworkInformation_NetworkAvailabilityChanged);
+
+            DispatchCommandResult(new PluginResult(PluginResult.Status.OK, checkConnectionType()));
+        }
+
+        //void DeviceNetworkInformation_NetworkAvailabilityChanged(object sender, NetworkNotificationEventArgs e)
+        //{
+        //    throw new NotImplementedException();
+        //}
+
+        private string checkConnectionType()
+        {
+
+            if (DeviceNetworkInformation.IsNetworkAvailable)
+            {
+                if (DeviceNetworkInformation.IsWiFiEnabled)
+                {
+                    return WIFI;
+                }
+                else
+                {
+                    if (DeviceNetworkInformation.IsCellularDataEnabled)
+                    {
+                        // WP7 doesn't let us determine which type of cell data network
+                        // DeviceNetworkInformation.CellularMobileOperator
+                        return CELL;
+                    }
+                    else
+                    {
+                        return UNKNOWN;
+                    }
+                }
+            }
+            else
+            {
+                return NONE;
+            }
+        }
+
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/f123d4d3/framework/Cordova/NativeExecution.cs
----------------------------------------------------------------------
diff --git a/framework/Cordova/NativeExecution.cs b/framework/Cordova/NativeExecution.cs
index 253c9e3..ea8a181 100644
--- a/framework/Cordova/NativeExecution.cs
+++ b/framework/Cordova/NativeExecution.cs
@@ -191,6 +191,7 @@ namespace WP7CordovaClassLib.Cordova
             {
                 try
                 {
+                    Debug.WriteLine("InvokingScript::" + script.ScriptName + " with args ::" + script.Args[0] + ", " + script.Args[1] + ", " + script.Args[2]);
                     this.webBrowser.InvokeScript(script.ScriptName, script.Args);
                 }
                 catch (Exception ex)

http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/f123d4d3/framework/CordovaView.xaml.cs
----------------------------------------------------------------------
diff --git a/framework/CordovaView.xaml.cs b/framework/CordovaView.xaml.cs
index fc44109..7086f9c 100644
--- a/framework/CordovaView.xaml.cs
+++ b/framework/CordovaView.xaml.cs
@@ -321,6 +321,10 @@ namespace WP7CordovaClassLib
         void GapBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
         {
             this.CordovaBrowser.Opacity = 1;
+
+            string nativeReady = "try{ cordova.require('cordova/channel').onNativeReady.fire() }catch(e){console.log('error firing nativeReady event' + e);}";
+
+            CordovaBrowser.InvokeScript("execScript",  new string[] { nativeReady });
         }
 
 
@@ -330,6 +334,10 @@ namespace WP7CordovaClassLib
             // TODO: tell any running plugins to stop doing what they are doing.
             // TODO: check whitelist / blacklist
             // NOTE: Navigation can be cancelled by setting :        e.Cancel = true;
+
+            
+
+
         }
 
         /*
@@ -358,7 +366,7 @@ namespace WP7CordovaClassLib
             }
 
             CordovaCommandCall commandCallParams = CordovaCommandCall.Parse(commandStr);
-
+            
             if (commandCallParams == null)
             {
                 // ERROR
@@ -376,6 +384,7 @@ namespace WP7CordovaClassLib
             }
             else
             {
+                Debug.WriteLine("ProcessCommand :: " + commandStr);
                 this.nativeExecution.ProcessCommand(commandCallParams);
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/f123d4d3/framework/WP7CordovaClassLib.csproj
----------------------------------------------------------------------
diff --git a/framework/WP7CordovaClassLib.csproj b/framework/WP7CordovaClassLib.csproj
index f90c702..daa1962 100644
--- a/framework/WP7CordovaClassLib.csproj
+++ b/framework/WP7CordovaClassLib.csproj
@@ -88,7 +88,7 @@
     <Compile Include="Cordova\CordovaCommandCall.cs" />
     <Compile Include="Cordova\CommandFactory.cs" />
     <Compile Include="Cordova\Commands\BaseCommand.cs" />
-    <Compile Include="Cordova\Commands\Connection.cs" />
+    <Compile Include="Cordova\Commands\NetworkStatus.cs" />
     <Compile Include="Cordova\Commands\DebugConsole.cs" />
     <Compile Include="Cordova\Commands\Device.cs" />
     <Compile Include="Cordova\Commands\File.cs" />

http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/f123d4d3/framework/js/network.js
----------------------------------------------------------------------
diff --git a/framework/js/network.js b/framework/js/network.js
index 3ab9337..9c84be7 100644
--- a/framework/js/network.js
+++ b/framework/js/network.js
@@ -26,6 +26,7 @@ var Connection = function()
     this._timer = null;
     this.timeout = 500;
 
+/*
     var me = this;
     this.getInfo(
         function(type) {
@@ -54,13 +55,14 @@ var Connection = function()
             if (me._firstRun) 
 			{
                 me._firstRun = false;
-				//console.log("onCordovaConnectionReady");
+				console.log("onCordovaConnectionReady");
                 Cordova.onCordovaConnectionReady.fire();
             }            
         },
         function(e) {
             console.log("Error initializing Network Connection: " + e);
         });
+*/
 };
 
 Connection.UNKNOWN = "unknown";