Adding the volume button event changes

This commit is contained in:
Joe Bowser 2012-06-08 16:25:09 -07:00
commit 9f42772b7e
3 changed files with 103 additions and 3 deletions

View File

@ -1,6 +1,6 @@
// commit ac0a3990438f4a89faa993316fb5614f61cf3be6
// commit 347de1a785b7ecbe86c2189343ab2549a9297f9b
// File generated at :: Tue Jun 05 2012 14:14:16 GMT-0700 (PDT)
// File generated at :: Fri Jun 08 2012 16:17:50 GMT-0700 (PDT)
/*
Licensed to the Apache Software Foundation (ASF) under one
@ -1067,6 +1067,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');
@ -1284,6 +1306,10 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) {
exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions]);
};
cameraExport.cleanup = function(successCallback, errorCallback) {
exec(successCallback, errorCallback, "Camera", "cleanup", []);
}
module.exports = cameraExport;
});
@ -2591,6 +2617,8 @@ var DirectoryEntry = require('cordova/plugin/DirectoryEntry');
var FileSystem = function(name, root) {
this.name = name || null;
if (root) {
console.log('root.name ' + name);
console.log('root.root ' + root);
this.root = new DirectoryEntry(root.name, root.fullPath);
}
};
@ -3637,6 +3665,21 @@ module.exports = {
exec(null, null, "App", "overrideBackbutton", [override]);
},
/**
* 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.
*/
@ -5723,4 +5766,4 @@ window.cordova = require('cordova');
}(window));
})();
})();

View File

@ -188,6 +188,17 @@ public class App extends Plugin {
this.ctx.bindBackButton(override);
}
/**
* Override the default behavior of the Android volume buttons.
* If overridden, when the volume button is pressed, the "volume[up|down]button" JavaScript event will be fired.
*
* @param button volumeup, volumedown
* @param override T=override, F=cancel override
*/
public void overrideButton(String button, boolean override) {
LOG.i("DroidGap", "WARNING: Volume Button Default Behaviour will be overridden. The volume event will be fired!");
((DroidGap)this.ctx).bindButton(button, override);
}
/**
* Return whether the Android back button is overridden by the user.
*

View File

@ -181,6 +181,10 @@ public class DroidGap extends Activity implements CordovaInterface {
// when another application (activity) is started.
protected boolean keepRunning = true;
private boolean volumeupBound;
private boolean volumedownBound;
/**
* Sets the authentication token.
*
@ -816,6 +820,38 @@ public class DroidGap extends Activity implements CordovaInterface {
return false;
}
/**
* Called when a key is pressed. (Key DOWN)
*
* @param keyCode
* @param event
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (this.appView == null) {
return super.onKeyDown(keyCode, event);
}
// If volumedown key
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
if (this.volumedownBound==true) {
// only override default behaviour is event bound
this.appView.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');");
return true;
}
}
// If volumeup key
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
if (this.volumeupBound==true) {
// only override default behaviour is event bound
this.appView.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
return true;
}
}
return false;
}
/**
* Launch an activity for which you would like a result when it finished. When this activity exits,
* your onActivityResult() method will be called.
@ -1013,6 +1049,16 @@ public class DroidGap extends Activity implements CordovaInterface {
}
}
public void bindButton(String button, boolean override) {
// TODO Auto-generated method stub
if (button.compareTo("volumeup")==0) {
this.volumeupBound = override;
}
else if (button.compareTo("volumedown")==0) {
this.volumedownBound = override;
}
}
protected Dialog splashDialog;
/**