Search in sources :

Example 1 with RefreshContentWrapper

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

use of com.scwang.smartrefresh.layout.impl.RefreshContentWrapper in project SmartRefreshLayout by scwang90.

the class SmartRefreshLayout method setRefreshContent.

/**
 * 设置指定的 Content
 * @param content 内容视图
 * @param width 宽度 可以使用 MATCH_PARENT, WRAP_CONTENT
 * @param height 高度 可以使用 MATCH_PARENT, WRAP_CONTENT
 * @return SmartRefreshLayout
 */
@Override
public RefreshLayout setRefreshContent(@NonNull View content, int width, int height) {
    final View thisView = this;
    if (mRefreshContent != null) {
        super.removeView(mRefreshContent.getView());
    }
    super.addView(content, 0, new LayoutParams(width, height));
    if (mRefreshHeader != null && mRefreshHeader.getSpinnerStyle() == SpinnerStyle.FixedBehind) {
        super.bringChildToFront(content);
        if (mRefreshFooter != null && mRefreshFooter.getSpinnerStyle() != SpinnerStyle.FixedBehind) {
            super.bringChildToFront(mRefreshFooter.getView());
        }
    } else if (mRefreshFooter != null && mRefreshFooter.getSpinnerStyle() == SpinnerStyle.FixedBehind) {
        super.bringChildToFront(content);
        if (mRefreshHeader != null && mRefreshHeader.getSpinnerStyle() == SpinnerStyle.FixedBehind) {
            super.bringChildToFront(mRefreshHeader.getView());
        }
    }
    mRefreshContent = new RefreshContentWrapper(content);
    if (mHandler != null) {
        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);
    }
    return this;
}
Also used : RefreshContentWrapper(com.scwang.smartrefresh.layout.impl.RefreshContentWrapper) View(android.view.View) TextView(android.widget.TextView) SmartUtil.isScrollableView(com.scwang.smartrefresh.layout.util.SmartUtil.isScrollableView)

Example 3 with RefreshContentWrapper

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

View (android.view.View)3 TextView (android.widget.TextView)3 RefreshContentWrapper (com.scwang.smartrefresh.layout.impl.RefreshContentWrapper)3 SmartUtil.isScrollableView (com.scwang.smartrefresh.layout.util.SmartUtil.isScrollableView)3 SuppressLint (android.annotation.SuppressLint)2 Paint (android.graphics.Paint)2 Handler (android.os.Handler)1 NestedScrollingParent (android.support.v4.view.NestedScrollingParent)1 ViewParent (android.view.ViewParent)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 RefreshFooterWrapper (com.scwang.smartrefresh.layout.impl.RefreshFooterWrapper)1 RefreshHeaderWrapper (com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper)1 DelayedRunnable (com.scwang.smartrefresh.layout.util.DelayedRunnable)1