incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject android commit: Tweaks to CordovaWebView to support other keys
Date Tue, 19 Jun 2012 23:36:05 GMT
Updated Branches:
  refs/heads/buttons 40b9810a6 -> f394f7457


Tweaks to CordovaWebView to support other keys


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/f394f745
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/f394f745
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/f394f745

Branch: refs/heads/buttons
Commit: f394f7457b52e7839c685abd615a6f3c95a94bda
Parents: 40b9810
Author: Joe Bowser <bowserj@apache.org>
Authored: Tue Jun 19 16:35:22 2012 -0700
Committer: Joe Bowser <bowserj@apache.org>
Committed: Tue Jun 19 16:35:22 2012 -0700

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaWebView.java     |   61 +++++++++-----
 1 files changed, 39 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/f394f745/framework/src/org/apache/cordova/CordovaWebView.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java
index 9f80112..17b92fc 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<Pattern> whiteList = new ArrayList<Pattern>();
     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 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) {
-            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;
+            // 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!
             }
         }
-
         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);
+       }
+    }
 }


Mime
View raw message