Search in sources :

Example 1 with RefreshLayout

use of com.scwang.smartrefresh.api.RefreshLayout 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)

Aggregations

Paint (android.graphics.Paint)1 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)1 ScrollingView (android.support.v4.view.ScrollingView)1 View (android.view.View)1 WebView (android.webkit.WebView)1 AbsListView (android.widget.AbsListView)1 ScrollView (android.widget.ScrollView)1 RefreshLayout (com.scwang.smartrefresh.api.RefreshLayout)1 RefreshContentWrapper (com.scwang.smartrefresh.impl.RefreshContentWrapper)1 OnLoadmoreListener (com.scwang.smartrefresh.listener.OnLoadmoreListener)1 OnRefreshListener (com.scwang.smartrefresh.listener.OnRefreshListener)1