Search in sources :

Example 41 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project GeekNews by codeestX.

the class ZhihuDetailActivity method initEventAndData.

@Override
protected void initEventAndData() {
    super.initEventAndData();
    setToolBar(viewToolbar, "");
    Intent intent = getIntent();
    id = intent.getExtras().getInt(Constants.IT_ZHIHU_DETAIL_ID);
    isNotTransition = intent.getBooleanExtra("isNotTransition", false);
    mPresenter.queryLikeData(id);
    mPresenter.getDetailData(id);
    mPresenter.getExtraData(id);
    stateLoading();
    WebSettings settings = wvDetailContent.getSettings();
    if (mPresenter.getNoImageState()) {
        settings.setBlockNetworkImage(true);
    }
    if (mPresenter.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 42 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project bdcodehelper by boredream.

the class FlingBehavior method onNestedFling.

@Override
public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, float velocityX, float velocityY, boolean consumed) {
    if (target instanceof RecyclerView && velocityY < 0) {
        final RecyclerView recyclerView = (RecyclerView) target;
        final View firstChild = recyclerView.getChildAt(0);
        final int childAdapterPosition = recyclerView.getChildAdapterPosition(firstChild);
        consumed = childAdapterPosition > TOP_CHILD_FLING_THRESHOLD;
    }
    // prevent fling flickering when going up
    if (target instanceof NestedScrollView && velocityY > 0) {
        consumed = true;
    }
    if (Math.abs(velocityY) < OPTIMAL_FLING_VELOCITY) {
        velocityY = OPTIMAL_FLING_VELOCITY * (velocityY < 0 ? -1 : 1);
    }
    return super.onNestedFling(coordinatorLayout, child, target, velocityX, velocityY, consumed);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) NestedScrollView(android.support.v4.widget.NestedScrollView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 43 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project smoke by textbrowser.

the class FireChannel method scrollMessagesView.

private void scrollMessagesView() {
    if (m_view == null)
        return;
    final NestedScrollView nestedScrollView = (NestedScrollView) m_view.findViewById(R.id.chat_scrollview);
    nestedScrollView.post(new Runnable() {

        @Override
        public void run() {
            nestedScrollView.fullScroll(NestedScrollView.FOCUS_DOWN);
        }
    });
    final TextView textView1 = (TextView) m_view.findViewById(R.id.chat_message);
    textView1.post(new Runnable() {

        @Override
        public void run() {
            textView1.requestFocus();
        }
    });
}
Also used : TextView(android.widget.TextView) NestedScrollView(android.support.v4.widget.NestedScrollView)

Aggregations

NestedScrollView (android.support.v4.widget.NestedScrollView)42 View (android.view.View)24 RecyclerView (android.support.v7.widget.RecyclerView)15 TextView (android.widget.TextView)11 ViewGroup (android.view.ViewGroup)9 AppBarLayout (android.support.design.widget.AppBarLayout)6 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)6 Toolbar (android.support.v7.widget.Toolbar)6 AbsListView (android.widget.AbsListView)6 ImageView (android.widget.ImageView)6 ScrollView (android.widget.ScrollView)6 ViewTreeObserver (android.view.ViewTreeObserver)5 SuppressLint (android.annotation.SuppressLint)4 ViewPager (android.support.v4.view.ViewPager)4 Test (org.junit.Test)4 Activity (android.app.Activity)3 Bundle (android.os.Bundle)3 TabLayout (android.support.design.widget.TabLayout)3 PagerAdapter (android.support.v4.view.PagerAdapter)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3