Search in sources :

Example 1 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout in project SmartRefreshLayout by scwang90.

the class TwoLevelPracticeFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull final View root, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(root, savedInstanceState);
    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);
    header.setOnTwoLevelListener(new OnTwoLevelListener() {

        @Override
        public boolean onTwoLevel(@NonNull RefreshLayout refreshLayout) {
            Toast.makeText(getContext(), "触发二楼事件", Toast.LENGTH_SHORT).show();
            refreshLayout.getLayout().postDelayed(new Runnable() {

                @Override
                public void run() {
                    header.finishTwoLevel();
                }
            }, 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.setPaddingSmart(getActivity(), root.findViewById(R.id.toolbar));
}
Also used : TwoLevelHeader(com.scwang.smartrefresh.layout.header.TwoLevelHeader) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) OnTwoLevelListener(com.scwang.smartrefresh.layout.api.OnTwoLevelListener) View(android.view.View) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout in project SmartRefreshLayout by scwang90.

the class PureScrollExampleFragmentFooter method onViewCreated.

@Override
public void onViewCreated(@NonNull 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();
        }
    });
    toolbar.setTitle("Footer单独使用");
    RefreshLayout refreshLayout = (RefreshLayout) root.findViewById(R.id.refreshLayout);
    refreshLayout.setEnablePureScrollMode(false);
    refreshLayout.setRefreshFooter(new FalsifyFooter(getContext()));
    View view = root.findViewById(R.id.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
            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);
            }
        });
    }
}
Also used : 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) FalsifyFooter(com.scwang.smartrefresh.layout.footer.FalsifyFooter) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Item(com.scwang.refreshlayout.fragment.example.PureScrollExampleFragment.Item) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout in project SmartRefreshLayout by scwang90.

the class PureScrollExampleFragmentHeader 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();
        }
    });
    RefreshLayout refreshLayout = (RefreshLayout) root.findViewById(R.id.refreshLayout);
    // 也可以在 XML 中添加 FalsifyHeader
    refreshLayout.setRefreshHeader(new FalsifyHeader(getContext()));
    View view = root.findViewById(R.id.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
            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);
            }
        });
    }
}
Also used : 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) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Item(com.scwang.refreshlayout.fragment.example.PureScrollExampleFragment.Item) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) FalsifyHeader(com.scwang.smartrefresh.layout.header.FalsifyHeader) RecyclerView(android.support.v7.widget.RecyclerView) Toolbar(android.support.v7.widget.Toolbar)

Example 4 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout 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 5 with RefreshLayout

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

Aggregations

RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)40 View (android.view.View)26 Toolbar (android.support.v7.widget.Toolbar)24 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)22 OnRefreshListener (com.scwang.smartrefresh.layout.listener.OnRefreshListener)20 SmartRefreshLayout (com.scwang.smartrefresh.layout.SmartRefreshLayout)17 RecyclerView (android.support.v7.widget.RecyclerView)15 OnLoadmoreListener (com.scwang.smartrefresh.layout.listener.OnLoadmoreListener)12 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)11 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)10 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)10 AdapterView (android.widget.AdapterView)10 SimpleMultiPurposeListener (com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener)9 BaseRecyclerAdapter (com.scwang.refreshlayout.adapter.BaseRecyclerAdapter)7 RefreshHeader (com.scwang.smartrefresh.layout.api.RefreshHeader)7 TextView (android.widget.TextView)6 ImageView (android.widget.ImageView)5 RefreshState (com.scwang.smartrefresh.layout.constant.RefreshState)5 ClassicsHeader (com.scwang.smartrefresh.layout.header.ClassicsHeader)5 OnLoadMoreListener (com.scwang.smartrefresh.layout.listener.OnLoadMoreListener)5