Search in sources :

Example 6 with RefreshState

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

the class EmptyLayoutExampleFragmentInner 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));
    mEmptyLayout = root.findViewById(R.id.empty);
    ImageView image = (ImageView) root.findViewById(R.id.empty_image);
    image.setImageResource(R.drawable.ic_empty);
    TextView empty = (TextView) root.findViewById(R.id.empty_text);
    empty.setText("暂无数据下拉刷新");
    /*主动演示刷新*/
    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) ClassicsHeader(com.scwang.smartrefresh.layout.header.ClassicsHeader) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) R.id.recyclerView(com.scwang.refreshlayout.R.id.recyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RefreshState(com.scwang.smartrefresh.layout.constant.RefreshState) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Toolbar(android.support.v7.widget.Toolbar)

Example 7 with RefreshState

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

the class SmartRefreshLayout method notifyStateChanged.

// /*
// * 这段代码来自谷歌官方的 SwipeRefreshLayout
// * 应用场景已经在英文注释中解释清楚
// * 大部分第三方下拉刷新库都保留了这段代码,本库也不例外
// */
// @Override
// public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
// // if this is a List < L or another view that doesn't support nested
// // scrolling, ignore this request so that the vertical scroll event
// // isn't stolen
// View target = mRefreshContent.getScrollableView();
// if ((android.os.Build.VERSION.SDK_INT >= 21 || !(target instanceof AbsListView))
// && (target == null || ViewCompat.isNestedScrollingEnabled(target))) {
// super.requestDisallowInterceptTouchEvent(disallowIntercept);
// //} else {
// // Nope.
// }
// }
// </editor-fold>
// <editor-fold desc="状态更改 state changes">
protected void notifyStateChanged(RefreshState state) {
    final RefreshState oldState = mState;
    if (oldState != state) {
        mState = state;
        mViceState = state;
        final OnStateChangedListener refreshHeader = mRefreshHeader;
        final OnStateChangedListener refreshFooter = mRefreshFooter;
        final OnStateChangedListener refreshListener = mOnMultiPurposeListener;
        if (refreshHeader != null) {
            refreshHeader.onStateChanged(this, oldState, state);
        }
        if (refreshFooter != null) {
            refreshFooter.onStateChanged(this, oldState, state);
        }
        if (refreshListener != null) {
            refreshListener.onStateChanged(this, oldState, state);
        }
    }
}
Also used : OnStateChangedListener(com.scwang.smartrefresh.layout.listener.OnStateChangedListener) RefreshState(com.scwang.smartrefresh.layout.constant.RefreshState)

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