You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/08/12 22:38:08 UTC
js commit: CB-870 android: Add volume button event support
Repository: cordova-js
Updated Branches:
refs/heads/master 13b556e43 -> ff0358bf3
CB-870 android: Add volume button event support
github: close #72
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/ff0358bf
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/ff0358bf
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/ff0358bf
Branch: refs/heads/master
Commit: ff0358bf34b2e16820163fec21f6ff098094ac8f
Parents: 13b556e
Author: schettino72 <sc...@gmail.com>
Authored: Thu Jul 10 16:14:20 2014 +0800
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Aug 12 16:37:18 2014 -0400
----------------------------------------------------------------------
src/android/platform.js | 11 +++++++++++
src/android/plugin/android/app.js | 15 +++++++++++++++
2 files changed, 26 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ff0358bf/src/android/platform.js
----------------------------------------------------------------------
diff --git a/src/android/platform.js b/src/android/platform.js
index c6def3f..4d613c3 100644
--- a/src/android/platform.js
+++ b/src/android/platform.js
@@ -45,6 +45,17 @@ module.exports = {
cordova.addDocumentEventHandler('menubutton');
cordova.addDocumentEventHandler('searchbutton');
+ function bindButtonChannel(buttonName) {
+ // generic button bind used for volumeup/volumedown buttons
+ var volumeButtonChannel = cordova.addDocumentEventHandler(buttonName + 'button');
+ volumeButtonChannel.onHasSubscribersChange = function() {
+ exec(null, null, "App", "overrideButton", [buttonName, this.numHandlers == 1]);
+ };
+ }
+ // Inject a listener for the volume buttons on the document.
+ bindButtonChannel('volumeup');
+ bindButtonChannel('volumedown');
+
// Let native code know we are all done on the JS side.
// Native code will then un-hide the WebView.
channel.onCordovaReady.subscribe(function() {
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ff0358bf/src/android/plugin/android/app.js
----------------------------------------------------------------------
diff --git a/src/android/plugin/android/app.js b/src/android/plugin/android/app.js
index c2a4df5..7fccc40 100644
--- a/src/android/plugin/android/app.js
+++ b/src/android/plugin/android/app.js
@@ -84,6 +84,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() {