Search in sources :

Example 1 with NestedScrollingParent

use of android.support.v4.view.NestedScrollingParent in project SmartRefreshLayout by scwang90.

the class SmartRefreshLayout method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    final View thisView = this;
    if (!thisView.isInEditMode()) {
        if (mHandler == null) {
            mHandler = new Handler();
        }
        if (mListDelayedRunnable != null) {
            for (DelayedRunnable runnable : mListDelayedRunnable) {
                mHandler.postDelayed(runnable, runnable.delayMillis);
            }
            mListDelayedRunnable.clear();
            mListDelayedRunnable = null;
        }
        if (mRefreshHeader == null) {
            setRefreshHeader(sHeaderCreator.createRefreshHeader(thisView.getContext(), this));
        }
        if (mRefreshFooter == null) {
            setRefreshFooter(sFooterCreator.createRefreshFooter(thisView.getContext(), this));
        } else {
            mEnableLoadMore = mEnableLoadMore || !mManualLoadMore;
        }
        if (mRefreshContent == null) {
            for (int i = 0, len = getChildCount(); i < len; i++) {
                View view = getChildAt(i);
                if ((mRefreshHeader == null || view != mRefreshHeader.getView()) && (mRefreshFooter == null || view != mRefreshFooter.getView())) {
                    mRefreshContent = new RefreshContentWrapper(view);
                }
            }
        }
        if (mRefreshContent == null) {
            final int padding = DensityUtil.dp2px(20);
            final TextView errorView = new TextView(thisView.getContext());
            errorView.setTextColor(0xffff6600);
            errorView.setGravity(Gravity.CENTER);
            errorView.setTextSize(20);
            errorView.setText(R.string.srl_content_empty);
            super.addView(errorView, MATCH_PARENT, MATCH_PARENT);
            mRefreshContent = new RefreshContentWrapper(errorView);
            mRefreshContent.getView().setPadding(padding, padding, padding, padding);
        }
        View fixedHeaderView = mFixedHeaderViewId > 0 ? thisView.findViewById(mFixedHeaderViewId) : null;
        View fixedFooterView = mFixedFooterViewId > 0 ? thisView.findViewById(mFixedFooterViewId) : null;
        mRefreshContent.setScrollBoundaryDecider(mScrollBoundaryDecider);
        mRefreshContent.setEnableLoadMoreWhenContentNotFull(mEnableLoadMoreWhenContentNotFull);
        mRefreshContent.setUpComponent(mKernel, fixedHeaderView, fixedFooterView);
        if (mSpinner != 0) {
            notifyStateChanged(RefreshState.None);
            mRefreshContent.moveSpinner(mSpinner = 0);
        }
        if (!mManualNestedScrolling && !isNestedScrollingEnabled()) {
            post(new Runnable() {

                @Override
                public void run() {
                    final View thisView = SmartRefreshLayout.this;
                    for (ViewParent parent = thisView.getParent(); parent != null; ) {
                        if (parent instanceof NestedScrollingParent) {
                            View target = SmartRefreshLayout.this;
                            // noinspection RedundantCast
                            if (((NestedScrollingParent) parent).onStartNestedScroll(target, target, ViewCompat.SCROLL_AXIS_VERTICAL)) {
                                setNestedScrollingEnabled(true);
                                mManualNestedScrolling = false;
                                break;
                            }
                        }
                        View thisParent = (View) parent;
                        parent = thisParent.getParent();
                    }
                }
            });
        }
    }
    if (mPrimaryColors != null) {
        if (mRefreshHeader != null) {
            mRefreshHeader.setPrimaryColors(mPrimaryColors);
        }
        if (mRefreshFooter != null) {
            mRefreshFooter.setPrimaryColors(mPrimaryColors);
        }
    }
    // 重新排序
    if (mRefreshContent != null) {
        super.bringChildToFront(mRefreshContent.getView());
    }
    if (mRefreshHeader != null && mRefreshHeader.getSpinnerStyle() != SpinnerStyle.FixedBehind) {
        super.bringChildToFront(mRefreshHeader.getView());
    }
    if (mRefreshFooter != null && mRefreshFooter.getSpinnerStyle() != SpinnerStyle.FixedBehind) {
        super.bringChildToFront(mRefreshFooter.getView());
    }
}
Also used : NestedScrollingParent(android.support.v4.view.NestedScrollingParent) ViewParent(android.view.ViewParent) DelayedRunnable(com.scwang.smartrefresh.layout.util.DelayedRunnable) RefreshContentWrapper(com.scwang.smartrefresh.layout.impl.RefreshContentWrapper) Handler(android.os.Handler) DelayedRunnable(com.scwang.smartrefresh.layout.util.DelayedRunnable) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView) SmartUtil.isScrollableView(com.scwang.smartrefresh.layout.util.SmartUtil.isScrollableView) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 2 with NestedScrollingParent

use of android.support.v4.view.NestedScrollingParent in project SmartRefreshLayout by scwang90.

the class RefreshContentWrapper method findScrollableView.

// <editor-fold desc="findScrollableView">
protected void findScrollableView(View content, RefreshKernel kernel) {
    View scrollableView = null;
    boolean isInEditMode = mContentView.isInEditMode();
    while (scrollableView == null || (scrollableView instanceof NestedScrollingParent && !(scrollableView instanceof NestedScrollingChild))) {
        content = findScrollableViewInternal(content, scrollableView == null);
        if (content == scrollableView) {
            break;
        }
        if (!isInEditMode) {
            DesignUtil.checkCoordinatorLayout(content, kernel, this);
        }
        scrollableView = content;
    }
    if (scrollableView != null) {
        mScrollableView = scrollableView;
    }
}
Also used : NestedScrollingParent(android.support.v4.view.NestedScrollingParent) NestedScrollingChild(android.support.v4.view.NestedScrollingChild) View(android.view.View) AbsListView(android.widget.AbsListView) SmartUtil.isScrollableView(com.scwang.smartrefresh.layout.util.SmartUtil.isScrollableView) ScrollBoundaryUtil.isTransformedTouchPointInView(com.scwang.smartrefresh.layout.util.ScrollBoundaryUtil.isTransformedTouchPointInView)

Example 3 with NestedScrollingParent

use of android.support.v4.view.NestedScrollingParent in project CollapsingRefresh by ckrgithub.

the class RefreshContentWrapper method findScrollableViewInternal.

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;
}
Also used : NestedScrollingParent(android.support.v4.view.NestedScrollingParent) NestedScrollView(android.support.v4.widget.NestedScrollView) ScrollView(android.widget.ScrollView) NestedScrollingChild(android.support.v4.view.NestedScrollingChild) ViewGroup(android.view.ViewGroup) ScrollingView(android.support.v4.view.ScrollingView) AbsListView(android.widget.AbsListView) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) WebView(android.webkit.WebView) ScrollingView(android.support.v4.view.ScrollingView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) WebView(android.webkit.WebView) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) ViewPager(android.support.v4.view.ViewPager)

Example 4 with NestedScrollingParent

use of android.support.v4.view.NestedScrollingParent in project CollapsingRefresh by ckrgithub.

the class SmartRefreshLayout method onFinishInflate.

// </editor-fold>
// <editor-fold desc="生命周期 life cycle">
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    Logd(TAG, "onFinish,Inflate: ");
    final int count = getChildCount();
    if (count > 3) {
        throw new RuntimeException("最多只支持3个子View,Most only support three sub view");
    } else if (mEnablePureScrollMode && count > 1) {
        throw new RuntimeException("PureScrollMode模式只支持一个子View,Most only support one sub view in PureScrollMode");
    }
    Logw(TAG, "onFinishInflate: count:" + count);
    // 定义为确认的子View索引
    boolean[] uncertains = new boolean[count];
    // 第一次查找确认的 子View
    for (int i = 0; i < count; i++) {
        View view = getChildAt(i);
        Logw(TAG, "onFinishInflate: view:" + view);
        if (view instanceof RefreshHeader && mRefreshHeader == null) {
            mRefreshHeader = ((RefreshHeader) view);
        } else if (view instanceof RefreshFooter && mRefreshFooter == null) {
            mEnableLoadmore = mEnableLoadmore || !mManualLoadmore;
            mRefreshFooter = ((RefreshFooter) view);
        } else if (mRefreshContent == null && (view instanceof AbsListView || view instanceof WebView || view instanceof ScrollView || view instanceof ScrollingView || view instanceof NestedScrollingChild || view instanceof NestedScrollingParent || view instanceof ViewPager)) {
            mRefreshContent = new RefreshContentWrapper(view);
        } else if (RefreshHeaderWrapper.isTagedHeader(view) && mRefreshHeader == null) {
            mRefreshHeader = new RefreshHeaderWrapper(view);
        } else if (RefreshFooterWrapper.isTagedFooter(view) && mRefreshFooter == null) {
            mRefreshFooter = new RefreshFooterWrapper(view);
        } else if (RefreshContentWrapper.isTagedContent(view) && mRefreshContent == null) {
            mRefreshContent = new RefreshContentWrapper(view);
        } else {
            // 标记未确认
            uncertains[i] = true;
        }
    }
    // 如果有 未确认(uncertains)的子View 通过智能算法计算
    for (int i = 0; i < count; i++) {
        if (uncertains[i]) {
            View view = getChildAt(i);
            Logd(TAG, "onFinishInflate: uncertains:" + view);
            if (count == 1 && mRefreshContent == null) {
                mRefreshContent = new RefreshContentWrapper(view);
            } else if (i == 0 && mRefreshHeader == null) {
                mRefreshHeader = new RefreshHeaderWrapper(view);
            } else if (count == 2 && mRefreshContent == null) {
                mRefreshContent = new RefreshContentWrapper(view);
            } else if (i == 2 && mRefreshFooter == null) {
                mEnableLoadmore = mEnableLoadmore || !mManualLoadmore;
                mRefreshFooter = new RefreshFooterWrapper(view);
            } else if (mRefreshContent == null) {
                mRefreshContent = new RefreshContentWrapper(view);
            }
        }
    }
    if (isInEditMode()) {
        if (mPrimaryColors != null) {
            if (mRefreshHeader != null) {
                mRefreshHeader.setPrimaryColors(mPrimaryColors);
            }
            if (mRefreshFooter != null) {
                mRefreshFooter.setPrimaryColors(mPrimaryColors);
            }
        }
        // TODO: 2017/10/8 头部、内容、底部排序
        if (mRefreshContent != null) {
            bringChildToFront(mRefreshContent.getView());
        }
        if (mRefreshHeader != null && mRefreshHeader.getSpinnerStyle() != SpinnerStyle.FixedBehind) {
            if (isHeaderFixBehind) {
            } else {
                bringChildToFront(mRefreshHeader.getView());
            }
        }
        if (mRefreshFooter != null && mRefreshFooter.getSpinnerStyle() != SpinnerStyle.FixedBehind) {
            bringChildToFront(mRefreshFooter.getView());
        }
        if (mKernel == null) {
            mKernel = new RefreshKernelImpl();
        }
    }
}
Also used : RefreshHeaderWrapper(com.scwang.smartrefresh.impl.RefreshHeaderWrapper) RefreshHeader(com.scwang.smartrefresh.api.RefreshHeader) RefreshFooter(com.scwang.smartrefresh.api.RefreshFooter) ScrollingView(android.support.v4.view.ScrollingView) AbsListView(android.widget.AbsListView) ScrollingView(android.support.v4.view.ScrollingView) View(android.view.View) WebView(android.webkit.WebView) AbsListView(android.widget.AbsListView) ScrollView(android.widget.ScrollView) ViewPager(android.support.v4.view.ViewPager) Paint(android.graphics.Paint) NestedScrollingParent(android.support.v4.view.NestedScrollingParent) RefreshFooterWrapper(com.scwang.smartrefresh.impl.RefreshFooterWrapper) ScrollView(android.widget.ScrollView) NestedScrollingChild(android.support.v4.view.NestedScrollingChild) RefreshContentWrapper(com.scwang.smartrefresh.impl.RefreshContentWrapper) WebView(android.webkit.WebView)

Aggregations

NestedScrollingParent (android.support.v4.view.NestedScrollingParent)4 View (android.view.View)4 NestedScrollingChild (android.support.v4.view.NestedScrollingChild)3 AbsListView (android.widget.AbsListView)3 Paint (android.graphics.Paint)2 ScrollingView (android.support.v4.view.ScrollingView)2 ViewPager (android.support.v4.view.ViewPager)2 WebView (android.webkit.WebView)2 ScrollView (android.widget.ScrollView)2 SmartUtil.isScrollableView (com.scwang.smartrefresh.layout.util.SmartUtil.isScrollableView)2 SuppressLint (android.annotation.SuppressLint)1 Handler (android.os.Handler)1 NestedScrollView (android.support.v4.widget.NestedScrollView)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ViewGroup (android.view.ViewGroup)1 ViewParent (android.view.ViewParent)1 TextView (android.widget.TextView)1 RefreshFooter (com.scwang.smartrefresh.api.RefreshFooter)1 RefreshHeader (com.scwang.smartrefresh.api.RefreshHeader)1 RefreshContentWrapper (com.scwang.smartrefresh.impl.RefreshContentWrapper)1