incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject android commit: Moving the fix for # and ? to a new class to fix CB-995
Date Tue, 31 Jul 2012 23:18:14 GMT
Updated Branches:
  refs/heads/master db7ee192f -> ecd6ca017


Moving the fix for # and ? to a new class to fix CB-995


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

Branch: refs/heads/master
Commit: ecd6ca0172de56d6524c25fd2996913184b575fb
Parents: db7ee19
Author: Joe Bowser <bowserj@apache.org>
Authored: Tue Jul 31 16:16:57 2012 -0700
Committer: Joe Bowser <bowserj@apache.org>
Committed: Tue Jul 31 16:16:57 2012 -0700

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaWebView.java     |   19 ++++-
 .../org/apache/cordova/CordovaWebViewClient.java   |   39 ---------
 .../cordova/IceCreamCordovaWebViewClient.java      |   65 +++++++++++++++
 3 files changed, 81 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/ecd6ca01/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 7fd5775..0ce63c0 100755
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -119,7 +119,7 @@ public class CordovaWebView extends WebView {
             Log.d(TAG, "Your activity must implement CordovaInterface to work");
         }
         this.setWebChromeClient(new CordovaChromeClient(this.cordova, this));
-        this.setWebViewClient(new CordovaWebViewClient(this.cordova, this));
+        this.initWebViewClient(this.cordova);
         this.loadConfiguration();
         this.setup();
     }
@@ -143,7 +143,7 @@ public class CordovaWebView extends WebView {
             Log.d(TAG, "Your activity must implement CordovaInterface to work");
         }
         this.setWebChromeClient(new CordovaChromeClient(this.cordova, this));
-        this.setWebViewClient(new CordovaWebViewClient(this.cordova, this));
+        this.initWebViewClient(this.cordova);
         this.loadConfiguration();
         this.setup();
     }
@@ -167,11 +167,24 @@ public class CordovaWebView extends WebView {
             Log.d(TAG, "Your activity must implement CordovaInterface to work");
         }
         this.setWebChromeClient(new CordovaChromeClient(this.cordova));
-        this.setWebViewClient(new CordovaWebViewClient(this.cordova));
+        this.initWebViewClient(this.cordova);
         this.loadConfiguration();
         this.setup();
     }
 
+
+    private void initWebViewClient(CordovaInterface cordova) {
+        if(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.HONEYCOMB)
+        {
+            this.setWebViewClient(new CordovaWebViewClient(this.cordova, this));
+        }
+        else
+        {
+            this.setWebViewClient(new IceCreamCordovaWebViewClient(this.cordova, this));
+        }
+    }
+
+    
     /**
      * Initialize webview.
      */

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/ecd6ca01/framework/src/org/apache/cordova/CordovaWebViewClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebViewClient.java b/framework/src/org/apache/cordova/CordovaWebViewClient.java
index 4934c8f..6e4ff7f 100755
--- a/framework/src/org/apache/cordova/CordovaWebViewClient.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java
@@ -459,43 +459,4 @@ public class CordovaWebViewClient extends WebViewClient {
         this.authenticationTokens.clear();
     }
 
-    @Override
-    public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
-        if(url.contains("?") || url.contains("#")){
-            return generateWebResourceResponse(url);
-        } else {
-            return super.shouldInterceptRequest(view, url);
-        }
-    }
-
-    private WebResourceResponse generateWebResourceResponse(String url) {
-        final String ANDROID_ASSET = "file:///android_asset/";
-        if (url.startsWith(ANDROID_ASSET)) {
-            String niceUrl = url;
-            niceUrl = url.replaceFirst(ANDROID_ASSET, "");
-            if(niceUrl.contains("?")){
-                niceUrl = niceUrl.split("\\?")[0];
-            }
-            else if(niceUrl.contains("#"))
-            {
-                niceUrl = niceUrl.split("#")[0];
-            }
-
-            String mimetype = null;
-            if(niceUrl.endsWith(".html")){
-                mimetype = "text/html";
-            }
-
-            try {
-                AssetManager assets = cordova.getActivity().getAssets();
-                Uri uri = Uri.parse(niceUrl);
-                InputStream stream = assets.open(uri.getPath(), AssetManager.ACCESS_STREAMING);
-                WebResourceResponse response = new WebResourceResponse(mimetype, "UTF-8",
stream);
-                return response;
-            } catch (IOException e) {
-                LOG.e("generateWebResourceResponse", e.getMessage(), e);
-            }
-        }
-        return null;
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/ecd6ca01/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
new file mode 100644
index 0000000..24a9daa
--- /dev/null
+++ b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
@@ -0,0 +1,65 @@
+package org.apache.cordova;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.cordova.api.CordovaInterface;
+import org.apache.cordova.api.LOG;
+
+import android.content.res.AssetManager;
+import android.net.Uri;
+import android.webkit.WebResourceResponse;
+import android.webkit.WebView;
+
+public class IceCreamCordovaWebViewClient extends CordovaWebViewClient {
+
+
+    public IceCreamCordovaWebViewClient(CordovaInterface cordova) {
+        super(cordova);
+    }
+    
+    public IceCreamCordovaWebViewClient(CordovaInterface cordova, CordovaWebView view) {
+        super(cordova, view);
+    }
+
+    @Override
+    public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
+        if(url.contains("?") || url.contains("#")){
+            return generateWebResourceResponse(url);
+        } else {
+            return super.shouldInterceptRequest(view, url);
+        }
+    }
+
+    private WebResourceResponse generateWebResourceResponse(String url) {
+        final String ANDROID_ASSET = "file:///android_asset/";
+        if (url.startsWith(ANDROID_ASSET)) {
+            String niceUrl = url;
+            niceUrl = url.replaceFirst(ANDROID_ASSET, "");
+            if(niceUrl.contains("?")){
+                niceUrl = niceUrl.split("\\?")[0];
+            }
+            else if(niceUrl.contains("#"))
+            {
+                niceUrl = niceUrl.split("#")[0];
+            }
+
+            String mimetype = null;
+            if(niceUrl.endsWith(".html")){
+                mimetype = "text/html";
+            }
+
+            try {
+                AssetManager assets = cordova.getActivity().getAssets();
+                Uri uri = Uri.parse(niceUrl);
+                InputStream stream = assets.open(uri.getPath(), AssetManager.ACCESS_STREAMING);
+                WebResourceResponse response = new WebResourceResponse(mimetype, "UTF-8",
stream);
+                return response;
+            } catch (IOException e) {
+                LOG.e("generateWebResourceResponse", e.getMessage(), e);
+            }
+        }
+        return null;
+    }
+    
+}


Mime
View raw message