use of com.scwang.smartrefresh.layout.api.RefreshHeader in project SmartRefreshLayout by scwang90.
the class RefreshStylesFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
StatusBarUtil.setPaddingSmart(getContext(), root.findViewById(R.id.toolbar));
View view = root.findViewById(recyclerView);
if (view instanceof RecyclerView) {
RecyclerView recyclerView = (RecyclerView) view;
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
recyclerView.setAdapter(new BaseRecyclerAdapter<Item>(Arrays.asList(Item.values()), simple_list_item_2, this) {
@Override
public SmartViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
SmartViewHolder holder = super.onCreateViewHolder(parent, viewType);
if (viewType == 0) {
holder.itemView.setVisibility(View.GONE);
holder.itemView.setLayoutParams(new RecyclerView.LayoutParams(0, 0));
}
return holder;
}
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public int getItemViewType(int position) {
return position == 0 ? 0 : 1;
}
@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.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
}
RefreshLayout refreshLayout = (RefreshLayout) root.findViewById(R.id.refreshLayout);
if (refreshLayout != null) {
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
refreshLayout.finishRefresh(3000);
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
RefreshHeader refreshHeader = refreshLayout.getRefreshHeader();
if (refreshHeader instanceof RefreshHeaderWrapper) {
refreshLayout.setRefreshHeader(new PhoenixHeader(getContext()));
} else if (refreshHeader instanceof PhoenixHeader) {
refreshLayout.setRefreshHeader(new DropBoxHeader(getContext()));
} else if (refreshHeader instanceof DropBoxHeader) {
refreshLayout.setRefreshHeader(new FunGameHitBlockHeader(getContext()));
} else if (refreshHeader instanceof FunGameHitBlockHeader) {
refreshLayout.setRefreshHeader(new ClassicsHeader(getContext()));
} else {
refreshLayout.setRefreshHeader(new RefreshHeaderWrapper(new BallPulseFooter(getContext())));
}
refreshLayout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);
}
}, 4000);
}
});
}
}
use of com.scwang.smartrefresh.layout.api.RefreshHeader 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.api.RefreshHeader 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.RefreshHeader 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.api.RefreshHeader in project SmartRefreshLayout by scwang90.
the class FlyRefreshStyleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fly_refresh);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
/*-----------------------------------------------------------
* 关键代码-开始
*----------------------------------------------------------*/
MountainSceneView mSceneView = (MountainSceneView) findViewById(R.id.mountain);
mFlyView = (FlyView) findViewById(R.id.flyView);
mFlyRefreshHeader = (FlyRefreshHeader) findViewById(R.id.flyRefresh);
// 绑定场景和纸飞机
mFlyRefreshHeader.setUp(mSceneView, mFlyView);
mRefreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
// 设置回弹插值器,会带有弹簧震动效果
mRefreshLayout.setReboundInterpolator(new ElasticOutInterpolator());
// 设置回弹动画时长
mRefreshLayout.setReboundDuration(800);
mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
View child = mListView.getChildAt(0);
if (child != null) {
// 开始刷新的时候个第一个item设置动画效果
bounceAnimateView(child.findViewById(R.id.icon));
}
// 改变主题颜色
updateTheme();
mRefreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
// 通知刷新完成,这里改为通知Header,让纸飞机飞回来
mFlyRefreshHeader.finishRefresh(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator animation) {
// 在纸飞机回到原位之后添加数据效果更真实
addItemData();
}
});
}
}, // 模拟两秒的后台数据加载
2000);
}
});
// 设置 让 AppBarLayout 和 RefreshLayout 的滚动同步 并不保持 toolbar 位置不变
final AppBarLayout appBar = (AppBarLayout) findViewById(R.id.appbar);
mRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
@Override
public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
appBar.setTranslationY(offset);
toolbar.setTranslationY(-offset);
}
});
if (isFirstEnter) {
isFirstEnter = false;
// 第一次进入触发自动刷新,演示效果
mRefreshLayout.autoRefresh();
}
/*
* 初始化列表数据
*/
initDataSet();
mAdapter = new ItemAdapter(this);
mLayoutManager = new LinearLayoutManager(this);
mListView = (RecyclerView) findViewById(R.id.recyclerView);
mListView.setLayoutManager(mLayoutManager);
mListView.setAdapter(mAdapter);
mListView.setItemAnimator(new SampleItemAnimator());
mToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbarLayout);
mActionButton = (FloatingActionButton) findViewById(R.id.fab);
/*
* 设置点击 ActionButton 时候触发自动刷新 并改变主题颜色
*/
mActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateTheme();
mRefreshLayout.autoRefresh();
}
});
/*
* 监听 AppBarLayout 的关闭和开启 给 FlyView(纸飞机) 和 ActionButton 设置关闭隐藏动画
*/
appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
boolean misAppbarExpand = true;
@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;
mActionButton.animate().scaleX(0).scaleY(0);
mFlyView.animate().scaleX(0).scaleY(0);
ValueAnimator animator = ValueAnimator.ofInt(mListView.getPaddingTop(), 0);
animator.setDuration(300);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mListView.setPadding(0, (int) animation.getAnimatedValue(), 0, 0);
}
});
animator.start();
}
if (fraction > 0.8 && !misAppbarExpand) {
misAppbarExpand = true;
mActionButton.animate().scaleX(1).scaleY(1);
mFlyView.animate().scaleX(1).scaleY(1);
ValueAnimator animator = ValueAnimator.ofInt(mListView.getPaddingTop(), DensityUtil.dp2px(25));
animator.setDuration(300);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mListView.setPadding(0, (int) animation.getAnimatedValue(), 0, 0);
}
});
animator.start();
}
}
});
// 状态栏透明和间距处理
StatusBarUtil.immersive(this);
StatusBarUtil.setPaddingSmart(this, toolbar);
}
Aggregations