Search in sources :

Example 11 with RefreshHeader

use of com.scwang.smartrefresh.layout.api.RefreshHeader 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();
            }
        }
    });
}
Also used : AppBarLayout(android.support.design.widget.AppBarLayout) R(json.chao.com.wanandroid.R) ElasticOutInterpolator(json.chao.com.wanandroid.widget.interpolator.ElasticOutInterpolator) Bundle(android.os.Bundle) StatusBarUtil(json.chao.com.wanandroid.utils.StatusBarUtil) PackageManager(android.content.pm.PackageManager) ButterKnife(butterknife.ButterKnife) FlyRefreshHeader(com.scwang.smartrefresh.header.FlyRefreshHeader) LinkMovementMethod(android.text.method.LinkMovementMethod) BindView(butterknife.BindView) ColorStateList(android.content.res.ColorStateList) SmartRefreshLayout(com.scwang.smartrefresh.layout.SmartRefreshLayout) RefreshHeader(com.scwang.smartrefresh.layout.api.RefreshHeader) DensityUtil(com.scwang.smartrefresh.layout.util.DensityUtil) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) AbstractSimpleActivity(json.chao.com.wanandroid.base.activity.AbstractSimpleActivity) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) MountainSceneView(com.scwang.smartrefresh.header.flyrefresh.MountainSceneView) FloatingActionButton(android.support.design.widget.FloatingActionButton) ContextCompat(android.support.v4.content.ContextCompat) FlyView(com.scwang.smartrefresh.header.flyrefresh.FlyView) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar) Html(android.text.Html) SimpleMultiPurposeListener(com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener) ValueAnimator(android.animation.ValueAnimator) FlyRefreshHeader(com.scwang.smartrefresh.header.FlyRefreshHeader) RefreshHeader(com.scwang.smartrefresh.layout.api.RefreshHeader) SimpleMultiPurposeListener(com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener) ValueAnimator(android.animation.ValueAnimator) ElasticOutInterpolator(json.chao.com.wanandroid.widget.interpolator.ElasticOutInterpolator) PackageManager(android.content.pm.PackageManager) AppBarLayout(android.support.design.widget.AppBarLayout)

Example 12 with RefreshHeader

use of com.scwang.smartrefresh.layout.api.RefreshHeader in project MVP by yuchengren.

the class BaseApplication method initRefreshView.

private void initRefreshView() {
    SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {

        @NonNull
        @Override
        public RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull RefreshLayout layout) {
            return new MKRefreshHeader(context);
        }
    });
    SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {

        @NonNull
        @Override
        public RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull RefreshLayout layout) {
            ClassicsFooter classicsFooter = new ClassicsFooter(context);
            ClassicsFooter.REFRESH_FOOTER_NOTHING = "没有更多数据啦";
            classicsFooter.setTextSizeTitle(14);
            classicsFooter.setAccentColorId(R.color.text_color_medium);
            return classicsFooter;
        }
    });
}
Also used : Context(android.content.Context) MKRefreshHeader(com.ycr.module.base.view.pullrefresh.MKRefreshHeader) RefreshHeader(com.scwang.smartrefresh.layout.api.RefreshHeader) RefreshFooter(com.scwang.smartrefresh.layout.api.RefreshFooter) DefaultRefreshFooterCreator(com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator) DefaultRefreshHeaderCreator(com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator) SmartRefreshLayout(com.scwang.smartrefresh.layout.SmartRefreshLayout) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) NonNull(android.support.annotation.NonNull) MKRefreshHeader(com.ycr.module.base.view.pullrefresh.MKRefreshHeader) ClassicsFooter(com.ycr.lib.ui.pullrefresh.smart.footer.ClassicsFooter)

Aggregations

RefreshHeader (com.scwang.smartrefresh.layout.api.RefreshHeader)12 View (android.view.View)8 RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)7 Toolbar (android.support.v7.widget.Toolbar)5 SimpleMultiPurposeListener (com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener)5 ValueAnimator (android.animation.ValueAnimator)4 TextView (android.widget.TextView)4 RefreshFooter (com.scwang.smartrefresh.layout.api.RefreshFooter)4 SmartRefreshLayout (com.scwang.smartrefresh.layout.SmartRefreshLayout)3 RefreshHeaderWrapper (com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper)3 Animator (android.animation.Animator)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 Context (android.content.Context)2 NonNull (android.support.annotation.NonNull)2 AppBarLayout (android.support.design.widget.AppBarLayout)2 NestedScrollView (android.support.v4.widget.NestedScrollView)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 ViewGroup (android.view.ViewGroup)2 FlyRefreshHeader (com.scwang.smartrefresh.header.FlyRefreshHeader)2