ripple-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brentlint...@apache.org
Subject [1/4] git commit: Adding BatteryStatus support
Date Sun, 07 Sep 2014 22:09:09 GMT
Repository: incubator-ripple
Updated Branches:
  refs/heads/master 8cb3a4a82 -> cc5e3ee24


Adding BatteryStatus support


Project: http://git-wip-us.apache.org/repos/asf/incubator-ripple/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ripple/commit/2c733fa6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ripple/tree/2c733fa6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ripple/diff/2c733fa6

Branch: refs/heads/master
Commit: 2c733fa61f79c71e05f0acad69f8df9eebe1b86b
Parents: 77d179a
Author: Ilya Buziuk <ibuziuk@exadel.com>
Authored: Fri Aug 1 16:23:31 2014 +0300
Committer: Ilya Buziuk <ibuziuk@exadel.com>
Committed: Mon Aug 4 19:31:13 2014 +0300

----------------------------------------------------------------------
 lib/client/constants.js                         |  10 +-
 lib/client/platform/cordova/2.0.0/bridge.js     |   1 +
 .../platform/cordova/2.0.0/bridge/battery.js    |  37 +++++++
 lib/client/platform/cordova/2.0.0/spec/ui.js    |   1 +
 lib/client/ui/plugins/battery-status/panel.html |  48 +++++++++
 lib/client/ui/plugins/batteryStatus.js          | 100 +++++++++++++++++++
 6 files changed, 196 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/2c733fa6/lib/client/constants.js
----------------------------------------------------------------------
diff --git a/lib/client/constants.js b/lib/client/constants.js
index 12030dc..9af311e 100644
--- a/lib/client/constants.js
+++ b/lib/client/constants.js
@@ -107,7 +107,7 @@ module.exports = {
         "MAP_ZOOM_MIN": 0,
         "MAP_ZOOM_LEVEL_CONTAINER": "geo-map-zoomlevel-value",
         "MAP_ZOOM_KEY": "geo-map-zoom-key",
-        "GPXGO_LABELS": {
+        "GPXGO_LABELS": {
             "GO": "Go",
             "STOP": "Stop"
         }
@@ -153,6 +153,14 @@ module.exports = {
         }
     },
 
+    "BATTERY_STATUS" : {
+        "BATTERY_STATUS_KEY": "battery-status-key",
+        "IS_PLUGGED_KEY" : "is-plugged-key",
+        "LEVEL_LABEL" : "battery-level-label",
+        "LEVEL_VALUE" : "battery-level",
+        "IS_PLUGGED_CHECKBOX" : "is-plugged"
+    },
+
     "CSS_PREFIX":  {
         "IRRELEVANT" : "irrelevant"
     },

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/2c733fa6/lib/client/platform/cordova/2.0.0/bridge.js
----------------------------------------------------------------------
diff --git a/lib/client/platform/cordova/2.0.0/bridge.js b/lib/client/platform/cordova/2.0.0/bridge.js
index 01173cb..9e49b78 100644
--- a/lib/client/platform/cordova/2.0.0/bridge.js
+++ b/lib/client/platform/cordova/2.0.0/bridge.js
@@ -22,6 +22,7 @@ var _prompt = ripple('ui/plugins/exec-dialog'),
     emulator = {
         "App": ripple('platform/cordova/2.0.0/bridge/app'),
         "Accelerometer": ripple('platform/cordova/2.0.0/bridge/accelerometer'),
+        "Battery" : ripple('platform/cordova/2.0.0/bridge/battery'),
         "Compass": ripple('platform/cordova/2.0.0/bridge/compass'),
         "Camera": ripple('platform/cordova/2.0.0/bridge/camera'),
         "Capture": ripple('platform/cordova/2.0.0/bridge/capture'),

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/2c733fa6/lib/client/platform/cordova/2.0.0/bridge/battery.js
----------------------------------------------------------------------
diff --git a/lib/client/platform/cordova/2.0.0/bridge/battery.js b/lib/client/platform/cordova/2.0.0/bridge/battery.js
new file mode 100644
index 0000000..bb80527
--- /dev/null
+++ b/lib/client/platform/cordova/2.0.0/bridge/battery.js
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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 constants = ripple('constants'),
+    db = ripple('db');
+
+module.exports = {
+    start: function(win, fail, args) {
+        var batteryLevel = db.retrieve(constants.BATTERY_STATUS.BATTERY_STATUS_KEY) || 100;
+        var isPlugged = db.retrieve(constants.BATTERY_STATUS.IS_PLUGGED_KEY) || false;
+        var info = {
+            level: batteryLevel,
+            isPlugged: isPlugged
+        };
+        win(info);
+    },
+
+    stop: function(win, fail, args) {}
+}

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/2c733fa6/lib/client/platform/cordova/2.0.0/spec/ui.js
----------------------------------------------------------------------
diff --git a/lib/client/platform/cordova/2.0.0/spec/ui.js b/lib/client/platform/cordova/2.0.0/spec/ui.js
index 84c4ca8..556d95c 100644
--- a/lib/client/platform/cordova/2.0.0/spec/ui.js
+++ b/lib/client/platform/cordova/2.0.0/spec/ui.js
@@ -23,6 +23,7 @@ module.exports = {
         "accelerometer",
         "deviceSettings",
         "geoView",
+        "batteryStatus",
         "widgetConfig",
         "platformEvents"
     ]

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/2c733fa6/lib/client/ui/plugins/battery-status/panel.html
----------------------------------------------------------------------
diff --git a/lib/client/ui/plugins/battery-status/panel.html b/lib/client/ui/plugins/battery-status/panel.html
new file mode 100644
index 0000000..da38ab4
--- /dev/null
+++ b/lib/client/ui/plugins/battery-status/panel.html
@@ -0,0 +1,48 @@
+<!--
+ *
+ * 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.
+ *
+-->
+<section id="battery-status-container" class="ui-box ui-state-default ui-corner-all">
+    <section class="h2 info-header">
+        <section class="collapse-handle">Battery Status</section>
+        <section class="drag-handle ui-state-default ui-corner-all ui-state-hover">
+            <span class="ui-icon ui-icon-arrow-4"></span>
+        </section>
+    </section>
+
+    <section class="info ui-widget-content ui-corner-all" style="display: none;">
+        <table class="panel-table">
+            <tr id="battery-level-container">
+                <td><span class="ui-text-label">Battery Level</span></td>
+                <td>
+                    <label id="battery-level-label" class="range-label-left">100 %</label>
+                    <input id="battery-level" type="range" value="100" min="0" max="100"
class="ui-state-default ui-corner-all">
+                </td>
+            </tr>
+            <tr id="is-plugged-container">
+                <td>
+                    <span class="ui-text-label">Is Plugged</span>
+                </td>
+                <td>
+                    <input id="is-plugged" type="checkbox" />
+                </td>
+            </tr>
+        </table>
+    </section>
+</section>

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/2c733fa6/lib/client/ui/plugins/batteryStatus.js
----------------------------------------------------------------------
diff --git a/lib/client/ui/plugins/batteryStatus.js b/lib/client/ui/plugins/batteryStatus.js
new file mode 100644
index 0000000..45a2ec7
--- /dev/null
+++ b/lib/client/ui/plugins/batteryStatus.js
@@ -0,0 +1,100 @@
+/*
+ *
+ * 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 constants = ripple('constants'),
+    db = ripple('db'),
+    batteryLevel = document.getElementById(constants.BATTERY_STATUS.LEVEL_VALUE),
+    batteryLevelLabel = document.getElementById(constants.BATTERY_STATUS.LEVEL_LABEL),
+    isPlugged = document.getElementById(constants.BATTERY_STATUS.IS_PLUGGED_CHECKBOX);
+
+function _getCurrentStatus() {
+    var status = {
+        level: batteryLevel.value,
+        isPlugged: isPlugged.checked
+    };
+    return status;
+}
+
+function _saveStatus(status) {
+    if (status) {
+        db.save(constants.BATTERY_STATUS.BATTERY_STATUS_KEY, status.level);
+        db.save(constants.BATTERY_STATUS.IS_PLUGGED_KEY, status.isPlugged);
+    }
+}
+
+function _updateUI(status) {
+    if (status) {
+        batteryLevel.value = status.level;
+        batteryLevelLabel.innerHTML = status.level + " %";
+        isPlugged.checked = status.isPlugged;
+    }
+}
+
+function _fireBatteryEvent(status) {
+    var win = ripple('emulatorBridge').window();
+
+    if (!win.cordova) {
+        throw "You must have cordova.js included in your projects, to be able to trigger
events";
+    } else if (status) {
+        win.cordova.fireWindowEvent("batterystatus", status);
+
+        var level = parseInt(status.level)
+        if (level === 20 || level === 5) {
+            if (level === 20) {
+                win.cordova.fireWindowEvent("batterylow", status);
+            } else {
+                win.cordova.fireWindowEvent("batterycritical", status);
+            }
+        }
+    }
+}
+
+function _processStatusChanged() {
+    var status = _getCurrentStatus();
+    _saveStatus(status);
+    _updateUI(status);
+    _fireBatteryEvent(status);
+}
+
+module.exports = {
+    panel: {
+        domId: "battery-status-container",
+        collapsed: true,
+        pane: "left"
+    },
+
+    initialize: function() {
+        jQuery("#" + constants.BATTERY_STATUS.LEVEL_VALUE).bind("mouseup", function() {
+            _processStatusChanged();
+        });
+
+        jQuery("#" + constants.BATTERY_STATUS.IS_PLUGGED_CHECKBOX).bind("click", function()
{
+            _processStatusChanged();
+        });
+
+        var status = {
+            level: db.retrieve(constants.BATTERY_STATUS.BATTERY_STATUS_KEY) || 100,
+            isPlugged: db.retrieve(constants.BATTERY_STATUS.IS_PLUGGED_KEY) || false,
+        };
+
+        _updateUI(status);
+    }
+};


Mime
View raw message