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