incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [3/3] js commit: android: add channel handlers for volume buttons
Date Mon, 11 Jun 2012 17:30:49 GMT
android: add channel handlers for volume buttons


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/f9f44914
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/f9f44914
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/f9f44914

Branch: refs/heads/volumebtns
Commit: f9f44914d03e7630ed564b9ac7a38af3ffb9323e
Parents: 7065728
Author: Julien Bouquillon <julien@bouquillon.com>
Authored: Fri Jun 1 12:15:22 2012 +0200
Committer: Julien Bouquillon <julien@bouquillon.com>
Committed: Fri Jun 1 12:15:22 2012 +0200

----------------------------------------------------------------------
 lib/android/platform.js           |   22 ++++++++++++++++++++++
 lib/android/plugin/android/app.js |   15 +++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/f9f44914/lib/android/platform.js
----------------------------------------------------------------------
diff --git a/lib/android/platform.js b/lib/android/platform.js
index 58394ab..b27cb83 100644
--- a/lib/android/platform.js
+++ b/lib/android/platform.js
@@ -51,6 +51,28 @@ module.exports = {
         cordova.addDocumentEventHandler('menubutton');
         cordova.addDocumentEventHandler('searchbutton');
 
+        function bindButtonChannel(buttonName) {
+            // generic button bind used for volumeup/volumedown buttons
+            return cordova.addDocumentEventHandler(buttonName + 'button', {
+                onSubscribe:function() {
+                    // If we just attached the first handler, let native know we need to
override the button.
+                    if (this.numHandlers === 1) {
+                        exec(null, null, "App", "overrideButton", [buttonName, true]);
+                    }
+                },
+                onUnsubscribe:function() {
+                    // If we just detached the last handler, let native know we no longer
override the volumeup button.
+                    if (this.numHandlers === 0) {
+                        exec(null, null, "App", "overrideButton", [buttonName, false]);
+                    }
+                }
+            });
+
+        }
+        // Inject a listener for the volume buttons on the document.
+        var volumeUpButtonChannel = bindButtonChannel('volumeup');
+        var volumeDownButtonChannel = bindButtonChannel('volumedown');
+
         // Figure out if we need to shim-in localStorage and WebSQL
         // support from the native side.
         var storage = require('cordova/plugin/android/storage');

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/f9f44914/lib/android/plugin/android/app.js
----------------------------------------------------------------------
diff --git a/lib/android/plugin/android/app.js b/lib/android/plugin/android/app.js
index c0b9769..53fb2db 100644
--- a/lib/android/plugin/android/app.js
+++ b/lib/android/plugin/android/app.js
@@ -63,6 +63,21 @@ module.exports = {
   },
 
   /**
+   * Override the default behavior of the Android volume button.
+   * If overridden, when the volume button is pressed, the "volume[up|down]button" JavaScript
event will be fired.
+   *
+   * Note: The user should not have to call this method.  Instead, when the user
+   *       registers for the "volume[up|down]button" event, this is automatically done.
+   *
+   * @param button          volumeup, volumedown
+   * @param override        T=override, F=cancel override
+   */
+  overrideButton:function(button, override) {
+    exec(null, null, "App", "overrideButton", [button, override]);
+  },
+
+
+  /**
    * Exit and terminate the application.
    */
   exitApp:function() {


Mime
View raw message