use of json.chao.com.wanandroid.widget.interpolator.ElasticOutInterpolator in project Awesome-WanAndroid by JsonChao.
the class AboutUsActivity method initEventAndData.
@Override
protected void initEventAndData() {
setSupportActionBar(mToolbar);
StatusBarUtil.immersive(this);
StatusBarUtil.setPaddingSmart(this, mToolbar);
mToolbar.setNavigationOnClickListener(v -> onBackPressedSupport());
// 设置内容
mAboutContent.setText(Html.fromHtml(getString(R.string.about_content)));
mAboutContent.setMovementMethod(LinkMovementMethod.getInstance());
try {
String versionStr = getString(R.string.awesome_wan_android) + " V" + getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
mAboutVersion.setText(versionStr);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
// 绑定场景和纸飞机
mFlyRefreshHeader.setUp(mAboutUsMountain, mAboutUsFlyView);
mAboutUsRefreshLayout.setReboundInterpolator(new ElasticOutInterpolator());
mAboutUsRefreshLayout.setReboundDuration(800);
mAboutUsRefreshLayout.setOnRefreshListener(refreshLayout -> {
updateTheme();
refreshLayout.finishRefresh(1000);
});
// 设置让Toolbar和AppBarLayout的滚动同步
mAboutUsRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
@Override
public void onHeaderPulling(RefreshHeader header, float percent, int offset, int headerHeight, int extendHeight) {
if (mAboutUsAppBar == null || mToolbar == null) {
return;
}
mAboutUsAppBar.setTranslationY(offset);
mToolbar.setTranslationY(-offset);
}
@Override
public void onHeaderReleasing(RefreshHeader header, float percent, int offset, int footerHeight, int extendHeight) {
if (mAboutUsAppBar == null || mToolbar == null) {
return;
}
mAboutUsAppBar.setTranslationY(offset);
mToolbar.setTranslationY(-offset);
}
});
// 进入界面时自动刷新
mAboutUsRefreshLayout.autoRefresh();
// 点击悬浮按钮时自动刷新
mAboutUsFab.setOnClickListener(v -> mAboutUsRefreshLayout.autoRefresh());
/*
* 监听 AppBarLayout 的关闭和开启 给 FlyView(纸飞机) 和 ActionButton 设置关闭隐藏动画
*/
mAboutUsAppBar.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;
double minFraction = 0.1;
double maxFraction = 0.8;
if (fraction < minFraction && misAppbarExpand) {
misAppbarExpand = false;
mAboutUsFab.animate().scaleX(0).scaleY(0);
mAboutUsFlyView.animate().scaleX(0).scaleY(0);
ValueAnimator animator = ValueAnimator.ofInt(mScrollView.getPaddingTop(), 0);
animator.setDuration(300);
animator.addUpdateListener(animation -> mScrollView.setPadding(0, (int) animation.getAnimatedValue(), 0, 0));
animator.start();
}
if (fraction > maxFraction && !misAppbarExpand) {
misAppbarExpand = true;
mAboutUsFab.animate().scaleX(1).scaleY(1);
mAboutUsFlyView.animate().scaleX(1).scaleY(1);
ValueAnimator animator = ValueAnimator.ofInt(mScrollView.getPaddingTop(), DensityUtil.dp2px(25));
animator.setDuration(300);
animator.addUpdateListener(animation -> mScrollView.setPadding(0, (int) animation.getAnimatedValue(), 0, 0));
animator.start();
}
}
});
}
Aggregations