cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bennma...@apache.org
Subject git commit: first pass at wp7 support
Date Tue, 28 May 2013 00:29:27 GMT
Updated Branches:
  refs/heads/master ec25c1f3d -> a339c3f5c


first pass at wp7 support


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/commit/a339c3f5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/tree/a339c3f5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/diff/a339c3f5

Branch: refs/heads/master
Commit: a339c3f5c629da84f66c0a26de29083d7530e697
Parents: ec25c1f
Author: Benn Mapes <benn.mapes@gmail.com>
Authored: Mon May 27 17:26:01 2013 -0700
Committer: Benn Mapes <benn.mapes@gmail.com>
Committed: Mon May 27 17:29:10 2013 -0700

----------------------------------------------------------------------
 plugin.xml         |   13 +++++++-
 src/wp7/Battery.cs |   79 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/a339c3f5/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 4599a52..663177f 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.BatteryListener">
     version="0.1.0">
@@ -31,5 +31,16 @@ id="org.apache.cordova.core.BatteryListener">
         <header-file src="src/ios/CDVBattery.h" />
 	    <source-file src="src/ios/CDVBattery.m" />
     </platform>
+
+    <!-- wp7 -->
+    <platform name="wp7">
+        <config-file target="config.xml" parent="/*">
+            <feature name="Battery">
+                <param name="wp-package" value="Battery"/>
+            </feature>
+        </config-file>
+
+        <source-file src="src/wp7/Battery.cs" />
+    </platform>
     
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/a339c3f5/src/wp7/Battery.cs
----------------------------------------------------------------------
diff --git a/src/wp7/Battery.cs b/src/wp7/Battery.cs
new file mode 100644
index 0000000..962959e
--- /dev/null
+++ b/src/wp7/Battery.cs
@@ -0,0 +1,79 @@
+/*  
+	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.Info;
+
+namespace WPCordovaClassLib.Cordova.Commands
+{
+    /// <summary>
+    /// Listens for changes to the state of the battery on the device.
+    /// Currently only the "isPlugged" parameter available via native APIs.
+    /// </summary>
+    public class Battery : BaseCommand
+    {
+        private bool isPlugged = false;
+        private EventHandler powerChanged;
+
+        public Battery()
+        {
+            powerChanged = new EventHandler(DeviceStatus_PowerSourceChanged);
+            isPlugged = DeviceStatus.PowerSource.ToString().CompareTo("External") == 0;
+        }
+
+        public void start(string options)
+        {
+            // Register power changed event handler
+            DeviceStatus.PowerSourceChanged += powerChanged;
+
+            PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
+            result.KeepCallback = true;
+            DispatchCommandResult(result);
+        }
+        public void stop(string options)
+        {
+            // Unregister power changed event handler
+            DeviceStatus.PowerSourceChanged -= powerChanged;
+        }
+
+        private void DeviceStatus_PowerSourceChanged(object sender, EventArgs e)
+        {
+            isPlugged = DeviceStatus.PowerSource.ToString().CompareTo("External") == 0;
+            PluginResult result = new PluginResult(PluginResult.Status.OK, GetCurrentBatteryStateFormatted());
+            result.KeepCallback = true;
+            DispatchCommandResult(result);
+        }
+
+        private string GetCurrentBatteryStateFormatted()
+        {
+            string batteryState = String.Format("\"level\":{0},\"isPlugged\":{1}",
+                                                    "null",
+                                                    isPlugged ? "true" : "false"
+                            );
+            batteryState = "{" + batteryState + "}";
+            return batteryState;
+        }
+
+    }
+}


Mime
View raw message