use of com.tencent.smtt.sdk.WebChromeClient in project GeekNews by codeestX.
the class TechDetailActivity method initEventAndData.
@Override
protected void initEventAndData() {
mRealmHelper = App.getAppComponent().realmHelper();
Intent intent = getIntent();
type = intent.getExtras().getInt(Constants.IT_DETAIL_TYPE);
title = intent.getExtras().getString(Constants.IT_DETAIL_TITLE);
url = intent.getExtras().getString(Constants.IT_DETAIL_URL);
imgUrl = intent.getExtras().getString(Constants.IT_DETAIL_IMG_URL);
id = intent.getExtras().getString(Constants.IT_DETAIL_ID);
setToolBar(toolBar, title);
WebSettings settings = wvTechContent.getSettings();
if (SharedPreferenceUtil.getNoImageState()) {
settings.setBlockNetworkImage(true);
}
if (SharedPreferenceUtil.getAutoCacheState()) {
settings.setAppCacheEnabled(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
if (SystemUtil.isNetworkConnected()) {
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
} else {
settings.setCacheMode(WebSettings.LOAD_CACHE_ONLY);
}
}
settings.setJavaScriptEnabled(true);
settings.setLoadWithOverviewMode(true);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
settings.setSupportZoom(true);
wvTechContent.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
wvTechContent.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
if (tvProgress == null)
return;
if (newProgress == 100) {
tvProgress.setVisibility(View.GONE);
} else {
tvProgress.setVisibility(View.VISIBLE);
ViewGroup.LayoutParams lp = tvProgress.getLayoutParams();
lp.width = App.SCREEN_WIDTH * newProgress / 100;
}
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
setTitle(title);
}
});
wvTechContent.loadUrl(url);
}
Aggregations