incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject android commit: Starting the Buttons Branch
Date Mon, 18 Jun 2012 18:32:44 GMT
Updated Branches:
  refs/heads/buttons [created] 40b9810a6


Starting the Buttons Branch


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/40b9810a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/40b9810a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/40b9810a

Branch: refs/heads/buttons
Commit: 40b9810a63c9fc456a8e44331d7b0eae9222227f
Parents: 451afab
Author: Joe Bowser <bowserj@apache.org>
Authored: Mon Jun 18 11:31:53 2012 -0700
Committer: Joe Bowser <bowserj@apache.org>
Committed: Mon Jun 18 11:31:53 2012 -0700

----------------------------------------------------------------------
 framework/src/org/apache/cordova/App.java          |    4 +-
 .../src/org/apache/cordova/CordovaWebView.java     |   94 +++++++++++++++
 framework/src/org/apache/cordova/DroidGap.java     |   82 +-------------
 3 files changed, 97 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/40b9810a/framework/src/org/apache/cordova/App.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/App.java b/framework/src/org/apache/cordova/App.java
index ed9ec77..629d422 100755
--- a/framework/src/org/apache/cordova/App.java
+++ b/framework/src/org/apache/cordova/App.java
@@ -188,7 +188,7 @@ public class App extends Plugin {
      */
     public void overrideBackbutton(boolean override) {
         LOG.i("App", "WARNING: Back Button Default Behaviour will be overridden.  The backbutton
event will be fired!");
-        this.ctx.bindBackButton(override);
+        webView.bindButton(override);
     }
 
     /**
@@ -200,7 +200,7 @@ public class App extends Plugin {
      */
     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);
+        webView.bindButton(button, override);
     }
     /**
      * Return whether the Android back button is overridden by the user.

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/40b9810a/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 308d222..9f80112 100755
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -39,6 +39,7 @@ import android.net.Uri;
 import android.os.Bundle;
 import android.util.AttributeSet;
 import android.util.Log;
+import android.view.KeyEvent;
 import android.view.WindowManager;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
@@ -70,6 +71,12 @@ public class CordovaWebView extends WebView {
     // Flag to track that a loadUrl timeout occurred
     int loadUrlTimeout = 0;
 
+    private boolean bound;
+
+    private boolean volumedownBound;
+
+    private boolean volumeupBound;
+
     /**
      * Constructor.
      * 
@@ -660,4 +667,91 @@ public class CordovaWebView extends WebView {
         }
         return p.toString();
     }
+    
+    /*
+     * onKeyDown 
+     */
+    
+    @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 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;
+    }
+    
+    @Override
+    public boolean onKeyUp(int keyCode, KeyEvent event)
+    {
+        
+        Log.d(TAG, "KeyDown has been triggered on the view");
+
+        // If back key
+        if (keyCode == KeyEvent.KEYCODE_BACK) {
+            // If back key is bound, then send event to JavaScript
+            if (this.bound) {
+                this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');");
+                return true;
+            } else {
+                // If not bound
+                // Go to previous page in webview if it is possible to go back
+                if (this.backHistory()) {
+                    return true;
+                }
+                // If not, then invoke default behaviour 
+                else {
+                    //this.activityState = ACTIVITY_EXITING;
+                    return false;
+                }
+            }
+        }
+
+        // If menu key
+        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;
+        }
+        
+        Log.d(TAG, "KeyUp has been triggered on the view");
+        return false;
+    }
+    
+    public void bindButton(boolean override)
+    {
+        this.bound = override;
+    }
+    
+    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;
+        }
+      }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/40b9810a/framework/src/org/apache/cordova/DroidGap.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java
index d4c142d..f0f31f1 100755
--- a/framework/src/org/apache/cordova/DroidGap.java
+++ b/framework/src/org/apache/cordova/DroidGap.java
@@ -784,87 +784,7 @@ public class DroidGap extends Activity implements CordovaInterface {
         super.finish();
     }
 
-    /**
-     * Called when a key is released. (Key UP)
-     *
-     * @param keyCode
-     * @param event
-     */
-    @Override
-    public boolean onKeyUp(int keyCode, KeyEvent event) {
-        if (this.appView == null) {
-            return super.onKeyUp(keyCode, event);
-        }
-
-        // If back key
-        if (keyCode == KeyEvent.KEYCODE_BACK) {
-            // If back key is bound, then send event to JavaScript
-            if (this.bound) {
-                this.appView.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');");
-                return true;
-            } else {
-                // If not bound
-                // Go to previous page in webview if it is possible to go back
-                if (this.backHistory()) {
-                    return true;
-                }
-                // If not, then invoke behavior of super class
-                else {
-                    this.activityState = ACTIVITY_EXITING;
-                    return super.onKeyUp(keyCode, event);
-                }
-            }
-        }
-
-        // If menu key
-        else if (keyCode == KeyEvent.KEYCODE_MENU) {
-            this.appView.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');");
-            return super.onKeyUp(keyCode, event);
-        }
-
-        // If search key
-        else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
-            this.appView.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');");
-            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
-        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
-            if (this.volumedownBound==true) {
-                // only override default behaviour is event bound
-                LOG.d(TAG, "Down Key Hit");
-                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
-                LOG.d(TAG, "Up Key Hit");
-                this.appView.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
-                return true;
-            }
-        }
-        return super.onKeyDown(keyCode, event);
-    }
-
+    
     /**
      * Launch an activity for which you would like a result when it finished. When this activity
exits, 
      * your onActivityResult() method will be called.


Mime
View raw message