use of com.scwang.smartrefresh.layout.constant.RefreshState in project SmartRefreshLayout by scwang90.
the class AssignCodeExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_assign_code);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
// 设置 Header 为 Material风格
refreshLayout.setRefreshHeader(new MaterialHeader(this).setShowBezierWave(true));
// 设置 Footer 为 球脉冲
refreshLayout.setRefreshFooter(new BallPulseFooter(this).setSpinnerStyle(SpinnerStyle.Scale));
/*
* 以下代码仅仅为了演示效果而已,不是必须的
*/
// 设置主题颜色
refreshLayout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);
if (isFirstEnter) {
isFirstEnter = false;
// 触发上拉加载
refreshLayout.autoLoadMore(250, 250, 1.5f);
// 通过多功能监听接口实现 在第一次加载完成之后 自动刷新
refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
@Override
public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
if (oldState == RefreshState.LoadFinish && newState == RefreshState.None) {
refreshLayout.autoRefresh();
refreshLayout.setOnMultiPurposeListener(null);
}
}
@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
refreshLayout.finishLoadMore(2000);
}
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
refreshLayout.finishRefresh(3000);
}
});
}
}
use of com.scwang.smartrefresh.layout.constant.RefreshState in project SmartRefreshLayout by scwang90.
the class AssignDefaultExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
install();
setContentView(R.layout.activity_example_assign_default);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
/*
* 以下代码仅仅为了演示效果而已,不是必须的
* 关键代码在构造函数中
*/
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
// 触发上拉加载
refreshLayout.autoLoadMore();
// 通过多功能监听接口实现 在第一次加载完成之后 自动刷新
refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
@Override
public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
if (oldState == RefreshState.LoadFinish && newState == RefreshState.None) {
refreshLayout.autoRefresh();
refreshLayout.setOnMultiPurposeListener(null);
}
}
@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
refreshLayout.finishLoadMore(2000);
}
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
refreshLayout.finishRefresh(3000);
}
});
}
}
use of com.scwang.smartrefresh.layout.constant.RefreshState in project SmartRefreshLayout by scwang90.
the class AssignXmlExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_assign_xml);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
/*
* 以下代码仅仅为了演示效果而已,不是必须的
* 关键代码在 activity_example_assign_xml 中
*/
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
// 触发上拉加载
refreshLayout.autoLoadMore(250, 250, 1.5f);
// 通过多功能监听接口实现 在第一次加载完成之后 自动刷新
refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
@Override
public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
if (oldState == RefreshState.LoadFinish && newState == RefreshState.None) {
refreshLayout.autoRefresh();
refreshLayout.setOnMultiPurposeListener(null);
}
}
@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
refreshLayout.finishLoadMore(2000);
}
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
refreshLayout.finishRefresh(3000);
}
});
}
}
use of com.scwang.smartrefresh.layout.constant.RefreshState in project SmartRefreshLayout by scwang90.
the class ListenerExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_listener);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
mTvContent = (TextView) findViewById(R.id.content);
mTvContent.setMovementMethod(ScrollingMovementMethod.getInstance());
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
@Override
public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
mHeaderMoving = String.format(Locale.CHINA, "%s\nisDragging=%b,percent=%.02f offset=%03d\nheight=%03d extend=%03d", FORMAT.format(new Date()), isDragging, percent, offset, headerHeight, maxDragHeight);
updateContent();
}
// @Override
// public void onHeaderPulling(@NonNull RefreshHeader header, float percent, int offset, int headerHeight, int maxDragHeight) {
// mHeaderPulling = String.format(Locale.CHINA, "%s\npercent=%.02f offset=%03d\nheight=%03d extend=%03d",
// FORMAT.format(new Date()),
// percent,offset,headerHeight,maxDragHeight);
// updateContent();
// }
//
// @Override
// public void onHeaderReleasing(@NonNull RefreshHeader header, float percent, int offset, int headerHeight, int maxDragHeight) {
// mHeaderReleasing = String.format(Locale.CHINA, "%s\npercent=%.02f offset=%03d\nheight=%03d extend=%03d",
// FORMAT.format(new Date()),
// percent,offset,headerHeight,maxDragHeight);
// updateContent();
// }
@Override
public void onHeaderStartAnimator(@NonNull RefreshHeader header, int headerHeight, int maxDragHeight) {
mHeaderStartAnimator = String.format(Locale.CHINA, "%s\nheight=%03d extend=%03d", FORMAT.format(new Date()), headerHeight, maxDragHeight);
updateContent();
}
@Override
public void onHeaderFinish(@NonNull RefreshHeader header, boolean success) {
mHeaderFinish = String.format(Locale.CHINA, "%s - " + success, FORMAT.format(new Date()));
updateContent();
}
@Override
public void onFooterMoving(RefreshFooter footer, boolean isDragging, float percent, int offset, int footerHeight, int maxDragHeight) {
mFooterMoving = String.format(Locale.CHINA, "%s\nisDragging=%b,percent=%.02f offset=%03d\nheight=%03d extend=%03d", FORMAT.format(new Date()), isDragging, percent, offset, footerHeight, maxDragHeight);
updateContent();
}
// @Override
// public void onFooterPulling(@NonNull RefreshFooter footer, float percent, int offset, int footerHeight, int maxDragHeight) {
// mFooterPulling = String.format(Locale.CHINA, "%s\npercent=%.02f\noffset=%03d height=%03d\nextend=%03d",
// FORMAT.format(new Date()),
// percent,offset,footerHeight,maxDragHeight);
// updateContent();
// }
//
// @Override
// public void onFooterReleasing(@NonNull RefreshFooter footer, float percent, int offset, int footerHeight, int maxDragHeight) {
// mFooterReleasing = String.format(Locale.CHINA, "%s\npercent=%.02f\noffset=%03d height=%03d\nextend=%03d",
// FORMAT.format(new Date()),
// percent,offset,footerHeight,maxDragHeight);
// updateContent();
// }
@Override
public void onFooterStartAnimator(@NonNull RefreshFooter footer, int footerHeight, int maxDragHeight) {
mFooterStartAnimator = String.format(Locale.CHINA, "%s\nheight=%03d extend=%03d", FORMAT.format(new Date()), footerHeight, maxDragHeight);
updateContent();
}
@Override
public void onFooterFinish(@NonNull RefreshFooter footer, boolean success) {
mFooterFinish = String.format(Locale.CHINA, "%s - " + success, FORMAT.format(new Date()));
updateContent();
}
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
mRefresh = String.format(Locale.CHINA, "%s", FORMAT.format(new Date()));
updateContent();
refreshLayout.finishRefresh(2000);
}
@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
mLoadMore = String.format(Locale.CHINA, "%s", FORMAT.format(new Date()));
updateContent();
refreshLayout.finishLoadMore(1000);
}
@Override
public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
mStateChanged = String.format(Locale.CHINA, "%s\nnew=%s\nold=%s", FORMAT.format(new Date()), newState.name(), oldState.name());
updateContent();
}
});
if (isFirstEnter) {
isFirstEnter = false;
// 触发自动刷新
refreshLayout.autoRefresh();
} else {
updateContent();
}
}
use of com.scwang.smartrefresh.layout.constant.RefreshState in project SmartRefreshLayout by scwang90.
the class EmptyLayoutExampleFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
final Toolbar toolbar = (Toolbar) root.findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().finish();
}
});
mRefreshLayout = (RefreshLayout) root.findViewById(refreshLayout);
mRefreshLayout.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white));
mRefreshLayout.setOnRefreshListener(this);
mRecyclerView = (RecyclerView) root.findViewById(recyclerView);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
mLoadingLayout = (LoadingLayout) root.findViewById(R.id.loading);
mLoadingLayout.showEmpty();
/*主动演示刷新*/
if (mIsNeedDemo) {
mRefreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
if (mIsNeedDemo) {
mRefreshLayout.autoRefresh();
}
}
}, 3000);
mRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
@Override
public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
mIsNeedDemo = false;
}
});
}
}
Aggregations