• Stars
    star
    191
  • Rank 202,877 (Top 4 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 8 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android RefreshView Library,support all view to refresh,custom refresh header,implement NestedScrollingParent and NestedScrollingChild

CoolRefreshView

###1. 支持任意View的刷新
###2. 支持自定义Header ###3. 支持NestedScrollingParent,NestedScrollingChild的事件分发 ###4. 嵌套ViewPager不会有事件冲突

###7.导入方式 <1>gradle导入

compile 'com.shizhefei:CoolRefreshView:1.0.4'
由于用到了v4和recyclerview所以也要导入他们  
compile 'com.android.support:support-v4:23.4.0'  

<2>jar包方式导入

Download sample Apk

###8.历史版本和更新信息
https://github.com/LuckyJayce/CoolRefreshView/releases

效果图

image

使用方法

xml

 <com.shizhefei.view.coolrefreshview.CoolRefreshView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</com.shizhefei.view.coolrefreshview.CoolRefreshView>

代码

 coolRefreshView.setPullHeader(new MaterialHeader(getContext()));
 //添加刷新监听
 coolRefreshView.addOnPullListener(new SimpleOnPullListener() {
        @Override
        public void onRefreshing(CoolRefreshView refreshView) {
            
        }
    });

其它可用方法

设置全局的IPullHeaderFactory

  //静态设置全局的IPullHeaderFactory,一次配置,所有默认使用这个factory生成的PullHeader
  //就不用每个界面设置,该代码可以放在Application onCreate

  CoolRefreshView.setPullHeaderFactory(new IPullHeaderFactory() {
      @Override
      public PullHeader made(Context context) {
          JellyHeader jellyHeader = new JellyHeader(getContext());
          jellyHeader.setDragLayoutColor(ContextCompat.getColor(getContext(), R.color.primary));
          jellyHeader.setLoadingView(R.layout.layout_jelley_header);
          return jellyHeader;
      }

      @Override
      public boolean isPinContent() {
          return false;
      }
  });

设置ContentView是否和头部一起下拉

/**
 * @param pullHeader   刷新的头部
 * @param isPinContent true滚定内容不下拉,只下拉头部, false 一起下拉
 */
setPullHeader(PullHeader pullHeader, boolean isPinContent) 

自定义Header

##<1>简单的实现
实现PullHeader

public class TestHeader implements PullHeader {
    private View headView;
    private TextView mTextView;

    @Override
    public View createHeaderView(final CoolRefreshView refreshView) {
        headView = LayoutInflater.from(refreshView.getContext()).inflate(R.layout.coolrecyclerview_testhead, refreshView, false);
        mTextView = (TextView) headView.findViewById(R.id.coolrecyclerview_testhead_text1_textView);
        return headView;
    }

    /**
     * 开始拖动
     */
    @Override
    public void onPullBegin(CoolRefreshView refreshView) {
        isDownArrow = true;
    }

    /**
     * 位置变化
     *
     * @param refreshView
     * @param status          状态 /没有任何操作
     *                        public final static byte PULL_STATUS_INIT = 1;
     *                        //开始下拉
     *                        public final static byte PULL_STATUS_TOUCH_MOVE = 2;
     *                        //回到原始位置
     *                        public final static byte PULL_STATUS_RESET = 3;
     *                        //刷新中
     *                        public final static byte PULL_STATUS_REFRESHING = 4;
     *                        //刷新完成
     *                        public final static byte PULL_STATUS_COMPLETE = 5;
     * @param dy              下拉事件的位移
     * @param currentDistance 当前位移的距离
     */
    @Override
    public void onPositionChange(CoolRefreshView refreshView, int status, int dy, int currentDistance) {
        int offsetToRefresh = getConfig().offsetToRefresh(refreshView, headView);
        if (status == CoolRefreshView.PULL_STATUS_TOUCH_MOVE) {
            if (currentDistance < offsetToRefresh) {
                if (!isDownArrow) {
                    mTextView.setText("下拉刷新");
                    isDownArrow = true;
                }
            } else {
                if (isDownArrow) {
                    mTextView.setText("释放立即刷新");
                    isDownArrow = false;
                }
            }
        }
    }

    private boolean isDownArrow;

    /**
     * 刷新中
     */
    @Override
    public void onRefreshing(CoolRefreshView refreshView) {
        mTextView.setText("刷新中..");
    }

    /**
     * 没有刷新的释放回去
     */
    @Override
    public void onReset(CoolRefreshView refreshView, boolean pullRelease) {

    }

    /**
     * 设置刷新完成,并且释放回去
     */
    @Override
    public void onPullRefreshComplete(CoolRefreshView frame) {

    }

    @Override
    public Config getConfig() {
        return config;
    }

	//使用默认的配置
    private DefaultConfig config = new DefaultConfig();

}

也可以直接继承View 实现 PullHeader

public class TestHeader extends View  implements PullHeader {
    @Override
    public View createHeaderView(final CoolRefreshView refreshView) {
        return this;
    }
}

##<2>配置距离,可以实现更丰富的效果

 abstract class Config {
        /**
         * 超出这个偏移量,松开手指就会触发刷新。
         */
        public abstract int offsetToRefresh(CoolRefreshView refreshView, View headerView);

        /**
         * 显示刷新的位置的偏移量
         */
        public abstract int offsetToKeepHeaderWhileLoading(CoolRefreshView refreshView, View headerView);

        /**
         * 刷新控件总共可以下拉拖动的距离
         */
        public abstract int totalDistance(CoolRefreshView refreshView, View headerView);

        /**
         * headView 在布局中的偏移量
         */
        public abstract int headerViewLayoutOffset(CoolRefreshView refreshView, View headerView);

        /**
         * contentView 是否可以向上滚动,用来判断是否可以下拉刷新,如果可以向上滚动就不做下拉刷新动作
         */
        public abstract boolean contentCanScrollUp(CoolRefreshView refreshView, View contentView);

        /**
         * 拦截滑动事件
         *
         * @param refreshView
         * @param dy              触摸滑动的偏移量
         * @param currentDistance 当前的滑动的距离
         * @param totalDistance   总的可下拉距离
         * @return
         */
        public abstract int dispatchTouchMove(CoolRefreshView refreshView, int dy, int currentDistance, int totalDistance);

    }

默认的配置

//滑动的总距离是header高度3倍
//触发刷新的距离是header的1.2倍
//正在刷新中的距离是header的高度
class DefaultConfig extends Config {

    @Override
    public int offsetToRefresh(CoolRefreshView refreshView, View headerView) {
        return (int) (headerView.getMeasuredHeight() * 1.2f);
    }

    @Override
    public int offsetToKeepHeaderWhileLoading(CoolRefreshView refreshView, View headerView) {
        return headerView.getMeasuredHeight();
    }

    @Override
    public int totalDistance(CoolRefreshView refreshView, View headerView) {
        return headerView.getMeasuredHeight() * 3;
    }

	.....
}

第二种常用的配置

//总的滑动是header的高度,也就是滑动显示的区域控制在header里
//正在刷新的距离是header3分之一,在header底部的3分之一区域作为正在刷新中的区域
//触发刷新的距离是正在刷新距离的1.2倍.

private DefaultConfig config = new DefaultConfig() {
    @Override
    public int offsetToRefresh(CoolRefreshView refreshView, View headerView) {
        return (int) (headerView.getMeasuredHeight() / 3 * 1.2f);
    }

    @Override
    public int offsetToKeepHeaderWhileLoading(CoolRefreshView refreshView, View headerView) {
        return headerView.getMeasuredHeight() / 3;
    }

    @Override
    public int totalDistance(CoolRefreshView refreshView, View headerView) {
        return headerView.getMeasuredHeight();
    }
};

##配合MVCHelper类库使用,上滑加载更多 配合 https://github.com/LuckyJayce/MVCHelper
代码只要5行,就可以实现下拉刷新,滚动底部自动加载更多,分页加载,自动切换显示网络失败布局,暂无数据布局

CoolRefreshView coolRefreshView = (CoolRefreshView) findViewById(R.id.coolRefreshView);
MVCHelper<List<Book>> mvcHelper = new MVCCoolHelper<List<Book>>(coolRefreshView);

// 设置数据源
mvcHelper.setDataSource(new BooksDataSource());
// 设置适配器
mvcHelper.setAdapter(new BooksAdapter(this));

// 加载数据
mvcHelper.refresh();

更多的详细使用参照 https://github.com/LuckyJayce/MVCHelper 的demo

说明

滑动事件的处理是参照 v4包的 SwipeRefreshLayout,从而支持了支持NestedScrollingParent,NestedScrollingChild的事件分发和避免了嵌套 ViewPager事件冲突

结构是参考 https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh 的结构,它的结构很不错。可以让使用者根据需求自定义Header

Header的下拉我采用了两种实现
<1>Header下拉,内容固定不下拉采用 ViewCompat.offsetTopAndBottom(mHeaderView, -deltaY);
<2>Header和内容一起下拉的采用 scrollTo的方式一起滑动.

##主力类库##

1.https://github.com/LuckyJayce/ViewPagerIndicator
Indicator 取代 tabhost,实现网易顶部tab,新浪微博主页底部tab,引导页,无限轮播banner等效果,高度自定义tab和特效

2.https://github.com/LuckyJayce/MVCHelper
实现下拉刷新,滚动底部自动加载更多,分页加载,自动切换显示网络失败布局,暂无数据布局,支持任意view,支持切换主流下拉刷新框架。

3.https://github.com/LuckyJayce/MultiTypeView
简化RecyclerView的多种type的adapter,Fragment可以动态添加到RecyclerView上,实现复杂的界面分多个模块开发

4.https://github.com/LuckyJayce/EventBus
事件总线,通过动态代理接口的形式发布,接收事件。定义一个接口把事件发给注册并实现接口的类

5.https://github.com/LuckyJayce/LargeImage
大图加载,可供学习

6.https://github.com/LuckyJayce/GuideHelper
新手引导页,轻松的实现对应的view上面的显示提示信息和展示功能给用户

7.https://github.com/LuckyJayce/HVScrollView
可以双向滚动的ScrollView,支持嵌套ScrollView联级滑动,支持设置支持的滚动方向

8.https://github.com/LuckyJayce/CoolRefreshView
下拉刷新RefreshView,支持任意View的刷新 ,支持自定义Header,支持NestedScrollingParent,NestedScrollingChild的事件分发,嵌套ViewPager不会有事件冲突

有了这些类库,让你6的飞起

说明

项目 ViewPagerIndicator_Demo 是示例代码。 看了这个例子你会惊奇的发现里面居然都是通过viewpager实现,没有使用tabhost,而所有形式的tab都是用Indicator实现。 项目 ViewPagerIndicator_Library 是类库

有什么建议可以发到我的邮箱 [email protected]

联系方式和问题建议

License

/*
 * Copyright (C) 2016 LuckyJayce
 * Copyright (C) 2016 liaohuqiu
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

More Repositories

1

ViewPagerIndicator

Indicator 取代 tabhost,实现网易顶部tab,新浪微博主页底部tab,引导页,无限轮播banner等效果,高度自定义tab和特效,LazyFragment
Java
2,585
star
2

LargeImage

Android 加载大图 可以高清显示10000*10000像素的图片,轻松实现微博长图功能
Java
2,334
star
3

MVCHelper

实现下拉刷新,滚动底部自动加载更多,分页加载,自动切换显示网络失败布局,暂无数据布局,支持任意view,支持切换主流下拉刷新框架,真正的android MVC架构,listview,RecyclerView,refresh,loadmore
Java
1,406
star
4

GuideHelper

新手引导页,轻松的实现对应的view上面的显示提示信息和展示功能给用户
Java
461
star
5

MultiTypeView

[DEPRECATED] 不再维护,可以使用 https://github.com/drakeet/MultiType
Java
422
star
6

HVScrollView

可以配置水平和垂直滚动的HVScrollView,参照NestedScrollView和RecyclerView代码写的
Java
153
star
7

LoadViewHelper

android 切换加载中,加载失败,加载成功布局,定义一个LoadViewHelper所有界面通用。
Java
148
star
8

DBExecutor

android 数据库框架,sqlite database
HTML
77
star
9

EventBus

[DEPRECATED] 使用EventBus-Apt优化实现,不过用法类似,项目地址:https://github.com/LuckyJayce/EventBus-Apt
Java
58
star
10

EventBus-Apt

事件总线,通过定义事件接口,apt方式生成事件代理分发事件给注册并实现的接口类
Java
38
star
11

StatusBarDemo

沉浸式状态栏,支持设置状态栏背景和颜色,修复其他项目出现的键盘弹起遮挡输入框问题,以及5.1 的设备CoordinatorLayout +AppBarLayout 滑动问题
Java
18
star
12

MeiZhi

http://gank.io 的第三方 客户端 ,material design的设计,沉浸状态栏和虚拟按键全屏体验,代码精简
Java
17
star
13

Material-Design

8
star
14

DownloadManager

Java
5
star
15

Task

将执行过程抽象成Task
Java
4
star
16

provider_key

easy to use provider
Dart
3
star
17

flutter_load_data

Dart
2
star