use of com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener in project SmartRefreshLayout by scwang90.
the class SecondFloorPracticeFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull final View root, @Nullable Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
final View floor = root.findViewById(R.id.secondfloor);
final Toolbar toolbar = (Toolbar) root.findViewById(R.id.toolbar);
final TwoLevelHeader header = (TwoLevelHeader) root.findViewById(R.id.header);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().finish();
}
});
final RefreshLayout refreshLayout = (RefreshLayout) root.findViewById(R.id.refreshLayout);
refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
refreshLayout.finishLoadMore(2000);
}
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
Toast.makeText(getContext(), "触发刷新事件", Toast.LENGTH_SHORT).show();
refreshLayout.finishRefresh(2000);
}
@Override
public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
toolbar.setAlpha(1 - Math.min(percent, 1));
floor.setTranslationY(Math.min(offset - floor.getHeight() + toolbar.getHeight(), refreshLayout.getLayout().getHeight() - floor.getHeight()));
}
});
header.setOnTwoLevelListener(new OnTwoLevelListener() {
@Override
public boolean onTwoLevel(@NonNull RefreshLayout refreshLayout) {
Toast.makeText(getContext(), "触发二楼事件", Toast.LENGTH_SHORT).show();
root.findViewById(R.id.secondfloor_content).animate().alpha(1).setDuration(2000);
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
header.finishTwoLevel();
root.findViewById(R.id.secondfloor_content).animate().alpha(0).setDuration(1000);
}
}, 5000);
// true 将会展开二楼状态 false 关闭刷新
return true;
}
});
// refreshLayout.setOnRefreshListener(new OnRefreshListener() {
// @Override
// public void onRefresh(@NonNull RefreshLayout refreshLayout) {
// Toast.makeText(getContext(),"触发刷新事件",Toast.LENGTH_SHORT).show();
// refreshLayout.finishRefresh(2000);
// }
// });
// 状态栏透明和间距处理
StatusBarUtil.immersive(getActivity());
StatusBarUtil.setMargin(getActivity(), root.findViewById(R.id.classics));
StatusBarUtil.setPaddingSmart(getActivity(), root.findViewById(R.id.toolbar));
StatusBarUtil.setPaddingSmart(getActivity(), root.findViewById(R.id.contentPanel));
}
use of com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener 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.listener.SimpleMultiPurposeListener 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.listener.SimpleMultiPurposeListener 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.listener.SimpleMultiPurposeListener 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();
}
}
Aggregations