Search in sources :

Example 6 with OnRefreshListener

use of com.scwang.smartrefresh.layout.listener.OnRefreshListener in project yoo_home_Android by culturer.

the class RecommendFragment method initRefresh.

private void initRefresh() {
    final RefreshLayout refreshLayout = contentView.findViewById(R.id.mrefreshLayout);
    refreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh(RefreshLayout refreshlayout) {
            // 传入false表示刷新失败
            refreshlayout.finishRefresh(2000);
            refresh(refreshlayout);
        }
    });
    refreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {

        @Override
        public void onLoadmore(RefreshLayout refreshlayout) {
            loadMore(refreshlayout);
            // 传入false表示加载失败
            refreshlayout.finishLoadmore(2000);
        }
    });
}
Also used : RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) OnLoadmoreListener(com.scwang.smartrefresh.layout.listener.OnLoadmoreListener) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener)

Example 7 with OnRefreshListener

use of com.scwang.smartrefresh.layout.listener.OnRefreshListener in project SmartRefreshLayout by scwang90.

the class BasicExampleActivity method onCreate.

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

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    AbsListView listView = (AbsListView) findViewById(R.id.listView);
    listView.setAdapter(mAdapter = new BaseRecyclerAdapter<Void>(simple_list_item_2) {

        @Override
        protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) {
            holder.text(android.R.id.text1, getString(R.string.item_example_number_title, position));
            holder.text(android.R.id.text2, getString(R.string.item_example_number_abstract, position));
            holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
        }
    });
    mAdapter.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            BottomSheetDialog dialog = new BottomSheetDialog(BasicExampleActivity.this);
            View dialogView = View.inflate(BasicExampleActivity.this, R.layout.activity_example_basic, null);
            dialog.setContentView(dialogView);
            AbsListView listView = (AbsListView) dialogView.findViewById(R.id.listView);
            listView.setAdapter(mAdapter);
            ViewGroup parentGroup = (ViewGroup) listView.getParent();
            parentGroup.removeView(listView);
            // ViewGroup parentRoot = (ViewGroup) parentGroup.getParent();
            // parentRoot.removeView(parentGroup);
            RecyclerView recyclerView = new RecyclerView(BasicExampleActivity.this);
            recyclerView.setLayoutManager(new LinearLayoutManager(BasicExampleActivity.this));
            recyclerView.setAdapter(mAdapter);
            ((SmartRefreshLayout) parentGroup).setEnableRefresh(false);
            // ((SmartRefreshLayout) parentGroup).startNestedScroll(0);
            // ((SmartRefreshLayout) parentGroup).setEnableOverScrollDrag(false);
            ((SmartRefreshLayout) parentGroup).setRefreshContent(recyclerView);
            // parentRoot.addView(recyclerView, -1, -1);
            dialog.show();
        }
    });
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    // 开启自动加载功能(非必须)
    refreshLayout.setEnableAutoLoadMore(true);
    refreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
            refreshLayout.getLayout().postDelayed(new Runnable() {

                @Override
                public void run() {
                    mAdapter.refresh(initData());
                    refreshLayout.finishRefresh();
                    refreshLayout.setNoMoreData(false);
                }
            }, 2000);
        }
    });
    refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {

        @Override
        public void onLoadMore(@NonNull final RefreshLayout refreshLayout) {
            refreshLayout.getLayout().postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (mAdapter.getItemCount() > 30) {
                        Toast.makeText(getApplication(), "数据全部加载完毕", Toast.LENGTH_SHORT).show();
                        // 将不会再次触发加载更多事件
                        refreshLayout.finishLoadMoreWithNoMoreData();
                    } else {
                        mAdapter.loadMore(initData());
                        refreshLayout.finishLoadMore();
                    }
                }
            }, 2000);
        }
    });
    // 触发自动刷新
    refreshLayout.autoRefresh();
}
Also used : OnLoadMoreListener(com.scwang.smartrefresh.layout.listener.OnLoadMoreListener) SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) ViewGroup(android.view.ViewGroup) AbsListView(android.widget.AbsListView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView) BaseRecyclerAdapter(com.scwang.refreshlayout.adapter.BaseRecyclerAdapter) BottomSheetDialog(android.support.design.widget.BottomSheetDialog) SmartRefreshLayout(com.scwang.smartrefresh.layout.SmartRefreshLayout) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener) Toolbar(android.support.v7.widget.Toolbar)

Example 8 with OnRefreshListener

use of com.scwang.smartrefresh.layout.listener.OnRefreshListener in project SmartRefreshLayout by scwang90.

the class CustomExampleActivity method onCreate.

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

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    ListView listView = (ListView) findViewById(R.id.listView);
    listView.setAdapter(mAdapter = new BaseRecyclerAdapter<Void>(simple_list_item_2) {

        @Override
        protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) {
            holder.text(android.R.id.text1, getString(R.string.item_example_number_title, position));
            holder.text(android.R.id.text2, getString(R.string.item_example_number_abstract, position));
            holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
        }
    });
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    refreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
            refreshLayout.getLayout().postDelayed(new Runnable() {

                @Override
                public void run() {
                    mAdapter.refresh(initData());
                    refreshLayout.finishRefresh();
                }
            }, 2000);
        }
    });
    refreshLayout.setRefreshHeader(new ClassicsHeader(this));
    refreshLayout.setHeaderHeight(60);
    // 触发自动刷新
    if (isFirstEnter) {
        isFirstEnter = false;
        refreshLayout.autoRefresh();
    } else {
        mAdapter.refresh(initData());
    }
}
Also used : ListView(android.widget.ListView) SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) BaseRecyclerAdapter(com.scwang.refreshlayout.adapter.BaseRecyclerAdapter) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener) Toolbar(android.support.v7.widget.Toolbar)

Example 9 with OnRefreshListener

use of com.scwang.smartrefresh.layout.listener.OnRefreshListener in project SmartRefreshLayout by scwang90.

the class OverScrollExampleActivity method onCreate.

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

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    final WebView webView = (WebView) findViewById(R.id.webView);
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    refreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh(@NonNull RefreshLayout refreshLayout) {
            webView.loadUrl("http://github.com");
        }
    });
    refreshLayout.autoRefresh();
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageCommitVisible(WebView view, String url) {
            refreshLayout.finishRefresh();
        }
    });
// TextView textView = (TextView) findViewById(R.id.textView);
// textView.setMovementMethod(new ScrollingMovementMethod());
}
Also used : RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) WebView(android.webkit.WebView) View(android.view.View) WebView(android.webkit.WebView) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener) Toolbar(android.support.v7.widget.Toolbar) WebViewClient(android.webkit.WebViewClient)

Example 10 with OnRefreshListener

use of com.scwang.smartrefresh.layout.listener.OnRefreshListener in project SmartRefreshLayout by scwang90.

the class FlyRefreshStyleActivity method onCreate.

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

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    /*-----------------------------------------------------------
         * 关键代码-开始
         *----------------------------------------------------------*/
    MountainSceneView mSceneView = (MountainSceneView) findViewById(R.id.mountain);
    mFlyView = (FlyView) findViewById(R.id.flyView);
    mFlyRefreshHeader = (FlyRefreshHeader) findViewById(R.id.flyRefresh);
    // 绑定场景和纸飞机
    mFlyRefreshHeader.setUp(mSceneView, mFlyView);
    mRefreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    // 设置回弹插值器,会带有弹簧震动效果
    mRefreshLayout.setReboundInterpolator(new ElasticOutInterpolator());
    // 设置回弹动画时长
    mRefreshLayout.setReboundDuration(800);
    mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh(@NonNull RefreshLayout refreshLayout) {
            View child = mListView.getChildAt(0);
            if (child != null) {
                // 开始刷新的时候个第一个item设置动画效果
                bounceAnimateView(child.findViewById(R.id.icon));
            }
            // 改变主题颜色
            updateTheme();
            mRefreshLayout.getLayout().postDelayed(new Runnable() {

                @Override
                public void run() {
                    // 通知刷新完成,这里改为通知Header,让纸飞机飞回来
                    mFlyRefreshHeader.finishRefresh(new AnimatorListenerAdapter() {

                        public void onAnimationEnd(Animator animation) {
                            // 在纸飞机回到原位之后添加数据效果更真实
                            addItemData();
                        }
                    });
                }
            }, // 模拟两秒的后台数据加载
            2000);
        }
    });
    // 设置 让 AppBarLayout 和 RefreshLayout 的滚动同步 并不保持 toolbar 位置不变
    final AppBarLayout appBar = (AppBarLayout) findViewById(R.id.appbar);
    mRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {

        @Override
        public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
            appBar.setTranslationY(offset);
            toolbar.setTranslationY(-offset);
        }
    });
    if (isFirstEnter) {
        isFirstEnter = false;
        // 第一次进入触发自动刷新,演示效果
        mRefreshLayout.autoRefresh();
    }
    /*
         * 初始化列表数据
         */
    initDataSet();
    mAdapter = new ItemAdapter(this);
    mLayoutManager = new LinearLayoutManager(this);
    mListView = (RecyclerView) findViewById(R.id.recyclerView);
    mListView.setLayoutManager(mLayoutManager);
    mListView.setAdapter(mAdapter);
    mListView.setItemAnimator(new SampleItemAnimator());
    mToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbarLayout);
    mActionButton = (FloatingActionButton) findViewById(R.id.fab);
    /*
         * 设置点击 ActionButton 时候触发自动刷新 并改变主题颜色
         */
    mActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            updateTheme();
            mRefreshLayout.autoRefresh();
        }
    });
    /*
         * 监听 AppBarLayout 的关闭和开启 给 FlyView(纸飞机) 和 ActionButton 设置关闭隐藏动画
         */
    appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        boolean misAppbarExpand = true;

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            int scrollRange = appBarLayout.getTotalScrollRange();
            float fraction = 1f * (scrollRange + verticalOffset) / scrollRange;
            if (fraction < 0.1 && misAppbarExpand) {
                misAppbarExpand = false;
                mActionButton.animate().scaleX(0).scaleY(0);
                mFlyView.animate().scaleX(0).scaleY(0);
                ValueAnimator animator = ValueAnimator.ofInt(mListView.getPaddingTop(), 0);
                animator.setDuration(300);
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        mListView.setPadding(0, (int) animation.getAnimatedValue(), 0, 0);
                    }
                });
                animator.start();
            }
            if (fraction > 0.8 && !misAppbarExpand) {
                misAppbarExpand = true;
                mActionButton.animate().scaleX(1).scaleY(1);
                mFlyView.animate().scaleX(1).scaleY(1);
                ValueAnimator animator = ValueAnimator.ofInt(mListView.getPaddingTop(), DensityUtil.dp2px(25));
                animator.setDuration(300);
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        mListView.setPadding(0, (int) animation.getAnimatedValue(), 0, 0);
                    }
                });
                animator.start();
            }
        }
    });
    // 状态栏透明和间距处理
    StatusBarUtil.immersive(this);
    StatusBarUtil.setPaddingSmart(this, toolbar);
}
Also used : FlyRefreshHeader(com.scwang.smartrefresh.header.FlyRefreshHeader) RefreshHeader(com.scwang.smartrefresh.layout.api.RefreshHeader) SimpleMultiPurposeListener(com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ValueAnimator(android.animation.ValueAnimator) ImageView(android.widget.ImageView) View(android.view.View) MountainSceneView(com.scwang.smartrefresh.header.flyrefresh.MountainSceneView) RecyclerView(android.support.v7.widget.RecyclerView) FlyView(com.scwang.smartrefresh.header.flyrefresh.FlyView) TextView(android.widget.TextView) Animator(android.animation.Animator) BaseItemAnimator(jp.wasabeef.recyclerview.animators.BaseItemAnimator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) MountainSceneView(com.scwang.smartrefresh.header.flyrefresh.MountainSceneView) AppBarLayout(android.support.design.widget.AppBarLayout) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)20 OnRefreshListener (com.scwang.smartrefresh.layout.listener.OnRefreshListener)20 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)13 SmartRefreshLayout (com.scwang.smartrefresh.layout.SmartRefreshLayout)11 View (android.view.View)10 OnLoadmoreListener (com.scwang.smartrefresh.layout.listener.OnLoadmoreListener)10 Toolbar (android.support.v7.widget.Toolbar)8 RecyclerView (android.support.v7.widget.RecyclerView)6 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)4 WebView (android.webkit.WebView)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 WeicoAdapter (com.gapcoder.weico.Index.Adapter.WeicoAdapter)3 Intent (android.content.Intent)2 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)2 ViewGroup (android.view.ViewGroup)2 WebViewClient (android.webkit.WebViewClient)2 AdapterView (android.widget.AdapterView)2 BaseRecyclerAdapter (com.scwang.refreshlayout.adapter.BaseRecyclerAdapter)2 RefreshHeader (com.scwang.smartrefresh.layout.api.RefreshHeader)2