diff --git a/src/net/i2p/android/apps/EepGetFetcher.java b/src/net/i2p/android/apps/EepGetFetcher.java index 9290f50a9ca8b0f954c58dcbf72e0d81a5f880a5..4d2159214d76bf88ffd4b9e728581b3080b18a3e 100644 --- a/src/net/i2p/android/apps/EepGetFetcher.java +++ b/src/net/i2p/android/apps/EepGetFetcher.java @@ -52,9 +52,12 @@ public class EepGetFetcher implements EepGet.StatusListener { if (!_success) return "text/plain"; String rv = _eepget.getContentType(); - if (rv == null || rv.equals("text/html")) - return "text/html; charset=utf-8"; - return rv; + if (rv == null) + return "text/html"; + int semi = rv.indexOf(";"); + if (semi > 0) + rv = rv.substring(0, semi); + return rv.toLowerCase(); } /** @@ -71,14 +74,15 @@ public class EepGetFetcher implements EepGet.StatusListener { } /** + * Only call ONCE! * FIXME we don't get the proxy error pages this way */ public String getData() { String rv; if (!_file.exists()) { - rv = "Fetch failed"; + rv = "Fetch failed for url \"" + _url + '"'; } else if (_file.length() <= 0) { - rv = "Fetch failed"; + rv = "Fetch failed for url \"" + _url + '"'; _file.delete(); } else { InputStream fis = null; diff --git a/src/net/i2p/android/router/activity/I2PWebViewClient.java b/src/net/i2p/android/router/activity/I2PWebViewClient.java index f6033557ce3d765af0c78450f896e520b5439051..bd893f133d8e37b7aebe6a68c76b8ccd176bd628 100644 --- a/src/net/i2p/android/router/activity/I2PWebViewClient.java +++ b/src/net/i2p/android/router/activity/I2PWebViewClient.java @@ -5,6 +5,7 @@ import android.app.ProgressDialog; import android.os.AsyncTask; import android.webkit.WebView; import android.webkit.WebViewClient; +import android.widget.Toast; import java.net.URI; import java.net.URISyntaxException; @@ -22,29 +23,37 @@ class I2PWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { System.err.println("Should override? " + url); + view.stopLoading(); try { URI uri = new URI(url); String s = uri.getScheme(); - if (s == null) - return false; + if (s == null) { + Toast toast = Toast.makeText(view.getContext(), "Bad URL " + url, Toast.LENGTH_SHORT); + return true; + } s = s.toLowerCase(); if (!(s.equals("http") || s.equals("https"))) return false; String h = uri.getHost(); - if (h == null) - return false; + if (h == null) { + Toast toast = Toast.makeText(view.getContext(), "Bad URL " + url, Toast.LENGTH_SHORT); + return true; + } - view.stopLoading(); - view.getSettings().setBuiltInZoomControls(true); h = h.toLowerCase(); if (h.endsWith(".i2p")) { // if (s.equals("https") // return false; view.getSettings().setLoadsImagesAutomatically(false); + ///////// API 8 + // Otherwise hangs waiting for CSS + view.getSettings().setBlockNetworkLoads(true); //view.loadData(ERROR_EEPSITE, "text/html", "UTF-8"); (new BackgroundEepLoad(view, h)).execute(url); } else { view.getSettings().setLoadsImagesAutomatically(true); + ///////// API 8 + view.getSettings().setBlockNetworkLoads(false); //view.loadUrl(url); (new BackgroundLoad(view)).execute(url); } @@ -81,6 +90,9 @@ class I2PWebViewClient extends WebViewClient { } } + // http://stackoverflow.com/questions/3961589/android-webview-and-loaddata + private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; + private static class BackgroundEepLoad extends AsyncTask<String, Integer, Integer> implements EepGet.StatusListener { private final WebView _view; private final String _host; @@ -101,11 +113,15 @@ class I2PWebViewClient extends WebViewClient { boolean success = fetcher.fetch(); if (!success) System.err.println("Fetch failed for " + url); - String d = fetcher.getData(); String t = fetcher.getContentType(); + String d = fetcher.getData(); + int len = d.length(); + // http://stackoverflow.com/questions/3961589/android-webview-and-loaddata + if (success && t.startsWith("text/html") && !d.startsWith("<?xml")) + d = XML_HEADER + d; String e = fetcher.getEncoding(); - System.err.println("Len: " + d.length() + " type: \"" + t + "\" encoding: \"" + e + '"'); - _view.loadData(d, t, e); + System.err.println("Len: " + len + " type: \"" + t + "\" encoding: \"" + e + '"'); + _view.loadDataWithBaseURL(url, d, t, e, url); return Integer.valueOf(0); } @@ -117,7 +133,7 @@ class I2PWebViewClient extends WebViewClient { ProgressDialog d = new ProgressDialog(_view.getContext()); d.setCancelable(true); d.setTitle("Fetching..."); - d.setMessage("from " + _host); + d.setMessage("...from " + _host); d.setIndeterminate(true); d.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); d.show(); diff --git a/src/net/i2p/android/router/activity/NewsActivity.java b/src/net/i2p/android/router/activity/NewsActivity.java index 564926d8b363bba71810d5bc3e08a7a18b84d1e3..31fe242fb77b9565cc81f5a3ec432b0b74b99c62 100644 --- a/src/net/i2p/android/router/activity/NewsActivity.java +++ b/src/net/i2p/android/router/activity/NewsActivity.java @@ -37,6 +37,7 @@ public class NewsActivity extends I2PActivityBase { WebView wv = (WebView) findViewById(R.id.news_webview); wv.getSettings().setLoadsImagesAutomatically(false); wv.setWebViewClient(new I2PWebViewClient()); + wv.getSettings().setBuiltInZoomControls(true); } @Override diff --git a/src/net/i2p/android/router/activity/WebActivity.java b/src/net/i2p/android/router/activity/WebActivity.java index 32c5abb7d3652d6b836b4dd2a985a5d8aa42efad..3c8858bab366c04dc0a5868aa9839a0b925bb204 100644 --- a/src/net/i2p/android/router/activity/WebActivity.java +++ b/src/net/i2p/android/router/activity/WebActivity.java @@ -32,15 +32,14 @@ public class WebActivity extends I2PActivityBase { tv.setText(WARNING); WebView wv = (WebView) findViewById(R.id.browser_webview); wv.setWebViewClient(new I2PWebViewClient()); + wv.getSettings().setBuiltInZoomControls(true); Intent intent = getIntent(); Uri uri = intent.getData(); if (uri != null) { wv.getSettings().setLoadsImagesAutomatically(true); - wv.getSettings().setBuiltInZoomControls(true); wv.loadUrl(uri.toString()); } else { wv.getSettings().setLoadsImagesAutomatically(false); - wv.getSettings().setBuiltInZoomControls(false); int id = intent.getIntExtra(HTML_RESOURCE_ID, R.raw.welcome_html); loadResource(wv, id); }