You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2014/04/25 20:11:46 UTC
git commit: CB-6521: Remove development branch
Repository: cordova-plugin-battery-status
Updated Branches:
refs/heads/dev 362c457e2 -> 936bb5ec1
CB-6521: Remove development branch
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/936bb5ec
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/tree/936bb5ec
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/diff/936bb5ec
Branch: refs/heads/dev
Commit: 936bb5ec117a8e6b269434c330263bf468348b2c
Parents: 362c457
Author: Ian Clelland <ic...@chromium.org>
Authored: Fri Apr 25 14:09:46 2014 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Apr 25 14:09:46 2014 -0400
----------------------------------------------------------------------
LICENSE | 202 ----------------------------------
NOTICE | 5 -
README.md | 2 +
RELEASENOTES.md | 47 --------
doc/index.md | 136 -----------------------
plugin.xml | 110 ------------------
src/android/BatteryListener.java | 163 ---------------------------
src/blackberry10/index.js | 77 -------------
src/ios/CDVBattery.h | 40 -------
src/ios/CDVBattery.m | 152 -------------------------
src/tizen/BatteryStatusProxy.js | 47 --------
src/ubuntu/battery.cpp | 78 -------------
src/ubuntu/battery.h | 62 -----------
src/wp/Battery.cs | 104 -----------------
www/battery.js | 99 -----------------
15 files changed, 2 insertions(+), 1322 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index 7a4a3ea..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,202 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- 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.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/NOTICE
----------------------------------------------------------------------
diff --git a/NOTICE b/NOTICE
deleted file mode 100644
index 8ec56a5..0000000
--- a/NOTICE
+++ /dev/null
@@ -1,5 +0,0 @@
-Apache Cordova
-Copyright 2012 The Apache Software Foundation
-
-This product includes software developed at
-The Apache Software Foundation (http://www.apache.org/).
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 017dc54..0958a55 100644
--- a/README.md
+++ b/README.md
@@ -20,3 +20,5 @@
# org.apache.cordova.battery-status
Plugin documentation: [doc/index.md](doc/index.md)
+
+This is `dev` - the deprecated development branch of this plugin; development of this plugin has moved to the `master` branch
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/RELEASENOTES.md
----------------------------------------------------------------------
diff --git a/RELEASENOTES.md b/RELEASENOTES.md
deleted file mode 100644
index 5d46b67..0000000
--- a/RELEASENOTES.md
+++ /dev/null
@@ -1,47 +0,0 @@
-<!--
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you 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.
-#
--->
-# Release Notes
-
-### 0.2.3 (Sept 25, 2013)
-* CB-4889 bumping&resetting version
-* [CB-4752] Incremented plugin version on dev branch.
-* CB-4889 renaming org.apache.cordova.core.battery-status to org.apache.cordova.battery-status
-
-### 0.2.4 (Oct 25, 2013)
-* CB-5128: added repo + issue tag to plugin.xml for battery status plugin
-* [CB-4915] Incremented plugin version on dev branch.
-
-### 0.2.5 (Dec 4, 2013)
-* Merged WP8 support for level, but #def'd it out so the same code runs on wp7. Updated docs to reflect WP8 support for battery level, and low+critical events
-* wp8 add support in level
-* add ubuntu platform
-* 1. Updated platform name amazon->amazon-fireos. Deleted src files. 2. Change to use amazon-fireos as the platform if user agent string contains 'cordova-amazon-fireos'
-
-### 0.2.6 (Jan 02, 2014)
-* CB-5658 Add doc/index.md for Battery Status.
-
-### 0.2.7 (Feb 05, 2014)
-* Add Tizen plugin.
-
-### 0.2.8 (Apr 17, 2014)
-* CB-6465: Add license headers to Tizen code
-* CB-6460: Update license headers
-* Add NOTICE file
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
deleted file mode 100644
index 9d946f9..0000000
--- a/doc/index.md
+++ /dev/null
@@ -1,136 +0,0 @@
-<!---
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you 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.
--->
-
-# org.apache.cordova.battery-status
-
-This plugin provides an implementation of an old version of the [Battery Status Events API](http://www.w3.org/TR/2011/WD-battery-status-20110915/).
-
-It adds the following three `window` events:
-
-* batterystatus
-* batterycritical
-* batterylow
-
-## Installation
-
- cordova plugin add org.apache.cordova.battery-status
-
-## batterystatus
-
-This event fires when the percentage of battery charge changes by at
-least 1 percent, or if the device is plugged in or unplugged.
-
-The battery status handler is passed an object that contains two
-properties:
-
-- __level__: The percentage of battery charge (0-100). _(Number)_
-
-- __isPlugged__: A boolean that indicates whether the device is plugged in. _(Boolean)_
-
-Applications typically should use `window.addEventListener` to
-attach an event listener once the `deviceready` event fires. e.g.:
-
-### Supported Platforms
-
-- Amazon Fire OS
-- iOS
-- Android
-- BlackBerry 10
-- Windows Phone 7 and 8
-- Tizen
-
-### Windows Phone 7 and 8 Quirks
-
-Windows Phone 7 does not provide native APIs to determine battery
-level, so the `level` property is unavailable. The `isPlugged`
-parameter _is_ supported.
-
-### Example
-
- window.addEventListener("batterystatus", onBatteryStatus, false);
-
- function onBatteryStatus(info) {
- // Handle the online event
- console.log("Level: " + info.level + " isPlugged: " + info.isPlugged);
- }
-
-## batterycritical
-
-The event fires when the percentage of battery charge has reached the
-critical battery threshold. The value is device-specific.
-
-The `batterycritical` handler is passed an object that contains two
-properties:
-
-- __level__: The percentage of battery charge (0-100). _(Number)_
-
-- __isPlugged__: A boolean that indicates whether the device is plugged in. _(Boolean)_
-
-Applications typically should use `window.addEventListener` to attach
-an event listener once the `deviceready` event fires.
-
-### Supported Platforms
-
-- Amazon Fire OS
-- iOS
-- Android
-- BlackBerry 10
-- Tizen
-
-### Example
-
- window.addEventListener("batterycritical", onBatteryCritical, false);
-
- function onBatteryCritical(info) {
- // Handle the battery critical event
- alert("Battery Level Critical " + info.level + "%\nRecharge Soon!");
- }
-
-## batterylow
-
-The event fires when the percentage of battery charge has reached the
-low battery threshold, device-specific value.
-
-The `batterylow` handler is passed an object that contains two
-properties:
-
-- __level__: The percentage of battery charge (0-100). _(Number)_
-
-- __isPlugged__: A boolean that indicates whether the device is plugged in. _(Boolean)_
-
-Applications typically should use `window.addEventListener` to
-attach an event listener once the `deviceready` event fires.
-
-### Supported Platforms
-
-- Amazon Fire OS
-- iOS
-- Android
-- BlackBerry 10
-- Tizen
-
-### Example
-
- window.addEventListener("batterylow", onBatteryLow, false);
-
- function onBatteryLow(info) {
- // Handle the battery low event
- alert("Battery Level Low " + info.level + "%");
- }
-
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
deleted file mode 100644
index f29babb..0000000
--- a/plugin.xml
+++ /dev/null
@@ -1,110 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you 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.
--->
-
-<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
- id="org.apache.cordova.battery-status"
- version="0.2.9-dev">
- <name>Battery</name>
- <description>Cordova Battery Plugin</description>
- <license>Apache 2.0</license>
- <keywords>cordova,battery</keywords>
- <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status.git</repo>
- <issue>https://issues.apache.org/jira/browse/CB/component/12320643</issue>
-
- <js-module src="www/battery.js" name="battery">
- <clobbers target="navigator.battery" />
- </js-module>
-
- <!-- android -->
- <platform name="android">
- <config-file target="res/xml/config.xml" parent="/*">
- <feature name="Battery" >
- <param name="android-package" value="org.apache.cordova.batterystatus.BatteryListener"/>
- </feature>
- </config-file>
-
- <source-file src="src/android/BatteryListener.java" target-dir="src/org/apache/cordova/batterystatus" />
- </platform>
-
- <!-- amazon-fireos -->
- <platform name="amazon-fireos">
- <config-file target="res/xml/config.xml" parent="/*">
- <feature name="Battery" >
- <param name="android-package" value="org.apache.cordova.batterystatus.BatteryListener"/>
- </feature>
- </config-file>
-
- <source-file src="src/android/BatteryListener.java" target-dir="src/org/apache/cordova/batterystatus" />
- </platform>
-
- <!-- ubuntu -->
- <platform name="ubuntu">
- <header-file src="src/ubuntu/battery.h" />
- <source-file src="src/ubuntu/battery.cpp" />
- </platform>
-
- <!-- ios -->
- <platform name="ios">
- <config-file target="config.xml" parent="/*">
- <feature name="Battery">
- <param name="ios-package" value="CDVBattery" />
- </feature>
- </config-file>
- <header-file src="src/ios/CDVBattery.h" />
- <source-file src="src/ios/CDVBattery.m" />
- </platform>
-
- <!-- blackberry10 -->
- <platform name="blackberry10">
- <source-file src="src/blackberry10/index.js" target-dir="Battery" />
- <config-file target="www/config.xml" parent="/widget">
- <feature name="Battery" value="Battery"/>
- </config-file>
- </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/wp/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/wp/Battery.cs" />
- </platform>
-
- <!-- tizen -->
- <platform name="tizen">
- <js-module src="src/tizen/BatteryStatusProxy.js" name="BatteryStatusProxy">
- <runs/>
- </js-module>
- </platform>
-</plugin>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/src/android/BatteryListener.java
----------------------------------------------------------------------
diff --git a/src/android/BatteryListener.java b/src/android/BatteryListener.java
deleted file mode 100755
index ca47faa..0000000
--- a/src/android/BatteryListener.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you 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.
-*/
-package org.apache.cordova.batterystatus;
-
-import org.apache.cordova.CallbackContext;
-import org.apache.cordova.CordovaPlugin;
-import org.apache.cordova.PluginResult;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.util.Log;
-
-public class BatteryListener extends CordovaPlugin {
-
- private static final String LOG_TAG = "BatteryManager";
-
- BroadcastReceiver receiver;
-
- private CallbackContext batteryCallbackContext = null;
-
- /**
- * Constructor.
- */
- public BatteryListener() {
- this.receiver = null;
- }
-
- /**
- * Executes the request.
- *
- * @param action The action to execute.
- * @param args JSONArry of arguments for the plugin.
- * @param callbackContext The callback context used when calling back into JavaScript.
- * @return True if the action was valid, false if not.
- */
- public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
- if (action.equals("start")) {
- if (this.batteryCallbackContext != null) {
- callbackContext.error( "Battery listener already running.");
- return true;
- }
- this.batteryCallbackContext = callbackContext;
-
- // We need to listen to power events to update battery status
- IntentFilter intentFilter = new IntentFilter();
- intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
- if (this.receiver == null) {
- this.receiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- updateBatteryInfo(intent);
- }
- };
- cordova.getActivity().registerReceiver(this.receiver, intentFilter);
- }
-
- // Don't return any result now, since status results will be sent when events come in from broadcast receiver
- PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
- pluginResult.setKeepCallback(true);
- callbackContext.sendPluginResult(pluginResult);
- return true;
- }
-
- else if (action.equals("stop")) {
- removeBatteryListener();
- this.sendUpdate(new JSONObject(), false); // release status callback in JS side
- this.batteryCallbackContext = null;
- callbackContext.success();
- return true;
- }
-
- return false;
- }
-
- /**
- * Stop battery receiver.
- */
- public void onDestroy() {
- removeBatteryListener();
- }
-
- /**
- * Stop battery receiver.
- */
- public void onReset() {
- removeBatteryListener();
- }
-
- /**
- * Stop the battery receiver and set it to null.
- */
- private void removeBatteryListener() {
- if (this.receiver != null) {
- try {
- this.cordova.getActivity().unregisterReceiver(this.receiver);
- this.receiver = null;
- } catch (Exception e) {
- Log.e(LOG_TAG, "Error unregistering battery receiver: " + e.getMessage(), e);
- }
- }
- }
-
- /**
- * Creates a JSONObject with the current battery information
- *
- * @param batteryIntent the current battery information
- * @return a JSONObject containing the battery status information
- */
- private JSONObject getBatteryInfo(Intent batteryIntent) {
- JSONObject obj = new JSONObject();
- try {
- obj.put("level", batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, 0));
- obj.put("isPlugged", batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_PLUGGED, -1) > 0 ? true : false);
- } catch (JSONException e) {
- Log.e(LOG_TAG, e.getMessage(), e);
- }
- return obj;
- }
-
- /**
- * Updates the JavaScript side whenever the battery changes
- *
- * @param batteryIntent the current battery information
- * @return
- */
- private void updateBatteryInfo(Intent batteryIntent) {
- sendUpdate(this.getBatteryInfo(batteryIntent), true);
- }
-
- /**
- * Create a new plugin result and send it back to JavaScript
- *
- * @param connection the network info to set as navigator.connection
- */
- private void sendUpdate(JSONObject info, boolean keepCallback) {
- if (this.batteryCallbackContext != null) {
- PluginResult result = new PluginResult(PluginResult.Status.OK, info);
- result.setKeepCallback(keepCallback);
- this.batteryCallbackContext.sendPluginResult(result);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/src/blackberry10/index.js
----------------------------------------------------------------------
diff --git a/src/blackberry10/index.js b/src/blackberry10/index.js
deleted file mode 100644
index f757ee7..0000000
--- a/src/blackberry10/index.js
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- *
-*/
-
- var _clientListeners = {},
- _webkitBattery = navigator.webkitBattery || navigator.battery;
-
-module.exports = {
- start: function (success, fail, args, env) {
- var result = new PluginResult(args, env),
- listener = function (info) {
- var resultInfo = {};
- if (info) {
- if (info.srcElement) {
- //webkitBattery listeners store webkitBattery in srcElement object
- info = info.srcElement;
- }
-
- //put data from webkitBattery into a format cordova expects
- //webkitBattery seems to return level as a decimal pre 10.2
- resultInfo.level = info.level <= 1 ? info.level * 100 : info.level,
- resultInfo.isPlugged = info.charging
- }
-
- result.callbackOk(resultInfo, true);
- };
-
- if (_clientListeners[env.webview.id]) {
- //TODO: Change back to erroring out after reset is implemented
- //result.error("Battery listener already running");
- _webkitBattery.onchargingchange = null;
- _webkitBattery.onlevelchange = null;
- }
-
- _clientListeners[env.webview.id] = listener;
-
- _webkitBattery.onchargingchange = listener;
- _webkitBattery.onlevelchange = listener;
-
- setTimeout(function(){
- //Call callback with webkitBattery data right away
- listener(_webkitBattery);
- });
-
- result.noResult(true);
- },
- stop: function (success, fail, args, env) {
- var result = new PluginResult(args, env),
- listener = _clientListeners[env.webview.id];
-
- if (!listener) {
- result.error("Battery listener has not started");
- } else {
- _webkitBattery.onchargingchange = null;
- _webkitBattery.onlevelchange = null;
- delete _clientListeners[env.webview.id];
- result.noResult(false);
- }
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/src/ios/CDVBattery.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVBattery.h b/src/ios/CDVBattery.h
deleted file mode 100644
index f8b7d39..0000000
--- a/src/ios/CDVBattery.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import <Cordova/CDVPlugin.h>
-
-@interface CDVBattery : CDVPlugin {
- UIDeviceBatteryState state;
- float level;
- bool isPlugged;
- NSString* callbackId;
-}
-
-@property (nonatomic) UIDeviceBatteryState state;
-@property (nonatomic) float level;
-@property (nonatomic) bool isPlugged;
-@property (strong) NSString* callbackId;
-
-- (void)updateBatteryStatus:(NSNotification*)notification;
-- (NSDictionary*)getBatteryStatus;
-- (void)start:(CDVInvokedUrlCommand*)command;
-- (void)stop:(CDVInvokedUrlCommand*)command;
-- (void)dealloc;
-@end
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/src/ios/CDVBattery.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVBattery.m b/src/ios/CDVBattery.m
deleted file mode 100644
index 681511c..0000000
--- a/src/ios/CDVBattery.m
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you 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.
- */
-
-#import "CDVBattery.h"
-
-@interface CDVBattery (PrivateMethods)
-- (void)updateOnlineStatus;
-@end
-
-@implementation CDVBattery
-
-@synthesize state, level, callbackId, isPlugged;
-
-/* determining type of event occurs on JavaScript side
-- (void) updateBatteryLevel:(NSNotification*)notification
-{
- // send batterylow event for less than 25% battery
- // send batterycritical event for less than 10% battery
- // W3c says to send batteryStatus event when batterylevel changes by more than 1% (iOS seems to notify each 5%)
- // always update the navigator.device.battery info
- float currentLevel = [[UIDevice currentDevice] batteryLevel];
- NSString* type = @"";
- // no check for level == -1 since this api is only called when monitoring is enabled so level should be valid
- if (currentLevel < 0.10){
- type = @"batterycritical";
- } else if (currentLevel < 0.25) {
- type = @"batterylow";
- } else {
- float onePercent = 0.1;
- if (self.level >= 0 ){
- onePercent = self.level * 0.01;
- }
- if (fabsf(currentLevel - self.level) > onePercent){
- // issue batteryStatus event
- type = @"batterystatus";
- }
- }
- // update the battery info and fire event
- NSString* jsString = [NSString stringWithFormat:@"navigator.device.battery._status(\"%@\", %@)", type,[[self getBatteryStatus] JSONRepresentation]];
- [super writeJavascript:jsString];
-}
- */
-
-- (void)updateBatteryStatus:(NSNotification*)notification
-{
- NSDictionary* batteryData = [self getBatteryStatus];
-
- if (self.callbackId) {
- CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:batteryData];
- [result setKeepCallbackAsBool:YES];
- [self.commandDelegate sendPluginResult:result callbackId:self.callbackId];
- }
-}
-
-/* Get the current battery status and level. Status will be unknown and level will be -1.0 if
- * monitoring is turned off.
- */
-- (NSDictionary*)getBatteryStatus
-{
- UIDevice* currentDevice = [UIDevice currentDevice];
- UIDeviceBatteryState currentState = [currentDevice batteryState];
-
- isPlugged = FALSE; // UIDeviceBatteryStateUnknown or UIDeviceBatteryStateUnplugged
- if ((currentState == UIDeviceBatteryStateCharging) || (currentState == UIDeviceBatteryStateFull)) {
- isPlugged = TRUE;
- }
- float currentLevel = [currentDevice batteryLevel];
-
- if ((currentLevel != self.level) || (currentState != self.state)) {
- self.level = currentLevel;
- self.state = currentState;
- }
-
- // W3C spec says level must be null if it is unknown
- NSObject* w3cLevel = nil;
- if ((currentState == UIDeviceBatteryStateUnknown) || (currentLevel == -1.0)) {
- w3cLevel = [NSNull null];
- } else {
- w3cLevel = [NSNumber numberWithFloat:(currentLevel * 100)];
- }
- NSMutableDictionary* batteryData = [NSMutableDictionary dictionaryWithCapacity:2];
- [batteryData setObject:[NSNumber numberWithBool:isPlugged] forKey:@"isPlugged"];
- [batteryData setObject:w3cLevel forKey:@"level"];
- return batteryData;
-}
-
-/* turn on battery monitoring*/
-- (void)start:(CDVInvokedUrlCommand*)command
-{
- self.callbackId = command.callbackId;
-
- if ([UIDevice currentDevice].batteryMonitoringEnabled == NO) {
- [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateBatteryStatus:)
- name:UIDeviceBatteryStateDidChangeNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateBatteryStatus:)
- name:UIDeviceBatteryLevelDidChangeNotification object:nil];
- }
-}
-
-/* turn off battery monitoring */
-- (void)stop:(CDVInvokedUrlCommand*)command
-{
- // callback one last time to clear the callback function on JS side
- if (self.callbackId) {
- CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self getBatteryStatus]];
- [result setKeepCallbackAsBool:NO];
- [self.commandDelegate sendPluginResult:result callbackId:self.callbackId];
- }
- self.callbackId = nil;
- [[UIDevice currentDevice] setBatteryMonitoringEnabled:NO];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceBatteryStateDidChangeNotification object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceBatteryLevelDidChangeNotification object:nil];
-}
-
-- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView
-{
- self = (CDVBattery*)[super initWithWebView:theWebView];
- if (self) {
- self.state = UIDeviceBatteryStateUnknown;
- self.level = -1.0;
- }
- return self;
-}
-
-- (void)dealloc
-{
- [self stop:nil];
-}
-
-- (void)onReset
-{
- [self stop:nil];
-}
-
-@end
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/src/tizen/BatteryStatusProxy.js
----------------------------------------------------------------------
diff --git a/src/tizen/BatteryStatusProxy.js b/src/tizen/BatteryStatusProxy.js
deleted file mode 100644
index 44dad00..0000000
--- a/src/tizen/BatteryStatusProxy.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- *
-*/
-
-var cordova = require('cordova');
-
-var batteryListenerId = null;
-
-module.exports = {
- start: function(successCallback, errorCallback) {
- var batterySuccessCallback = function(power) {
- if (successCallback) {
- successCallback({level: Math.round(power.level * 100), isPlugged: power.isCharging});
- }
- };
-
- if (batteryListenerId === null) {
- batteryListenerId = tizen.systeminfo.addPropertyValueChangeListener("BATTERY", batterySuccessCallback);
- }
-
- tizen.systeminfo.getPropertyValue("BATTERY", batterySuccessCallback, errorCallback);
- },
-
- stop: function(successCallback, errorCallback) {
- tizen.systeminfo.removePropertyValueChangeListener(batteryListenerId);
- batteryListenerId = null;
- }
-};
-
-require("cordova/tizen/commandProxy").add("Battery", module.exports);
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/src/ubuntu/battery.cpp
----------------------------------------------------------------------
diff --git a/src/ubuntu/battery.cpp b/src/ubuntu/battery.cpp
deleted file mode 100644
index f3b8f80..0000000
--- a/src/ubuntu/battery.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- *
-*/
-
-#include <QtCore>
-
-#include "battery.h"
-
-BatteryStatus::BatteryStatus(Cordova *cordova) : CPlugin(cordova) {
- _scId = 0;
-
- connect(&_batteryInfo, SIGNAL(remainingCapacityChanged(int,int)), this, SLOT(remainingCapacityChanged(int,int)));
- connect(&_batteryInfo, SIGNAL(chargerTypeChanged(QBatteryInfo::ChargerType)), this, SLOT(chargerTypeChanged(QBatteryInfo::ChargerType)));
-}
-
-void BatteryStatus::remainingCapacityChanged(int battery, int capacity) {
- Q_UNUSED(battery);
- Q_UNUSED(capacity);
-
- fireEvents();
-}
-
-void BatteryStatus::chargerTypeChanged(QBatteryInfo::ChargerType type) {
- Q_UNUSED(type);
-
- fireEvents();
-}
-
-void BatteryStatus::fireEvents() {
- int fullCount = 0;
- bool isPlugged = false;
-
- int remaining = 0, total = 0;
- for (int i = 0; i < _batteryInfo.batteryCount(); i++) {
- isPlugged = (_batteryInfo.chargingState(i) == QBatteryInfo::Charging) || isPlugged;
- fullCount += _batteryInfo.chargingState(i) == QBatteryInfo::Full;
-
- remaining += _batteryInfo.remainingCapacity(i);
- total += _batteryInfo.maximumCapacity(i);
- }
-
- isPlugged = isPlugged || (_batteryInfo.batteryCount() == fullCount);
-
- if (_scId) {
- QVariantMap obj;
- obj.insert("isPlugged", (int)isPlugged);
- if (total != 0)
- obj.insert("level", remaining * 100 / total);
- else
- obj.insert("level", 100);
-
- this->callbackWithoutRemove(_scId, CordovaInternal::format(obj));
- }
-}
-
-void BatteryStatus::start(int scId, int) {
- _scId = scId;
-}
-
-void BatteryStatus::stop(int, int) {
- _scId = 0;
-}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/src/ubuntu/battery.h
----------------------------------------------------------------------
diff --git a/src/ubuntu/battery.h b/src/ubuntu/battery.h
deleted file mode 100644
index cec7856..0000000
--- a/src/ubuntu/battery.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- *
-*/
-
-#ifndef BATTERY_H_AAAAAAAA
-#define BATTERY_H_AAAAAAAA
-
-#include <QBatteryInfo>
-
-#include <cplugin.h>
-
-class BatteryStatus: public CPlugin {
- Q_OBJECT
-public:
- explicit BatteryStatus(Cordova *cordova);
-
- virtual const QString fullName() override {
- return BatteryStatus::fullID();
- }
-
- virtual const QString shortName() override {
- return "Battery";
- }
-
- static const QString fullID() {
- return "Battery";
- }
-
-public slots:
- void start(int scId, int ecId);
- void stop(int scId, int ecId);
-
-private slots:
- void remainingCapacityChanged(int battery, int capacity);
- void chargerTypeChanged(QBatteryInfo::ChargerType type);
- void onlineStatusChanged(bool isOnline);
-
-private:
- void fireEvents();
-
- QBatteryInfo _batteryInfo;
-
- int _scId;
-};
-
-#endif
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/src/wp/Battery.cs
----------------------------------------------------------------------
diff --git a/src/wp/Battery.cs b/src/wp/Battery.cs
deleted file mode 100644
index 219d8ff..0000000
--- a/src/wp/Battery.cs
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- 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.
- /// </summary>
- public class Battery : BaseCommand
- {
- private bool isPlugged = false;
- private EventHandler powerChanged;
-#if WP8
- private Windows.Phone.Devices.Power.Battery battery;
-#endif
- public Battery()
- {
- powerChanged = new EventHandler(DeviceStatus_PowerSourceChanged);
- isPlugged = DeviceStatus.PowerSource.ToString().CompareTo("External") == 0;
-
-#if WP8
- battery = Windows.Phone.Devices.Power.Battery.GetDefault();
-#endif
- }
-
- public void start(string options)
- {
- // Register power changed event handler
- DeviceStatus.PowerSourceChanged += powerChanged;
-
-#if WP8
- battery.RemainingChargePercentChanged += Battery_RemainingChargePercentChanged;
-#endif
-
- 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;
-#if WP8
- battery.RemainingChargePercentChanged -= Battery_RemainingChargePercentChanged;
-#endif
- }
-
- 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 void Battery_RemainingChargePercentChanged(object sender, object e)
- {
- PluginResult result = new PluginResult(PluginResult.Status.OK, GetCurrentBatteryStateFormatted());
- result.KeepCallback = true;
- DispatchCommandResult(result);
- }
-
- private string GetCurrentBatteryStateFormatted()
- {
- int remainingChargePercent = -1;
-#if WP8
- remainingChargePercent = battery.RemainingChargePercent;
-#endif
-
-
- string batteryState = String.Format("\"level\":{0},\"isPlugged\":{1}",
- remainingChargePercent,
- isPlugged ? "true" : "false"
- );
- batteryState = "{" + batteryState + "}";
- return batteryState;
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/936bb5ec/www/battery.js
----------------------------------------------------------------------
diff --git a/www/battery.js b/www/battery.js
deleted file mode 100644
index 1b012ab..0000000
--- a/www/battery.js
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- *
-*/
-
-/**
- * This class contains information about the current battery status.
- * @constructor
- */
-var cordova = require('cordova'),
- exec = require('cordova/exec');
-
-function handlers() {
- return battery.channels.batterystatus.numHandlers +
- battery.channels.batterylow.numHandlers +
- battery.channels.batterycritical.numHandlers;
-}
-
-var Battery = function() {
- this._level = null;
- this._isPlugged = null;
- // Create new event handlers on the window (returns a channel instance)
- this.channels = {
- batterystatus:cordova.addWindowEventHandler("batterystatus"),
- batterylow:cordova.addWindowEventHandler("batterylow"),
- batterycritical:cordova.addWindowEventHandler("batterycritical")
- };
- for (var key in this.channels) {
- this.channels[key].onHasSubscribersChange = Battery.onHasSubscribersChange;
- }
-};
-/**
- * Event handlers for when callbacks get registered for the battery.
- * Keep track of how many handlers we have so we can start and stop the native battery listener
- * appropriately (and hopefully save on battery life!).
- */
-Battery.onHasSubscribersChange = function() {
- // If we just registered the first handler, make sure native listener is started.
- if (this.numHandlers === 1 && handlers() === 1) {
- exec(battery._status, battery._error, "Battery", "start", []);
- } else if (handlers() === 0) {
- exec(null, null, "Battery", "stop", []);
- }
-};
-
-/**
- * Callback for battery status
- *
- * @param {Object} info keys: level, isPlugged
- */
-Battery.prototype._status = function(info) {
- if (info) {
- var me = battery;
- var level = info.level;
- if (me._level !== level || me._isPlugged !== info.isPlugged) {
- // Fire batterystatus event
- cordova.fireWindowEvent("batterystatus", info);
-
- // Fire low battery event
- if (level === 20 || level === 5) {
- if (level === 20) {
- cordova.fireWindowEvent("batterylow", info);
- }
- else {
- cordova.fireWindowEvent("batterycritical", info);
- }
- }
- }
- me._level = level;
- me._isPlugged = info.isPlugged;
- }
-};
-
-/**
- * Error callback for battery start
- */
-Battery.prototype._error = function(e) {
- console.log("Error initializing Battery: " + e);
-};
-
-var battery = new Battery();
-
-module.exports = battery;