mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-16 00:11:03 +08:00
Tweaks to CordovaWebView to support other keys
This commit is contained in:
parent
40b9810a63
commit
f394f7457b
@ -52,9 +52,13 @@ public class CordovaWebView extends WebView {
|
|||||||
/** The whitelist **/
|
/** The whitelist **/
|
||||||
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
|
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
|
||||||
private HashMap<String, Boolean> whiteListCache = new HashMap<String, Boolean>();
|
private HashMap<String, Boolean> whiteListCache = new HashMap<String, Boolean>();
|
||||||
|
private ArrayList<Integer> keyDownCodes = new ArrayList<Integer>();
|
||||||
|
private ArrayList<Integer> keyUpCodes = new ArrayList<Integer>();
|
||||||
|
|
||||||
public PluginManager pluginManager;
|
public PluginManager pluginManager;
|
||||||
public CallbackServer callbackServer;
|
public CallbackServer callbackServer;
|
||||||
|
|
||||||
|
|
||||||
/** Actvities and other important classes **/
|
/** Actvities and other important classes **/
|
||||||
private CordovaInterface mCtx;
|
private CordovaInterface mCtx;
|
||||||
CordovaWebViewClient viewClient;
|
CordovaWebViewClient viewClient;
|
||||||
@ -675,26 +679,25 @@ public class CordovaWebView extends WebView {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||||
{
|
{
|
||||||
// If volumedown key
|
if(keyDownCodes.contains(keyCode))
|
||||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
{
|
||||||
if (this.volumedownBound==true) {
|
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||||
// only override default behaviour is event bound
|
// only override default behaviour is event bound
|
||||||
LOG.d(TAG, "Down Key Hit");
|
LOG.d(TAG, "Down Key Hit");
|
||||||
this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');");
|
this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');");
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
// If volumeup key
|
||||||
|
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
||||||
|
LOG.d(TAG, "Up Key Hit");
|
||||||
|
this.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Do some other stuff!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If volumeup key
|
|
||||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
|
||||||
if (this.volumeupBound==true) {
|
|
||||||
// only override default behaviour is event bound
|
|
||||||
LOG.d(TAG, "Up Key Hit");
|
|
||||||
this.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -723,18 +726,21 @@ public class CordovaWebView extends WebView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Legacy
|
||||||
// If menu key
|
|
||||||
else if (keyCode == KeyEvent.KEYCODE_MENU) {
|
else if (keyCode == KeyEvent.KEYCODE_MENU) {
|
||||||
this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');");
|
this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');");
|
||||||
return super.onKeyUp(keyCode, event);
|
return super.onKeyUp(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If search key
|
// If search key
|
||||||
else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
|
else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
|
||||||
this.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');");
|
this.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if(keyUpCodes.contains(keyCode))
|
||||||
|
{
|
||||||
|
//What the hell should this do?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Log.d(TAG, "KeyUp has been triggered on the view");
|
Log.d(TAG, "KeyUp has been triggered on the view");
|
||||||
return false;
|
return false;
|
||||||
@ -748,10 +754,21 @@ public class CordovaWebView extends WebView {
|
|||||||
public void bindButton(String button, boolean override) {
|
public void bindButton(String button, boolean override) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
if (button.compareTo("volumeup")==0) {
|
if (button.compareTo("volumeup")==0) {
|
||||||
this.volumeupBound = override;
|
keyDownCodes.add(KeyEvent.KEYCODE_VOLUME_DOWN);
|
||||||
}
|
}
|
||||||
else if (button.compareTo("volumedown")==0) {
|
else if (button.compareTo("volumedown")==0) {
|
||||||
this.volumedownBound = override;
|
keyDownCodes.add(KeyEvent.KEYCODE_VOLUME_UP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void bindButton(int keyCode, boolean keyDown, boolean override) {
|
||||||
|
if(keyDown)
|
||||||
|
{
|
||||||
|
keyDownCodes.add(keyCode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
keyUpCodes.add(keyCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user