Search in sources :

Example 1 with RefreshContentWrapper

use of com.scwang.smartrefresh.impl.RefreshContentWrapper in project CollapsingRefresh by ckrgithub.

the class SmartRefreshLayout method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    Logd(TAG, "onFinish,onAttachedToWindow: ");
    if (isInEditMode())
        return;
    if (mRefreshContent == null && mRefreshHeader == null && mRefreshFooter == null) {
        onFinishInflate();
    }
    if (mKernel == null) {
        mKernel = new RefreshKernelImpl();
    }
    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) {
            mRefreshContent = new RefreshContentWrapper(getContext());
            mRefreshContent.getView().setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
        }
    }
    if (mFixedHeaderViewId > 0 && mFixedHeaderView == null) {
        mFixedHeaderView = findViewById(mFixedHeaderViewId);
    }
    if (mFixedFooterViewId > 0 && mFixedFooterView == null) {
        mFixedFooterView = findViewById(mFixedFooterViewId);
    }
    mRefreshContent.setupComponent(mKernel, mFixedHeaderView, mFixedFooterView);
    if (mRefreshHeader == null) {
        if (mEnablePureScrollMode) {
        // 注释此效果       ckr  by 2017.8.15
        // mRefreshHeader = new FalsifyHeader(getContext());
        } else {
            mRefreshHeader = sHeaderCreater.createRefreshHeader(getContext(), this);
        }
        if (!(mRefreshHeader.getView().getLayoutParams() instanceof MarginLayoutParams)) {
            if (mRefreshHeader.getSpinnerStyle() == SpinnerStyle.Scale) {
                addView(mRefreshHeader.getView(), MATCH_PARENT, MATCH_PARENT);
            } else {
                addView(mRefreshHeader.getView(), MATCH_PARENT, WRAP_CONTENT);
            }
        }
    }
    if (mRefreshFooter == null) {
        if (mEnablePureScrollMode) {
        // 注释此效果       ckr  by 2017.8.15
        // mRefreshFooter = new RefreshFooterWrapper(new FalsifyHeader(getContext()));
        // mEnableLoadmore = mEnableLoadmore || !mManualLoadmore;
        } else {
            mRefreshFooter = sFooterCreater.createRefreshFooter(getContext(), this);
            mEnableLoadmore = mEnableLoadmore || (!mManualLoadmore && sManualFooterCreater);
        }
        if (!(mRefreshFooter.getView().getLayoutParams() instanceof MarginLayoutParams)) {
            if (mRefreshFooter.getSpinnerStyle() == SpinnerStyle.Scale) {
                addView(mRefreshFooter.getView(), MATCH_PARENT, MATCH_PARENT);
            } else {
                addView(mRefreshFooter.getView(), MATCH_PARENT, WRAP_CONTENT);
            }
        }
    }
    // 重新排序
    bringChildToFront(mRefreshContent.getView());
    // TODO: 2017/10/8 头部、内容、底部排序
    if (mRefreshHeader.getSpinnerStyle() != SpinnerStyle.FixedBehind) {
        if (isHeaderFixBehind) {
        } else {
            bringChildToFront(mRefreshHeader.getView());
        }
    }
    if (mRefreshFooter.getSpinnerStyle() != SpinnerStyle.FixedBehind) {
        bringChildToFront(mRefreshFooter.getView());
    }
    if (mRefreshListener == null) {
        mRefreshListener = new OnRefreshListener() {

            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                refreshlayout.finishRefresh(3000);
            }
        };
    }
    if (mLoadmoreListener == null) {
        mLoadmoreListener = new OnLoadmoreListener() {

            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {
                refreshlayout.finishLoadmore(2000);
            }
        };
    }
    if (mPrimaryColors != null) {
        mRefreshHeader.setPrimaryColors(mPrimaryColors);
        mRefreshFooter.setPrimaryColors(mPrimaryColors);
    }
    try {
        if (!mManualNestedScrolling && !isNestedScrollingEnabled() && getLayoutParams() instanceof CoordinatorLayout.LayoutParams) {
            setNestedScrollingEnabled(true);
        }
    } catch (Throwable e) {
    // try 不能删除
    }
}
Also used : ScrollingView(android.support.v4.view.ScrollingView) View(android.view.View) WebView(android.webkit.WebView) AbsListView(android.widget.AbsListView) ScrollView(android.widget.ScrollView) OnLoadmoreListener(com.scwang.smartrefresh.listener.OnLoadmoreListener) Paint(android.graphics.Paint) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) RefreshLayout(com.scwang.smartrefresh.api.RefreshLayout) RefreshContentWrapper(com.scwang.smartrefresh.impl.RefreshContentWrapper) OnRefreshListener(com.scwang.smartrefresh.listener.OnRefreshListener)

Example 2 with RefreshContentWrapper

use of com.scwang.smartrefresh.impl.RefreshContentWrapper 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

Paint (android.graphics.Paint)2 ScrollingView (android.support.v4.view.ScrollingView)2 View (android.view.View)2 WebView (android.webkit.WebView)2 AbsListView (android.widget.AbsListView)2 ScrollView (android.widget.ScrollView)2 RefreshContentWrapper (com.scwang.smartrefresh.impl.RefreshContentWrapper)2 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)1 NestedScrollingChild (android.support.v4.view.NestedScrollingChild)1 NestedScrollingParent (android.support.v4.view.NestedScrollingParent)1 ViewPager (android.support.v4.view.ViewPager)1 RefreshFooter (com.scwang.smartrefresh.api.RefreshFooter)1 RefreshHeader (com.scwang.smartrefresh.api.RefreshHeader)1 RefreshLayout (com.scwang.smartrefresh.api.RefreshLayout)1 RefreshFooterWrapper (com.scwang.smartrefresh.impl.RefreshFooterWrapper)1 RefreshHeaderWrapper (com.scwang.smartrefresh.impl.RefreshHeaderWrapper)1 OnLoadmoreListener (com.scwang.smartrefresh.listener.OnLoadmoreListener)1 OnRefreshListener (com.scwang.smartrefresh.listener.OnRefreshListener)1