Search in sources :

Example 1 with RefreshInternal

use of com.scwang.smartrefresh.layout.api.RefreshInternal in project SmartRefreshLayout by scwang90.

the class SmartRefreshLayout method onFinishInflate.

// </editor-fold>
// <editor-fold desc="生命周期 life cycle">
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    final int count = super.getChildCount();
    if (count > 3) {
        throw new RuntimeException("最多只支持3个子View,Most only support three sub view");
    }
    int contentLevel = 0;
    int indexContent = -1;
    for (int i = 0; i < count; i++) {
        View view = super.getChildAt(i);
        if (isScrollableView(view) && (contentLevel < 2 || i == 1)) {
            indexContent = i;
            contentLevel = 2;
        } else if (!(view instanceof RefreshInternal) && contentLevel < 1) {
            indexContent = i;
            contentLevel = i > 0 ? 1 : 0;
        }
    }
    // int[] indexArray = {1,0,2};
    // 
    // for (int index : indexArray) {
    // if (index < count) {
    // View view = super.getChildAt(index);
    // if (!(view instanceof RefreshInternal)) {
    // indexContent = index;
    // }
    // if (isScrollableView(view)) {
    // indexContent = index;
    // break;
    // }
    // }
    // }
    int indexHeader = -1;
    int indexFooter = -1;
    if (indexContent >= 0) {
        mRefreshContent = new RefreshContentWrapper(super.getChildAt(indexContent));
        if (indexContent == 1) {
            indexHeader = 0;
            if (count == 3) {
                indexFooter = 2;
            }
        } else if (count == 2) {
            indexFooter = 1;
        }
    }
    for (int i = 0; i < count; i++) {
        View view = super.getChildAt(i);
        if (i == indexHeader || (i != indexFooter && indexHeader == -1 && mRefreshHeader == null && view instanceof RefreshHeader)) {
            mRefreshHeader = (view instanceof RefreshHeader) ? (RefreshHeader) view : new RefreshHeaderWrapper(view);
        } else if (i == indexFooter || (indexFooter == -1 && view instanceof RefreshFooter)) {
            mEnableLoadMore = (mEnableLoadMore || !mManualLoadMore);
            mRefreshFooter = (view instanceof RefreshFooter) ? (RefreshFooter) view : new RefreshFooterWrapper(view);
        // } else if (mRefreshContent == null) {
        // mRefreshContent = new RefreshContentWrapper(view);
        }
    }
}
Also used : RefreshInternal(com.scwang.smartrefresh.layout.api.RefreshInternal) RefreshHeaderWrapper(com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper) RefreshHeader(com.scwang.smartrefresh.layout.api.RefreshHeader) RefreshFooter(com.scwang.smartrefresh.layout.api.RefreshFooter) RefreshFooterWrapper(com.scwang.smartrefresh.layout.impl.RefreshFooterWrapper) RefreshContentWrapper(com.scwang.smartrefresh.layout.impl.RefreshContentWrapper) 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)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 View (android.view.View)1 TextView (android.widget.TextView)1 RefreshFooter (com.scwang.smartrefresh.layout.api.RefreshFooter)1 RefreshHeader (com.scwang.smartrefresh.layout.api.RefreshHeader)1 RefreshInternal (com.scwang.smartrefresh.layout.api.RefreshInternal)1 RefreshContentWrapper (com.scwang.smartrefresh.layout.impl.RefreshContentWrapper)1 RefreshFooterWrapper (com.scwang.smartrefresh.layout.impl.RefreshFooterWrapper)1 RefreshHeaderWrapper (com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper)1 SmartUtil.isScrollableView (com.scwang.smartrefresh.layout.util.SmartUtil.isScrollableView)1