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);
}
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());
}
}
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));
}
Aggregations