Search in sources :

Example 1 with WebView

use of com.tencent.smtt.sdk.WebView in project GeekNews by codeestX.

the class ZhihuDetailActivity method initEventAndData.

@Override
protected void initEventAndData() {
    setToolBar(viewToolbar, "");
    Intent intent = getIntent();
    id = intent.getExtras().getInt("id");
    isNotTransition = intent.getBooleanExtra("isNotTransition", false);
    mPresenter.queryLikeData(id);
    mPresenter.getDetailData(id);
    mPresenter.getExtraData(id);
    ivProgress.start();
    WebSettings settings = wvDetailContent.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);
    wvDetailContent.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
    nsvScroller.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {

        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            if (scrollY - oldScrollY > 0 && isBottomShow) {
                //下移隐藏
                isBottomShow = false;
                llDetailBottom.animate().translationY(llDetailBottom.getHeight());
            } else if (scrollY - oldScrollY < 0 && !isBottomShow) {
                //上移出现
                isBottomShow = true;
                llDetailBottom.animate().translationY(0);
            }
        }
    });
    (getWindow().getSharedElementEnterTransition()).addListener(new Transition.TransitionListener() {

        @Override
        public void onTransitionStart(Transition transition) {
        }

        @Override
        public void onTransitionEnd(Transition transition) {
            /**
                 * 测试发现部分手机(如红米note2)上加载图片会变形,没有达到centerCrop效果
                 * 查阅资料发现Glide配合SharedElementTransition是有坑的,需要在Transition动画结束后再加载图片
                 * https://github.com/TWiStErRob/glide-support/blob/master/src/glide3/java/com/bumptech/glide/supportapp/github/_847_shared_transition/DetailFragment.java
                 */
            isTransitionEnd = true;
            if (imgUrl != null) {
                isImageShow = true;
                ImageLoader.load(mContext, imgUrl, detailBarImage);
            }
        }

        @Override
        public void onTransitionCancel(Transition transition) {
        }

        @Override
        public void onTransitionPause(Transition transition) {
        }

        @Override
        public void onTransitionResume(Transition transition) {
        }
    });
}
Also used : WebSettings(com.tencent.smtt.sdk.WebSettings) Transition(android.transition.Transition) Intent(android.content.Intent) WebView(com.tencent.smtt.sdk.WebView) NestedScrollView(android.support.v4.widget.NestedScrollView) WebViewClient(com.tencent.smtt.sdk.WebViewClient)

Example 2 with WebView

use of com.tencent.smtt.sdk.WebView 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)2 WebSettings (com.tencent.smtt.sdk.WebSettings)2 WebView (com.tencent.smtt.sdk.WebView)2 WebViewClient (com.tencent.smtt.sdk.WebViewClient)2 NestedScrollView (android.support.v4.widget.NestedScrollView)1 Transition (android.transition.Transition)1 WebChromeClient (com.tencent.smtt.sdk.WebChromeClient)1