Last active
August 29, 2015 14:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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