Adding the volume button event changes

This commit is contained in:
Joe Bowser
2012-06-08 16:25:09 -07:00
3 changed files with 103 additions and 3 deletions
+11
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.
*
@@ -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;
/**