Search in sources :

Example 1 with WebChromeClient

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);
}
Also used : WebSettings(com.tencent.smtt.sdk.WebSettings) WebChromeClient(com.tencent.smtt.sdk.WebChromeClient) Intent(android.content.Intent) WebView(com.tencent.smtt.sdk.WebView) WebViewClient(com.tencent.smtt.sdk.WebViewClient)

Aggregations

Intent (android.content.Intent)1 WebChromeClient (com.tencent.smtt.sdk.WebChromeClient)1 WebSettings (com.tencent.smtt.sdk.WebSettings)1 WebView (com.tencent.smtt.sdk.WebView)1 WebViewClient (com.tencent.smtt.sdk.WebViewClient)1