cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [2/2] android commit: This time, we fixed the back button for real! CB-1658
Date Fri, 12 Oct 2012 21:27:10 GMT
This time, we fixed the back button for real! CB-1658


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

Branch: refs/heads/master
Commit: 0f2303e8d508451753961b85c52298e33f4cea56
Parents: 0d409f0
Author: Joe Bowser <bowserj@apache.org>
Authored: Fri Oct 12 14:26:36 2012 -0700
Committer: Joe Bowser <bowserj@apache.org>
Committed: Fri Oct 12 14:26:36 2012 -0700

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaWebView.java     |   27 +++++++++++++-
 1 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/0f2303e8/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 10a1c6c..017c3d3 100755
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -577,6 +577,7 @@ public class CordovaWebView extends WebView {
         if (super.canGoBack()) {
         	printBackForwardList();
             super.goBack();
+            
             return true;
         }
 
@@ -779,6 +780,17 @@ public class CordovaWebView extends WebView {
                 return super.onKeyDown(keyCode, event);
             }
         }
+        else if(keyCode == KeyEvent.KEYCODE_BACK)
+        {
+            //Because exit is fired on the keyDown and not the key up on Android 4.x
+            //we need to check for this.
+            //Also, I really wished "canGoBack" worked!
+            if(this.useBrowserHistory)
+                return !(this.startOfHistory()) || this.bound;
+            else
+                return this.urls.size() > 1 || this.bound;
+        }
+        
         return super.onKeyDown(keyCode, event);
     }
     
@@ -942,8 +954,6 @@ public class CordovaWebView extends WebView {
         }
     }
     
-    
-    
     public void printBackForwardList() {
     	WebBackForwardList currentList = this.copyBackForwardList();
     	int currentSize = currentList.getSize();
@@ -954,4 +964,17 @@ public class CordovaWebView extends WebView {
     		LOG.d(TAG, "The URL at index: " + Integer.toString(i) + "is " + url );
     	}
     }
+    
+    
+    //Can Go Back is BROKEN!
+    public boolean startOfHistory()
+    {
+        WebBackForwardList currentList = this.copyBackForwardList();
+        WebHistoryItem item = currentList.getItemAtIndex(0);
+        String url = item.getUrl();
+        String currentUrl = this.getUrl();
+        LOG.d(TAG, "The current URL is: " + currentUrl);
+        LOG.d(TAG, "The URL at item 0 is:" + url);
+        return currentUrl.equals(url);
+    }
 }


Mime
View raw message