You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2012/01/03 19:57:11 UTC

[40/50] git commit: Refactor backHistory() code so calling navigator.app.backHistory() has consistent behavior with backbutton.

Refactor backHistory() code so calling navigator.app.backHistory() has consistent behavior with backbutton.


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

Branch: refs/heads/master
Commit: 2a866e2a7ce11c33f3cf8381899939176f82b6bf
Parents: 827af8a
Author: Bryce Curtis <cu...@gmail.com>
Authored: Wed Nov 9 23:37:16 2011 -0600
Committer: Bryce Curtis <cu...@gmail.com>
Committed: Wed Nov 9 23:37:16 2011 -0600

----------------------------------------------------------------------
 framework/src/com/phonegap/DroidGap.java |   27 ++++++++++++++++--------
 1 files changed, 18 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/2a866e2a/framework/src/com/phonegap/DroidGap.java
----------------------------------------------------------------------
diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java
index 35c1700..b639dd6 100755
--- a/framework/src/com/phonegap/DroidGap.java
+++ b/framework/src/com/phonegap/DroidGap.java
@@ -577,13 +577,27 @@ public class DroidGap extends PhonegapActivity {
     
     /**
      * Go to previous page in history.  (We manage our own history)
+     * 
+     * @return true if we went back, false if we are already at top
      */
-    public void backHistory() {
+    public boolean backHistory() {
+
+        // Check webview first to see if there is a history
+        // This is needed to support curPage#diffLink, since they are added to appView's history, but not our history url array (JQMobile behavior)
+        if (this.appView.canGoBack()) {
+            this.appView.goBack();  
+            return true;
+        }
+
+        // If our managed history has prev url
         if (this.urls.size() > 1) {
-            this.urls.pop(); // Pop current url
-            String url = this.urls.pop(); // Pop prev url that we want to load
+            this.urls.pop();                // Pop current url
+            String url = this.urls.pop();   // Pop prev url that we want to load, since it will be added back by loadUrl()
             this.loadUrl(url);
+            return true;
         }
+        
+        return false;
     }
 
     @Override
@@ -1466,12 +1480,7 @@ public class DroidGap extends PhonegapActivity {
             else {
 
                 // Go to previous page in webview if it is possible to go back
-                if (this.appView.canGoBack()) {
-                    this.appView.goBack();  // This is needed to support curPage#diffLink, since they are added to appView's history, but not our history url array (JQMobile behavior)
-                    return true;
-                }
-                else if (this.urls.size() > 1) {
-                    this.backHistory();
+                if (this.backHistory()) {
                     return true;
                 }