Search in sources :

Example 1 with RefreshState

use of com.scwang.smartrefresh.layout.constant.RefreshState 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)

Example 2 with RefreshState

use of com.scwang.smartrefresh.layout.constant.RefreshState in project SmartRefreshLayout by scwang90.

the class AssignDefaultExampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    install();
    setContentView(R.layout.activity_example_assign_default);
    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);
    if (isFirstEnter) {
        isFirstEnter = false;
        // 触发上拉加载
        refreshLayout.autoLoadMore();
        // 通过多功能监听接口实现 在第一次加载完成之后 自动刷新
        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 : SimpleMultiPurposeListener(com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener) SmartRefreshLayout(com.scwang.smartrefresh.layout.SmartRefreshLayout) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RefreshState(com.scwang.smartrefresh.layout.constant.RefreshState) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with RefreshState

use of com.scwang.smartrefresh.layout.constant.RefreshState in project SmartRefreshLayout by scwang90.

the class AssignXmlExampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_example_assign_xml);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    /*
         * 以下代码仅仅为了演示效果而已,不是必须的
         * 关键代码在 activity_example_assign_xml 中
         */
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    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 : 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)

Example 4 with RefreshState

use of com.scwang.smartrefresh.layout.constant.RefreshState in project SmartRefreshLayout by scwang90.

the class ListenerExampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_example_listener);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    mTvContent = (TextView) findViewById(R.id.content);
    mTvContent.setMovementMethod(ScrollingMovementMethod.getInstance());
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {

        @Override
        public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
            mHeaderMoving = String.format(Locale.CHINA, "%s\nisDragging=%b,percent=%.02f offset=%03d\nheight=%03d extend=%03d", FORMAT.format(new Date()), isDragging, percent, offset, headerHeight, maxDragHeight);
            updateContent();
        }

        // @Override
        // public void onHeaderPulling(@NonNull RefreshHeader header, float percent, int offset, int headerHeight, int maxDragHeight) {
        // mHeaderPulling = String.format(Locale.CHINA, "%s\npercent=%.02f offset=%03d\nheight=%03d extend=%03d",
        // FORMAT.format(new Date()),
        // percent,offset,headerHeight,maxDragHeight);
        // updateContent();
        // }
        // 
        // @Override
        // public void onHeaderReleasing(@NonNull RefreshHeader header, float percent, int offset, int headerHeight, int maxDragHeight) {
        // mHeaderReleasing = String.format(Locale.CHINA, "%s\npercent=%.02f offset=%03d\nheight=%03d extend=%03d",
        // FORMAT.format(new Date()),
        // percent,offset,headerHeight,maxDragHeight);
        // updateContent();
        // }
        @Override
        public void onHeaderStartAnimator(@NonNull RefreshHeader header, int headerHeight, int maxDragHeight) {
            mHeaderStartAnimator = String.format(Locale.CHINA, "%s\nheight=%03d extend=%03d", FORMAT.format(new Date()), headerHeight, maxDragHeight);
            updateContent();
        }

        @Override
        public void onHeaderFinish(@NonNull RefreshHeader header, boolean success) {
            mHeaderFinish = String.format(Locale.CHINA, "%s - " + success, FORMAT.format(new Date()));
            updateContent();
        }

        @Override
        public void onFooterMoving(RefreshFooter footer, boolean isDragging, float percent, int offset, int footerHeight, int maxDragHeight) {
            mFooterMoving = String.format(Locale.CHINA, "%s\nisDragging=%b,percent=%.02f offset=%03d\nheight=%03d extend=%03d", FORMAT.format(new Date()), isDragging, percent, offset, footerHeight, maxDragHeight);
            updateContent();
        }

        // @Override
        // public void onFooterPulling(@NonNull RefreshFooter footer, float percent, int offset, int footerHeight, int maxDragHeight) {
        // mFooterPulling = String.format(Locale.CHINA, "%s\npercent=%.02f\noffset=%03d height=%03d\nextend=%03d",
        // FORMAT.format(new Date()),
        // percent,offset,footerHeight,maxDragHeight);
        // updateContent();
        // }
        // 
        // @Override
        // public void onFooterReleasing(@NonNull RefreshFooter footer, float percent, int offset, int footerHeight, int maxDragHeight) {
        // mFooterReleasing = String.format(Locale.CHINA, "%s\npercent=%.02f\noffset=%03d height=%03d\nextend=%03d",
        // FORMAT.format(new Date()),
        // percent,offset,footerHeight,maxDragHeight);
        // updateContent();
        // }
        @Override
        public void onFooterStartAnimator(@NonNull RefreshFooter footer, int footerHeight, int maxDragHeight) {
            mFooterStartAnimator = String.format(Locale.CHINA, "%s\nheight=%03d extend=%03d", FORMAT.format(new Date()), footerHeight, maxDragHeight);
            updateContent();
        }

        @Override
        public void onFooterFinish(@NonNull RefreshFooter footer, boolean success) {
            mFooterFinish = String.format(Locale.CHINA, "%s - " + success, FORMAT.format(new Date()));
            updateContent();
        }

        @Override
        public void onRefresh(@NonNull RefreshLayout refreshLayout) {
            mRefresh = String.format(Locale.CHINA, "%s", FORMAT.format(new Date()));
            updateContent();
            refreshLayout.finishRefresh(2000);
        }

        @Override
        public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
            mLoadMore = String.format(Locale.CHINA, "%s", FORMAT.format(new Date()));
            updateContent();
            refreshLayout.finishLoadMore(1000);
        }

        @Override
        public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
            mStateChanged = String.format(Locale.CHINA, "%s\nnew=%s\nold=%s", FORMAT.format(new Date()), newState.name(), oldState.name());
            updateContent();
        }
    });
    if (isFirstEnter) {
        isFirstEnter = false;
        // 触发自动刷新
        refreshLayout.autoRefresh();
    } else {
        updateContent();
    }
}
Also used : RefreshHeader(com.scwang.smartrefresh.layout.api.RefreshHeader) RefreshFooter(com.scwang.smartrefresh.layout.api.RefreshFooter) SimpleMultiPurposeListener(com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener) TextView(android.widget.TextView) View(android.view.View) Date(java.util.Date) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RefreshState(com.scwang.smartrefresh.layout.constant.RefreshState) Toolbar(android.support.v7.widget.Toolbar)

Example 5 with RefreshState

use of com.scwang.smartrefresh.layout.constant.RefreshState in project SmartRefreshLayout by scwang90.

the class EmptyLayoutExampleFragment 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.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white));
    mRefreshLayout.setOnRefreshListener(this);
    mRecyclerView = (RecyclerView) root.findViewById(recyclerView);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
    mLoadingLayout = (LoadingLayout) root.findViewById(R.id.loading);
    mLoadingLayout.showEmpty();
    /*主动演示刷新*/
    if (mIsNeedDemo) {
        mRefreshLayout.getLayout().postDelayed(new Runnable() {

            @Override
            public void run() {
                if (mIsNeedDemo) {
                    mRefreshLayout.autoRefresh();
                }
            }
        }, 3000);
        mRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {

            @Override
            public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
                mIsNeedDemo = false;
            }
        });
    }
}
Also used : SimpleMultiPurposeListener(com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) ClassicsHeader(com.scwang.smartrefresh.layout.header.ClassicsHeader) RefreshState(com.scwang.smartrefresh.layout.constant.RefreshState) 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) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

RefreshState (com.scwang.smartrefresh.layout.constant.RefreshState)7 Toolbar (android.support.v7.widget.Toolbar)6 View (android.view.View)6 RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)6 SimpleMultiPurposeListener (com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener)6 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)2 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 AdapterView (android.widget.AdapterView)2 TextView (android.widget.TextView)2 R.id.recyclerView (com.scwang.refreshlayout.R.id.recyclerView)2 ClassicsHeader (com.scwang.smartrefresh.layout.header.ClassicsHeader)2 ImageView (android.widget.ImageView)1 MaterialHeader (com.scwang.smartrefresh.header.MaterialHeader)1 SmartRefreshLayout (com.scwang.smartrefresh.layout.SmartRefreshLayout)1 RefreshFooter (com.scwang.smartrefresh.layout.api.RefreshFooter)1 RefreshHeader (com.scwang.smartrefresh.layout.api.RefreshHeader)1 BallPulseFooter (com.scwang.smartrefresh.layout.footer.BallPulseFooter)1 OnStateChangedListener (com.scwang.smartrefresh.layout.listener.OnStateChangedListener)1