- Add toast for some errors
- Fix eepsite loads by adding xml header - Use loadDataWithBaseURL() but block network loads, requires API 8 - Turn zoom controls on for local pages too
This commit is contained in:
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user