You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2013/05/07 17:18:42 UTC

[05/30] git commit: adding wp7

adding wp7


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

Branch: refs/heads/future
Commit: f66a171576c3b32b571d3ad6a5bd3300e01552bd
Parents: 33d79ba
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Apr 12 01:16:15 2013 -0700
Committer: Anis Kadri <an...@apache.org>
Committed: Mon Apr 22 16:28:05 2013 -0700

----------------------------------------------------------------------
 platforms/wp7.js                                   |  117 +++++++++
 plugman.js                                         |    3 +-
 test/plugins/ChildBrowser/plugin.xml               |   21 ++
 .../ChildBrowser/src/wp7/ChildBrowserCommand.cs    |  197 +++++++++++++++
 .../src/wp7/Images/appbar.back.rest.png            |  Bin 0 -> 375 bytes
 .../src/wp7/Images/appbar.close.rest.png           |  Bin 0 -> 359 bytes
 .../src/wp7/Images/appbar.next.rest.png            |  Bin 0 -> 388 bytes
 7 files changed, 337 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f66a1715/platforms/wp7.js
----------------------------------------------------------------------
diff --git a/platforms/wp7.js b/platforms/wp7.js
new file mode 100644
index 0000000..2889f87
--- /dev/null
+++ b/platforms/wp7.js
@@ -0,0 +1,117 @@
+/*
+ *
+ * Copyright 2013 Jesse MacFadyen
+ *
+ * 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.
+ *
+*/
+
+/*
+$ node plugman --platform wp7 
+  --project '/c//users/jesse/documents/visual studio 2012/Projects/TestPlugin7/' 
+  --plugin '.\test\plugins\ChildBrowser\'
+*/
+
+var fs = require('fs'),
+    path = require('path'),
+    glob = require('glob'),
+    shell = require('shelljs'),
+    et = require('elementtree'),
+    assetsDir = 'www'; // relative path to project's web assets
+
+function copyFileSync(srcPath, destPath) {
+
+  var stats = fs.statSync(srcPath);
+  if(stats.isDirectory()) {
+     shell.mkdir('-p', destPath);
+     // without the added slash at the end, we will get an extra folder inside destination
+     shell.cp('-r', srcPath + "/" , destPath);
+  }
+  else if(fs.existsSync(srcPath)) {
+    shell.cp(srcPath, destPath);
+  }
+  else {
+    console.log("File does not exist :: " + srcPath);
+    return;
+  }
+
+  var msg = shell.error();
+  if(msg) {
+    console.log("msg" + msg);
+    throw { name: "ShellError", message: msg};
+  }
+}    
+
+function install(project_dir, plugin_dir, plugin_et, variables) {
+
+  var unix_projPath = project_dir.split("\\").join("/");
+  var project_file = glob.sync('*.csproj',{nocase:true,cwd:unix_projPath})[0];
+  var projPath = path.join(unix_projPath,project_file);
+  var assets = plugin_et.findall('./asset');
+  var platformTag = plugin_et.find('./platform[@name="wp7"]');
+  var sourceFiles = platformTag.findall('./source-file');
+  var projectChanges = platformTag.findall('./config-file[@target=".csproj"]');
+
+
+  // move asset files
+  assets && assets.forEach(function (asset) {
+      var srcPath = path.resolve(plugin_dir, asset.attrib['src']);
+      var targetPath = path.resolve(project_dir, assetsDir,  asset.attrib['target']);
+      copyFileSync(srcPath, targetPath);
+  });
+
+  // move source files
+  sourceFiles && sourceFiles.forEach(function (sourceFile) {
+      var srcFilePath = path.resolve(plugin_dir,  sourceFile.attrib['src']);
+      var destDir = path.resolve(project_dir, sourceFile.attrib['target-dir']);
+      var destFilePath = path.resolve(destDir, path.basename(sourceFile.attrib['src']));
+      copyFileSync(srcFilePath, destFilePath);
+  });
+
+  et.register_namespace("csproj", "http://schemas.microsoft.com/developer/msbuild/2003");
+  projectChanges && projectChanges.forEach(function (configNode) {
+
+    var docStr = fs.readFileSync(projPath,"utf8");
+
+    // child is the configNode child that we will insert into csproj
+    var child = configNode.find('*'); 
+
+    var newNodeText = new et.ElementTree(child).write({xml_declaration:false});
+        newNodeText = newNodeText.split("&#xA;").join("\n").split("&#xD;").join("\r");
+    // insert text right before closing tag
+    var newDocStr = docStr.replace("</Project>",newNodeText + "\n</Project>");
+    // save it, and get out
+    fs.writeFileSync(projPath, newDocStr);
+  });
+}
+
+function uninstall(project_dir, plugin_dir, plugin_et, variables) {
+   // uninstall would be : shell.rm('-rf', targetPath);
+}
+
+exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et, variables) {
+
+    switch(action) {
+        case 'install' :
+            //console.log('installing');
+            install(project_dir, plugin_dir, plugin_et, variables);
+            break;
+        case 'uninstall' :
+            console.log('uninstalling');
+            break;
+        default :
+          throw 'error unknown action';
+          break;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f66a1715/plugman.js
----------------------------------------------------------------------
diff --git a/plugman.js b/plugman.js
index a422dab..fd8e0dd 100755
--- a/plugman.js
+++ b/plugman.js
@@ -30,10 +30,11 @@ var fs = require('fs')
         'android': require('./platforms/android'),
         'ios': require('./platforms/ios'),
         'blackberry': require('./platforms/blackberry'),
+        'wp7': require('./platforms/wp7'),
         'www': require('./platforms/www')
     };
 
-var known_opts = { 'platform' : [ 'ios', 'android', 'blackberry' ,'www' ]
+var known_opts = { 'platform' : [ 'ios', 'android', 'blackberry' ,'wp7' , 'www' ]
             , 'project' : path
             , 'plugin' : [String, path, url]
             , 'remove' : Boolean

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f66a1715/test/plugins/ChildBrowser/plugin.xml
----------------------------------------------------------------------
diff --git a/test/plugins/ChildBrowser/plugin.xml b/test/plugins/ChildBrowser/plugin.xml
index 25524e2..e166870 100644
--- a/test/plugins/ChildBrowser/plugin.xml
+++ b/test/plugins/ChildBrowser/plugin.xml
@@ -101,4 +101,25 @@
         <framework src="social.framework" weak="true" />
         <framework src="music.framework" weak="rabbit" />
     </platform>
+
+    <!-- wp7 -->
+    <platform name="wp7">
+        <resource-file src="src\wp7\Images\appbar.back.rest.png" />
+        <config-file target="config.xml" parent="/widget/plugins">
+            <plugin name="ChildBrowser"
+                value="ChildBrowser"/>
+        </config-file>
+
+        <source-file src="src\wp7\ChildBrowserCommand.cs"
+                     target-dir="Plugins\" />
+
+        <!-- modify the project file to include the added files -->
+        <config-file target=".csproj" parent=".">
+            <ItemGroup>
+                <Compile Include="Plugins\\ChildBrowserCommand.cs"/>
+                <Content Include="www\\childbrowser.js" />
+            </ItemGroup>    
+        </config-file> 
+
+    </platform>
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f66a1715/test/plugins/ChildBrowser/src/wp7/ChildBrowserCommand.cs
----------------------------------------------------------------------
diff --git a/test/plugins/ChildBrowser/src/wp7/ChildBrowserCommand.cs b/test/plugins/ChildBrowser/src/wp7/ChildBrowserCommand.cs
new file mode 100644
index 0000000..f56c7e5
--- /dev/null
+++ b/test/plugins/ChildBrowser/src/wp7/ChildBrowserCommand.cs
@@ -0,0 +1,197 @@
+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.Controls;
+using System.Diagnostics;
+using System.Runtime.Serialization;
+using Microsoft.Phone.Shell;
+
+namespace WPCordovaClassLib.Cordova.Commands
+{
+    [DataContract]
+    public class BrowserOptions
+    {
+        [DataMember]
+        public string url;
+
+        [DataMember]
+        public bool isGeolocationEnabled;
+    }
+
+    public class ChildBrowserCommand : BaseCommand
+    {
+
+        private static WebBrowser browser;
+        private static ApplicationBarIconButton backButton;
+        private static ApplicationBarIconButton fwdButton;
+
+        // Display an inderminate progress indicator
+        public void showWebPage(string options)
+        {
+            BrowserOptions opts = JSON.JsonHelper.Deserialize<BrowserOptions>(options);
+
+            Uri loc = new Uri(opts.url);
+
+            Deployment.Current.Dispatcher.BeginInvoke(() =>
+            {
+                if (browser != null)
+                {
+                    browser.IsGeolocationEnabled = opts.isGeolocationEnabled;
+                    browser.Navigate(loc);
+                }
+                else
+                {
+                    PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
+                    if (frame != null)
+                    {
+                        PhoneApplicationPage page = frame.Content as PhoneApplicationPage;
+                        if (page != null)
+                        {
+                            Grid grid = page.FindName("LayoutRoot") as Grid;
+                            if (grid != null)
+                            {
+                                browser = new WebBrowser();
+                                browser.Navigate(loc);
+
+                                browser.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(browser_LoadCompleted);
+
+                                browser.Navigating += new EventHandler<NavigatingEventArgs>(browser_Navigating);
+                                browser.NavigationFailed += new System.Windows.Navigation.NavigationFailedEventHandler(browser_NavigationFailed);
+                                browser.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(browser_Navigated);
+                                browser.IsScriptEnabled = true;
+                                browser.IsGeolocationEnabled = opts.isGeolocationEnabled;
+                                grid.Children.Add(browser);
+                            }
+
+                            ApplicationBar bar = new ApplicationBar();
+                            bar.BackgroundColor = Colors.Black;
+                            bar.IsMenuEnabled = false;
+
+                            backButton = new ApplicationBarIconButton();
+                            backButton.Text = "Back";
+                            backButton.IconUri = new Uri("/Images/appbar.back.rest.png", UriKind.Relative);
+                            backButton.Click += new EventHandler(backButton_Click);
+                            backButton.IsEnabled = false;
+                            bar.Buttons.Add(backButton);
+
+
+                            fwdButton = new ApplicationBarIconButton();
+                            fwdButton.Text = "Forward";
+                            fwdButton.IconUri = new Uri("/Images/appbar.next.rest.png", UriKind.Relative);
+                            fwdButton.Click += new EventHandler(fwdButton_Click);
+                            fwdButton.IsEnabled = false;
+                            bar.Buttons.Add(fwdButton);
+
+                            ApplicationBarIconButton closeBtn = new ApplicationBarIconButton();
+                            closeBtn.Text = "Close";
+                            closeBtn.IconUri = new Uri("/Images/appbar.close.rest.png", UriKind.Relative);
+                            closeBtn.Click += new EventHandler(closeBtn_Click);
+                            bar.Buttons.Add(closeBtn);
+
+                            page.ApplicationBar = bar;
+                        }
+
+                    }
+                }
+            });
+        }
+
+        void browser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
+        {
+            
+        }
+
+        void fwdButton_Click(object sender, EventArgs e)
+        {
+            if (browser != null)
+            {
+                try
+                {
+                    browser.InvokeScript("execScript", "history.forward();");
+                }
+                catch(Exception)
+                {
+
+                }
+            }
+        }
+
+        void backButton_Click(object sender, EventArgs e)
+        {
+            if (browser != null)
+            {
+                try
+                {
+                    browser.InvokeScript("execScript", "history.back();");
+                }
+                catch (Exception)
+                {
+
+                }
+            }
+        }
+
+        void closeBtn_Click(object sender, EventArgs e)
+        {
+            this.close();
+        }
+
+
+        public void close(string options="")
+        {
+            if (browser != null)
+            {
+                Deployment.Current.Dispatcher.BeginInvoke(() =>
+                {
+                    PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
+                    if (frame != null)
+                    {
+                        PhoneApplicationPage page = frame.Content as PhoneApplicationPage;
+                        if (page != null)
+                        {
+                            Grid grid = page.FindName("LayoutRoot") as Grid;
+                            if (grid != null)
+                            {
+                                grid.Children.Remove(browser);
+                            }
+                            page.ApplicationBar = null;
+                        }
+                    }
+                    browser = null;
+                });
+            }
+        }
+
+        void browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
+        {
+            string message = "{\"type\":\"locationChanged\", \"location\":\"" + e.Uri.AbsoluteUri + "\"}";
+            PluginResult result = new PluginResult(PluginResult.Status.OK, message);
+            result.KeepCallback = true;
+            this.DispatchCommandResult(result);
+        }
+
+        void browser_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
+        {
+            string message = "{\"type\":\"navigationError\",\"location\":\"" + e.Uri.AbsoluteUri + "\"}";
+            PluginResult result = new PluginResult(PluginResult.Status.ERROR, message);
+            result.KeepCallback = true;
+            this.DispatchCommandResult(result);
+        }
+
+        void browser_Navigating(object sender, NavigatingEventArgs e)
+        {
+            string message = "{\"type\":\"locationAboutToChange\",\"location\":\"" + e.Uri.AbsoluteUri + "\"}";
+            PluginResult result = new PluginResult(PluginResult.Status.OK, message);
+            result.KeepCallback = true;
+            this.DispatchCommandResult(result);
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f66a1715/test/plugins/ChildBrowser/src/wp7/Images/appbar.back.rest.png
----------------------------------------------------------------------
diff --git a/test/plugins/ChildBrowser/src/wp7/Images/appbar.back.rest.png b/test/plugins/ChildBrowser/src/wp7/Images/appbar.back.rest.png
new file mode 100644
index 0000000..4bc2b92
Binary files /dev/null and b/test/plugins/ChildBrowser/src/wp7/Images/appbar.back.rest.png differ

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f66a1715/test/plugins/ChildBrowser/src/wp7/Images/appbar.close.rest.png
----------------------------------------------------------------------
diff --git a/test/plugins/ChildBrowser/src/wp7/Images/appbar.close.rest.png b/test/plugins/ChildBrowser/src/wp7/Images/appbar.close.rest.png
new file mode 100644
index 0000000..8166a1c
Binary files /dev/null and b/test/plugins/ChildBrowser/src/wp7/Images/appbar.close.rest.png differ

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f66a1715/test/plugins/ChildBrowser/src/wp7/Images/appbar.next.rest.png
----------------------------------------------------------------------
diff --git a/test/plugins/ChildBrowser/src/wp7/Images/appbar.next.rest.png b/test/plugins/ChildBrowser/src/wp7/Images/appbar.next.rest.png
new file mode 100644
index 0000000..ed577d7
Binary files /dev/null and b/test/plugins/ChildBrowser/src/wp7/Images/appbar.next.rest.png differ