I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit dbc6c221 authored by zzz's avatar zzz
Browse files

more progress dialog fixups

parent e62ce19a
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,8 @@ import net.i2p.util.EepGet; ...@@ -30,6 +30,8 @@ import net.i2p.util.EepGet;
class I2PWebViewClient extends WebViewClient { class I2PWebViewClient extends WebViewClient {
private BGLoad _lastTask; private BGLoad _lastTask;
/** save it here so we can dismiss it in onPageFinished() */
private ProgressDialog _lastDialog;
// TODO add some inline style // TODO add some inline style
private static final String CONTENT = "content"; private static final String CONTENT = "content";
...@@ -104,7 +106,8 @@ class I2PWebViewClient extends WebViewClient { ...@@ -104,7 +106,8 @@ class I2PWebViewClient extends WebViewClient {
///////// API 8 ///////// API 8
// Otherwise hangs waiting for CSS // Otherwise hangs waiting for CSS
view.getSettings().setBlockNetworkLoads(false); view.getSettings().setBlockNetworkLoads(false);
BGLoad task = new BackgroundEepLoad(view, h); _lastDialog = new ProgressDialog(view.getContext());
BGLoad task = new BackgroundEepLoad(view, h, _lastDialog);
_lastTask = task; _lastTask = task;
task.execute(url); task.execute(url);
} else { } else {
...@@ -159,6 +162,14 @@ class I2PWebViewClient extends WebViewClient { ...@@ -159,6 +162,14 @@ class I2PWebViewClient extends WebViewClient {
@Override @Override
public void onPageFinished(WebView view, String url) { public void onPageFinished(WebView view, String url) {
Util.e("OPF URL: " + url); Util.e("OPF URL: " + url);
ProgressDialog d = _lastDialog;
if (d != null && d.isShowing()) {
try {
// throws IAE - not attached to window manager - on screen rotation
// isShowing() may cover it though.
d.dismiss();
} catch (Exception e) {}
}
super.onPageFinished(view, url); super.onPageFinished(view, url);
} }
...@@ -203,15 +214,23 @@ class I2PWebViewClient extends WebViewClient { ...@@ -203,15 +214,23 @@ class I2PWebViewClient extends WebViewClient {
private abstract static class BGLoad extends AsyncTask<String, Integer, Integer> implements DialogInterface.OnCancelListener { private abstract static class BGLoad extends AsyncTask<String, Integer, Integer> implements DialogInterface.OnCancelListener {
protected final WebView _view; protected final WebView _view;
protected ProgressDialog _dialog; protected final ProgressDialog _dialog;
public BGLoad(WebView view) { public BGLoad(WebView view, ProgressDialog dialog) {
_view = view; _view = view;
dialog.setCancelable(true);
_dialog = dialog;
} }
@Override @Override
protected void onPostExecute(Integer result) { protected void onPostExecute(Integer result) {
dismiss(); if (_dialog != null && _dialog.isShowing()) {
// since webkit is just going to sit there...
try {
_dialog.setTitle("Downloading...");
_dialog.setMessage("...CSS and images...");
} catch (Exception e) {}
}
} }
@Override @Override
...@@ -239,7 +258,7 @@ class I2PWebViewClient extends WebViewClient { ...@@ -239,7 +258,7 @@ class I2PWebViewClient extends WebViewClient {
private static class BackgroundLoad extends BGLoad { private static class BackgroundLoad extends BGLoad {
public BackgroundLoad(WebView view) { public BackgroundLoad(WebView view) {
super(view); super(view, null);
} }
protected Integer doInBackground(String... urls) { protected Integer doInBackground(String... urls) {
...@@ -256,11 +275,11 @@ class I2PWebViewClient extends WebViewClient { ...@@ -256,11 +275,11 @@ class I2PWebViewClient extends WebViewClient {
protected void onProgressUpdate(Integer... progress) { protected void onProgressUpdate(Integer... progress) {
if (isCancelled()) if (isCancelled())
return; return;
if (progress[0].intValue() < 0) { //if (progress[0].intValue() < 0) {
_dialog = ProgressDialog.show(_view.getContext(), "Loading", "some url"); // _dialog = ProgressDialog.show(_view.getContext(), "Loading", "some url");
_dialog.setOnCancelListener(this); // _dialog.setOnCancelListener(this);
_dialog.setCancelable(true); // _dialog.setCancelable(true);
} //}
} }
...@@ -273,8 +292,8 @@ class I2PWebViewClient extends WebViewClient { ...@@ -273,8 +292,8 @@ class I2PWebViewClient extends WebViewClient {
private final String _host; private final String _host;
private int _total; private int _total;
public BackgroundEepLoad(WebView view, String host) { public BackgroundEepLoad(WebView view, String host, ProgressDialog dialog) {
super(view); super(view, dialog);
_host = host; _host = host;
} }
...@@ -379,17 +398,12 @@ class I2PWebViewClient extends WebViewClient { ...@@ -379,17 +398,12 @@ class I2PWebViewClient extends WebViewClient {
return; return;
int prog = progress[0].intValue(); int prog = progress[0].intValue();
if (prog < 0) { if (prog < 0) {
// Can't change style on the fly later, results in an NPE in setMax() _dialog.setTitle("Contacting...");
//_dialog = ProgressDialog.show(_view.getContext(), "Fetching...", "from " + _host); _dialog.setMessage(_host);
ProgressDialog d = new ProgressDialog(_view.getContext()); _dialog.setIndeterminate(true);
d.setCancelable(true); _dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
d.setTitle("Contacting..."); _dialog.setOnCancelListener(this);
d.setMessage(_host); _dialog.show();
d.setIndeterminate(true);
d.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
d.show();
d.setOnCancelListener(this);
_dialog = d;
} else if (prog == 0 && _total > 0) { } else if (prog == 0 && _total > 0) {
_dialog.setTitle("Downloading..."); _dialog.setTitle("Downloading...");
_dialog.setMessage("...from " + _host); _dialog.setMessage("...from " + _host);
...@@ -397,7 +411,8 @@ class I2PWebViewClient extends WebViewClient { ...@@ -397,7 +411,8 @@ class I2PWebViewClient extends WebViewClient {
_dialog.setMax(_total); _dialog.setMax(_total);
_dialog.setProgress(0); _dialog.setProgress(0);
} else if (_total > 0) { } else if (_total > 0) {
_dialog.setProgress(prog); // so it isn't at 100% while loading images and CSS
_dialog.setProgress(Math.min(prog, _total * 99 / 100));
} else if (prog > 0) { } else if (prog > 0) {
// ugly, need custom // ugly, need custom
_dialog.setTitle("Downloading..."); _dialog.setTitle("Downloading...");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment