use of com.scwang.smartrefresh.layout.api.RefreshLayout in project SmartRefreshLayout by scwang90.
the class BottomSheetExampleFragment 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();
}
});
RefreshLayout refreshLayout = (RefreshLayout) root.findViewById(R.id.refreshLayout);
refreshLayout.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white));
refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore(@NonNull final RefreshLayout refreshLayout) {
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
mAdapter.loadMore(initData());
refreshLayout.finishLoadMore();
}
}, 2000);
}
});
RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.recyclerView);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter<Void>(initData(), simple_list_item_2) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) {
holder.text(android.R.id.text1, getString(R.string.item_example_number_title, position));
holder.text(android.R.id.text2, getString(R.string.item_example_number_abstract, position));
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
((ViewGroup) refreshLayout.getLayout().getParent()).removeView(refreshLayout.getLayout());
BottomSheetDialog dialog = new BottomSheetDialog(getContext());
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
getActivity().finish();
}
});
dialog.setContentView(refreshLayout.getLayout());
dialog.show();
}
use of com.scwang.smartrefresh.layout.api.RefreshLayout in project SmartRefreshLayout by scwang90.
the class NestedScrollExampleFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull final View root, @Nullable Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
Toolbar toolbar = (Toolbar) root.findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().finish();
}
});
final BaseRecyclerAdapter<Item> adapter;
RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.recyclerView);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
recyclerView.setAdapter(adapter = new BaseRecyclerAdapter<Item>(Arrays.asList(Item.values()), simple_list_item_2, NestedScrollExampleFragment.this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
holder.text(android.R.id.text2, model.name);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
if (mNestedPager) {
final Runnable loadMore = new Runnable() {
@Override
public void run() {
adapter.loadMore(Arrays.asList(Item.values()));
adapter.loadMore(Arrays.asList(Item.values()));
adapter.loadMore(Arrays.asList(Item.values()));
adapter.loadMore(Arrays.asList(Item.values()));
adapter.loadMore(Arrays.asList(Item.values()));
adapter.loadMore(Arrays.asList(Item.values()));
adapter.loadMore(Arrays.asList(Item.values()));
}
};
final RefreshLayout refreshLayout = (RefreshLayout) root.findViewById(R.id.refreshLayout);
refreshLayout.setEnableFooterFollowWhenLoadFinished(true);
refreshLayout.setRefreshFooter(new ClassicsFooter(getContext()));
refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
if (adapter.getItemCount() < 20) {
loadMore.run();
refreshLayout.finishLoadMore(2000);
} else {
refreshLayout.finishLoadMoreWithNoMoreData();
}
}
});
loadMore.run();
}
/*
* 监听 AppBarLayout 的关闭和开启 ActionButton 设置关闭隐藏动画
*/
AppBarLayout appBarLayout = (AppBarLayout) root.findViewById(R.id.appbar);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
boolean misAppbarExpand = true;
View fab = root.findViewById(R.id.fab);
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
int scrollRange = appBarLayout.getTotalScrollRange();
float fraction = 1f * (scrollRange + verticalOffset) / scrollRange;
if (fraction < 0.1 && misAppbarExpand) {
misAppbarExpand = false;
fab.animate().scaleX(0).scaleY(0);
}
if (fraction > 0.8 && !misAppbarExpand) {
misAppbarExpand = true;
fab.animate().scaleX(1).scaleY(1);
}
}
});
}
use of com.scwang.smartrefresh.layout.api.RefreshLayout 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.api.RefreshLayout in project SmartRefreshLayout by scwang90.
the class AssignDefaultExampleActivity method install.
/*
* 关键代码,需要在布局生成之前设置,建议代码放在 Application 中
*/
private static void install() {
// 设置全局的Header构建器
SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
@NonNull
@Override
public RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull RefreshLayout layout) {
ClassicsHeader header = new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.FixedBehind);
header.setPrimaryColorId(R.color.colorPrimary);
header.setAccentColorId(android.R.color.white);
// 指定为经典Header,默认是 贝塞尔雷达Header
return header;
}
});
// 设置全局的Footer构建器
SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
@NonNull
@Override
public RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull RefreshLayout layout) {
// 内容不满一页时候启用加载更多
layout.setEnableLoadMoreWhenContentNotFull(true);
ClassicsFooter footer = new ClassicsFooter(context);
footer.setBackgroundResource(android.R.color.white);
// 设置为拉伸模式
footer.setSpinnerStyle(SpinnerStyle.Scale);
// 指定为经典Footer,默认是 BallPulseFooter
return footer;
}
});
}
use of com.scwang.smartrefresh.layout.api.RefreshLayout in project SmartRefreshLayout by scwang90.
the class NestedLayoutExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_region);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
View view = findViewById(R.id.recyclerView);
if (view instanceof RecyclerView) {
RecyclerView recyclerView = (RecyclerView) view;
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
recyclerView.setAdapter(new BaseRecyclerAdapter<String>(Arrays.asList(provinces), android.R.layout.simple_list_item_1) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, String model, int position) {
holder.text(android.R.id.text1, model);
}
}.setOnItemClickListener(this));
}
/**
* 以下代码仅仅为了演示效果而已,不是必须的
* 关键代码在 activity_example_assign_xml 中
*/
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
if (isFirstEnter && refreshLayout != null) {
isFirstEnter = false;
// 触发上拉加载
refreshLayout.autoRefresh();
}
}
Aggregations