Skip to content

Instantly share code, notes, and snippets.

@jpardogo
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpardogo/4e22c02405fdc403cee0 to your computer and use it in GitHub Desktop.
Save jpardogo/4e22c02405fdc403cee0 to your computer and use it in GitHub Desktop.
Method to load a WebView that will receive the real 100% progress of the WebView avoiding fake 100% progress due redirections
private void loadPage() {
WebSettings seetings = mWebView.getSettings();
seetings.setJavaScriptEnabled(true);
seetings.setBuiltInZoomControls(false);
seetings.setSupportZoom(true);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
mLoadingCount++;
return super.shouldOverrideUrlLoading(view, url);
}
});
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
getActivity().setProgress(progress * 100);
if(progress==100){
if(mLoadingCount ==0 ) {
//WebView 100% loaded
mProgresBar.setVisibility(View.GONE);
}
if(mLoadingCount >0 ) {
mLoadingCount--;
}
}
Log.d(TAG, "Progress: " + progress + "%");
}
});
mWebView.loadUrl(mURL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment