Skip to content

Instantly share code, notes, and snippets.

@esabook
Created May 15, 2019 15:08
Show Gist options
  • Save esabook/84bc91838154d87670cfcaebb2116e66 to your computer and use it in GitHub Desktop.
Save esabook/84bc91838154d87670cfcaebb2116e66 to your computer and use it in GitHub Desktop.
setup monitored webview
protected void setupWebview() {
webChromeClient = new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
boolean onGoing = newProgress != 100;
vBinding.setOnGoing(onGoing);
vBinding.action.setImageResource(onGoing ? R.drawable.ic_cancel : R.drawable.ic_refresh);
vBinding.setCanBack(view.canGoBack());
vBinding.setCanForward(view.canGoForward());
}
};
webViewClient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
vBinding.setOnGoing(false);
vBinding.action.setImageResource(R.drawable.ic_refresh);
if (mUrlListener != null) mUrlListener.onUrlChange(url);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
vBinding.action.setImageResource(R.drawable.ic_cancel);
vBinding.setOnGoing(true);
}
};
getWebView().setWebChromeClient(webChromeClient);
getWebView().setWebViewClient(webViewClient);
getWebView().getSettings().setJavaScriptEnabled(true);
getWebView().getSettings().setPluginState(WebSettings.PluginState.ON);
// getWebView().setLayerType(View.LAYER_TYPE_HARDWARE, null);
getWebView().getSettings().setDomStorageEnabled(true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment