cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [4/8] git commit: wp8 add support in level
Date Thu, 05 Dec 2013 00:55:39 GMT
wp8 add support in level


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/7f98d285
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/tree/7f98d285
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/diff/7f98d285

Branch: refs/heads/master
Commit: 7f98d2855befc1097d7d8336ecd7bee0448c8947
Parents: c35a2e2
Author: fupw_pc <fupw@polyvi.com>
Authored: Fri Nov 1 17:10:09 2013 +0800
Committer: fupw_pc <fupw@polyvi.com>
Committed: Fri Nov 1 17:10:09 2013 +0800

----------------------------------------------------------------------
 docs/events.batterystatus.md |  2 +-
 src/wp/Battery.cs            | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/7f98d285/docs/events.batterystatus.md
----------------------------------------------------------------------
diff --git a/docs/events.batterystatus.md b/docs/events.batterystatus.md
index 6ef4a25..40c86c1 100644
--- a/docs/events.batterystatus.md
+++ b/docs/events.batterystatus.md
@@ -45,7 +45,7 @@ Supported Platforms
 - Windows Phone 7 and 8
 - Tizen
 
-Windows Phone 7 and 8 Quirks
+Windows Phone 7 Quirks
 ----------------------
 
 The `level` property is unavailable as Windows Phone 7 does not provide

http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/7f98d285/src/wp/Battery.cs
----------------------------------------------------------------------
diff --git a/src/wp/Battery.cs b/src/wp/Battery.cs
index 962959e..d187107 100644
--- a/src/wp/Battery.cs
+++ b/src/wp/Battery.cs
@@ -29,23 +29,25 @@ 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;
+        private Windows.Phone.Devices.Power.Battery battery;
 
         public Battery()
         {
             powerChanged = new EventHandler(DeviceStatus_PowerSourceChanged);
             isPlugged = DeviceStatus.PowerSource.ToString().CompareTo("External") == 0;
+            battery = Windows.Phone.Devices.Power.Battery.GetDefault();
         }
 
         public void start(string options)
         {
             // Register power changed event handler
             DeviceStatus.PowerSourceChanged += powerChanged;
+            battery.RemainingChargePercentChanged += Battery_RemainingChargePercentChanged;
 
             PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
             result.KeepCallback = true;
@@ -55,6 +57,7 @@ namespace WPCordovaClassLib.Cordova.Commands
         {
             // Unregister power changed event handler
             DeviceStatus.PowerSourceChanged -= powerChanged;
+            battery.RemainingChargePercentChanged -= Battery_RemainingChargePercentChanged;
         }
 
         private void DeviceStatus_PowerSourceChanged(object sender, EventArgs e)
@@ -65,10 +68,17 @@ namespace WPCordovaClassLib.Cordova.Commands
             DispatchCommandResult(result);
         }
 
+        private void Battery_RemainingChargePercentChanged(object sender, object e)
+        {
+            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",
+                                                    battery.RemainingChargePercent,
                                                     isPlugged ? "true" : "false"
                             );
             batteryState = "{" + batteryState + "}";


Mime
View raw message