Search in sources :

Example 1 with BallPulseFooter

use of com.scwang.smartrefresh.layout.footer.BallPulseFooter 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);
            }
        });
    }
}
Also used : RefreshHeaderWrapper(com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper) RefreshHeader(com.scwang.smartrefresh.layout.api.RefreshHeader) SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) ViewGroup(android.view.ViewGroup) ClassicsHeader(com.scwang.smartrefresh.layout.header.ClassicsHeader) DropBoxHeader(com.scwang.smartrefresh.header.DropBoxHeader) 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) R.id.recyclerView(com.scwang.refreshlayout.R.id.recyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) BallPulseFooter(com.scwang.smartrefresh.layout.footer.BallPulseFooter) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) PhoenixHeader(com.scwang.smartrefresh.header.PhoenixHeader) RecyclerView(android.support.v7.widget.RecyclerView) FunGameHitBlockHeader(com.scwang.smartrefresh.header.FunGameHitBlockHeader) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener)

Example 2 with BallPulseFooter

use of com.scwang.smartrefresh.layout.footer.BallPulseFooter 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);
            }
        });
    }
}
Also used : MaterialHeader(com.scwang.smartrefresh.header.MaterialHeader) SimpleMultiPurposeListener(com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RefreshState(com.scwang.smartrefresh.layout.constant.RefreshState) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar) BallPulseFooter(com.scwang.smartrefresh.layout.footer.BallPulseFooter)

Aggregations

View (android.view.View)2 RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)2 BallPulseFooter (com.scwang.smartrefresh.layout.footer.BallPulseFooter)2 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 R.id.recyclerView (com.scwang.refreshlayout.R.id.recyclerView)1 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)1 DropBoxHeader (com.scwang.smartrefresh.header.DropBoxHeader)1 FunGameHitBlockHeader (com.scwang.smartrefresh.header.FunGameHitBlockHeader)1 MaterialHeader (com.scwang.smartrefresh.header.MaterialHeader)1 PhoenixHeader (com.scwang.smartrefresh.header.PhoenixHeader)1 RefreshHeader (com.scwang.smartrefresh.layout.api.RefreshHeader)1 RefreshState (com.scwang.smartrefresh.layout.constant.RefreshState)1 ClassicsHeader (com.scwang.smartrefresh.layout.header.ClassicsHeader)1 RefreshHeaderWrapper (com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper)1