Search in sources :

Example 1 with DelayedRunnable

use of com.scwang.smartrefresh.layout.util.DelayedRunnable in project SmartRefreshLayout by scwang90.

the class SmartRefreshLayout method postDelayed.

@Override
public boolean postDelayed(@NonNull Runnable action, long delayMillis) {
    if (delayMillis == 0) {
        new DelayedRunnable(action, 0).run();
        return true;
    }
    if (mHandler == null) {
        mListDelayedRunnable = mListDelayedRunnable == null ? new ArrayList<DelayedRunnable>() : mListDelayedRunnable;
        mListDelayedRunnable.add(new DelayedRunnable(action, delayMillis));
        return false;
    }
    return mHandler.postDelayed(new DelayedRunnable(action, 0), delayMillis);
}
Also used : ArrayList(java.util.ArrayList) DelayedRunnable(com.scwang.smartrefresh.layout.util.DelayedRunnable)

Example 2 with DelayedRunnable

use of com.scwang.smartrefresh.layout.util.DelayedRunnable 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 3 with DelayedRunnable

use of com.scwang.smartrefresh.layout.util.DelayedRunnable in project SmartRefreshLayout by scwang90.

the class SmartRefreshLayout method post.

// </editor-fold>
// <editor-fold desc="内存泄漏 postDelayed优化">
@Override
public boolean post(@NonNull Runnable action) {
    if (mHandler == null) {
        mListDelayedRunnable = mListDelayedRunnable == null ? new ArrayList<DelayedRunnable>() : mListDelayedRunnable;
        mListDelayedRunnable.add(new DelayedRunnable(action, 0));
        return false;
    }
    return mHandler.post(new DelayedRunnable(action, 0));
}
Also used : ArrayList(java.util.ArrayList) DelayedRunnable(com.scwang.smartrefresh.layout.util.DelayedRunnable)

Aggregations

DelayedRunnable (com.scwang.smartrefresh.layout.util.DelayedRunnable)3 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 Handler (android.os.Handler)1 NestedScrollingParent (android.support.v4.view.NestedScrollingParent)1 View (android.view.View)1 ViewParent (android.view.ViewParent)1 TextView (android.widget.TextView)1 RefreshContentWrapper (com.scwang.smartrefresh.layout.impl.RefreshContentWrapper)1 SmartUtil.isScrollableView (com.scwang.smartrefresh.layout.util.SmartUtil.isScrollableView)1