Search in sources :

Example 1 with OnTwoLevelListener

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

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

Toolbar (android.support.v7.widget.Toolbar)2 View (android.view.View)2 OnTwoLevelListener (com.scwang.smartrefresh.layout.api.OnTwoLevelListener)2 RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)2 TwoLevelHeader (com.scwang.smartrefresh.layout.header.TwoLevelHeader)2 RefreshHeader (com.scwang.smartrefresh.layout.api.RefreshHeader)1 OnRefreshListener (com.scwang.smartrefresh.layout.listener.OnRefreshListener)1 SimpleMultiPurposeListener (com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener)1