From f394f7457b52e7839c685abd615a6f3c95a94bda Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Tue, 19 Jun 2012 16:35:22 -0700 Subject: [PATCH] Tweaks to CordovaWebView to support other keys --- .../org/apache/cordova/CordovaWebView.java | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index 9f801120..17b92fc4 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -52,8 +52,12 @@ public class CordovaWebView extends WebView { /** The whitelist **/ private ArrayList whiteList = new ArrayList(); private HashMap whiteListCache = new HashMap(); + private ArrayList keyDownCodes = new ArrayList(); + private ArrayList keyUpCodes = new ArrayList(); + public PluginManager pluginManager; public CallbackServer callbackServer; + /** Actvities and other important classes **/ private CordovaInterface mCtx; @@ -675,26 +679,25 @@ public class CordovaWebView extends WebView { @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - // If volumedown key - if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { - if (this.volumedownBound==true) { - // only override default behaviour is event bound - LOG.d(TAG, "Down Key Hit"); - this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');"); - return true; + if(keyDownCodes.contains(keyCode)) + { + if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { + // only override default behaviour is event bound + LOG.d(TAG, "Down Key Hit"); + this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');"); + 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; } @@ -723,18 +726,21 @@ public class CordovaWebView extends WebView { } } } - - // If menu key + // Legacy else if (keyCode == KeyEvent.KEYCODE_MENU) { this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');"); return super.onKeyUp(keyCode, event); } - // If search key else if (keyCode == KeyEvent.KEYCODE_SEARCH) { this.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');"); return true; } + else if(keyUpCodes.contains(keyCode)) + { + //What the hell should this do? + } + Log.d(TAG, "KeyUp has been triggered on the view"); return false; @@ -748,10 +754,21 @@ public class CordovaWebView extends WebView { public void bindButton(String button, boolean override) { // TODO Auto-generated method stub if (button.compareTo("volumeup")==0) { - this.volumeupBound = override; + keyDownCodes.add(KeyEvent.KEYCODE_VOLUME_DOWN); } 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); + } + } }