mirror of
https://github.com/apache/cordova-android.git
synced 2026-05-30 00:00:04 +08:00
listening to volume events now override default behaviour
This commit is contained in:
@@ -62,6 +62,9 @@ public class App extends Plugin {
|
||||
}
|
||||
else if (action.equals("overrideBackbutton")) {
|
||||
this.overrideBackbutton(args.getBoolean(0));
|
||||
}
|
||||
else if (action.equals("overrideButton")) {
|
||||
this.overrideButton(args.getString(0), args.getBoolean(1));
|
||||
}
|
||||
else if (action.equals("isBackbuttonOverridden")) {
|
||||
boolean b = this.isBackbuttonOverridden();
|
||||
@@ -180,6 +183,17 @@ public class App extends Plugin {
|
||||
((DroidGap)this.ctx).bound = 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.
|
||||
*
|
||||
|
||||
@@ -158,6 +158,8 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
|
||||
protected LinearLayout root;
|
||||
public boolean bound = false;
|
||||
public boolean volumeupBound = false;
|
||||
public boolean volumedownBound = false;
|
||||
public CallbackServer callbackServer;
|
||||
protected PluginManager pluginManager;
|
||||
protected boolean cancelLoadUrl = false;
|
||||
@@ -1087,18 +1089,38 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
return true;
|
||||
}
|
||||
|
||||
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
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
this.appView.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');");
|
||||
return true;
|
||||
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) {
|
||||
this.appView.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
|
||||
return true;
|
||||
if (this.volumeupBound==true) {
|
||||
// only override default behaviour is event bound
|
||||
this.appView.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1416,6 +1438,16 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
return this.bound;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user