Java Code Examples for android.support.v4.view.NestedScrollingChild

The following examples show how to use android.support.v4.view.NestedScrollingChild. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: CollapsingRefresh   Source File: RefreshContentWrapper.java    License: Apache License 2.0 6 votes vote down vote up
private void findScrollableView(View content, RefreshKernel kernel) {
    mScrollableView = findScrollableViewInternal(content, true);
    try {
        if (mScrollableView instanceof CoordinatorLayout) {
            kernel.getRefreshLayout().setNestedScrollingEnabled(false);
            wrapperCoordinatorLayout(((CoordinatorLayout) mScrollableView), kernel.getRefreshLayout());
        }
    } catch (Throwable e) {//try 不能删除
    }
    if (mScrollableView instanceof NestedScrollingParent
            && !(mScrollableView instanceof NestedScrollingChild)) {
        mScrollableView = findScrollableViewInternal(mScrollableView, false);
    }
    if (mScrollableView instanceof ViewPager) {
        wrapperViewPager((ViewPager) this.mScrollableView);
    }
    if (mScrollableView == null) {
        mScrollableView = content;
    }
}
 
Example 2
Source Project: CollapsingRefresh   Source File: RefreshContentWrapper.java    License: Apache License 2.0 6 votes vote down vote up
private View findScrollableViewInternal(View content, boolean selfable) {
    View scrollableView = null;
    Queue<View> views = new LinkedBlockingQueue<>(Collections.singletonList(content));
    while (!views.isEmpty() && scrollableView == null) {
        View view = views.poll();
        if (view != null) {
            if ((selfable || view != content) && (view instanceof AbsListView
                    || view instanceof ScrollView
                    || view instanceof ScrollingView
                    || view instanceof NestedScrollingChild
                    || view instanceof NestedScrollingParent
                    || view instanceof WebView
                    || view instanceof ViewPager)) {
                scrollableView = view;
            } else if (view instanceof ViewGroup) {
                ViewGroup group = (ViewGroup) view;
                for (int j = 0; j < group.getChildCount(); j++) {
                    views.add(group.getChildAt(j));
                }
            }
        }
    }
    return scrollableView;
}
 
Example 3
Source Project: CollapsingRefresh   Source File: RefreshContentWrapper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
    super.setPrimaryItem(container, position, object);
    if (object instanceof View) {
        mScrollableView = ((View) object);
    } else if (object instanceof Fragment) {
        mScrollableView = ((Fragment) object).getView();
    }
    if (mScrollableView != null) {
        mScrollableView = findScrollableViewInternal(mScrollableView, true);
        if (mScrollableView instanceof NestedScrollingParent
                && !(mScrollableView instanceof NestedScrollingChild)) {
            mScrollableView = findScrollableViewInternal(mScrollableView, false);
        }
    }
}
 
Example 4
Source Project: RefreshLayout   Source File: QRefreshLayout.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    if (getChildCount() > 1) {
        throw new IllegalStateException("QRefreshLayout can only have one child");
    }
    mTarget = getChildAt(0);
    mTarget.setClickable(true);
    boolean targetNestedScrollingEnabled = false;
    if (mTarget instanceof NestedScrollingChild) {
        targetNestedScrollingEnabled = ((NestedScrollingChild) mTarget).isNestedScrollingEnabled();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        targetNestedScrollingEnabled = mTarget.isNestedScrollingEnabled();
    }
    setNestedScrollingEnabled(targetNestedScrollingEnabled);
    ViewGroup.LayoutParams params = mTarget.getLayoutParams();
    params.width = LayoutParams.MATCH_PARENT;
    params.height = LayoutParams.MATCH_PARENT;
    mTarget.setLayoutParams(params);
    if (mHeaderView == null) {
        setHeaderView(new HeaderView(getContext()));
    }
    if (mFooterView == null) {
        setFooterView(new FooterView(getContext()));
    }
}
 
Example 5
Source Project: paper-launcher   Source File: BottomSheetBehaviorV2.java    License: MIT License 5 votes vote down vote up
private View findScrollingChild(View view) {
    if (view instanceof NestedScrollingChild) {
        return view;
    }
    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        for (int i = 0, count = group.getChildCount(); i < count; i++) {
            View scrollingChild = findScrollingChild(group.getChildAt(i));
            if (scrollingChild != null) {
                return scrollingChild;
            }
        }
    }
    return null;
}
 
Example 6
Source Project: Nibo   Source File: BottomSheetBehaviorGoogleMapsLike.java    License: MIT License 5 votes vote down vote up
private View findScrollingChild(View view) {
    if (view instanceof NestedScrollingChild) {
        return view;
    }
    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        for (int i = 0, count = group.getChildCount(); i < count; i++) {
            View scrollingChild = findScrollingChild(group.getChildAt(i));
            if (scrollingChild != null) {
                return scrollingChild;
            }
        }
    }
    return null;
}
 
Example 7
Source Project: AndroidTopSheet   Source File: TopSheetBehavior.java    License: Apache License 2.0 5 votes vote down vote up
private View findScrollingChild(View view) {
    if (view instanceof NestedScrollingChild) {
        return view;
    }
    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        for (int i = 0, count = group.getChildCount(); i < count; i++) {
            View scrollingChild = findScrollingChild(group.getChildAt(i));
            if (scrollingChild != null) {
                return scrollingChild;
            }
        }
    }
    return null;
}
 
Example 8
private View findScrollingChild(View view) {
  if (view instanceof NestedScrollingChild) {
    return view;
  }
  if (view instanceof ViewGroup) {
    ViewGroup group = (ViewGroup) view;
    for (int i = 0, count = group.getChildCount(); i < count; i++) {
      View scrollingChild = findScrollingChild(group.getChildAt(i));
      if (scrollingChild != null) {
        return scrollingChild;
      }
    }
  }
  return null;
}
 
Example 9
Source Project: AndroidSweetBehavior   Source File: SheetBehavior.java    License: Apache License 2.0 5 votes vote down vote up
private View findScrollingChild(View view) {
    if (view instanceof NestedScrollingChild) {
        return view;
    }
    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        for (int i = 0, count = group.getChildCount(); i < count; i++) {
            View scrollingChild = findScrollingChild(group.getChildAt(i));
            if (scrollingChild != null) {
                return scrollingChild;
            }
        }
    }
    return null;
}
 
Example 10
Source Project: FamilyChat   Source File: CommonPtrLayout.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 通过id得到相应的view
 */
@Override
protected void onFinishInflate()
{
    final int childCount = getChildCount();

    if (childCount > 0)
    {
        mRefreshView = findViewById(com.lib.ptrview.R.id.common_ptrview_refresh_view);
        mContentView = findViewById(com.lib.ptrview.R.id.common_ptrview_content);
        mLoadMoreView = findViewById(com.lib.ptrview.R.id.common_ptrview_loadmore_view);
        mScrollContentView = findViewById(com.lib.ptrview.R.id.common_ptrview_content_scroll);
    }

    if (mContentView == null)
    {
        throw new IllegalStateException("CommonPtrLayout: mContentView is null");
    }

    if (mIsCoo)
    {
        if (mContentView instanceof CoordinatorLayout)
        {
            CoordinatorLayout coo = (CoordinatorLayout) mContentView;
            mAppBar = (AppBarLayout) coo.getChildAt(0);
            setAppBarListener();
        } else
        {
            throw new IllegalStateException("CommonPtrLayout: mContentView is not CoordinatorLayout");
        }

        if (mScrollContentView == null)
        {
            throw new IllegalStateException("CommonPtrLayout: mScrollContentView is null");
        }

        if (!(mScrollContentView instanceof NestedScrollingChild))
        {
            throw new IllegalStateException("CommonPtrLayout: mScrollContentView is not NestedScrollingChild");
        }
    }

    if (mRefreshEnabled)
    {
        if (mRefreshView == null)
            throw new IllegalStateException("CommonPrtLayout : You must set a refreshView when the refreshEnabled is true.");
        if (!(mRefreshView instanceof CommonPtrViewImpl))
            throw new IllegalStateException("CommonPrtLayout : The refreshView must instanceof CommonPtrViewImpl.");

        mRefreshView.setBackgroundResource(mRefreshBgResId);
        getRefreshView().setIsPullDownMode(true);
    }

    if (mLoadMoreEnabled)
    {
        if (mLoadMoreView == null)
            throw new IllegalStateException("CommonPrtLayout : You must set a loadMoreView when the refreshEnabled is true.");
        if (!(mLoadMoreView instanceof CommonPtrViewImpl))
            throw new IllegalStateException("CommonPrtLayout : The loadMoreView must instanceof CommonPtrViewImpl.");

        mLoadMoreView.setBackgroundResource(mLoadMoreBgResId);
        getLoadMoreView().setIsPullDownMode(false);
    }

    super.onFinishInflate();

    for (int i = 0; i < childCount; i++)
    {
        View v = getChildAt(i);
        if (v != mContentView)
            bringChildToFront(v);
    }
}
 
Example 11
Source Project: CanRefresh   Source File: CanRefreshLayout.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 通过id得到相应的view
 */
@Override
protected void onFinishInflate() {

    final int childCount = getChildCount();

    if (childCount > 0) {
        mHeaderView = findViewById(com.canyinghao.canrefresh.R.id.can_refresh_header);
        mContentView = findViewById(com.canyinghao.canrefresh.R.id.can_content_view);
        mFooterView = findViewById(com.canyinghao.canrefresh.R.id.can_refresh_footer);
        mScrollView = findViewById(com.canyinghao.canrefresh.R.id.can_scroll_view);
    }

    if (mContentView == null) {
        throw new IllegalStateException("mContentView is null");
    }

    if (mIsCoo) {
        if (mContentView instanceof CoordinatorLayout) {

            CoordinatorLayout coo = (CoordinatorLayout) mContentView;

            mAppBar = (AppBarLayout) coo.getChildAt(0);


            setAppBarListener();

        } else {
            throw new IllegalStateException("mContentView is not CoordinatorLayout");
        }

        if (mScrollView == null) {
            throw new IllegalStateException("mScrollView is null");
        }

        if (mScrollView instanceof ViewPager) {

            mViewPager = (ViewPager) mScrollView;
            mIsViewPager = true;

        } else if (mScrollView instanceof NestedScrollingChild) {

            mIsViewPager = false;

        } else {
            throw new IllegalStateException("mScrollView is not NestedScrollingChild or ViewPager");
        }
    }

    if (mHeaderView != null && !(mHeaderView instanceof CanRefresh)) {

        throw new IllegalStateException("mHeaderView  error");
    }
    if (mFooterView != null && !(mFooterView instanceof CanRefresh)) {

        throw new IllegalStateException("mFooterView error");
    }

    if (mHeaderView != null) {

        getHeaderInterface().setIsHeaderOrFooter(true);
    }

    if (mFooterView != null) {

        getFooterInterface().setIsHeaderOrFooter(false);
    }


    super.onFinishInflate();


    setStyle(mHeadStyle, mFootStyle);

}