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/24 23:10:00 UTC
git commit: [CB-3674] first pass wp8 support
Updated Branches:
refs/heads/master 478154b66 -> 5fd19bb5c
[CB-3674] first pass wp8 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/5fd19bb5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/tree/5fd19bb5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/diff/5fd19bb5
Branch: refs/heads/master
Commit: 5fd19bb5cca1950235816e1ea9fe37dedfdf487f
Parents: 478154b
Author: Benn Mapes <be...@gmail.com>
Authored: Mon Jun 24 14:06:42 2013 -0700
Committer: Benn Mapes <be...@gmail.com>
Committed: Mon Jun 24 14:09:08 2013 -0700
----------------------------------------------------------------------
plugin.xml | 11 +++++++
src/wp8/Battery.cs | 79 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 90 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/5fd19bb5/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 9c919ba..ca4e5f4 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -49,5 +49,16 @@ id="org.apache.cordova.core.BatteryListener" version="0.1.0">
<source-file src="src/wp7/Battery.cs" />
</platform>
+
+ <!-- wp8 -->
+ <platform name="wp8">
+ <config-file target="config.xml" parent="/*">
+ <feature name="Battery">
+ <param name="wp-package" value="Battery"/>
+ </feature>
+ </config-file>
+
+ <source-file src="src/wp8/Battery.cs" />
+ </platform>
</plugin>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/5fd19bb5/src/wp8/Battery.cs
----------------------------------------------------------------------
diff --git a/src/wp8/Battery.cs b/src/wp8/Battery.cs
new file mode 100644
index 0000000..962959e
--- /dev/null
+++ b/src/wp8/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;
+ }
+
+ }
+}