Search in sources :

Example 1 with ClassicsFooter

use of com.scwang.smartrefresh.layout.footer.ClassicsFooter 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);
            }
        }
    });
}
Also used : OnLoadMoreListener(com.scwang.smartrefresh.layout.listener.OnLoadMoreListener) SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) BaseRecyclerAdapter(com.scwang.refreshlayout.adapter.BaseRecyclerAdapter) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ClassicsFooter(com.scwang.smartrefresh.layout.footer.ClassicsFooter) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) AppBarLayout(android.support.design.widget.AppBarLayout) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with ClassicsFooter

use of com.scwang.smartrefresh.layout.footer.ClassicsFooter 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;
        }
    });
}
Also used : Context(android.content.Context) 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) ClassicsHeader(com.scwang.smartrefresh.layout.header.ClassicsHeader) NonNull(android.support.annotation.NonNull) ClassicsFooter(com.scwang.smartrefresh.layout.footer.ClassicsFooter)

Example 3 with ClassicsFooter

use of com.scwang.smartrefresh.layout.footer.ClassicsFooter in project SmartRefreshLayout by scwang90.

the class ViewPagerExampleFragment 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();
        }
    });
    mRefreshLayout = (RefreshLayout) root.findViewById(refreshLayout);
    mRefreshLayout.setOnRefreshLoadMoreListener(this);
    mRefreshLayout.setRefreshHeader(new ClassicsHeader(getContext()));
    mRefreshLayout.setRefreshFooter(new ClassicsFooter(getContext()));
    mViewPager = (ViewPager) root.findViewById(R.id.viewPager);
    mTabLayout = (TabLayout) root.findViewById(R.id.tableLayout);
    mViewPager.setAdapter(mAdapter = new SmartPagerAdapter(Item.values()));
    mTabLayout.setupWithViewPager(mViewPager, true);
}
Also used : ClassicsHeader(com.scwang.smartrefresh.layout.header.ClassicsHeader) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ClassicsFooter(com.scwang.smartrefresh.layout.footer.ClassicsFooter) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

ClassicsFooter (com.scwang.smartrefresh.layout.footer.ClassicsFooter)3 RecyclerView (android.support.v7.widget.RecyclerView)2 Toolbar (android.support.v7.widget.Toolbar)2 View (android.view.View)2 RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)2 ClassicsHeader (com.scwang.smartrefresh.layout.header.ClassicsHeader)2 Context (android.content.Context)1 NonNull (android.support.annotation.NonNull)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 AdapterView (android.widget.AdapterView)1 BaseRecyclerAdapter (com.scwang.refreshlayout.adapter.BaseRecyclerAdapter)1 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)1 SmartRefreshLayout (com.scwang.smartrefresh.layout.SmartRefreshLayout)1 DefaultRefreshFooterCreator (com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator)1 DefaultRefreshHeaderCreator (com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator)1 RefreshFooter (com.scwang.smartrefresh.layout.api.RefreshFooter)1 RefreshHeader (com.scwang.smartrefresh.layout.api.RefreshHeader)1