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/04/25 00:50:27 UTC

android commit: Tweaks to move history over into the WebView

Updated Branches:
  refs/heads/CordovaWebView 99b3693f4 -> 17c919edd


Tweaks to move history over into the WebView


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

Branch: refs/heads/CordovaWebView
Commit: 17c919edd99eb9016ac478e9cc777d9a25b14fd7
Parents: 99b3693
Author: Joe Bowser <bo...@apache.org>
Authored: Tue Apr 24 15:50:06 2012 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Tue Apr 24 15:50:06 2012 -0700

----------------------------------------------------------------------
 framework/src/org/apache/cordova/App.java          |    6 +-
 .../src/org/apache/cordova/CordovaWebView.java     |   63 +++++++++++++
 framework/src/org/apache/cordova/DroidGap.java     |   73 ++-------------
 3 files changed, 75 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/17c919ed/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 664fe35..21f66c0 100755
--- a/framework/src/org/apache/cordova/App.java
+++ b/framework/src/org/apache/cordova/App.java
@@ -87,7 +87,7 @@ public class App extends Plugin {
 	 * Clear the resource cache.
 	 */
 	public void clearCache() {
-		((DroidGap)this.ctx).clearCache();
+	  webView.clearCache(true);	
 	}
 	
 	/**
@@ -147,11 +147,11 @@ public class App extends Plugin {
 				e.printStackTrace();
 			}
 		}
-		((DroidGap)this.ctx).showWebPage(url, openExternal, clearHistory, params);
+		webView.showWebPage(url, openExternal, clearHistory, params);
 	}
 
 	/**
-	 * Cancel loadUrl before it has been loaded.
+	 * Cancel loadUrl before it has been loaded (Only works on a CordovaInterface class)
 	 */
 	public void cancelLoadUrl() {
 		((DroidGap)this.ctx).cancelLoadUrl();

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/17c919ed/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 1b139f3..59785e8 100644
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -14,7 +14,9 @@ import org.apache.cordova.api.PluginManager;
 import org.xmlpull.v1.XmlPullParserException;
 
 import android.content.Context;
+import android.content.Intent;
 import android.content.res.XmlResourceParser;
+import android.net.Uri;
 import android.util.AttributeSet;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
@@ -388,4 +390,65 @@ public class CordovaWebView extends WebView {
       
       return false;
   }
+  
+
+  /**
+   * Load the specified URL in the Cordova webview or a new browser instance.
+   * 
+   * NOTE: If openExternal is false, only URLs listed in whitelist can be loaded.
+   *
+   * @param url           The url to load.
+   * @param openExternal  Load url in browser instead of Cordova webview.
+   * @param clearHistory  Clear the history stack, so new page becomes top of history
+   * @param params        DroidGap parameters for new app
+   */
+  public void showWebPage(String url, boolean openExternal, boolean clearHistory, HashMap<String, Object> params) { //throws android.content.ActivityNotFoundException {
+      LOG.d(TAG, "showWebPage(%s, %b, %b, HashMap", url, openExternal, clearHistory);
+      
+      // If clearing history
+      if (clearHistory) {
+          this.clearHistory();
+      }
+      
+      // If loading into our webview
+      if (!openExternal) {
+          
+          // Make sure url is in whitelist
+          if (url.startsWith("file://") || url.indexOf(this.baseUrl) == 0 || isUrlWhiteListed(url)) {
+              // TODO: What about params?
+              
+              // Clear out current url from history, since it will be replacing it
+              if (clearHistory) {
+                  this.urls.clear();
+              }
+              
+              // Load new URL
+              this.loadUrl(url);
+          }
+          // Load in default viewer if not
+          else {
+              LOG.w(TAG, "showWebPage: Cannot load URL into webview since it is not in white list.  Loading into browser instead. (URL="+url+")");
+              try {
+                  Intent intent = new Intent(Intent.ACTION_VIEW);
+                  intent.setData(Uri.parse(url));
+                  mCtx.startActivity(intent);
+              } catch (android.content.ActivityNotFoundException e) {
+                  LOG.e(TAG, "Error loading url "+url, e);
+              }
+          }
+      }
+      
+      // Load in default view intent
+      else {
+          try {
+              Intent intent = new Intent(Intent.ACTION_VIEW);
+              intent.setData(Uri.parse(url));
+              mCtx.startActivity(intent);
+          } catch (android.content.ActivityNotFoundException e) {
+              LOG.e(TAG, "Error loading url "+url, e);
+          }
+      }
+  }
+  
+  
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/17c919ed/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 e523b00..0203dba 100755
--- a/framework/src/org/apache/cordova/DroidGap.java
+++ b/framework/src/org/apache/cordova/DroidGap.java
@@ -238,8 +238,8 @@ public class DroidGap extends Activity implements CordovaInterface {
         root = new LinearLayoutSoftKeyboardDetect(this, width, height);
         root.setOrientation(LinearLayout.VERTICAL);
         root.setBackgroundColor(this.backgroundColor);
-        root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 
-                ViewGroup.LayoutParams.FILL_PARENT, 0.0F));
+        root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
+                ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));
 
         // If url was passed in to intent, then init webview, which will load the url
         Bundle bundle = this.getIntent().getExtras();
@@ -280,8 +280,8 @@ public class DroidGap extends Activity implements CordovaInterface {
         this.loadConfiguration();
 
         this.appView.setLayoutParams(new LinearLayout.LayoutParams(
-                ViewGroup.LayoutParams.FILL_PARENT,
-                ViewGroup.LayoutParams.FILL_PARENT, 
+                ViewGroup.LayoutParams.MATCH_PARENT,
+                ViewGroup.LayoutParams.MATCH_PARENT, 
                 1.0F));
 
         // Add web view but make it invisible while loading URL
@@ -366,7 +366,6 @@ public class DroidGap extends Activity implements CordovaInterface {
 
                 // If loadingDialog property, then show the App loading dialog for first page of app
                 // (This doesn't seem to actually do anything here)
-                /*
                 String loading = null;
                 if (me.urls.size() == 1) {
                     loading = me.getStringProperty("loadingDialog", null);
@@ -392,7 +391,6 @@ public class DroidGap extends Activity implements CordovaInterface {
                     }
                     me.spinnerStart(title, message);
                 }
-                */
 
                 // Create a timeout timer for loadUrl
                 final int currentLoadUrlTimeout = me.loadUrlTimeout;
@@ -800,64 +798,6 @@ public class DroidGap extends Activity implements CordovaInterface {
     }
 
     /**
-     * Load the specified URL in the Cordova webview or a new browser instance.
-     * 
-     * NOTE: If openExternal is false, only URLs listed in whitelist can be loaded.
-     *
-     * @param url           The url to load.
-     * @param openExternal  Load url in browser instead of Cordova webview.
-     * @param clearHistory  Clear the history stack, so new page becomes top of history
-     * @param params        DroidGap parameters for new app
-     */
-    public void showWebPage(String url, boolean openExternal, boolean clearHistory, HashMap<String, Object> params) { //throws android.content.ActivityNotFoundException {
-        LOG.d(TAG, "showWebPage(%s, %b, %b, HashMap", url, openExternal, clearHistory);
-        
-        // If clearing history
-        if (clearHistory) {
-            this.clearHistory();
-        }
-        
-        // If loading into our webview
-        if (!openExternal) {
-            
-            // Make sure url is in whitelist
-            if (url.startsWith("file://") || url.indexOf(this.baseUrl) == 0 || isUrlWhiteListed(url)) {
-                // TODO: What about params?
-                
-                // Clear out current url from history, since it will be replacing it
-                if (clearHistory) {
-                    this.urls.clear();
-                }
-                
-                // Load new URL
-                this.loadUrl(url);
-            }
-            // Load in default viewer if not
-            else {
-                LOG.w(TAG, "showWebPage: Cannot load URL into webview since it is not in white list.  Loading into browser instead. (URL="+url+")");
-                try {
-                    Intent intent = new Intent(Intent.ACTION_VIEW);
-                    intent.setData(Uri.parse(url));
-                    this.startActivity(intent);
-                } catch (android.content.ActivityNotFoundException e) {
-                    LOG.e(TAG, "Error loading url "+url, e);
-                }
-            }
-        }
-        
-        // Load in default view intent
-        else {
-            try {
-                Intent intent = new Intent(Intent.ACTION_VIEW);
-                intent.setData(Uri.parse(url));
-                this.startActivity(intent);
-            } catch (android.content.ActivityNotFoundException e) {
-                LOG.e(TAG, "Error loading url "+url, e);
-            }
-        }
-    }
-    
-    /**
      * Show the spinner.  Must be called from the UI thread.
      * 
      * @param title         Title of the dialog
@@ -1189,4 +1129,9 @@ public class DroidGap extends Activity implements CordovaInterface {
       return appView.backHistory();
     }
 
+    public void showWebPage(String url, boolean openExternal,
+        boolean clearHistory, HashMap<String, Object> params) {
+      appView.showWebPage(url, openExternal, clearHistory, params);
+    }
+
 }