diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 00000000..7387295f
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,5 @@
+# These are supported funding model platforms
+
+custom: https://www.paypal.me/scwang90
+
+
diff --git a/.gitignore b/.gitignore
index 07487450..9816f370 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,8 @@
*.iml
-.gradle
-gradle
+*.txt
+.*
+repo
+release
+build
/local.properties
-/.idea
-/build
-/gradlew
-/gradlew.bat
\ No newline at end of file
+/bintrayUpload-key.bat
diff --git a/README.md b/README.md
index 9ba9d230..0c8affca 100644
--- a/README.md
+++ b/README.md
@@ -1,157 +1,241 @@
-# Android Smart Refresh Layout Framework
-[](https://www.apache.org/licenses/LICENSE-2.0)
-[ ](https://bintray.com/scwang90/maven/SmartRefreshLayout/_latestVersion)
-[](https://android-arsenal.com/api?level=12)
-[](https://github.com/scwang90)
-
-## English | [中文](README_CN.md)
-
-As the name says, SmartRefreshLayout is a "smart" refresh layout,Because of its "smart", it does not just support all the View as other refresh layouts said, but also support multi-layered nested view structures.
-In addition to "smart", SmartRefreshLayout also has a lot of features.
-It extends from ViewGroup rather than the other FrameLayout or LinearLayout, improving performance.
-It absorbs the advantages of various refresh layout in fashion now,Including Google official [SwipeRefreshLayout](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html)、[TwinklingRefreshLayout](https://github.com/lcodecorex/TwinklingRefreshLayout) 、[Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh)。Also integrates various cool Header and Footer.
-SmartRefreshLayout's goal is to build a strong, stable and mature refresh layout framework, and integrate all kinds of cool and diverse, practical, beautiful Header and Footer.
-
-## Features
-
- - Support all of the View (AbsListView RecyclerView WebView... View) and multi-layered nested view structures.
- - Support custom Header and Footer, and has integrated a lot of cool Header and Footer.
- - Support synchronous scrolling with ListView and NestedScrolling width RecyclerView、AppBarLayout、CoordinatorLayout.
- - Support preview in the Android Studio xml editor.
- - Support three ways (default、xml、java) to set the Header and Footer.
- - Support automatic refresh, automatic loading (automatic detection list, scroll to the bottom without having to manually pull).
- - Support generic refresh listener (OnRefreshListener) and more detailed scrolling listener (OnMultiPurposeListener).
- - Support custom rebound animation interpolator, to achieve a variety of cool animation effects.
- - Support set the theme to fit any scene of App, won't appear cool but very awkward situation.
- - Support for setting a variety of transformations (Translation, stretching, behind the fixed, top fixed, full screen) for Header and Footer.
- - Support content size adaptation (wrap_content).
- - Support rewrite and extension, internal implementation without private methods and fields.
- - Support cross-border rebound (Listview、RecyclerView、ScrollView、WebView...View).
-
-## Gateway
-
- - [Smart place](art/md_smart.md)
- - [Update log](art/md_update.md)
- - [Attribute method](art/md_property.md)
- - [Blog posts](https://segmentfault.com/a/1190000010066071)
-
+# Android智能下拉刷新框架-SmartRefreshLayout
+
+[](https://www.apache.org/licenses/LICENSE-2.0)
+[](https://android-arsenal.com/details/1/6001)
+[](https://bintray.com/scwang90/maven/refresh-layout-kernel/_latestVersion)
+[](https://android-arsenal.com/api?level=12)
+[](http://www.methodscount.com/?lib=com.scwang.smartrefresh%3ASmartRefreshLayout%3A1.0.4)
+
+## [English](README_EN.md) | 中文
+
+SmartRefreshLayout以打造一个强大,稳定,成熟的下拉刷新框架为目标,并集成各种的炫酷、多样、实用、美观的Header和Footer。
+正如名字所说,SmartRefreshLayout是一个“聪明”或者“智能”的下拉刷新布局,由于它的“智能”,它不只是支持所有的View,还支持多层嵌套的视图结构。
+它继承自ViewGroup 而不是FrameLayout或LinearLayout,提高了性能。
+也吸取了现在流行的各种刷新布局的优点,包括谷歌官方的 [SwipeRefreshLayout](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html),
+其他第三方的 [Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh)、[TwinklingRefreshLayout](https://github.com/lcodecorex/TwinklingRefreshLayout) 。
+还集成了各种炫酷的 Header 和 Footer。
+
+## 国内加速
+
+github 由于你懂的原因,下载速度缓慢,图片也无法查看,可以跳转 [国内镜像](https://gitee.com/scwang90/SmartRefreshLayout)
+
+## 特点功能:
+
+ - 支持多点触摸
+ - 支持淘宝二楼和二级刷新
+ - 支持嵌套多层的视图结构 Layout (LinearLayout,FrameLayout...)
+ - 支持所有的 View(AbsListView、RecyclerView、WebView....View)
+ - 支持自定义并且已经集成了很多炫酷的 Header 和 Footer.
+ - 支持和 ListView 的无缝同步滚动 和 CoordinatorLayout 的嵌套滚动 .
+ - 支持自动刷新、自动上拉加载(自动检测列表惯性滚动到底部,而不用手动上拉).
+ - 支持自定义回弹动画的插值器,实现各种炫酷的动画效果.
+ - 支持设置主题来适配任何场景的 App,不会出现炫酷但很尴尬的情况.
+ - 支持设多种滑动方式:平移、拉伸、背后固定、顶层固定、全屏
+ - 支持所有可滚动视图的越界回弹
+ - 支持 Header 和 Footer 交换混用
+ - 支持 AndroidX
+ - 支持[横向刷新](https://github.com/scwang90/SmartRefreshHorizontal)
+
+## 传送门
+
+ - [属性文档](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_property.md)
+ - [常见问题](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_faq.md)
+ - [智能之处](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_smart.md)
+ - [更新日志](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_update.md)
+ - [博客文章](https://segmentfault.com/a/1190000010066071)
+ - [源码下载](https://github.com/scwang90/SmartRefreshLayout/releases)
+ - [多点触摸](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_multitouch.md)
+ - [自定义Header](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_custom.md)
+
## Demo
-[Download APK-Demo](art/app-debug.apk)
+[下载 APK-Demo](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/app-debug.apk)
+
+
+
+#### 项目演示
+|个人首页|微博列表|
+|:---:|:---:|
+|||
-
+|餐饮美食|个人中心|
+|:---:|:---:|
+|||
-#### Practical
- 
+#### 样式演示 Style
+|Delivery|DropBox|
+|:---:|:---:|
+|||
+|[Refresh-your-delivery](https://dribbble.com/shots/2753803-Refresh-your-delivery)|[Dropbox-Refresh](https://dribbble.com/shots/3470499-DropBox-Refresh)|
- 
+上面这两个是我自己实现的,下面的是我把github上其它优秀的Header进行的整理和集合还有优化:
-#### Style
- 
+|BezierRadar|BezierCircle|
+|:---:|:---:|
+|||
+|[Pull To Refresh](https://dribbble.com/shots/1936194-Pull-To-Refresh)|[Pull Down To Refresh](https://dribbble.com/shots/1797373-Pull-Down-To-Refresh)|
-The two above is my own implementation of the Header, the design comes from: [Refresh-your-delivery](https://dribbble.com/shots/2753803-Refresh-your-delivery),[Dropbox-Refresh](https://dribbble.com/shots/3470499-Dropbox-Refresh)
+|FlyRefresh|Classics|
+|:---:|:---:|
+|||
+|[FlyRefresh](https://github.com/race604/FlyRefresh)|[ClassicsHeader](#1)|
- 
+|Phoenix|Taurus|
+|:---:|:---:|
+|||
+|[Yalantis/Phoenix](https://github.com/Yalantis/Phoenix)|[Yalantis/Taurus](https://github.com/Yalantis/Taurus)
-[TwinklingRefreshLayout](https://github.com/lcodecorex/TwinklingRefreshLayout/blob/master/art/gif_recyclerview2.gif),[Pull Down To Refresh](https://dribbble.com/shots/1797373-Pull-Down-To-Refresh)
+|BattleCity|HitBlock|
+|:---:|:---:|
+|||
+|[FunGame/BattleCity](https://github.com/Hitomis/FunGameRefresh)|[FunGame/HitBlock](https://github.com/Hitomis/FunGameRefresh)
- 
+|WaveSwipe|Material|
+|:---:|:---:|
+|||
+|[WaveSwipeRefreshLayout](https://github.com/recruit-lifestyle/WaveSwipeRefreshLayout)|[MaterialHeader](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html)
-[FlyRefresh](https://github.com/race604/FlyRefresh),[ClassicsHeader](#1)
+|StoreHouse|WaterDrop|
+|:---:|:---:|
+|||
+|[CRefreshLayout](https://github.com/cloay/CRefreshLayout)|[WaterDrop](https://github.com/THEONE10211024/WaterDropListView)
- 
-[Yalantis/Phoenix](https://github.com/Yalantis/Phoenix),[Yalantis/Taurus](https://github.com/Yalantis/Taurus)
+看到这么多炫酷的Header,是不是觉得很棒?这时你或许会担心这么多的Header集成在一起,但是平时只会用到一个,是不是要引入很多无用的代码和资源?
+V2.x 版本已经把依赖库拆分成8个包啦,用到的时候自行引用就可以啦!
- 
+ - refresh-layout-kernel 核心必须依赖
+ - refresh-header-classics 经典刷新头
+ - refresh-header-radar 雷达刷新头
+ - refresh-header-falsify 虚拟刷新头
+ - refresh-header-material 谷歌刷新头
+ - refresh-header-two-level 二级刷新头
+ - refresh-footer-ball 球脉冲加载
+ - refresh-footer-classics 经典加载
-[FunGame/BattleCity](https://github.com/Hitomis/FunGameRefresh),[FunGame/HitBlock](https://github.com/Hitomis/FunGameRefresh)
+## 简单用例
+#### 1.在 build.gradle 中添加依赖
- 
+[【V1.1.0】](https://github.com/scwang90/SmartRefreshLayout/tree/1.x#%E7%AE%80%E5%8D%95%E7%94%A8%E4%BE%8B) 如果正在使用1.x 版本请调转,当前2.0 版本已经重定制,不支持升级,请在新项目中使用。
+
+V2.x 相对于 V1.x 对包名做了修改如:com.scwang.smartrefresh 改为 com.scwang.smart.refresh。
+建议在新项目中使用,如果项目升级,java,xml 中都需要做包名替换,比较麻烦。
+但主要改动还是对 Smart 进行分包,减小不必要的依赖,比如不使用二级刷新就不依赖,避免代码冗余。
+但是未对 SmartRefreshHeader 分包,里面有十多个Header,建议需要使用哪个就复制哪个的源码到项目中。
+当然:大家也可以在讨论区讨论投票,选出里面使用频率比较高的Header,然后单独分离出来。
+
+```
+compile 'com.android.support:appcompat-v7:25.3.1' //必须 25.3.1 以上
-[WaveSwipeRefreshLayout](https://github.com/recruit-lifestyle/WaveSwipeRefreshLayout),[MaterialHeader](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html)
+// 注意:分包之后不会有默认的Header和Footer需要手动添加!还是原来的三种方法!
+implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3' //核心必须依赖
+implementation 'com.scwang.smart:refresh-header-classics:2.0.3' //经典刷新头
+implementation 'com.scwang.smart:refresh-header-radar:2.0.3' //雷达刷新头
+implementation 'com.scwang.smart:refresh-header-falsify:2.0.3' //虚拟刷新头
+implementation 'com.scwang.smart:refresh-header-material:2.0.3' //谷歌刷新头
+implementation 'com.scwang.smart:refresh-header-two-level:2.0.3' //二级刷新头
+implementation 'com.scwang.smart:refresh-footer-ball:2.0.3' //球脉冲加载
+implementation 'com.scwang.smart:refresh-footer-classics:2.0.3' //经典加载
- 
-[Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh),[WaterDrop](https://github.com/THEONE10211024/WaterDropListView)
+```
+如果使用 AndroidX 先在 gradle.properties 中添加,两行都不能少噢~
-See so many cool headers, is not it feel great? At this point you may be worried that so many headers together, but usually only use one, is not to introduce a lot of useless code and resources?
-Please rest assured that I have divided it into three packages, when used to reference their own it!
+```
+android.useAndroidX=true
+android.enableJetifier=true
- - **SmartRefreshLayout:** The core to realize,Bring ClassicsHeader and BezierRadarHeader.
- - **SmartRefreshHeader:** Integration of various kinds of the Header.
- - **SmartRefreshFooter:** Integration of various kinds of the Footer.
+```
-## Usage
-#### 1.Add a gradle dependency.
+需要依赖 androidx.appcompat
```
-compile 'com.android.support:appcompat-v7:25.3.1'
-compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.2-alpha-8'
-compile 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.2-alpha-8'//If you use the special Header
+implementation 'androidx.appcompat:appcompat:1.0.0' //必须 1.0.0 以上
+
+implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3' //核心必须依赖
+implementation 'com.scwang.smart:refresh-header-classics:2.0.3' //经典刷新头
+implementation 'com.scwang.smart:refresh-header-radar:2.0.3' //雷达刷新头
+implementation 'com.scwang.smart:refresh-header-falsify:2.0.3' //虚拟刷新头
+implementation 'com.scwang.smart:refresh-header-material:2.0.3' //谷歌刷新头
+implementation 'com.scwang.smart:refresh-header-two-level:2.0.3' //二级刷新头
+implementation 'com.scwang.smart:refresh-footer-ball:2.0.3' //球脉冲加载
+implementation 'com.scwang.smart:refresh-footer-classics:2.0.3' //经典加载
+
```
-#### 2.Add SmartRefreshLayout in the layout xml.
+#### 2.在XML布局文件中添加 SmartRefreshLayout
```xml
-
+
-
+
+
```
-#### 3.Coding in the Activity or Fragment.
+#### 3.在 Activity 或者 Fragment 中添加代码
```java
RefreshLayout refreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+refreshLayout.setRefreshHeader(new ClassicsHeader(this));
+refreshLayout.setRefreshFooter(new ClassicsFooter(this));
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(RefreshLayout refreshlayout) {
- refreshlayout.finishRefresh(2000).setSpinnerStyle(SpinnerStyle.Translate);
+ refreshlayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败
}
});
-refreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {
+refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
- public void onLoadmore(RefreshLayout refreshlayout) {
- refreshlayout.finishLoadmore(2000).setSpinnerStyle(SpinnerStyle.Translate);
+ public void onLoadMore(RefreshLayout refreshlayout) {
+ refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
}
});
```
-## Use the specified Header and Footer
+## 使用指定的 Header 和 Footer
-#### 1.Global settings
+#### 1.方法一 全局设置
```java
public class App extends Application {
- public void onCreate() {
- super.onCreate();
- SmartRefreshLayout.setDefaultRefreshHeaderCreater(new DefaultRefreshHeaderCreater() {
+ //static 代码段可以防止内存泄露
+ static {
+ //设置全局的Header构建器
+ SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
@Override
public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
- return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);
+ layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);//全局设置主题颜色
+ return new ClassicsHeader(context);//.setTimeFormat(new DynamicTimeFormat("更新于 %s"));//指定为经典Header,默认是 贝塞尔雷达Header
}
});
- SmartRefreshLayout.setDefaultRefreshFooterCreater(new DefaultRefreshFooterCreater() {
+ //设置全局的Footer构建器
+ SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
@Override
public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
- return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Translate);
+ //指定为经典Footer,默认是 BallPulseFooter
+ return new ClassicsFooter(context).setDrawableSize(20);
}
});
}
}
```
-Note: this method is the lowest priority.
+注意:方法一 设置的Header和Footer的优先级是最低的,如果同时还使用了方法二、三,将会被其它方法取代
-#### 2.Specified in the XML layout file
+#### 2.方法二 XML布局文件指定
```xml
-
-
-
-
+
+
-
-
+
```
-Note: this method of priority is medium。When using this method, the Android Studio will have preview effect, the following figure:
+注意:方法二 XML设置的Header和Footer的优先级是中等的,会被方法三覆盖。而且使用本方法的时候,Android Studio 会有预览效果,如下图:
-
+
-But don't worry, just a preview effect, run only the drop-down will appear.
+不过不用担心,只是预览效果,运行的时候只有下拉才会出现~
-#### 3.Specified in the java code
+#### 3.方法三 Java代码设置
```java
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
-refreshLayout.setRefreshHeader(new MaterialHeader(this).setShowBezierWave(true));
+//设置 Header 为 贝塞尔雷达 样式
+refreshLayout.setRefreshHeader(new BezierRadarHeader(this).setEnableHorizontalDrag(true));
+//设置 Footer 为 球脉冲 样式
refreshLayout.setRefreshFooter(new BallPulseFooter(this).setSpinnerStyle(SpinnerStyle.Scale));
```
-## Proguard
-
-This library does't use serialization and deserialization, JNI, reflection, so there is no need to add confusing filtering code, and it has been confusing tests pass, if you after the confusion in the use of the project appear problem, please inform me.
-
-## Donate
-
-If you like this library's design, feel it help to you, you can point the upper right corner "Star" support Thank you! ^ _ ^
-You can also scan the qr code below to ask the author to drink a cup of coffee.
-
- 
-
-If in the donation message note name, will be record to the list
-[Donation list](art/md_donationlist.md)
-
-## Discuss
-
-Contact me: scwang90@hotmail.com QQ group: 602537182
-The answers to the join the group can be found in this document~
-
-## Thanks
+#### 4.更多使用说明
+
+ - [属性文档](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_property.md)
+ - [常见问题](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_faq.md)
+ - [自定义Header](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_custom.md)
+
+## 混淆
+
+SmartRefreshLayout 不需要添加混淆过滤代码,并且已经混淆测试通过,如果你在项目的使用中混淆之后出现问题,请及时通知我。
+
+## 赞赏
+
+如果你喜欢 SmartRefreshLayout 的设计,感觉 SmartRefreshLayout 帮助到了你,可以点右上角 "Star" 支持一下 谢谢! ^_^
+你也还可以扫描下面的二维码~ 请作者喝一杯咖啡。
+
+  
+
+> 如果希望捐赠之后能获得相关的帮助,可以选择加入下面的付费群来取代普通捐赠,付费群可以直接获得作者的直接帮助,与问题反馈。
+
+如果在捐赠留言中备注名称,将会被记录到列表中~ 如果你也是github开源作者,捐赠时可以留下github项目地址或者个人主页地址,链接将会被添加到列表中起到互相推广的作用
+[捐赠列表](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_donationlist.md)
+
+#### 友情链接
+[github/afKT/DevUtils](https://github.com/afKT/DevUtils)
+[github/Loror](https://github.com/Loror)
+[github/faith-hb/WidgetCase](https://github.com/faith-hb/WidgetCase)
+[github/Bamboy120315/Freedom](https://github.com/Bamboy120315/Freedom)
+[github/TommyLemon/APIJSON](https://github.com/TommyLemon/APIJSON)
+[github/dengyuhan](https://github.com/dengyuhan)
+[github/zrp2017](https://github.com/zrp2017)
+[github/fly803/BaseProject](https://github.com/fly803/BaseProject)
+[github/razerdp](https://github.com/razerdp)
+[github/SuperChenC/s-mvp](https://github.com/SuperChenC/s-mvp)
+[github/KingJA/LoadSir](https://github.com/KingJA/LoadSir)
+[github/jianshijiuyou](https://github.com/jianshijiuyou)
+[github/zxy198717](https://github.com/zxy198717)
+[github/addappcn](https://github.com/addappcn)
+[github/RainliFu](https://github.com/RainliFu)
+[github/sugarya](https://github.com/sugarya)
+[github/stormzhang](https://github.com/stormzhang)
+
+## 讨论
+
+### QQ解决群 - 602537182 (付费)
+#### 进群须知
+自开群以来,还是有很多的朋友提出了很多问题,我也解决了很多问题,其中有大半问题是本库的Bug导致,也有些是使用者项目本
+身的环境问题,这花费了我大量的时间,经过我的观察和测试,到目前为止,本库的bug已经越来越少,当然不能说完全没有,但是
+已经能满足很大部分项目的需求。所以从现在起,我做出一个决定:把之前的讨论群改成解决群,并开启付费入群功能,专为解决大
+家在使用本库时遇到的问题,不管是本库bug还是,特殊的项目环境导致(包含项目本身的bug)。
+我也有自己的工作和娱乐时间,只有大家理解和支持我,我才能专心的为大家解决问题。不过用担心,我已经建立了另一个可以免费
+进入的QQ讨论群。
+
+### QQ讨论群 - 914275312 (新) 477963933 (满) 538979188 (满)
+#### 进群须知
+这个群,免费进入,大家可以相互讨论本库的相关使用和出现的问题,群主也会在里面解决问题,如果提出的问题,群成员不能帮助
+解决,需要群主解决,但是要花费群主五分钟以上的时间(本库Bug除外),群主将不会解决这个问题,如果项目紧急,请付费进入解
+决群解决(不过注意,付费群中群主会很认真很努力的解决问题,但也不能保证已经能完美解决)或者转换使用其他的刷新库。
+
+
+#### 温馨提示
+加入群的答案在本文档中可以找到~
+
+## 其他作品
+[MultiWaveHeader](https://github.com/scwang90/MultiWaveHeader)
+[SmartRefreshHorizontal](https://github.com/scwang90/SmartRefreshHorizontal)
+[诗和远方](http://android.myapp.com/myapp/detail.htm?apkName=com.poetry.kernel)
+
+## 感谢
[SwipeRefreshLayout](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html)
+[Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh)
[TwinklingRefreshLayout](https://github.com/lcodecorex/TwinklingRefreshLayout)
-[android-Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh)
+[BeautifulRefreshLayout](https://github.com/android-cjj/BeautifulRefreshLayout)
License
-------
@@ -229,4 +364,4 @@ License
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.
\ No newline at end of file
+ limitations under the License.
diff --git a/README_CN.md b/README_CN.md
deleted file mode 100644
index c4a1cc2d..00000000
--- a/README_CN.md
+++ /dev/null
@@ -1,259 +0,0 @@
-# Android智能下拉刷新框架-SmartRefreshLayout
-[](https://www.apache.org/licenses/LICENSE-2.0)
-[ ](https://bintray.com/scwang90/maven/SmartRefreshLayout/_latestVersion)
-[](https://android-arsenal.com/api?level=12)
-[](https://github.com/scwang90)
-
-
-## [English](README.md) | 中文
-
-正如名字所说,SmartRefreshLayout是一个“聪明”或者说“智能”的下拉刷新布局,由于它的“智能”,它不只是如其它的刷新布局所说的支持所有的View,还支持多层嵌套的视图结构。 除了“聪明”之外,SmartRefreshLayout还具备了很多的特点。
-它继承自ViewGroup 而不是其它的FrameLayout或者LinearLayout,提高了性能。
-吸取了现在流行的各种刷新布局的优点,包括谷歌官方的 SwipeRefreshLayout,现在非常流行的 [TwinklingRefreshLayout](https://github.com/lcodecorex/TwinklingRefreshLayout) 、[Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh)。还集成了各种炫酷的 Header 和 Footer。
-SmartRefreshLayout的目标是打造一个强大,稳定,成熟的下拉刷新框架,并集成各种的炫酷、多样、实用、美观的Header和Footer。
-
-## 特点功能:
-
- - 支持所有的 View(AbsListView、RecyclerView、WebView....View) 和多层嵌套的视图结构
- - 支持自定义并且已经集成了很多炫酷的 Header 和 Footer (图).
- - 支持和ListView的同步滚动 和 RecyclerView、AppBarLayout、CoordinatorLayout 的嵌套滚动 NestedScrolling.
- - 支持在Android Studio Xml 编辑器中预览 效果(图)
- - 支持分别在 Default(默认)、Xml、JavaCode 三个中设置 Header 和 Footer.
- - 支持自动刷新、自动上拉加载(自动检测列表滚动到底部,而不用手动上拉).
- - 支持通用的刷新监听器 OnRefreshListener 和更详细的滚动监听 OnMultiPurposeListener.
- - 支持自定义回弹动画的插值器,实现各种炫酷的动画效果.
- - 支持设置主题来适配任何场景的App,不会出现炫酷但很尴尬的情况.
- - 支持设置多种滑动方式来适配各种效果的Header和Footer:平移、拉伸、背后固定、顶层固定、全屏
- - 支持内容尺寸自适应 Content-wrap_content
- - 支持继承重写和扩展功能,内部实现没有 private 方法和字段,继承之后都可以重写覆盖
- - 支持越界回弹(Listview、RecyclerView、ScrollView、WebView...View)
-
-## 传送门
-
- - [智能之处](art/md_smart.md)
- - [更新日志](art/md_update.md)
- - [属性方法](art/md_property.md)
- - [博客文章](https://segmentfault.com/a/1190000010066071)
- - [自定义Header](art/md_custom.md)
-
-## Demo
-[下载 APK-Demo](art/app-debug.apk)
-
-
-
-#### 项目演示
- 
-
- 
-
-#### 风格演示
- 
-
-上面这两个是我自己实现的Header,设计来自:[Refresh-your-delivery](https://dribbble.com/shots/2753803-Refresh-your-delivery),[Dropbox-Refresh](https://dribbble.com/shots/3470499-Dropbox-Refresh)
-
-下面的Header是我把github上其它优秀的Header进行的整理和集合还有优化:
-
- 
-
-整理来自:[TwinklingRefreshLayout](https://github.com/lcodecorex/TwinklingRefreshLayout/blob/master/art/gif_recyclerview2.gif),[Pull Down To Refresh](https://dribbble.com/shots/1797373-Pull-Down-To-Refresh)
-
- 
-
-整理来自:[FlyRefresh](https://github.com/race604/FlyRefresh),[ClassicsHeader](#1)
-
- 
-
-整理来自:[Yalantis/Phoenix](https://github.com/Yalantis/Phoenix),[Yalantis/Taurus](https://github.com/Yalantis/Taurus)
-
- 
-
-整理来自:[FunGame/BattleCity](https://github.com/Hitomis/FunGameRefresh),[FunGame/HitBlock](https://github.com/Hitomis/FunGameRefresh)
-
- 
-
-整理来自:[WaveSwipeRefreshLayout](https://github.com/recruit-lifestyle/WaveSwipeRefreshLayout),[MaterialHeader](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html)
-
- 
-
-整理来自:[Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh),[WaterDrop](https://github.com/THEONE10211024/WaterDropListView)
-
-
-看到这么多炫酷的Header,是不是觉得很棒?这时你或许会担心这么多的Header集成在一起,但是平时只会用到一个,是不是要引入很多无用的代码和资源?
-请放心,我已经把刷新布局分成三个包啦,用到的时候自行引用就可以啦!
-
- - SmartRefreshLayout 刷新布局核心实现,自带ClassicsHeader(经典)、BezierRadarHeader(贝塞尔雷达)两个 Header.
- - SmartRefreshHeader 各种Header的集成,除了Layout自带的Header,其它都在这个包中.
- - SmartRefreshFooter 各种Footer的集成,除了Layout自带的Footer,其它都在这个包中.
-
-## 简单用例
-#### 1.在 buld.gradle 中添加依赖
-```
-compile 'com.android.support:appcompat-v7:25.3.1'
-compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.2-alpha-8'
-compile 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.2-alpha-8'//如果使用了特殊的Header
-```
-
-#### 2.在XML布局文件中添加 SmartRefreshLayout
-```xml
-
-
-
-
-```
-
-#### 3.在 Activity 或者 Fragment 中添加代码
-```java
-RefreshLayout refreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
-refreshLayout.setOnRefreshListener(new OnRefreshListener() {
- @Override
- public void onRefresh(RefreshLayout refreshlayout) {
- refreshlayout.finishRefresh(2000);
- }
-});
-refreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {
- @Override
- public void onLoadmore(RefreshLayout refreshlayout) {
- refreshlayout.finishLoadmore(2000);
- }
-});
-```
-
-## 使用指定的 Header 和 Footer
-
-#### 1.方法一 全局设置
-```java
-public class App extends Application {
- public void onCreate() {
- super.onCreate();
- //设置全局的Header构建器
- SmartRefreshLayout.setDefaultRefreshHeaderCreater(new DefaultRefreshHeaderCreater() {
- @Override
- public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
- //指定为经典Header,默认是 贝塞尔雷达Header
- return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);
- }
- });
- //设置全局的Footer构建器
- SmartRefreshLayout.setDefaultRefreshFooterCreater(new DefaultRefreshFooterCreater() {
- @Override
- public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
- //指定为经典Footer,默认是 BallPulseFooter
- return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Translate);
- }
- });
- }
-}
-```
-
-注意:方法一 设置的Header和Footer的优先级是最低的,如果同时还使用了方法二、三,将会被其它方法取代
-
-
-#### 2.方法二 XML布局文件指定
-```xml
-
-
-
-
-
-
-
-```
-
-注意:方法二 XML设置的Header和Footer的优先级是中等的,会被方法三覆盖。而且使用本方法的时候,Android Studio 会有预览效果,如下图:
-
-
-
-不过不用担心,只是预览效果,运行的时候只有下拉才会出现~
-
-#### 3.方法三 Java代码设置
-```java
-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));
-```
-
-## 混淆
-
-SmartRefreshLayout 没有使用到:序列化、反序列化、JNI、反射,所以并不需要添加混淆过滤代码,并且已经混淆测试通过,如果你在项目的使用中混淆之后出现问题,请及时通知我。
-
-## 赞赏
-
-如果你喜欢 SmartRefreshLayout 的设计,感觉 SmartRefreshLayout 帮助到了你,可以点右上角 "Star" 支持一下 谢谢! ^_^
-你也还可以扫描下面的二维码~ 请作者喝一杯咖啡。
-
- 
-
-如果在捐赠留言中备注名称,将会被记录到列表中~ 如果你也是github开源作者,捐赠时可以留下github项目地址或者个人主页地址,链接将会被添加到列表中起到互相推广的作用
-[捐赠列表](art/md_donationlist.md)
-
-## 讨论
-
-
-
-
-
-
-
-
-
-
-### QQ讨论群 - 602537182
-#### 进群须知
-
-
-
-
-
-
-本群专为 【Android智能下拉刷新框架-SmartRefreshLayout】开设,请不要讨论安卓和下拉刷新之外的内容。本群中后期会改为收费咨询群,并再开启免费讨论群,还没进群的童鞋赶紧~
-#### 温馨提示
-加入群的答案在本文档中可以找到~
-
-## 感谢
-[SwipeRefreshLayout](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html)
-[TwinklingRefreshLayout](https://github.com/lcodecorex/TwinklingRefreshLayout)
-[android-Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh)
-
-License
--------
-
- Copyright 2017 scwang90
-
- 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.
\ No newline at end of file
diff --git a/README_EN.md b/README_EN.md
new file mode 100644
index 00000000..accfcd69
--- /dev/null
+++ b/README_EN.md
@@ -0,0 +1,308 @@
+# SmartRefreshLayout
+
+[](https://www.apache.org/licenses/LICENSE-2.0)
+[](https://android-arsenal.com/details/1/6001)
+[](https://bintray.com/scwang90/maven/refresh-layout-kernel/_latestVersion)
+[](https://android-arsenal.com/api?level=12)
+[](http://www.methodscount.com/?lib=com.scwang.smartrefresh%3ASmartRefreshLayout%3A1.1.0)
+
+## English | [中文](README.md)
+
+SmartRefreshLayout's goal is to build a strong, stable and mature pull-down refresh layout framework, and to integrate all kinds of cool, diverse, practical and beautiful Headers and Footers.
+
+## Features
+
+ - Support multi-touch.
+ - Support multi-layered nested view structures.
+ - Support all the Views(AbsListView、RecyclerView、WebView....View)
+ - Support customizing Headers and Footers, and has integrated a lot of cool Headers and Footers.
+ - Support synchronous scrolling with ListView and NestedScrolling with CoordinatorLayout.
+ - Support automatically refresh, automatically pull-up loading (automatically detect list inertance and scroll to the bottom without having to manually pull).
+ - Support customizing rebound animation interpolator, to achieve a variety of cool animation effects.
+ - Support setting a theme to fit any scene of App, it won't appear a cool but very awkward situation.
+ - Support setting a variety of transformations (Translation, stretching, behind fixed, top fixed, full screen view) for Headers and Footers.
+ - Support rewrite and extension, internal implementation without private methods and fields.
+ - Support automatically cross-border rebound for all rolling Views (ListView、RecyclerView、ScrollView、WebView...View).
+ - Support the interchange of Header and Footer
+ - Support AndroidX
+ - Support [HorizontalRefresh](https://github.com/scwang90/SmartRefreshHorizontal)
+
+## Gateway
+
+ - [Smart place](art/md_smart.md)
+ - [Update log](art/md_update.md)
+ - [Attribute method](art/md_property.md)
+ - [Blog posts](https://segmentfault.com/a/1190000010066071)
+ - [Download the source code](https://github.com/scwang90/SmartRefreshLayout/releases)
+ - [Multi-touch](art/md_multitouch.md)
+## Demo
+[Download APK-Demo](art/app-debug.apk)
+
+
+
+#### Practical
+|Weibo|FeedList|
+|:---:|:---:|
+|||
+
+|Repast|Profile|
+|:---:|:---:|
+|||
+
+#### Style
+
+|Style|Delivery|DropBox|
+|:---:|:---:|:---:|
+|Demo|||
+|Design|[Refresh-your-delivery](https://dribbble.com/shots/2753803-Refresh-your-delivery)|[DropBox-Refresh](https://dribbble.com/shots/3470499-DropBox-Refresh)|
+
+The two above headers are implemented by myself, The following headers are collected and optimized from excellent Headers on github
+
+|Style|BezierRadar|BezierCircle|
+|:---:|:---:|:---:|
+|Demo|||
+|From|[TwinklingRefreshLayout](https://github.com/lcodecorex/TwinklingRefreshLayout/blob/master/art/gif_recyclerview2.gif)|[Pull Down To Refresh](https://dribbble.com/shots/1797373-Pull-Down-To-Refresh)|
+
+|Style|FlyRefresh|Classics|
+|:---:|:---:|:---:|
+|Demo|||
+|From|[FlyRefresh](https://github.com/race604/FlyRefresh)|[ClassicsHeader](#1)|
+
+|Style|Phoenix|Taurus|
+|:---:|:---:|:---:|
+|Demo|||
+|From|[Yalantis/Phoenix](https://github.com/Yalantis/Phoenix)|[Yalantis/Taurus](https://github.com/Yalantis/Taurus)
+
+|Style|BattleCity|HitBlock|
+|:---:|:---:|:---:|
+|Demo|||
+|From|[FunGame/BattleCity](https://github.com/Hitomis/FunGameRefresh)|[FunGame/HitBlock](https://github.com/Hitomis/FunGameRefresh)
+
+|Style|WaveSwipe|Material|
+|:---:|:---:|:---:|
+|Demo|||
+|From|[WaveSwipeRefreshLayout](https://github.com/recruit-lifestyle/WaveSwipeRefreshLayout)|[MaterialHeader](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html)
+
+|Style|StoreHouse|WaterDrop|
+|:---:|:---:|:---:|
+|Demo|||
+|From|[Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh)|[WaterDrop](https://github.com/THEONE10211024/WaterDropListView)
+
+
+See so many cool headers, is not it feel great? At this point you may be worried that so many headers together, but usually only use one, is not to introduce a lot of useless code and resources?
+Please rest assured that I have divided it into eight packages, when used to reference their own it!
+
+ - refresh-layout-kernel core
+ - refresh-header-classics ClassicsHeader
+ - refresh-header-radar BezierRadarHeader
+ - refresh-header-falsify FalsifyHeader
+ - refresh-header-material MaterialHeader
+ - refresh-header-two-level TwoLevelHeader
+ - refresh-footer-ball BallPulseFooter
+ - refresh-footer-classics ClassicsFooter
+
+## Usage
+#### 1.Add a gradle dependency.
+
+V 2.x changed the package name relative to 1.x, such as `com.scwang.smartrefresh` to `com.scwang.smart.refresh`.
+It is suggested that in the new project, if the old project is upgraded,
+the package name should be replaced, which is more troublesome.
+But the main change is to subcontract SmartRefreshLayout to reduce unnecessary dependencies and avoid code redundancy.
+However, there is no subcontracting to SmartRefreshHeader.
+There are more than ten headers in it.
+It is recommended that you copy the source code into the project whenever you need to use it.
+
+```
+// Note: There will be no default Header and Footer after subcontracting. It needs to be added manually!
+implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3' //core
+implementation 'com.scwang.smart:refresh-header-classics:2.0.3' //ClassicsHeader
+implementation 'com.scwang.smart:refresh-header-radar:2.0.3' //BezierRadarHeader
+implementation 'com.scwang.smart:refresh-header-falsify:2.0.3' //FalsifyHeader
+implementation 'com.scwang.smart:refresh-header-material:2.0.3' //MaterialHeader
+implementation 'com.scwang.smart:refresh-header-two-level:2.0.3' //TwoLevelHeader
+implementation 'com.scwang.smart:refresh-footer-ball:2.0.3' //BallPulseFooter
+implementation 'com.scwang.smart:refresh-footer-classics:2.0.3' //ClassicsFooter
+
+```
+
+
+
+
+
+If you use AndroidX, add it to gradle.properties
+
+```
+android.useAndroidX=true
+android.enableJetifier=true
+```
+
+#### 2.Add SmartRefreshLayout in the layout xml.
+```xml
+
+
+
+
+
+
+```
+
+#### 3.Coding in the Activity or Fragment.
+```java
+RefreshLayout refreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+refreshLayout.setRefreshHeader(new ClassicsHeader(this));
+refreshLayout.setRefreshFooter(new ClassicsFooter(this));
+refreshLayout.setOnRefreshListener(new OnRefreshListener() {
+ @Override
+ public void onRefresh(RefreshLayout refreshlayout) {
+ refreshlayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败
+ }
+});
+refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
+ @Override
+ public void onLoadMore(RefreshLayout refreshlayout) {
+ refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
+ }
+});
+```
+
+## Use the specified Header and Footer
+
+#### 1.Global settings
+```java
+public class App extends Application {
+ public void onCreate() {
+ super.onCreate();
+ SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
+ @Override
+ public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
+ return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);
+ }
+ });
+ SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
+ @Override
+ public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
+ return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Translate);
+ }
+ });
+ }
+}
+```
+
+Note: this method is the lowest priority.
+
+
+#### 2.Specified in the XML layout file
+```xml
+
+
+
+
+
+
+
+```
+
+Note: this method of priority is medium。When using this method, the Android Studio will have preview effect, the following figure:
+
+
+
+But don't worry, just a preview effect, run only the drop-down will appear.
+
+#### 3.Specified in the java code
+```java
+final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
+refreshLayout.setRefreshHeader(new MaterialHeader(this).setShowBezierWave(true));
+refreshLayout.setRefreshFooter(new BallPulseFooter(this).setSpinnerStyle(SpinnerStyle.Scale));
+```
+
+## ProGuard
+
+This library does't use serialization and deserialization, JNI, reflection, so there is no need to add confusing filtering code, and it has been confusing tests pass, if you after the confusion in the use of the project appear problem, please inform me.
+
+## Donate
+
+If you like this library's design, feel it help to you, you can point the upper right corner "Star" support Thank you! ^ _ ^
+You can also click the PayPal below to ask the author to drink a cup of coffee.
+
+[](https://www.paypal.me/scwang90)
+
+If in the donation message note name, it will be record to the list
+[Donation list](art/md_donationlist.md)
+
+#### blogroll
+[github/Loror](https://github.com/Loror)
+[github/faith-hb/WidgetCase](https://github.com/faith-hb/WidgetCase)
+[github/Bamboy120315/Freedom](https://github.com/Bamboy120315/Freedom)
+[github/TommyLemon/APIJSON](https://github.com/TommyLemon/APIJSON)
+[github/dengyuhan](https://github.com/dengyuhan)
+[github/zrp2017](https://github.com/zrp2017)
+[github/fly803/BaseProject](https://github.com/fly803/BaseProject)
+[github/razerdp](https://github.com/razerdp)
+[github/SuperChenC/s-mvp](https://github.com/SuperChenC/s-mvp)
+[github/KingJA/LoadSir](https://github.com/KingJA/LoadSir)
+[github/jianshijiuyou](https://github.com/jianshijiuyou)
+[github/zxy198717](https://github.com/zxy198717)
+[github/addappcn](https://github.com/addappcn)
+[github/RainliFu](https://github.com/RainliFu)
+[github/sugarya](https://github.com/sugarya)
+[github/stormzhang](https://github.com/stormzhang)
+
+## Discuss
+
+Contact me: scwang90@hotmail.com
+
+## Thanks
+[SwipeRefreshLayout](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html)
+[Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh)
+[TwinklingRefreshLayout](https://github.com/lcodecorex/TwinklingRefreshLayout)
+[BeautifulRefreshLayout](https://github.com/android-cjj/BeautifulRefreshLayout)
+
+## Other Works
+[MultiWaveHeader](https://github.com/scwang90/MultiWaveHeader)
+[SmartRefreshHorizontal](https://github.com/scwang90/SmartRefreshHorizontal)
+
+License
+-------
+
+ Copyright 2017 scwang90
+
+ 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.
diff --git a/app/build.gradle b/app/build.gradle
index 4c497cbf..a1c7abce 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,12 +1,14 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 25
- buildToolsVersion "25.0.3"
+
+ compileSdkVersion 28
+ buildToolsVersion '28.0.3'
+
defaultConfig {
- applicationId "com.scwang.refreshlayout"
- minSdkVersion 15
- targetSdkVersion 25
+ applicationId "com.scwang.refreshlayout.app"
+ minSdkVersion 16
+ targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -14,6 +16,7 @@ android {
renderscriptTargetApi 25
renderscriptSupportModeEnabled true // Enable RS support
+
}
signingConfigs {
debug {
@@ -23,42 +26,83 @@ android {
keyPassword "android"
}
}
+
buildTypes {
+ debug {
+ signingConfig = signingConfigs.debug
+ }
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig = signingConfigs.debug
}
}
+
lintOptions {
abortOnError false
}
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
}
+
+repositories {
+ maven { url "https://jitpack.io" }
+}
dependencies {
- compile fileTree(include: ['*.jar'], dir: 'libs')
- androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
+ implementation fileTree(include: ['*.jar'], dir: 'libs')
+ implementation 'com.android.support:support-v4:28.0.0'
+ androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
- compile project(':refresh-footer')
- compile project(':refresh-header')
- compile project(':refresh-layout')
- // compile 'com.android.support:support-v4:25.3.1'
-// compile 'com.android.support:support-vector-drawable:25.3.1'
-// compile 'com.android.support:recyclerview-v7:25.3.1'
-// compile 'com.android.support.constraint:constraint-layout:1.0.2'
- compile 'com.android.support:appcompat-v7:25.3.1'
- compile 'com.android.support:cardview-v7:25.3.1'
- compile 'com.android.support:design:25.3.1'
- compile 'com.flyco.roundview:FlycoRoundView_Lib:1.1.4@aar'
- compile 'com.github.mmin18:realtimeblurview:1.0.6'
- compile 'cn.carbs.android:AvatarImageView:1.0.4'
- compile 'de.hdodenhof:circleimageview:2.1.0'
- compile 'jp.wasabeef:recyclerview-animators:2.2.6'
- compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.3'
- compile 'in.srain.cube:ultra-ptr:1.0.11'
- compile 'com.github.cpoopc:scrollablelayoutlib:1.0.1'
-// compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.2-alpha-6'
-// compile 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.2-alpha-6'
- testCompile 'junit:junit:4.12'
+
+ debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
+ releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
+ testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
+
+ implementation project(':refresh-footer')
+ implementation project(':refresh-header')
+ implementation project(':refresh-layout')
+ implementation project(':refresh-drawable-path')
+
+ implementation project(':refresh-layout-kernel')
+ implementation project(':refresh-header-classics')
+ implementation project(':refresh-header-radar')
+ implementation project(':refresh-header-falsify')
+ implementation project(':refresh-header-material')
+ implementation project(':refresh-header-two-level')
+ implementation project(':refresh-footer-ball')
+
+// implementation 'com.scwang.smart:refresh-layout-kernel:2.0.0-alpha-1' //核心必须依赖
+// implementation 'com.scwang.smart:refresh-header-classics:2.0.0-alpha-1' //经典刷新头
+// implementation 'com.scwang.smart:refresh-header-radar:2.0.0-alpha-1' //雷达刷新头
+// implementation 'com.scwang.smart:refresh-header-falsify:2.0.0-alpha-1' //虚拟刷新头
+// implementation 'com.scwang.smart:refresh-header-material:2.0.0-alpha-1' //谷歌刷新头
+// implementation 'com.scwang.smart:refresh-header-two-level:2.0.0-alpha-1' //二级刷新头
+// implementation 'com.scwang.smart:refresh-footer-ball:2.0.0-alpha-1' //球脉冲加载
+// implementation 'com.scwang.smart:refresh-footer-classics:2.0.0-alpha-1' //经典加载
+
+
+ implementation 'com.android.support:design:28.0.0'
+ implementation 'com.android.support:cardview-v7:28.0.0'
+ implementation 'com.android.support.constraint:constraint-layout:1.1.3'
+
+ implementation 'com.flyco.roundview:FlycoRoundView_Lib:1.1.4@aar'
+ implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50'
+ implementation 'com.github.czy1121:loadinglayout:1.0.1'
+ implementation 'com.github.mmin18:realtimeblurview:1.0.6'
+ implementation 'com.google.code.gson:gson:2.8.5'
+ implementation 'com.google.android:flexbox:1.0.0'
+ implementation 'com.wang.avi:library:2.1.3'
+ implementation 'com.youth.banner:banner:1.4.10' //最新版本
+ implementation 'de.hdodenhof:circleimageview:2.2.0'
+ implementation 'jp.wasabeef:recyclerview-animators:2.2.6'
+ implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.3'
+ testImplementation 'junit:junit:4.12'
+
+ implementation 'com.github.bumptech.glide:glide:4.9.0'
+ annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}
diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
index 1ccdbfb6..a0a48efb 100644
--- a/app/proguard-rules.pro
+++ b/app/proguard-rules.pro
@@ -31,4 +31,9 @@
-keepclassmembers class android.support.v8.renderscript.RenderScript {
native *** rsn*(...);
native *** n*(...);
-}
\ No newline at end of file
+}
+
+-keep class com.wang.avi.** { *; }
+-keep class com.wang.avi.indicators.** { *; }
+
+-keep class com.scwang.refreshlayout.activity.practice.BannerPracticeActivity$Movie {*;}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 42a22688..c9292d84 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,8 +1,20 @@
+
+
+
+
+
+
+
+
+
+
-
+
-
+
+
+
+
+
diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png
index f34d7e7f..9af9a7a2 100644
Binary files a/app/src/main/ic_launcher-web.png and b/app/src/main/ic_launcher-web.png differ
diff --git a/app/src/main/java/com/scwang/refreshlayout/App.java b/app/src/main/java/com/scwang/refreshlayout/App.java
index 477334e4..6cd64651 100644
--- a/app/src/main/java/com/scwang/refreshlayout/App.java
+++ b/app/src/main/java/com/scwang/refreshlayout/App.java
@@ -3,30 +3,70 @@
import android.app.Application;
import android.content.Context;
import android.support.annotation.NonNull;
+import android.support.v7.app.AppCompatDelegate;
+import com.scwang.refreshlayout.util.DynamicTimeFormat;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
-import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreater;
+import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator;
+import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator;
+import com.scwang.smartrefresh.layout.api.DefaultRefreshInitializer;
+import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
-import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
+import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
+import com.squareup.leakcanary.LeakCanary;
/**
*
- * Created by SCWANG on 2017/6/11.
+ * Created by scwang on 2017/6/11.
*/
-
public class App extends Application {
- @Override
- public void onCreate() {
- super.onCreate();
- SmartRefreshLayout.setDefaultRefreshHeaderCreater(new DefaultRefreshHeaderCreater() {
+ static {
+ //启用矢量图兼容
+ AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
+ //设置全局默认配置(优先级最低,会被其他设置覆盖)
+ SmartRefreshLayout.setDefaultRefreshInitializer(new DefaultRefreshInitializer() {
+ @Override
+ public void initialize(@NonNull Context context, @NonNull RefreshLayout layout) {
+ //全局设置(优先级最低)
+ layout.setEnableAutoLoadMore(true);
+ layout.setEnableOverScrollDrag(false);
+ layout.setEnableOverScrollBounce(true);
+ layout.setEnableLoadMoreWhenContentNotFull(true);
+ layout.setEnableScrollContentWhenRefreshed(true);
+ layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);
+ layout.setFooterMaxDragRate(4.0F);
+ layout.setFooterHeight(45);
+ }
+ });
+ SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
+ @NonNull
+ @Override
+ public RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull RefreshLayout layout) {
+ //全局设置主题颜色(优先级第二低,可以覆盖 DefaultRefreshInitializer 的配置,与下面的ClassicsHeader绑定)
+ layout.setEnableHeaderTranslationContent(true);
+ return new ClassicsHeader(context).setTimeFormat(new DynamicTimeFormat("更新于 %s"));
+ }
+ });
+ SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
@NonNull
@Override
- public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
- return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);
+ public RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull RefreshLayout layout) {
+ return new ClassicsFooter(context);
}
});
}
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ if (LeakCanary.isInAnalyzerProcess(this)) {
+ // This process is dedicated to LeakCanary for heap analysis.
+ // You should not init your app in this process.
+ return;
+ }
+ LeakCanary.install(this);
+ }
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/ExperimentActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/ExperimentActivity.java
deleted file mode 100644
index 8c52c277..00000000
--- a/app/src/main/java/com/scwang/refreshlayout/activity/ExperimentActivity.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.scwang.refreshlayout.activity;
-
-import android.os.Bundle;
-import android.support.v7.app.AppCompatActivity;
-
-import com.scwang.refreshlayout.R;
-
-public class ExperimentActivity extends AppCompatActivity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_experiment);
- }
-}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/FragmentActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/FragmentActivity.java
new file mode 100644
index 00000000..2a5346c9
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/FragmentActivity.java
@@ -0,0 +1,98 @@
+package com.scwang.refreshlayout.activity;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentTransaction;
+import android.support.v7.app.AppCompatActivity;
+import android.widget.FrameLayout;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static android.R.id.widget_frame;
+
+/**
+ * Fragment 容器页面
+ * Created by scwang on 2017/10/10.
+ */
+@SuppressWarnings({"UnusedParameters", "unused"})
+public class FragmentActivity extends AppCompatActivity {
+
+ protected static final String EXTRA_FRAGMENT = "EXTRA_FRAGMENT";
+ private Fragment mFragment;
+
+ //
+ private static void start(Context context, Class> clazz, Object... params){
+ if (context != null && Fragment.class.isAssignableFrom(clazz)) {
+ context.startActivity(newIntent(clazz, context, params));
+ }
+ }
+
+ public static void start(Activity activity, Class> clazz, Object... params){
+ start((Context) activity, clazz, params);
+ }
+
+ public static void start(Fragment fragment, Class> clazz, Object... params){
+ if (fragment != null) {
+ start((Context) fragment.getActivity(), clazz, params);
+ }
+ }
+
+ private static Intent newIntent(Class> clazz, Context context, Object... params) {
+ Intent intent = new Intent(context, FragmentActivity.class);
+ intent.putExtra(EXTRA_FRAGMENT, clazz.getName());
+ return intent;
+ }
+ //
+
+ //
+
+ //@InjectExtra(value = EXTRA_FRAGMENT,remark = "Fragment类名")
+ protected String mFragmentClazz = null;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mFragmentClazz = getIntent().getStringExtra(EXTRA_FRAGMENT);
+ FrameLayout frameLayout = new FrameLayout(this);
+ frameLayout.setId(widget_frame);
+ setContentView(frameLayout);
+ replaceFragment();
+ }
+
+ protected void replaceFragment() {
+ try {
+ mFragment = (Fragment) getFragmentClass().newInstance();
+ FragmentManager manager = getSupportFragmentManager();
+ FragmentTransaction transaction = manager.beginTransaction();
+ transaction.replace(widget_frame, mFragment);
+ transaction.commit();
+ } catch (Exception e) {
+ e.printStackTrace();
+// AfExceptionHandler.handle(e, "AfFragmentActivity Fragment 类型错误:" + mFragmentClazz);
+ }
+ }
+
+ //
+ private static Map typeCache = new HashMap<>();
+ private Class> getFragmentClass() throws ClassNotFoundException {
+ Class type = typeCache.get(mFragmentClazz);
+ if (type == null) {
+ typeCache.put(mFragmentClazz, type = Class.forName(mFragmentClazz));
+ }
+ return type;
+ }
+ //
+
+ public Fragment getFragment() {
+ return mFragment;
+ }
+ //
+
+
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/IndexMainActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/IndexMainActivity.java
index 7b92995a..70ce8d49 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/IndexMainActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/IndexMainActivity.java
@@ -1,5 +1,6 @@
package com.scwang.refreshlayout.activity;
+import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
@@ -12,21 +13,24 @@
import android.view.MenuItem;
import com.scwang.refreshlayout.R;
-import com.scwang.refreshlayout.fragment.RefreshPractiveFragment;
-import com.scwang.refreshlayout.fragment.RefreshStylesFragment;
-import com.scwang.refreshlayout.fragment.RefreshUsingFragment;
+import com.scwang.refreshlayout.fragment.index.RefreshExampleFragment;
+import com.scwang.refreshlayout.fragment.index.RefreshPracticeFragment;
+import com.scwang.refreshlayout.fragment.index.RefreshStylesFragment;
+import com.scwang.refreshlayout.util.StatusBarUtil;
+
+import java.lang.reflect.Field;
public class IndexMainActivity extends AppCompatActivity implements OnNavigationItemSelectedListener {
private enum TabFragment {
- practice(R.id.navigation_practice,RefreshPractiveFragment.class),
- styles(R.id.navigation_style,RefreshStylesFragment.class),
- using(R.id.navigation_using,RefreshUsingFragment.class)
+ practice(R.id.navigation_practice, RefreshPracticeFragment.class),
+ styles(R.id.navigation_style, RefreshStylesFragment.class),
+ using(R.id.navigation_example, RefreshExampleFragment.class),
;
+ private Fragment fragment;
private final int menuId;
private final Class extends Fragment> clazz;
- private Fragment fragment;
TabFragment(@IdRes int menuId, Class extends Fragment> clazz) {
this.menuId = menuId;
@@ -62,35 +66,45 @@ public static void onDestroy() {
}
}
- ViewPager mViewPager;
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_index_main);
- final BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
+ final BottomNavigationView navigation = findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(this);
- mViewPager = (ViewPager) findViewById(R.id.viewPager);
- mViewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
- @Override
- public Fragment getItem(int position) {
- return TabFragment.values()[position].fragment();
- }
+ ViewPager viewPager = findViewById(R.id.content);
+ viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
@Override
public int getCount() {
return TabFragment.values().length;
}
+ @Override
+ public Fragment getItem(int position) {
+ return TabFragment.values()[position].fragment();
+ }
});
- mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
+ viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
@Override
public void onPageSelected(int position) {
navigation.setSelectedItemId(TabFragment.values()[position].menuId);
}
});
- navigation.setSelectedItemId(R.id.navigation_style);
+ //状态栏透明和间距处理
+ StatusBarUtil.immersive(this, 0xff000000, 0.1f);
+
+ try {
+ /*重置动画倍率-防止部分模拟器对动画速度的控制*/
+ Field field = ValueAnimator.class.getDeclaredField("sDurationScale");
+ field.setAccessible(true);
+ field.set(ValueAnimator.class, 1);
+ } catch (NoSuchFieldException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
}
@Override
@@ -101,11 +115,13 @@ protected void onDestroy() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
+ ((ViewPager)findViewById(R.id.content)).setCurrentItem(TabFragment.from(item.getItemId()).ordinal());
// getSupportFragmentManager()
// .beginTransaction()
+// .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
// .replace(R.id.content,TabFragment.from(item.getItemId()).fragment())
// .commit();
- mViewPager.setCurrentItem(TabFragment.from(item.getItemId()).ordinal());
return true;
}
+
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/using/AssignCodeUsingActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/example/AssignCodeExampleActivity.java
similarity index 60%
rename from app/src/main/java/com/scwang/refreshlayout/activity/using/AssignCodeUsingActivity.java
rename to app/src/main/java/com/scwang/refreshlayout/activity/example/AssignCodeExampleActivity.java
index 02328190..26144f84 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/using/AssignCodeUsingActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/example/AssignCodeExampleActivity.java
@@ -1,6 +1,7 @@
-package com.scwang.refreshlayout.activity.using;
+package com.scwang.refreshlayout.activity.example;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
@@ -16,16 +17,16 @@
/**
* 在Java代码中指定Header和Footer
*/
-public class AssignCodeUsingActivity extends AppCompatActivity {
+public class AssignCodeExampleActivity extends AppCompatActivity {
- private static boolean isFirstEnter = true;
+ private static boolean isFirstEnter = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_using_assign_code);
+ setContentView(R.layout.activity_example_assign_code);
- final Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
+ final Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -34,13 +35,13 @@ public void onClick(View v) {
});
- final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
+ final 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.setRefreshFooter(new BallPulseFooter(this).setSpinnerStyle(SpinnerStyle.FixedBehind));
- /**
+ /*
* 以下代码仅仅为了演示效果而已,不是必须的
*/
//设置主题颜色
@@ -48,17 +49,25 @@ public void onClick(View v) {
if (isFirstEnter) {
isFirstEnter = false;
- //触发上啦加载
- refreshLayout.autoLoadmore();
+// //触发上拉加载
+// mRefreshLayout.autoLoadMore(250, 250, 1.5f);
//通过多功能监听接口实现 在第一次加载完成之后 自动刷新
refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener(){
@Override
- public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, RefreshState newState) {
- if (oldState == RefreshState.LoadingFinish && newState == RefreshState.None) {
+ 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);
+ }
});
}
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/AssignDefaultExampleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/example/AssignDefaultExampleActivity.java
new file mode 100644
index 00000000..6df3964c
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/example/AssignDefaultExampleActivity.java
@@ -0,0 +1,123 @@
+package com.scwang.refreshlayout.activity.example;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.view.View;
+
+import com.scwang.refreshlayout.R;
+import com.scwang.refreshlayout.util.DynamicTimeFormat;
+import com.scwang.smartrefresh.layout.SmartRefreshLayout;
+import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator;
+import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator;
+import com.scwang.smartrefresh.layout.api.RefreshFooter;
+import com.scwang.smartrefresh.layout.api.RefreshHeader;
+import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import com.scwang.smartrefresh.layout.constant.RefreshState;
+import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
+import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
+import com.scwang.smartrefresh.layout.header.ClassicsHeader;
+import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;
+
+/**
+ * 全局指定默认的Header和Footer
+ */
+public class AssignDefaultExampleActivity extends AppCompatActivity {
+
+ private static boolean isFirstEnter = true;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ install();
+
+ setContentView(R.layout.activity_example_assign_default);
+
+ final Toolbar toolbar = findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ finish();
+ }
+ });
+
+ /*
+ * 以下代码仅仅为了演示效果而已,不是必须的
+ * 关键代码在构造函数中
+ */
+ final RefreshLayout refreshLayout = findViewById(R.id.refreshLayout);
+ if (isFirstEnter) {
+ isFirstEnter = false;
+// //触发上拉加载
+// mRefreshLayout.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);
+ }
+ });
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ restore();
+ }
+
+ /*
+ * 关键代码,需要在布局生成之前设置,建议代码放在 Application 中
+ */
+ private static void install() {
+ //设置全局的Header构建器
+ SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
+ @NonNull
+ @Override
+ public RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull RefreshLayout layout) {
+ ClassicsHeader header = new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.FixedBehind);
+ header.setPrimaryColorId(R.color.colorPrimary);
+ header.setAccentColorId(android.R.color.white);
+ return header;//指定为经典Header,默认是 贝塞尔雷达Header
+ }
+ });
+ //设置全局的Footer构建器
+ SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
+ @NonNull
+ @Override
+ public RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull RefreshLayout layout) {
+ layout.setEnableLoadMoreWhenContentNotFull(true);//内容不满一页时候启用加载更多
+ ClassicsFooter footer = new ClassicsFooter(context);
+ footer.setBackgroundResource(android.R.color.white);
+ footer.setSpinnerStyle(SpinnerStyle.FixedBehind);//设置为拉伸模式
+ return footer;//指定为经典Footer,默认是 BallPulseFooter
+ }
+ });
+ }
+
+ //还原默认 Header
+ private static void restore() {
+ SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
+ @NonNull
+ @Override
+ public RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull RefreshLayout layout) {
+ layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);//全局设置主题颜色
+ return new ClassicsHeader(context).setTimeFormat(new DynamicTimeFormat("更新于 %s"));
+ }
+ });
+ }
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/using/AssignXmlUsingActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/example/AssignXmlExampleActivity.java
similarity index 54%
rename from app/src/main/java/com/scwang/refreshlayout/activity/using/AssignXmlUsingActivity.java
rename to app/src/main/java/com/scwang/refreshlayout/activity/example/AssignXmlExampleActivity.java
index be125570..f7b70e71 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/using/AssignXmlUsingActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/example/AssignXmlExampleActivity.java
@@ -1,6 +1,7 @@
-package com.scwang.refreshlayout.activity.using;
+package com.scwang.refreshlayout.activity.example;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
@@ -13,16 +14,16 @@
/**
* 在XML中指定Header和Footer
*/
-public class AssignXmlUsingActivity extends AppCompatActivity {
+public class AssignXmlExampleActivity extends AppCompatActivity {
private static boolean isFirstEnter = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_using_assign_xml);
+ setContentView(R.layout.activity_example_assign_xml);
- final Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
+ final Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -30,25 +31,32 @@ public void onClick(View v) {
}
});
-
- /**
+ /*
* 以下代码仅仅为了演示效果而已,不是必须的
- * 关键代码在 activity_using_assign_xml 中
+ * 关键代码在 activity_example_assign_xml 中
*/
- final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
+ final RefreshLayout refreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
- //触发上啦加载
- refreshLayout.autoLoadmore();
+// //触发上拉加载
+// mRefreshLayout.autoLoadMore(250, 250, 1.5f);
//通过多功能监听接口实现 在第一次加载完成之后 自动刷新
refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener(){
@Override
- public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, RefreshState newState) {
- if (oldState == RefreshState.LoadingFinish && newState == RefreshState.None) {
+ 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);
+ }
});
}
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/BasicExampleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/example/BasicExampleActivity.java
new file mode 100644
index 00000000..aa5ceb2d
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/example/BasicExampleActivity.java
@@ -0,0 +1,170 @@
+package com.scwang.refreshlayout.activity.example;
+
+import android.os.Bundle;
+import android.support.design.widget.BottomSheetDialog;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.Toolbar;
+import android.view.View;
+import android.widget.AbsListView;
+import android.widget.ListView;
+import android.widget.Toast;
+
+import com.scwang.refreshlayout.R;
+import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
+import com.scwang.refreshlayout.adapter.SmartViewHolder;
+import com.scwang.smartrefresh.layout.api.RefreshFooter;
+import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Random;
+
+import ezy.ui.layout.LoadingLayout;
+
+import static android.R.layout.simple_list_item_2;
+
+/**
+ * 基本的功能使用
+ */
+public class BasicExampleActivity extends AppCompatActivity {
+
+
+ private Random random = new Random();
+ private BaseRecyclerAdapter mAdapter;
+ private LoadingLayout mLoadingLayout;
+ private com.scwang.smartrefresh.layout.api.RefreshLayout mRefreshLayout;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_example_basic);
+
+ final Toolbar toolbar = findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(v -> finish());
+
+ ListView listView = findViewById(R.id.listView);
+ listView.setAdapter(mAdapter = new BaseRecyclerAdapter(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);
+ }
+ });
+ //todo SCROLL_STATE_IDLE
+ listView.setOnScrollListener(new AbsListView.OnScrollListener() {
+ int SCROLL_STATE_IDLE = 0;
+ int SCROLL_STATE_TOUCH_SCROLL = 1;
+ int SCROLL_STATE_FLING = 2;
+ @Override
+ public void onScrollStateChanged(AbsListView view, int scrollState) {
+ if (scrollState == SCROLL_STATE_IDLE) {
+ System.out.println("SCROLL_STATE_IDLE");
+ } else if (scrollState == SCROLL_STATE_TOUCH_SCROLL) {
+ System.out.println("SCROLL_STATE_TOUCH_SCROLL");
+ } else if (scrollState == SCROLL_STATE_FLING) {
+ System.out.println("SCROLL_STATE_FLING");
+ }
+ }
+ @Override
+ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
+
+ }
+ });
+
+ mLoadingLayout = findViewById(R.id.loading);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
+ mRefreshLayout.setEnableAutoLoadMore(true);//开启自动加载功能(非必须)
+ mRefreshLayout.setOnRefreshListener(this::refresh);
+ mRefreshLayout.setOnLoadMoreListener(this::loadMore);
+ mLoadingLayout.setRetryListener(v -> {
+ mLoadingLayout.showContent();
+ mRefreshLayout.autoRefresh();
+ });
+
+ //触发自动刷新
+ mLoadingLayout.showContent();
+ mRefreshLayout.autoRefresh();
+ //item 点击测试
+ mAdapter.setOnItemClickListener((parent, view, position, id) -> {
+ BottomSheetDialog dialog=new BottomSheetDialog(BasicExampleActivity.this);
+ View dialogView = View.inflate(getBaseContext(), R.layout.activity_example_basic, null);
+ com.scwang.smartrefresh.layout.api.RefreshLayout refreshLayout1 = dialogView.findViewById(R.id.refreshLayout);
+ RecyclerView recyclerView = new RecyclerView(getBaseContext());
+ recyclerView.setLayoutManager(new LinearLayoutManager(getBaseContext()));
+ recyclerView.setAdapter(mAdapter);
+ refreshLayout1.setEnableRefresh(false);
+ refreshLayout1.setEnableNestedScroll(false);
+ refreshLayout1.setRefreshContent(recyclerView);
+ dialog.setContentView(dialogView);
+ dialog.show();
+ });
+
+ //点击测试
+ RefreshFooter footer = mRefreshLayout.getRefreshFooter();
+ if (footer instanceof com.scwang.smartrefresh.layout.footer.ClassicsFooter) {
+ mRefreshLayout.getRefreshFooter().getView().findViewById(ClassicsFooter.ID_TEXT_TITLE).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Toast.makeText(getBaseContext(), "点击测试", Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+ }
+
+ private void loadMore(com.scwang.smartrefresh.layout.api.RefreshLayout layout) {
+ layout.getLayout().postDelayed(() -> {
+ if (random.nextBoolean()) {
+ //如果刷新成功
+ mAdapter.loadMore(initData(10));
+ if (mAdapter.getItemCount() <= 30) {
+ //还有多的数据
+ layout.finishLoadMore();
+ } else {
+ //没有更多数据(上拉加载功能将显示没有更多数据)
+ Toast.makeText(getApplication(), "数据全部加载完毕", Toast.LENGTH_SHORT).show();
+ layout.finishLoadMoreWithNoMoreData();//将不会再次触发加载更多事件
+ }
+ } else {
+ //刷新失败
+ layout.finishLoadMore(false);
+ }
+ }, 2000);
+ }
+
+ private void refresh(RefreshLayout refresh) {
+ refresh.getLayout().postDelayed(() -> {
+ if (random.nextBoolean()) {
+ //如果刷新成功
+ mAdapter.refresh(initData(40));
+ if (mAdapter.getItemCount() <= 30) {
+ //还有多的数据
+ refresh.finishRefresh();
+ } else {
+ //没有更多数据(上拉加载功能将显示没有更多数据)
+ refresh.finishRefreshWithNoMoreData();
+ }
+ } else {
+ //刷新失败
+ refresh.finishRefresh(false);
+ if (mAdapter.isEmpty()) {
+ mLoadingLayout.showError();
+ mLoadingLayout.setErrorText("随机触发刷新失败演示!");
+ }
+ }
+ }, 2000);
+ }
+
+ private Collection initData(int max) {
+ int min = Math.min(10, max);
+ max = Math.max(0, max);
+ if (max > min) {
+ return Arrays.asList(new Void[min + random.nextInt(max - min)]);
+ } else {
+ return Arrays.asList(new Void[min]);
+ }
+ }
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/CustomExampleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/example/CustomExampleActivity.java
new file mode 100644
index 00000000..5fbbaaa8
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/example/CustomExampleActivity.java
@@ -0,0 +1,211 @@
+package com.scwang.refreshlayout.activity.example;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.util.AttributeSet;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.ListView;
+import android.widget.Space;
+import android.widget.TextView;
+
+import com.scwang.refreshlayout.R;
+import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
+import com.scwang.refreshlayout.adapter.SmartViewHolder;
+import com.scwang.smart.drawable.ProgressDrawable;
+import com.scwang.smart.refresh.classics.ArrowDrawable;
+import com.scwang.smart.refresh.layout.api.RefreshHeader;
+import com.scwang.smart.refresh.layout.api.RefreshKernel;
+import com.scwang.smart.refresh.layout.api.RefreshLayout;
+import com.scwang.smart.refresh.layout.constant.RefreshState;
+import com.scwang.smart.refresh.layout.constant.SpinnerStyle;
+import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
+import com.scwang.smart.refresh.layout.util.SmartUtil;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import static android.R.layout.simple_list_item_2;
+
+/**
+ * 自定义Header功能使用
+ */
+public class CustomExampleActivity extends AppCompatActivity {
+
+ private BaseRecyclerAdapter mAdapter;
+
+ private static boolean isFirstEnter = true;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_example_custom);
+
+ final Toolbar toolbar = findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ finish();
+ }
+ });
+
+ ListView listView = findViewById(R.id.listView);
+ listView.setAdapter(mAdapter = new BaseRecyclerAdapter(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 = 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());
+ }
+
+ }
+
+ private Collection initData() {
+ return Arrays.asList(null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
+ }
+
+ public static class ClassicsHeader extends LinearLayout implements RefreshHeader {
+
+ private TextView mHeaderText;//标题文本
+ private ImageView mArrowView;//下拉箭头
+ private ImageView mProgressView;//刷新动画视图
+ private ProgressDrawable mProgressDrawable;//刷新动画
+
+ public ClassicsHeader(Context context) {
+ this(context, null);
+ }
+ public ClassicsHeader(Context context, AttributeSet attrs) {
+ super(context, attrs, 0);
+ setGravity(Gravity.CENTER);
+ mHeaderText = new TextView(context);
+ mProgressDrawable = new ProgressDrawable();
+ mArrowView = new ImageView(context);
+ mProgressView = new ImageView(context);
+ mProgressView.setImageDrawable(mProgressDrawable);
+ mArrowView.setImageDrawable(new ArrowDrawable());
+ addView(mProgressView, SmartUtil.dp2px(20), SmartUtil.dp2px(20));
+ addView(mArrowView, SmartUtil.dp2px(20), SmartUtil.dp2px(20));
+ addView(new Space(context), SmartUtil.dp2px(20), SmartUtil.dp2px(20));
+ addView(mHeaderText, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ setMinimumHeight(SmartUtil.dp2px(60));
+ }
+ @NonNull
+ public View getView() {
+ return this;//真实的视图就是自己,不能返回null
+ }
+ @NonNull
+ @Override
+ public SpinnerStyle getSpinnerStyle() {
+ return SpinnerStyle.Translate;//指定为平移,不能null
+ }
+
+ @Override
+ public void onStartAnimator(@NonNull RefreshLayout layout, int height, int maxDragHeight) {
+ mProgressDrawable.start();//开始动画
+ }
+
+ @Override
+ public int onFinish(@NonNull RefreshLayout layout, boolean success) {
+ mProgressDrawable.stop();//停止动画
+ mProgressView.setVisibility(GONE);//隐藏动画
+ if (success){
+ mHeaderText.setText("刷新完成");
+ } else {
+ mHeaderText.setText("刷新失败");
+ }
+ return 500;//延迟500毫秒之后再弹回
+ }
+
+ @Override
+ public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
+ switch (newState) {
+ case None:
+ case PullDownToRefresh:
+ mHeaderText.setText("下拉开始刷新");
+ mArrowView.setVisibility(VISIBLE);//显示下拉箭头
+ mProgressView.setVisibility(GONE);//隐藏动画
+ mArrowView.animate().rotation(0);//还原箭头方向
+ break;
+ case Refreshing:
+ mHeaderText.setText("正在刷新");
+ mProgressView.setVisibility(VISIBLE);//显示加载动画
+ mArrowView.setVisibility(GONE);//隐藏箭头
+ break;
+ case ReleaseToRefresh:
+ mHeaderText.setText("释放立即刷新");
+ mArrowView.animate().rotation(180);//显示箭头改为朝上
+ break;
+ }
+ }
+
+ @Override
+ public void setPrimaryColors(int... colors) {
+
+ }
+
+ @Override
+ public void onInitialized(@NonNull RefreshKernel kernel, int height, int maxDragHeight) {
+
+ }
+
+ @Override
+ public void onMoving(boolean isDragging, float percent, int offset, int height, int maxDragHeight) {
+
+ }
+
+// @Override
+// public void onPulling(float percent, int offset, int height, int maxDragHeight) {
+//
+// }
+// @Override
+// public void onReleasing(float percent, int offset, int height, int maxDragHeight) {
+//
+// }
+
+ @Override
+ public void onReleased(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
+
+ }
+
+ @Override
+ public void onHorizontalDrag(float percentX, int offsetX, int offsetMax) {
+
+ }
+
+ @Override
+ public boolean isSupportHorizontalDrag() {
+ return false;
+ }
+ }
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/I18nExampleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/example/I18nExampleActivity.java
new file mode 100644
index 00000000..b12967a1
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/example/I18nExampleActivity.java
@@ -0,0 +1,106 @@
+package com.scwang.refreshlayout.activity.example;
+
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.os.Build;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.annotation.StringRes;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.util.DisplayMetrics;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ListView;
+
+import com.scwang.refreshlayout.R;
+import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
+import com.scwang.refreshlayout.adapter.SmartViewHolder;
+import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import com.scwang.smartrefresh.layout.header.ClassicsHeader;
+import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+
+import static android.R.layout.simple_list_item_2;
+
+public class I18nExampleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
+
+ private enum Item {
+ i1(R.string.item_example_i18n_system),
+ i2(R.string.item_example_i18n_chinese),
+ i3(R.string.item_example_i18n_english),
+ ;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
+ }
+ }
+
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_example_i18n);
+
+ Toolbar toolbar = findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(v -> finish());
+
+ RefreshLayout refreshLayout = findViewById(R.id.refreshLayout);
+ if (refreshLayout != null) {
+ refreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
+ refreshLayout.setRefreshHeader(new ClassicsHeader(this));
+ refreshLayout.setOnRefreshListener((OnRefreshListener) layout -> layout.finishRefresh(1000));
+ }
+
+ View view = findViewById(R.id.listView);
+ if (view instanceof ListView) {
+ ListView listView = ((ListView) view);
+ List- items = new ArrayList<>();
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ listView.setAdapter(new BaseRecyclerAdapter
- (items, simple_list_item_2, this) {
+ @Override
+ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
+ holder.text(android.R.id.text1, model.nameId);
+ holder.text(android.R.id.text2, getString(R.string.item_example_i18n_click, getString(model.nameId)));
+ holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
+ }
+ });
+ }
+ }
+
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ switch (Item.values()[position % Item.values().length].nameId) {
+ case R.string.item_example_i18n_system:
+ changeAppLanguage(Locale.getDefault());
+ break;
+ case R.string.item_example_i18n_chinese:
+ changeAppLanguage(Locale.CHINESE);
+ break;
+ case R.string.item_example_i18n_english:
+ changeAppLanguage(Locale.ENGLISH);
+ break;
+ }
+ }
+
+ private void changeAppLanguage(Locale locale) {
+ Resources res = getResources();
+ DisplayMetrics dm = res.getDisplayMetrics();
+ Configuration conf = res.getConfiguration();
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ conf.locale = locale;
+ } else {
+ conf.setLocale(locale);
+ }
+ res.updateConfiguration(conf, dm);
+ startActivity(new Intent(this, getClass()));
+ overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
+ finish();
+ }
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/ListenerExampleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/example/ListenerExampleActivity.java
new file mode 100644
index 00000000..def013dd
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/example/ListenerExampleActivity.java
@@ -0,0 +1,205 @@
+package com.scwang.refreshlayout.activity.example;
+
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.text.method.ScrollingMovementMethod;
+import android.view.View;
+import android.widget.TextView;
+
+import com.scwang.refreshlayout.R;
+import com.scwang.smartrefresh.layout.api.RefreshFooter;
+import com.scwang.smartrefresh.layout.api.RefreshHeader;
+import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import com.scwang.smartrefresh.layout.constant.RefreshState;
+import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * 多功能监听器的使用
+ */
+public class ListenerExampleActivity extends AppCompatActivity {
+
+ private static DateFormat FORMAT = new SimpleDateFormat("HH:mm sss", Locale.CHINA);
+
+ private TextView mTvContent;
+ private String mHeaderMoving;
+// private String mHeaderPulling;
+// private String mHeaderReleasing;
+ private String mFooterMoving;
+// private String mFooterPulling;
+// private String mFooterReleasing;
+ private String mFooterStartAnimator;
+ private String mHeaderStartAnimator;
+ private String mFooterFinish;
+ private String mHeaderFinish;
+ private String mRefresh;
+ private String mLoadMore;
+ private String mStateChanged;
+
+ private static boolean isFirstEnter = true;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_example_listener);
+
+ final Toolbar toolbar = findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ finish();
+ }
+ });
+
+ mTvContent = findViewById(R.id.content);
+ mTvContent.setMovementMethod(ScrollingMovementMethod.getInstance());
+
+ final 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();
+ }
+ }
+
+ private void updateContent() {
+ mTvContent.setText(String.format(Locale.CHINA,
+ "onStateChanged:%s\n\n" +
+ "onHeaderMoving:%s\n\n" +
+// "onHeaderPulling:%s\n\n" +
+// "onHeaderReleasing:%s\n\n" +
+ "onHeaderStartAnimator:%s\n\n" +
+ "onHeaderFinish:%s\n\n" +
+ "onFooterMoving:%s\n\n" +
+// "onFooterPulling:%s\n\n" +
+// "onFooterReleasing:%s\n\n" +
+ "onFooterStartAnimator:%s\n\n" +
+ "onFooterFinish:%s\n\n" +
+ "onRefresh:%s\n\n" +
+ "onLoadMore:%s\n\n",
+ mStateChanged,
+ mHeaderMoving,
+// mHeaderPulling,
+// mHeaderReleasing,
+ mHeaderStartAnimator,
+ mHeaderFinish,
+ mFooterMoving,
+// mFooterPulling,
+// mFooterReleasing,
+ mFooterStartAnimator,
+ mFooterFinish,
+ mRefresh,
+ mLoadMore));
+ }
+
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/using/NestLayoutUsingActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/example/NestedLayoutExampleActivity.java
similarity index 68%
rename from app/src/main/java/com/scwang/refreshlayout/activity/using/NestLayoutUsingActivity.java
rename to app/src/main/java/com/scwang/refreshlayout/activity/example/NestedLayoutExampleActivity.java
index d2f96c78..e0da5429 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/using/NestLayoutUsingActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/example/NestedLayoutExampleActivity.java
@@ -1,4 +1,4 @@
-package com.scwang.refreshlayout.activity.using;
+package com.scwang.refreshlayout.activity.example;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
@@ -7,6 +7,7 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
+import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;
@@ -16,9 +17,13 @@
import com.scwang.refreshlayout.adapter.SmartViewHolder;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Arrays;
+import java.util.Date;
+import java.util.Locale;
-public class NestLayoutUsingActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
+public class NestedLayoutExampleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private static String[] provinces = new String[]{
"北京","天津","上海","重庆",
@@ -32,9 +37,9 @@ public class NestLayoutUsingActivity extends AppCompatActivity implements Adapte
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_using_region);
+ setContentView(R.layout.activity_example_region);
- final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ final Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
@@ -56,15 +61,28 @@ protected void onBindViewHolder(SmartViewHolder holder, String model, int positi
holder.text(android.R.id.text1, model);
}
}.setOnItemClickListener(this));
+ recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss SSS", Locale.CHINA);
+ @Override
+ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
+ Log.e("recyclerView", dateFormat.format(new Date()) + " - onScrollStateChanged - " + newState);
+ super.onScrollStateChanged(recyclerView, newState);
+ }
+
+ @Override
+ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
+ super.onScrolled(recyclerView, dx, dy);
+ }
+ });
}
- /**
+ /*
* 以下代码仅仅为了演示效果而已,不是必须的
- * 关键代码在 activity_using_assign_xml 中
+ * 关键代码在 activity_example_assign_xml 中
*/
- final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
+ final RefreshLayout refreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter && refreshLayout != null) {
isFirstEnter = false;
- //触发上啦加载
+ //触发上拉加载
refreshLayout.autoRefresh();
}
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/using/OverScrollUsingActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/example/OverScrollExampleActivity.java
similarity index 70%
rename from app/src/main/java/com/scwang/refreshlayout/activity/using/OverScrollUsingActivity.java
rename to app/src/main/java/com/scwang/refreshlayout/activity/example/OverScrollExampleActivity.java
index fe9238f0..0870bde9 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/using/OverScrollUsingActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/example/OverScrollExampleActivity.java
@@ -1,6 +1,7 @@
-package com.scwang.refreshlayout.activity.using;
+package com.scwang.refreshlayout.activity.example;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
@@ -14,14 +15,14 @@
/**
* 越界回弹使用演示
*/
-public class OverScrollUsingActivity extends AppCompatActivity {
+public class OverScrollExampleActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_using_overscroll);
+ setContentView(R.layout.activity_example_overscroll);
- final Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
+ final Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -29,11 +30,11 @@ public void onClick(View v) {
}
});
- final WebView webView = (WebView) findViewById(R.id.webView);
- final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
+ final WebView webView = findViewById(R.id.webView);
+ final RefreshLayout refreshLayout = findViewById(R.id.refreshLayout);
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
- public void onRefresh(RefreshLayout refreshlayout) {
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
webView.loadUrl("http://github.com");
}
});
@@ -42,16 +43,18 @@ public void onRefresh(RefreshLayout refreshlayout) {
webView.setWebViewClient(new WebViewClient(){
@Override
+ @SuppressWarnings("deprecation")
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 textView = findViewById(R.id.textView);
// textView.setMovementMethod(new ScrollingMovementMethod());
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/SnapHelperExampleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/example/SnapHelperExampleActivity.java
new file mode 100644
index 00000000..a35c1649
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/example/SnapHelperExampleActivity.java
@@ -0,0 +1,86 @@
+package com.scwang.refreshlayout.activity.example;
+
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.DefaultItemAnimator;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.PagerSnapHelper;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.SnapHelper;
+import android.support.v7.widget.Toolbar;
+import android.view.View;
+import android.widget.Switch;
+
+import com.scwang.refreshlayout.R;
+import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
+import com.scwang.refreshlayout.adapter.SmartViewHolder;
+import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+/**
+ * 结合 SnapHelper 使用
+ * Created by scwang on 2017/8/4.
+ */
+public class SnapHelperExampleActivity extends AppCompatActivity {
+
+ private BaseRecyclerAdapter mAdapter;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_example_snaphelper);
+
+ final Toolbar toolbar = findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(v -> finish());
+
+ //初始化列表和监听
+ View view = findViewById(R.id.recyclerView);
+ if (view instanceof RecyclerView) {
+ RecyclerView recyclerView = (RecyclerView) view;
+ recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
+ recyclerView.setItemAnimator(new DefaultItemAnimator());
+ recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter(loadModels(), R.layout.item_example_snap_helper) {
+ @Override
+ protected void onBindViewHolder(SmartViewHolder holder, Integer model, int position) {
+ holder.image(R.id.imageView, model);
+ }
+ });
+ SnapHelper snapHelper = new PagerSnapHelper();
+ snapHelper.attachToRecyclerView(recyclerView);
+ }
+
+ RefreshLayout refreshLayout = findViewById(R.id.refreshLayout);
+ refreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
+ @Override
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
+ refreshLayout.getLayout().postDelayed(() -> {
+ mAdapter.refresh(loadModels());
+ refreshLayout.finishRefresh();
+ }, 2000);
+ }
+
+ @Override
+ public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
+ refreshLayout.getLayout().postDelayed(() -> {
+ mAdapter.loadMore(loadModels());
+ refreshLayout.finishLoadMore();
+ }, 2000);
+ }
+ });
+
+ Switch switcher = findViewById(R.id.switch_scroll_content);
+ if (switcher != null) {
+ refreshLayout.setEnableScrollContentWhenLoaded(switcher.isChecked());
+ switcher.setOnCheckedChangeListener((buttonView, isChecked) -> refreshLayout.setEnableScrollContentWhenLoaded(isChecked));
+ }
+ }
+
+ private Collection loadModels() {
+ return Arrays.asList( R.mipmap.image_weibo_home_1, R.mipmap.image_weibo_home_2);
+ }
+
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/BannerPracticeActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/practice/BannerPracticeActivity.java
new file mode 100644
index 00000000..752b3f5a
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/practice/BannerPracticeActivity.java
@@ -0,0 +1,208 @@
+package com.scwang.refreshlayout.activity.practice;
+
+import android.content.Context;
+import android.os.Build;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.DividerItemDecoration;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.Toolbar;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.Toast;
+
+import com.bumptech.glide.Glide;
+import com.chad.library.adapter.base.BaseQuickAdapter;
+import com.chad.library.adapter.base.BaseViewHolder;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.scwang.refreshlayout.R;
+import com.scwang.refreshlayout.util.StatusBarUtil;
+import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
+import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
+import com.youth.banner.Banner;
+import com.youth.banner.BannerConfig;
+import com.youth.banner.listener.OnBannerListener;
+import com.youth.banner.loader.ImageLoader;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
+
+/**
+ * 广告轮播-Banner
+ */
+@SuppressWarnings("ALL")
+public class BannerPracticeActivity extends AppCompatActivity {
+
+ private QuickAdapter mAdapter;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_practice_banner);
+
+ final Toolbar toolbar = findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ finish();
+ }
+ });
+
+ final RecyclerView recyclerView = findViewById(R.id.recyclerView);
+ final RefreshLayout refreshLayout = findViewById(R.id.refreshLayout);
+
+ mAdapter = new QuickAdapter();
+ recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
+ recyclerView.setLayoutManager(new LinearLayoutManager(this));
+ recyclerView.setAdapter(mAdapter);
+ final List movies = new Gson().fromJson(JSON_MOVIES, new TypeToken>() {}.getType());
+ mAdapter.replaceData(movies);
+ refreshLayout.setOnRefreshListener(new OnRefreshListener() {
+ @Override
+ public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
+ refreshLayout.getLayout().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ if (mAdapter.getItemCount() < 2) {
+ List movies = new Gson().fromJson(JSON_MOVIES, new TypeToken>() {}.getType());
+ mAdapter.replaceData(movies);
+ }
+ refreshLayout.finishRefresh();
+ }
+ },2000);
+ }
+ });
+// refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
+// @Override
+// public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
+// mAdapter.addData(movies);
+// refreshLayout.finishLoadMoreWithNoMoreData();
+// }
+// });
+ refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
+ @Override
+ public void onLoadMore(@NonNull RefreshLayout rl) {
+ mAdapter.addData(movies);
+ rl.finishLoadMoreWithNoMoreData();
+ }
+ });
+
+
+ //添加Header
+ View header = LayoutInflater.from(this).inflate(R.layout.item_movie_header, recyclerView, false);
+ Banner banner = (Banner) header;
+ banner.setImageLoader(new GlideImageLoader());
+ banner.setImages(BANNER_ITEMS);
+ banner.setOnBannerListener(new OnBannerListener() {
+ @Override
+ public void OnBannerClick(int i) {
+ Toast.makeText(BannerPracticeActivity.this, "点击了第" + i + "页", Toast.LENGTH_SHORT).show();
+ }
+ });
+ if (Build.VERSION.SDK_INT > 26) {
+ Stream stream = BANNER_ITEMS.stream().map(new Function() {
+ @Override
+ public String apply(BannerItem bannerItem) {
+ return bannerItem.title;
+ }
+ });
+ banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
+ banner.setBannerTitles(stream.collect(Collectors.toList()));
+ }
+ banner.start();
+ mAdapter.addHeaderView(banner);
+ mAdapter.openLoadAnimation();
+
+ //状态栏透明和间距处理
+ StatusBarUtil.immersive(this);
+ StatusBarUtil.setPaddingSmart(this, toolbar);
+ StatusBarUtil.setPaddingSmart(this, recyclerView);
+ StatusBarUtil.setMargin(this, findViewById(R.id.header));
+ StatusBarUtil.setPaddingSmart(this, findViewById(R.id.blurView));
+ }
+
+ public class QuickAdapter extends BaseQuickAdapter {
+ public QuickAdapter() {
+ super(R.layout.item_movie_item);
+ }
+
+ @Override
+ protected void convert(BaseViewHolder viewHolder, Movie item) {
+ viewHolder.setText(R.id.lmi_title, item.filmName)
+ .setText(R.id.lmi_actor, item.actors)
+ .setText(R.id.lmi_grade, item.grade)
+ .setText(R.id.lmi_describe, item.shortinfo);
+ Glide.with(mContext).load(item.picaddr).into((ImageView) viewHolder.getView(R.id.lmi_avatar));
+ }
+ }
+
+ public class GlideImageLoader extends ImageLoader {
+ @Override
+ public void displayImage(Context context, Object path, ImageView imageView) {
+ imageView.setImageResource(((BannerItem) path).pic);
+ }
+ }
+
+ public static class Movie {
+ public String actors;
+ public String filmName;
+ public String grade;
+ public String info;
+ public String picaddr;
+ public String shortinfo;
+ }
+
+ public static class BannerItem {
+
+ public int pic;
+ public String title;
+
+ public BannerItem() {
+ }
+
+ public BannerItem(String title, int pic) {
+ this.pic = pic;
+ this.title = title;
+ }
+ }
+
+ public static List BANNER_ITEMS = new ArrayList(){{
+ add(new BannerItem("最后的骑士", R.mipmap.image_movie_header_48621499931969370));
+ add(new BannerItem("三生三世十里桃花", R.mipmap.image_movie_header_12981501221820220));
+ add(new BannerItem("豆福传", R.mipmap.image_movie_header_12231501221682438));
+ }};
+
+
+ public static String JSON_MOVIES = "[" +
+ "{\"actors\":\"丹尼斯·威缇可宁|Emma|Nikki|Jiayao|Wang|Maggie|Mao|Gang-yun|Sa\",\"filmName\":\"神灵寨\",\"grade\":\"5.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3823.jpg\",\"releasedate\":\"2017-07-31\",\"shortinfo\":\"父亲忽病危 新娘真够黑\",\"type\":\"剧情|喜剧\"}," +
+ "{\"actors\":\"刘亦菲|杨洋|彭子苏|严屹宽|罗晋\",\"filmName\":\"三生三世十里桃花\",\"grade\":\"9.2\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3566.jpg\",\"releasedate\":\"2017-08-03\",\"shortinfo\":\"虐心姐弟恋 颜值要逆天\",\"type\":\"剧情|爱情|奇幻\"}," +
+ "{\"actors\":\"尹航|代旭|李晨浩|衣云鹤|张念骅\",\"filmName\":\"谁是球王\",\"grade\":\"10.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3750.jpg\",\"releasedate\":\"2017-08-03\",\"shortinfo\":\"足球变人生 再战可辉煌\",\"type\":\"剧情|喜剧\"}," +
+ "{\"actors\":null,\"filmName\":\"大象林旺之一夜成名\",\"grade\":\"10.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3757.jpg\",\"releasedate\":\"2017-08-04\",\"shortinfo\":\"大象参二战 一生好伙伴\",\"type\":\"动作|动画|战争|冒险\"}," +
+ "{\"actors\":\"薛凯琪|陈意涵|张钧甯|迈克·泰森\",\"filmName\":\"闺蜜2:无二不作\",\"grade\":\"8.3\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3776.jpg\",\"releasedate\":\"2017-08-04\",\"shortinfo\":\"闺蜜团出战 会一会新娘\",\"type\":\"喜剧|爱情\"}," +
+ "{\"actors\":\"彭禺厶|王萌|周凯文|曹琦|孟子叶\",\"filmName\":\"诡井\",\"grade\":\"5.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3824.jpg\",\"releasedate\":\"2017-08-04\",\"shortinfo\":\"午夜深井中 怨魂欲现形\",\"type\":\"恐怖|惊悚\"}," +
+ "{\"actors\":\"旺卓措|刘承宙|高欣生|段楠|来钰\",\"filmName\":\"荒野加油站\",\"grade\":\"5.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3821.jpg\",\"releasedate\":\"2017-08-04\",\"shortinfo\":\"夜半拉乘客 结果遇不测\",\"type\":\"惊悚|悬疑\"}," +
+ "{\"actors\":\"刘佩琦|曹云金|罗昱焜\",\"filmName\":\"龙之战\",\"grade\":\"5.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3778.jpg\",\"releasedate\":\"2017-08-04\",\"shortinfo\":\"持倭刀屹立 抗外敌救国\",\"type\":\"动作|战争|历史\"}," +
+ "{\"actors\":\"金巴|曲尼次仁|夏诺.扎西敦珠|索朗尼玛|益西旦增\",\"filmName\":\"皮绳上的魂\",\"grade\":\"5.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3801.jpg\",\"releasedate\":\"2017-08-04\",\"shortinfo\":\"走完朝圣路 又上降魔旅\",\"type\":\"剧情\"}," +
+ "{\"actors\":\"严丽祯|李晔|王衡|李传缨|李心仪\",\"filmName\":\"玩偶奇兵\",\"grade\":\"10.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3779.jpg\",\"releasedate\":\"2017-08-04\",\"shortinfo\":\"玩偶战数码 一头两个大\",\"type\":\"动画|冒险|奇幻\"}," +
+ "{\"actors\":\"斯蒂芬·马布里|吴尊|何冰|郑秀妍|王庆祥\",\"filmName\":\"我是马布里\",\"grade\":\"0.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3810.jpg\",\"releasedate\":\"2017-08-04\",\"shortinfo\":\"吴尊助冠军 热血灌篮魂\",\"type\":\"剧情|运动\"}," +
+ "{\"actors\":\"周鹏雨|穆建荣|陈泽帆|鹿露|宋星成\",\"filmName\":\"原罪的羔羊\",\"grade\":\"5.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3802.jpg\",\"releasedate\":\"2017-08-04\",\"shortinfo\":\"古镇来戏班 往事不一般\",\"type\":\"悬疑\"}," +
+ "{\"actors\":\"王大陆|张天爱|任达华|盛冠森|王迅\",\"filmName\":\"鲛珠传\",\"grade\":\"7.1\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3777.jpg\",\"releasedate\":\"2017-08-04\",\"shortinfo\":\"改编热IP 杠杠号召力\",\"type\":\"喜剧|动作|奇幻\"}," +
+ "{\"actors\":\"成龙|罗伯特·雷德福\",\"filmName\":\"地球:神奇的一天\",\"grade\":\"10.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3803.jpg\",\"releasedate\":\"2017-08-11\",\"shortinfo\":\"史诗纪录片 十年再相见\",\"type\":\"纪录片\"}," +
+ "{\"actors\":\"刘德华|舒淇|杨祐宁|张静初|让·雷诺|曾志伟|沙溢\",\"filmName\":\"侠盗联盟\",\"grade\":\"10.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3592.jpg\",\"releasedate\":\"2017-08-11\",\"shortinfo\":\"侠盗三剑客 越洋逃恐吓\",\"type\":\"动作|冒险\"}," +
+ "{\"actors\":\"廖凡|李易峰|万茜|李纯|张国柱\",\"filmName\":\"心理罪\",\"grade\":\"10.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3795.jpg\",\"releasedate\":\"2017-08-11\",\"shortinfo\":\"侦探两搭档 真相背后藏\",\"type\":\"悬疑|犯罪\"}," +
+ "{\"actors\":\"徐瑞阳|赵倩|姜启杨|徐万学|韩靓|韦安\",\"filmName\":\"隐隐惊马槽之绝战女僵尸\",\"grade\":\"5.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3825.jpg\",\"releasedate\":\"2017-08-11\",\"shortinfo\":\"阴兵来借道 尸占惊马槽\",\"type\":\"惊悚|动作|冒险|悬疑\"}," +
+ "{\"actors\":\"宋睿|王良|张佳浩|叶常清\",\"filmName\":\"左眼阴阳\",\"grade\":\"10.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3804.jpg\",\"releasedate\":\"2017-08-11\",\"shortinfo\":\"左眼见到鬼 是诡还是魅\",\"type\":\"恐怖|惊悚|悬疑\"}," +
+ "{\"actors\":null,\"filmName\":\"二十二\",\"grade\":\"10.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3811.jpg\",\"releasedate\":\"2017-08-14\",\"shortinfo\":\"二战女俘虏 讲述心中苦\",\"type\":\"纪录片\"}," +
+ "{\"actors\":\"郭富城|王千源|刘涛|余皑磊|冯嘉怡\",\"filmName\":\"破·局\",\"grade\":\"5.0\",\"picaddr\":\"http://app.infunpw.com/commons/images/cinema/cinema_films/3812.jpg\",\"releasedate\":\"2017-08-18\",\"shortinfo\":\"影帝硬碰硬 迷局谁怕谁\",\"type\":\"动作|犯罪\"}" +
+ "]";
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/FeedlistPracticeActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/practice/FeedListPracticeActivity.java
similarity index 77%
rename from app/src/main/java/com/scwang/refreshlayout/activity/practice/FeedlistPracticeActivity.java
rename to app/src/main/java/com/scwang/refreshlayout/activity/practice/FeedListPracticeActivity.java
index 8bb52240..c051526d 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/practice/FeedlistPracticeActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/practice/FeedListPracticeActivity.java
@@ -9,9 +9,9 @@
import com.scwang.smartrefresh.layout.api.RefreshLayout;
/**
- * 网页-Github
+ * 微博列表
*/
-public class FeedlistPracticeActivity extends AppCompatActivity {
+public class FeedListPracticeActivity extends AppCompatActivity {
private static boolean isFirstEnter = true;
@@ -20,7 +20,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_practice_feedlist);
- final Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
+ final Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -28,12 +28,11 @@ public void onClick(View v) {
}
});
+ final RefreshLayout refreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
- final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
refreshLayout.autoRefresh();
}
-
}
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/ProfilePracticeActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/practice/ProfilePracticeActivity.java
index d8b3fc6d..8ca0c915 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/practice/ProfilePracticeActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/practice/ProfilePracticeActivity.java
@@ -13,25 +13,19 @@
*/
public class ProfilePracticeActivity extends AppCompatActivity {
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_practice_profile);
- final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- toolbar.setNavigationOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
+ final Toolbar toolbar = findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(v -> finish());
//状态栏透明和间距处理
StatusBarUtil.immersive(this);
StatusBarUtil.setPaddingSmart(this, toolbar);
StatusBarUtil.setPaddingSmart(this, findViewById(R.id.profile));
- StatusBarUtil.setPaddingSmart(this, findViewById(R.id.blurview));
+ StatusBarUtil.setPaddingSmart(this, findViewById(R.id.blurView));
}
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/QQBrowserPracticeActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/practice/QQBrowserPracticeActivity.java
new file mode 100644
index 00000000..3b9a6f2d
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/practice/QQBrowserPracticeActivity.java
@@ -0,0 +1,59 @@
+package com.scwang.refreshlayout.activity.practice;
+
+import android.annotation.SuppressLint;
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.view.View;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+
+import com.scwang.refreshlayout.R;
+import com.scwang.refreshlayout.util.StatusBarUtil;
+
+import ezy.ui.layout.LoadingLayout;
+
+/**
+ * QQ浏览器-Github
+ */
+public class QQBrowserPracticeActivity extends AppCompatActivity {
+
+ @SuppressLint("SetJavaScriptEnabled")
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_practice_qqbrowser);
+
+ final Toolbar toolbar = findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ finish();
+ }
+ });
+
+ final LoadingLayout loading = findViewById(R.id.loading);
+
+ final WebView webView = findViewById(R.id.webView);
+ webView.loadUrl("https://github.com/scwang90/SmartRefreshLayout");
+ webView.getSettings().setJavaScriptEnabled(true);
+ webView.setWebViewClient(new WebViewClient(){
+ @Override
+ @SuppressWarnings("deprecation")
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
+ view.loadUrl(url);
+ return true;
+ }
+ @Override
+ public void onPageFinished(WebView view, String url) {
+ super.onPageFinished(view, url);
+ loading.showContent();
+ }
+ });
+
+ //状态栏透明和间距处理
+ StatusBarUtil.immersive(this);
+ StatusBarUtil.setPaddingSmart(this, toolbar);
+ }
+
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/RepastPracticeActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/practice/RepastPracticeActivity.java
index 11f13303..0654c550 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/practice/RepastPracticeActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/practice/RepastPracticeActivity.java
@@ -1,6 +1,7 @@
package com.scwang.refreshlayout.activity.practice;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
@@ -14,7 +15,8 @@
import com.scwang.refreshlayout.adapter.SmartViewHolder;
import com.scwang.refreshlayout.util.StatusBarUtil;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
-import com.scwang.smartrefresh.layout.listener.OnRefreshLoadmoreListener;
+import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
+import com.scwang.smartrefresh.layout.util.SmartUtil;
import java.util.Arrays;
import java.util.Collection;
@@ -24,7 +26,6 @@
*/
public class RepastPracticeActivity extends AppCompatActivity {
-
private class Model {
int imageId;
int avatarId;
@@ -40,7 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_practice_repast);
- final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ final Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -48,7 +49,8 @@ public void onClick(View v) {
}
});
- final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
+ final RefreshLayout refreshLayout = findViewById(R.id.refreshLayout);
+ refreshLayout.setEnableFooterFollowWhenNoMoreData(true);
//第一次进入演示刷新
if (isFirstEnter) {
@@ -62,7 +64,7 @@ public void onClick(View v) {
RecyclerView recyclerView = (RecyclerView) view;
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter(loadModels(), R.layout.listitem_practive_repast) {
+ recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter(loadModels(), R.layout.item_practice_repast) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Model model, int position) {
holder.text(R.id.name, model.name);
@@ -72,39 +74,48 @@ protected void onBindViewHolder(SmartViewHolder holder, Model model, int positio
}
});
- refreshLayout.setOnRefreshLoadmoreListener(new OnRefreshLoadmoreListener() {
+ refreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
@Override
- public void onRefresh(final RefreshLayout refreshlayout) {
+ public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
- refreshlayout.finishRefresh();
+ refreshLayout.finishRefresh();
+ refreshLayout.resetNoMoreData();//setNoMoreData(false);//恢复上拉状态
}
}, 2000);
}
@Override
- public void onLoadmore(final RefreshLayout refreshlayout) {
+ public void onLoadMore(@NonNull final RefreshLayout refreshLayout) {
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
- mAdapter.loadmore(loadModels());
- refreshlayout.finishLoadmore();
if (mAdapter.getCount() > 12) {
Toast.makeText(getBaseContext(), "数据全部加载完毕", Toast.LENGTH_SHORT).show();
- refreshlayout.setLoadmoreFinished(true);//设置之后,将不会再触发加载事件
+ refreshLayout.finishLoadMoreWithNoMoreData();//设置之后,将不会再触发加载事件
+ } else {
+ mAdapter.loadMore(loadModels());
+ refreshLayout.finishLoadMore();
}
}
}, 1000);
}
});
+
+ refreshLayout.getLayout().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ refreshLayout.setHeaderInsetStart(SmartUtil.px2dp(toolbar.getHeight()));
+ }
+ }, 500);
}
//状态栏透明和间距处理
StatusBarUtil.darkMode(this);
StatusBarUtil.setPaddingSmart(this, view);
StatusBarUtil.setPaddingSmart(this, toolbar);
- StatusBarUtil.setPaddingSmart(this, findViewById(R.id.blurview));
- StatusBarUtil.setMargin(this, findViewById(R.id.gifview));
+ StatusBarUtil.setPaddingSmart(this, findViewById(R.id.blurView));
+
}
/**
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/WebviewPracticeActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/practice/WebViewPracticeActivity.java
similarity index 74%
rename from app/src/main/java/com/scwang/refreshlayout/activity/practice/WebviewPracticeActivity.java
rename to app/src/main/java/com/scwang/refreshlayout/activity/practice/WebViewPracticeActivity.java
index 4b01ab1a..45b07f16 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/practice/WebviewPracticeActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/practice/WebViewPracticeActivity.java
@@ -2,6 +2,7 @@
import android.annotation.SuppressLint;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
@@ -12,14 +13,14 @@
import com.scwang.refreshlayout.util.StatusBarUtil;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
-import com.scwang.smartrefresh.layout.util.DensityUtil;
+import com.scwang.smartrefresh.layout.util.SmartUtil;
import java.util.Locale;
/**
* 网页-Github
*/
-public class WebviewPracticeActivity extends AppCompatActivity {
+public class WebViewPracticeActivity extends AppCompatActivity {
@SuppressLint("SetJavaScriptEnabled")
@Override
@@ -27,7 +28,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_practice_webview);
- final Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
+ final Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -35,11 +36,11 @@ public void onClick(View v) {
}
});
- final WebView webView = (WebView) findViewById(R.id.webView);
- final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
+ final WebView webView = findViewById(R.id.webView);
+ final RefreshLayout refreshLayout = findViewById(R.id.refreshLayout);
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
- public void onRefresh(RefreshLayout refreshlayout) {
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
webView.loadUrl("https://github.com/scwang90/SmartRefreshLayout");
}
});
@@ -49,14 +50,17 @@ public void onRefresh(RefreshLayout refreshlayout) {
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient(){
@Override
+ @SuppressWarnings("deprecation")
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
+
@Override
- public void onPageCommitVisible(WebView view, String url) {
+ public void onPageFinished(WebView view, String url) {
+ super.onPageFinished(view, url);
refreshLayout.finishRefresh();
- view.loadUrl(String.format(Locale.CHINA, "javascript:document.body.style.paddingTop='%fpx'; void 0", DensityUtil.px2dp(webView.getPaddingTop())));
+ view.loadUrl(String.format(Locale.CHINA, "javascript:document.body.style.paddingTop='%fpx'; void 0", SmartUtil.px2dp(webView.getPaddingTop())));
}
});
@@ -65,7 +69,7 @@ public void onPageCommitVisible(WebView view, String url) {
StatusBarUtil.setPaddingSmart(this, webView);
StatusBarUtil.setPaddingSmart(this, toolbar);
StatusBarUtil.setMargin(this, findViewById(R.id.header));
- StatusBarUtil.setPaddingSmart(this, findViewById(R.id.blurview));
+ StatusBarUtil.setPaddingSmart(this, findViewById(R.id.blurView));
}
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/WeiboPracticeActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/practice/WeiboPracticeActivity.java
index 22ef1e78..cc295ef4 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/practice/WeiboPracticeActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/practice/WeiboPracticeActivity.java
@@ -1,21 +1,23 @@
package com.scwang.refreshlayout.activity.practice;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
+import android.widget.Toast;
import com.scwang.refreshlayout.R;
import com.scwang.refreshlayout.util.StatusBarUtil;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;
-import com.scwang.smartrefresh.layout.util.DensityUtil;
+import com.scwang.smartrefresh.layout.util.SmartUtil;
/**
- * 微博列表
+ * 微博主页
*/
public class WeiboPracticeActivity extends AppCompatActivity {
@@ -27,7 +29,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_practice_weibo);
- final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ final Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -38,29 +40,58 @@ public void onClick(View v) {
//状态栏透明和间距处理
StatusBarUtil.immersive(this);
StatusBarUtil.setPaddingSmart(this, toolbar);
+ StatusBarUtil.setMargin(this, findViewById(R.id.header));
final View parallax = findViewById(R.id.parallax);
final View buttonBar = findViewById(R.id.buttonBarLayout);
- final NestedScrollView scrollView = (NestedScrollView)findViewById(R.id.scrollView);
- final RefreshLayout refreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ final NestedScrollView scrollView = findViewById(R.id.scrollView);
+ final RefreshLayout refreshLayout = findViewById(R.id.refreshLayout);
+
+ findViewById(R.id.attention).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Toast.makeText(view.getContext(),"点击了关注",Toast.LENGTH_SHORT).show();
+ }
+ });
+ findViewById(R.id.leaveword).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Toast.makeText(view.getContext(),"点击了留言",Toast.LENGTH_SHORT).show();
+ }
+ });
refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
@Override
- public void onHeaderPulling(RefreshHeader header, float percent, int offset, int bottomHeight, int extendHeight) {
- mOffset = offset / 2;
- parallax.setTranslationY(mOffset - mScrollY);
- toolbar.setAlpha(1 - Math.min(percent, 1));
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
+ refreshLayout.finishRefresh(3000);
+ }
+
+ @Override
+ public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
+ refreshLayout.finishLoadMore(2000);
}
@Override
- public void onHeaderReleasing(RefreshHeader header, float percent, int offset, int bottomHeight, int extendHeight) {
+ public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
mOffset = offset / 2;
parallax.setTranslationY(mOffset - mScrollY);
toolbar.setAlpha(1 - Math.min(percent, 1));
}
+// @Override
+// public void onHeaderPulling(@NonNull RefreshHeader header, float percent, int offset, int bottomHeight, int maxDragHeight) {
+// mOffset = offset / 2;
+// parallax.setTranslationY(mOffset - mScrollY);
+// toolbar.setAlpha(1 - Math.min(percent, 1));
+// }
+// @Override
+// public void onHeaderReleasing(@NonNull RefreshHeader header, float percent, int offset, int bottomHeight, int maxDragHeight) {
+// mOffset = offset / 2;
+// parallax.setTranslationY(mOffset - mScrollY);
+// toolbar.setAlpha(1 - Math.min(percent, 1));
+// }
});
scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
private int lastScrollY = 0;
- private int h = DensityUtil.dp2px(170);
+ private int h = SmartUtil.dp2px(170);
private int color = ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary)&0x00ffffff;
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/CircleStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/BezierCircleStyleActivity.java
similarity index 76%
rename from app/src/main/java/com/scwang/refreshlayout/activity/style/CircleStyleActivity.java
rename to app/src/main/java/com/scwang/refreshlayout/activity/style/BezierCircleStyleActivity.java
index f07b55ff..9b2bd813 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/CircleStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/BezierCircleStyleActivity.java
@@ -2,6 +2,7 @@
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
@@ -17,24 +18,26 @@
import com.scwang.refreshlayout.adapter.SmartViewHolder;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import static android.R.layout.simple_list_item_2;
import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
-public class CircleStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
+public class BezierCircleStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private enum Item {
- 内容不偏移("下拉的时候列表内容停留在原位不动"),
- 内容跟随偏移("下拉的时候列表内容跟随向下偏移"),
- 橙色主题("更改为橙色主题颜色"),
- 红色主题("更改为红色主题颜色"),
- 绿色主题("更改为绿色主题颜色"),
- 蓝色主题("更改为蓝色主题颜色"),
+ 内容不偏移(R.string.item_style_content_translation_off),
+ 内容跟随偏移(R.string.item_style_content_translation_on),
+ 橙色主题(R.string.item_style_theme_orange_abstract),
+ 红色主题(R.string.item_style_theme_red_abstract),
+ 绿色主题(R.string.item_style_theme_green_abstract),
+ 蓝色主题(R.string.item_style_theme_blue_abstract),
;
- public String name;
- Item(String name) {
- this.name = name;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
}
}
@@ -47,7 +50,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_style_circle);
- mToolbar = (Toolbar)findViewById(R.id.toolbar);
+ mToolbar = findViewById(R.id.toolbar);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -55,7 +58,7 @@ public void onClick(View v) {
}
});
- mRefreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
mRefreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
@@ -67,11 +70,14 @@ public void onClick(View v) {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2,this) {
+ List
- items = new ArrayList<>();
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ recyclerView.setAdapter(new BaseRecyclerAdapter
- (items, simple_list_item_2,this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
- holder.text(android.R.id.text2, model.name);
+ holder.text(android.R.id.text2, model.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
@@ -80,7 +86,7 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- switch (Item.values()[position]) {
+ switch (Item.values()[position % Item.values().length]) {
case 内容不偏移:
mRefreshLayout.setEnableHeaderTranslationContent(false);
break;
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/WaveSwipStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/BezierRadarStyleActivity.java
similarity index 67%
rename from app/src/main/java/com/scwang/refreshlayout/activity/style/WaveSwipStyleActivity.java
rename to app/src/main/java/com/scwang/refreshlayout/activity/style/BezierRadarStyleActivity.java
index 79cbfe6a..400452ce 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/WaveSwipStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/BezierRadarStyleActivity.java
@@ -2,6 +2,7 @@
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
@@ -16,38 +17,44 @@
import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
import com.scwang.refreshlayout.adapter.SmartViewHolder;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import com.scwang.smartrefresh.layout.header.BezierRadarHeader;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import static android.R.layout.simple_list_item_2;
import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
-public class WaveSwipStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
+public class BezierRadarStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private enum Item {
- 内容不偏移("下拉的时候列表内容停留在原位不动"),
- 内容跟随偏移("下拉的时候列表内容跟随向下偏移"),
- 橙色主题("更改为橙色主题颜色"),
- 红色主题("更改为红色主题颜色"),
- 绿色主题("更改为绿色主题颜色"),
- 蓝色主题("更改为蓝色主题颜色"),
+ 打开左右拖动(R.string.item_style_horizontal_drag_on),
+ 关闭左右拖动(R.string.item_style_horizontal_drag_off),
+ 内容不偏移(R.string.item_style_content_translation_off),
+ 内容跟随偏移(R.string.item_style_content_translation_on),
+ 橙色主题(R.string.item_style_theme_orange_abstract),
+ 红色主题(R.string.item_style_theme_red_abstract),
+ 绿色主题(R.string.item_style_theme_green_abstract),
+ 蓝色主题(R.string.item_style_theme_blue_abstract),
;
- public String name;
- Item(String name) {
- this.name = name;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
}
}
private Toolbar mToolbar;
private RefreshLayout mRefreshLayout;
+ private BezierRadarHeader mRefreshHeader;
private static boolean isFirstEnter = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_style_wave_swip);
+ setContentView(R.layout.activity_style_bezier);
- mToolbar = (Toolbar)findViewById(R.id.toolbar);
+ mToolbar = findViewById(R.id.toolbar);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -55,7 +62,8 @@ public void onClick(View v) {
}
});
- mRefreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
+ mRefreshHeader = findViewById(R.id.header);
if (isFirstEnter) {
isFirstEnter = false;
mRefreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
@@ -67,11 +75,14 @@ public void onClick(View v) {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2,this) {
+ List
- items = new ArrayList<>();
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ recyclerView.setAdapter(new BaseRecyclerAdapter
- (items, simple_list_item_2,this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
- holder.text(android.R.id.text2, model.name);
+ holder.text(android.R.id.text2, model.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
@@ -80,7 +91,7 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- switch (Item.values()[position]) {
+ switch (Item.values()[position % Item.values().length]) {
case 内容不偏移:
mRefreshLayout.setEnableHeaderTranslationContent(false);
break;
@@ -99,6 +110,12 @@ public void onItemClick(AdapterView> parent, View view, int position, long id)
case 橙色主题:
setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark);
break;
+ case 打开左右拖动:
+ mRefreshHeader.setEnableHorizontalDrag(true);
+ break;
+ case 关闭左右拖动:
+ mRefreshHeader.setEnableHorizontalDrag(false);
+ break;
}
mRefreshLayout.autoRefresh();
}
@@ -111,4 +128,5 @@ private void setThemeColor(int colorPrimary, int colorPrimaryDark) {
}
}
+
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/ClassicsStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/ClassicsStyleActivity.java
index a15b4d36..b274bf98 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/ClassicsStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/ClassicsStyleActivity.java
@@ -1,7 +1,11 @@
package com.scwang.refreshlayout.activity.style;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
+import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
@@ -11,20 +15,21 @@
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
+import android.widget.ImageView;
import com.scwang.refreshlayout.R;
import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
import com.scwang.refreshlayout.adapter.SmartViewHolder;
import com.scwang.refreshlayout.util.DynamicTimeFormat;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
-import com.scwang.smartrefresh.layout.constant.RefreshState;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
-import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
+import java.util.List;
import java.util.Locale;
import java.util.Random;
@@ -36,19 +41,21 @@ public class ClassicsStyleActivity extends AppCompatActivity implements AdapterV
private BaseRecyclerAdapter
- mAdpater;
private enum Item {
- 尺寸拉伸("下拉的时候Header的高度跟随变大"),
- 位置平移("下拉的时候Header的位置向下偏移"),
- 背后固定("下拉的时候Header固定在背后"),
- 默认主题("更改为默认主题颜色"),
- 橙色主题("更改为橙色主题颜色"),
- 红色主题("更改为红色主题颜色"),
- 绿色主题("更改为绿色主题颜色"),
- 蓝色主题("更改为蓝色主题颜色"),
- 加载更多("上啦加载更多"),
+ 尺寸拉伸(R.string.item_style_spinner_scale),
+ 位置平移(R.string.item_style_spinner_translation),
+ 背后固定(R.string.item_style_spinner_behind),
+ 显示时间(R.string.item_style_spinner_update_on),
+ 隐藏时间(R.string.item_style_spinner_update_off),
+// 加载更多(R.string.item_style_load_more),
+ 默认主题(R.string.item_style_theme_default_abstract),
+ 橙色主题(R.string.item_style_theme_orange_abstract),
+ 红色主题(R.string.item_style_theme_red_abstract),
+ 绿色主题(R.string.item_style_theme_green_abstract),
+ 蓝色主题(R.string.item_style_theme_blue_abstract),
;
- public String name;
- Item(String name) {
- this.name = name;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
}
}
@@ -56,6 +63,7 @@ private enum Item {
private RecyclerView mRecyclerView;
private RefreshLayout mRefreshLayout;
private ClassicsHeader mClassicsHeader;
+ private Drawable mDrawableProgress;
private static boolean isFirstEnter = true;
@Override
@@ -63,7 +71,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_style_classics);
- mToolbar = (Toolbar)findViewById(R.id.toolbar);
+ mToolbar = findViewById(R.id.toolbar);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -71,14 +79,19 @@ public void onClick(View v) {
}
});
- mRefreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
- int deta = new Random().nextInt(7 * 24 * 60 * 60 * 1000);
+ int delta = new Random().nextInt(7 * 24 * 60 * 60 * 1000);
mClassicsHeader = (ClassicsHeader)mRefreshLayout.getRefreshHeader();
- mClassicsHeader.setLastUpdateTime(new Date(System.currentTimeMillis()-deta));
+ mClassicsHeader.setLastUpdateTime(new Date(System.currentTimeMillis()-delta));
mClassicsHeader.setTimeFormat(new SimpleDateFormat("更新于 MM-dd HH:mm", Locale.CHINA));
mClassicsHeader.setTimeFormat(new DynamicTimeFormat("更新于 %s"));
+// mDrawableProgress = mClassicsHeader.getProgressView().getDrawable();
+ mDrawableProgress = ((ImageView)mClassicsHeader.findViewById(ClassicsHeader.ID_IMAGE_PROGRESS)).getDrawable();
+ if (mDrawableProgress instanceof LayerDrawable) {
+ mDrawableProgress = ((LayerDrawable) mDrawableProgress).getDrawable(0);
+ }
View view = findViewById(R.id.recyclerView);
if (view instanceof RecyclerView) {
@@ -86,11 +99,14 @@ public void onClick(View v) {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(mAdpater = new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2,this) {
+ List
- items = new ArrayList<>();
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ recyclerView.setAdapter(mAdpater = new BaseRecyclerAdapter
- (items, simple_list_item_2,this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
- holder.text(android.R.id.text2, model.name);
+ holder.text(android.R.id.text2, model.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
@@ -99,67 +115,50 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position
if (isFirstEnter) {
isFirstEnter = false;
- //触发上啦加载
- mRefreshLayout.autoLoadmore();
- //通过多功能监听接口实现 在第一次加载完成之后 自动刷新
- mRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener(){
- @Override
- public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, RefreshState newState) {
- if (oldState == RefreshState.LoadingFinish && newState == RefreshState.None) {
- mRefreshLayout.autoRefresh();
- mRefreshLayout.setOnMultiPurposeListener(null);//保准只有第一次关联
- }
- }
- });
+ //触发自动刷新
+ mRefreshLayout.autoRefresh();
}
-// mRefreshLayout.setOnRefreshLoadmoreListener(new OnRefreshLoadmoreListener() {
-// @Override
-// public void onRefresh(RefreshLayout refreshlayout) {
-// refreshlayout.getLayout().postDelayed(new Runnable() {
-// @Override
-// public void run() {
-// mRefreshLayout.finishRefresh();
-// mAdpater.refresh(Arrays.asList(Item.values()));
-// }
-// },2000);
-// }
-//
-// @Override
-// public void onLoadmore(RefreshLayout refreshlayout) {
-// refreshlayout.getLayout().postDelayed(new Runnable() {
-// @Override
-// public void run() {
-// mRefreshLayout.finishLoadmore();
-// mAdpater.loadmore(Arrays.asList(Item.values()));
-// }
-// },2000);
-// }
-// });
}
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- switch (Item.values()[position]) {
+ switch (Item.values()[position % Item.values().length]) {
case 背后固定:
mClassicsHeader.setSpinnerStyle(SpinnerStyle.FixedBehind);
mRefreshLayout.setPrimaryColors(0xff444444, 0xffffffff);
- /**
+ if (Build.VERSION.SDK_INT >= 21) {
+ mDrawableProgress.setTint(0xffffffff);
+ } else if (mDrawableProgress instanceof VectorDrawableCompat) {
+ ((VectorDrawableCompat) mDrawableProgress).setTint(0xffffffff);
+ }
+ /*
* 由于是后面才设置,需要手动更改视图的位置
* 如果在 onCreate 或者 xml 中设置好[SpinnerStyle] 就不用手动调整位置了
*/
mRefreshLayout.getLayout().bringChildToFront(mRecyclerView);
break;
case 尺寸拉伸:
- mClassicsHeader.setSpinnerStyle(SpinnerStyle.Scale);
+ mClassicsHeader.setSpinnerStyle(SpinnerStyle.values[1]);
break;
case 位置平移:
mClassicsHeader.setSpinnerStyle(SpinnerStyle.Translate);
break;
+ case 显示时间:
+ mClassicsHeader.setEnableLastTime(true);
+ break;
+ case 隐藏时间:
+ mClassicsHeader.setEnableLastTime(false);
+ break;
case 默认主题:
setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark);
mRefreshLayout.getLayout().setBackgroundResource(android.R.color.transparent);
- mRefreshLayout.setPrimaryColorsId(android.R.color.transparent, android.R.color.tertiary_text_dark);
+ mRefreshLayout.setPrimaryColors(0, 0xff666666);
+ if (Build.VERSION.SDK_INT >= 21) {
+ mDrawableProgress.setTint(0xff666666);
+ } else if (mDrawableProgress instanceof VectorDrawableCompat) {
+ ((VectorDrawableCompat) mDrawableProgress).setTint(0xff666666);
+ }
break;
case 蓝色主题:
setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark);
@@ -173,9 +172,9 @@ public void onItemClick(AdapterView> parent, View view, int position, long id)
case 橙色主题:
setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark);
break;
- case 加载更多:
- mRefreshLayout.autoLoadmore();
- return;
+// case 加载更多:
+// mRefreshLayout.autoLoadMore();
+// return;
}
mRefreshLayout.autoRefresh();
}
@@ -185,6 +184,9 @@ private void setThemeColor(int colorPrimary, int colorPrimaryDark) {
mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white);
if (Build.VERSION.SDK_INT >= 21) {
getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark));
+ mDrawableProgress.setTint(0xffffffff);
+ } else if (mDrawableProgress instanceof VectorDrawableCompat) {
+ ((VectorDrawableCompat) mDrawableProgress).setTint(0xffffffff);
}
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/DeliveryStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/DeliveryStyleActivity.java
index 94240bbf..64688c34 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/DeliveryStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/DeliveryStyleActivity.java
@@ -2,6 +2,7 @@
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
@@ -17,22 +18,24 @@
import com.scwang.refreshlayout.adapter.SmartViewHolder;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
-import static com.scwang.refreshlayout.R.layout.listitem_style_delivery;
+import static com.scwang.refreshlayout.R.layout.item_style_delivery;
public class DeliveryStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private enum Item {
- 默认主题("更改为默认主题颜色"),
- 橙色主题("更改为橙色主题颜色"),
- 红色主题("更改为红色主题颜色"),
- 绿色主题("更改为绿色主题颜色"),
- 蓝色主题("更改为蓝色主题颜色"),
+ 默认主题(R.string.item_style_theme_default_abstract),
+ 橙色主题(R.string.item_style_theme_orange_abstract),
+ 红色主题(R.string.item_style_theme_red_abstract),
+ 绿色主题(R.string.item_style_theme_green_abstract),
+ 蓝色主题(R.string.item_style_theme_blue_abstract),
;
- public String name;
- Item(String name) {
- this.name = name;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
}
}
@@ -54,7 +57,7 @@ protected void onCreate(Bundle savedInstanceState) {
window.getDecorView().setSystemUiVisibility(systemUiVisibility);
}
- mToolbar = (Toolbar)findViewById(R.id.toolbar);
+ mToolbar = findViewById(R.id.toolbar);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -62,7 +65,7 @@ public void onClick(View v) {
}
});
- mRefreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
mRefreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
@@ -73,7 +76,10 @@ public void onClick(View v) {
RecyclerView recyclerView = (RecyclerView) view;
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), listitem_style_delivery,this) {
+ List
- items = new ArrayList<>();
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ recyclerView.setAdapter(new BaseRecyclerAdapter
- (items, item_style_delivery,this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
}
@@ -83,7 +89,7 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- switch (Item.values()[position]) {
+ switch (Item.values()[position % Item.values().length]) {
case 默认主题:
mToolbar.setBackgroundResource(android.R.color.white);
mToolbar.setTitleTextColor(0xffbbbbbb);
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/DropboxStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/DropBoxStyleActivity.java
similarity index 72%
rename from app/src/main/java/com/scwang/refreshlayout/activity/style/DropboxStyleActivity.java
rename to app/src/main/java/com/scwang/refreshlayout/activity/style/DropBoxStyleActivity.java
index ee6a86c2..2f718ada 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/DropboxStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/DropBoxStyleActivity.java
@@ -2,6 +2,7 @@
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
@@ -22,18 +23,32 @@
import static android.R.layout.simple_list_item_2;
import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
-public class DropboxStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
+public class DropBoxStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private enum Item {
- 默认主题("更改为默认主题颜色"),
- 橙色主题("更改为橙色主题颜色"),
- 红色主题("更改为红色主题颜色"),
- 绿色主题("更改为绿色主题颜色"),
- 蓝色主题("更改为蓝色主题颜色"),
+ 默认主题(R.string.item_style_theme_default_abstract),
+ 橙色主题(R.string.item_style_theme_orange_abstract),
+ 红色主题(R.string.item_style_theme_red_abstract),
+ 绿色主题(R.string.item_style_theme_green_abstract),
+ 蓝色主题(R.string.item_style_theme_blue_abstract),
+
+
+ 默认1主题(R.string.item_style_theme_default_abstract),
+ 橙色1主题(R.string.item_style_theme_orange_abstract),
+ 红色1主题(R.string.item_style_theme_red_abstract),
+ 绿色1主题(R.string.item_style_theme_green_abstract),
+ 蓝色1主题(R.string.item_style_theme_blue_abstract),
+
+
+ 默认2主题(R.string.item_style_theme_default_abstract),
+ 橙色2主题(R.string.item_style_theme_orange_abstract),
+ 红色2主题(R.string.item_style_theme_red_abstract),
+ 绿色2主题(R.string.item_style_theme_green_abstract),
+ 蓝色2主题(R.string.item_style_theme_blue_abstract),
;
- public String name;
- Item(String name) {
- this.name = name;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
}
}
@@ -46,7 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_style_dropbox);
- mToolbar = (Toolbar)findViewById(R.id.toolbar);
+ mToolbar = findViewById(R.id.toolbar);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -54,7 +69,7 @@ public void onClick(View v) {
}
});
- mRefreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
mRefreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
@@ -70,7 +85,7 @@ public void onClick(View v) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
- holder.text(android.R.id.text2, model.name);
+ holder.text(android.R.id.text2, model.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
@@ -79,7 +94,7 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- switch (Item.values()[position]) {
+ switch (Item.values()[position % Item.values().length]) {
case 默认主题:
setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark);
mRefreshLayout.setPrimaryColors(0xff283645, 0xff6ea9ff);
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/FlyRefreshStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/FlyRefreshStyleActivity.java
index ff12f190..4c4b8fd4 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/FlyRefreshStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/FlyRefreshStyleActivity.java
@@ -11,6 +11,7 @@
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
@@ -32,15 +33,16 @@
import com.scwang.refreshlayout.R;
import com.scwang.refreshlayout.util.StatusBarUtil;
import com.scwang.smartrefresh.header.FlyRefreshHeader;
-import com.scwang.smartrefresh.header.flyrefresh.FlyView;
-import com.scwang.smartrefresh.header.flyrefresh.MountanScenceView;
+import com.scwang.smart.refresh.header.flyrefresh.FlyView;
+import com.scwang.smart.refresh.header.flyrefresh.MountainSceneView;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;
-import com.scwang.smartrefresh.layout.util.DensityUtil;
+import com.scwang.smartrefresh.layout.util.SmartUtil;
import java.text.DateFormat;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -51,14 +53,13 @@
public class FlyRefreshStyleActivity extends AppCompatActivity {
private RecyclerView mListView;
- private RefreshLayout mRefreshlayout;
+ private RefreshLayout mRefreshLayout;
private ItemAdapter mAdapter;
private FlyView mFlyView;
private ArrayList mDataSet = new ArrayList<>();
- private LinearLayoutManager mLayoutManager;
- private MountanScenceView mScenceView;
+ private LinearLayoutManager mLayoutManager;
private FlyRefreshHeader mFlyRefreshHeader;
private CollapsingToolbarLayout mToolbarLayout;
private FloatingActionButton mActionButton;
@@ -69,7 +70,7 @@ public class FlyRefreshStyleActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fly_refresh);
- final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
@@ -78,27 +79,27 @@ public void onClick(View v) {
}
});
- /************************************************************
+ /*-----------------------------------------------------------
* 关键代码-开始
- ************************************************************/
-
- mFlyView = (FlyView) findViewById(R.id.flyview);
- mScenceView = (MountanScenceView) findViewById(R.id.mountan);
- mFlyRefreshHeader = (FlyRefreshHeader)findViewById(R.id.flyrefresh);
- mFlyRefreshHeader.setUp(mScenceView, mFlyView);//绑定场景和纸飞机
- mRefreshlayout = (RefreshLayout) findViewById(R.id.refreshLayout);
- mRefreshlayout.setReboundInterpolator(new ElasticOutInterpolator());//设置回弹插值器,会带有弹簧震动效果
- mRefreshlayout.setReboundDuration(800);//设置回弹动画时长
- mRefreshlayout.setOnRefreshListener(new OnRefreshListener() {
+ *----------------------------------------------------------*/
+
+ MountainSceneView mSceneView = findViewById(R.id.mountain);
+ mFlyView = findViewById(R.id.flyView);
+ mFlyRefreshHeader = findViewById(R.id.flyRefresh);
+ mFlyRefreshHeader.setUp(mSceneView, mFlyView);//绑定场景和纸飞机
+ mRefreshLayout = findViewById(R.id.refreshLayout);
+ mRefreshLayout.setReboundInterpolator(new ElasticOutInterpolator());//设置回弹插值器,会带有弹簧震动效果
+ mRefreshLayout.setReboundDuration(800);//设置回弹动画时长
+ mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
- public void onRefresh(RefreshLayout refreshlayout) {
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
View child = mListView.getChildAt(0);
if (child != null) {
//开始刷新的时候个第一个item设置动画效果
bounceAnimateView(child.findViewById(R.id.icon));
}
updateTheme();//改变主题颜色
- mListView.postDelayed(new Runnable() {
+ mRefreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
//通知刷新完成,这里改为通知Header,让纸飞机飞回来
@@ -112,51 +113,56 @@ public void onAnimationEnd(Animator animation) {
}
});
//设置 让 AppBarLayout 和 RefreshLayout 的滚动同步 并不保持 toolbar 位置不变
- final AppBarLayout appBar = (AppBarLayout) findViewById(R.id.app_bar);
- mRefreshlayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
+ final AppBarLayout appBar = findViewById(R.id.appbar);
+ mRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
@Override
- public void onHeaderPulling(RefreshHeader header, float percent, int offset, int footerHeight, int extendHeight) {
- appBar.setTranslationY(offset);
- toolbar.setTranslationY(-offset);
- }
- @Override
- public void onHeaderReleasing(RefreshHeader header, float percent, int offset, int footerHeight, int extendHeight) {
+ public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
appBar.setTranslationY(offset);
toolbar.setTranslationY(-offset);
}
+// @Override
+// public void onHeaderPulling(@NonNull RefreshHeader header, float percent, int offset, int footerHeight, int maxDragHeight) {
+// appBar.setTranslationY(offset);
+// toolbar.setTranslationY(-offset);
+// }
+// @Override
+// public void onHeaderReleasing(@NonNull RefreshHeader header, float percent, int offset, int footerHeight, int maxDragHeight) {
+// appBar.setTranslationY(offset);
+// toolbar.setTranslationY(-offset);
+// }
});
- /************************************************************
+ /*-----------------------------------------------------------
* 关键代码-结束
- ************************************************************/
+ *----------------------------------------------------------*/
if (isFirstEnter) {
isFirstEnter = false;
- mRefreshlayout.autoRefresh();//第一次进入触发自动刷新,演示效果
+ mRefreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
}
- /**
+ /*
* 初始化列表数据
*/
initDataSet();
mAdapter = new ItemAdapter(this);
mLayoutManager = new LinearLayoutManager(this);
- mListView = (RecyclerView) findViewById(R.id.recyclerView);
+ mListView = findViewById(R.id.recyclerView);
mListView.setLayoutManager(mLayoutManager);
mListView.setAdapter(mAdapter);
mListView.setItemAnimator(new SampleItemAnimator());
- mToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
- mActionButton = (FloatingActionButton) findViewById(R.id.fab);
- /**
+ mToolbarLayout = findViewById(R.id.toolbarLayout);
+ mActionButton = findViewById(R.id.fab);
+ /*
* 设置点击 ActionButton 时候触发自动刷新 并改变主题颜色
*/
mActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateTheme();
- mRefreshlayout.autoRefresh();
+ mRefreshLayout.autoRefresh();
}
});
- /**
+ /*
* 监听 AppBarLayout 的关闭和开启 给 FlyView(纸飞机) 和 ActionButton 设置关闭隐藏动画
*/
appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@@ -183,7 +189,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
misAppbarExpand = true;
mActionButton.animate().scaleX(1).scaleY(1);
mFlyView.animate().scaleX(1).scaleY(1);
- ValueAnimator animator = ValueAnimator.ofInt(mListView.getPaddingTop(), DensityUtil.dp2px(25));
+ ValueAnimator animator = ValueAnimator.ofInt(mListView.getPaddingTop(), SmartUtil.dp2px(25));
animator.setDuration(300);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
@@ -200,8 +206,6 @@ public void onAnimationUpdate(ValueAnimator animation) {
//状态栏透明和间距处理
StatusBarUtil.immersive(this);
StatusBarUtil.setPaddingSmart(this, toolbar);
-// StatusBarUtil.setPaddingSmart(this, findViewById(R.id.profile));
-// StatusBarUtil.setPaddingSmart(this, findViewById(R.id.blurview));
}
private void updateTheme() {
@@ -218,7 +222,7 @@ private void updateTheme() {
@Override
public void onClick(View v) {
int color = ContextCompat.getColor(getApplication(), ids[index % ids.length]);
- mRefreshlayout.setPrimaryColors(color);
+ mRefreshLayout.setPrimaryColors(color);
mActionButton.setBackgroundColor(color);
mActionButton.setBackgroundTintList(ColorStateList.valueOf(color));
mToolbarLayout.setContentScrimColor(color);
@@ -230,13 +234,18 @@ public void onClick(View v) {
}
private void initDataSet() {
- mDataSet.add(new ItemData(Color.parseColor("#76A9FC"), R.drawable.ic_fly_refresh_poll, "Meeting Minutes", new Date(2014 - 1900, 2, 9)));
- mDataSet.add(new ItemData(Color.GRAY, R.drawable.ic_fly_refresh_folder, "Favorites Photos", new Date(2014 - 1900, 1, 3)));
- mDataSet.add(new ItemData(Color.GRAY, R.drawable.ic_fly_refresh_folder, "Photos", new Date(2014 - 1900, 0, 9)));
+ try {
+ DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
+ mDataSet.add(new ItemData(0xFF76A9FC, R.drawable.ic_fly_refresh_poll, "Meeting Minutes", format.parse("2014-03-09")));
+ mDataSet.add(new ItemData(Color.GRAY, R.drawable.ic_fly_refresh_folder, "Favorites Photos", format.parse("2014-02-03")));
+ mDataSet.add(new ItemData(Color.GRAY, R.drawable.ic_fly_refresh_folder, "Photos", format.parse("2014-01-09")));
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
}
private void addItemData() {
- ItemData itemData = new ItemData(Color.parseColor("#FFC970"), R.drawable.ic_fly_refresh_smartphone, "Magic Cube Show", new Date());
+ ItemData itemData = new ItemData(0xFFFFC970, R.drawable.ic_fly_refresh_phone, "Magic Cube Show", new Date());
mDataSet.add(0, itemData);
mAdapter.notifyItemInserted(0);
mLayoutManager.scrollToPosition(0);
@@ -264,23 +273,24 @@ private class ItemAdapter extends RecyclerView.Adapter {
private LayoutInflater mInflater;
private DateFormat dateFormat;
- public ItemAdapter(Context context) {
+ ItemAdapter(Context context) {
mInflater = LayoutInflater.from(context);
dateFormat = SimpleDateFormat.getDateInstance(DateFormat.DEFAULT, Locale.ENGLISH);
}
+ @NonNull
@Override
- public ItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
+ public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = mInflater.inflate(R.layout.activity_fly_refresh_item, viewGroup, false);
return new ItemViewHolder(view);
}
@Override
- public void onBindViewHolder(ItemViewHolder itemViewHolder, int i) {
+ public void onBindViewHolder(@NonNull ItemViewHolder itemViewHolder, int i) {
final ItemData data = mDataSet.get(i);
ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
drawable.getPaint().setColor(data.color);
- itemViewHolder.icon.setBackgroundDrawable(drawable);
+ itemViewHolder.icon.setBackground(drawable);
itemViewHolder.icon.setImageResource(data.icon);
itemViewHolder.title.setText(data.title);
itemViewHolder.subTitle.setText(dateFormat.format(data.time));
@@ -298,7 +308,7 @@ private static class ItemViewHolder extends RecyclerView.ViewHolder {
TextView title;
TextView subTitle;
- public ItemViewHolder(View itemView) {
+ ItemViewHolder(View itemView) {
super(itemView);
icon = (ImageView) itemView.findViewById(R.id.icon);
title = (TextView) itemView.findViewById(R.id.title);
@@ -309,20 +319,16 @@ public ItemViewHolder(View itemView) {
public class ItemData {
int color;
- public int icon;
+ int icon;
+ Date time;
public String title;
- public Date time;
- public ItemData(int color, int icon, String title, Date time) {
+ ItemData(int color, int icon, String title, Date time) {
this.color = color;
this.icon = icon;
this.title = title;
this.time = time;
}
-
- public ItemData(int icon, String title) {
- this(Color.DKGRAY, icon, title, new Date());
- }
}
public class SampleItemAnimator extends BaseItemAnimator {
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameBattleCityStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameBattleCityStyleActivity.java
index ff72e43d..2694e8e6 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameBattleCityStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameBattleCityStyleActivity.java
@@ -2,6 +2,7 @@
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
@@ -17,7 +18,9 @@
import com.scwang.refreshlayout.adapter.SmartViewHolder;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import static android.R.layout.simple_list_item_2;
import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
@@ -25,15 +28,15 @@
public class FunGameBattleCityStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private enum Item {
- 默认主题("更改为橙色默认颜色"),
- 橙色主题("更改为橙色主题颜色"),
- 红色主题("更改为红色主题颜色"),
- 绿色主题("更改为绿色主题颜色"),
- 蓝色主题("更改为蓝色主题颜色"),
+ 默认主题(R.string.item_style_theme_default_abstract),
+ 橙色主题(R.string.item_style_theme_orange_abstract),
+ 红色主题(R.string.item_style_theme_red_abstract),
+ 绿色主题(R.string.item_style_theme_green_abstract),
+ 蓝色主题(R.string.item_style_theme_blue_abstract),
;
- public String name;
- Item(String name) {
- this.name = name;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
}
}
@@ -46,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_style_fungame_battlecity);
- mToolbar = (Toolbar)findViewById(R.id.toolbar);
+ mToolbar = findViewById(R.id.toolbar);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -54,7 +57,7 @@ public void onClick(View v) {
}
});
- mRefreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
mRefreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
@@ -66,11 +69,15 @@ public void onClick(View v) {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2,this) {
+ List
- items = new ArrayList<>();
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ recyclerView.setAdapter(new BaseRecyclerAdapter
- (items, simple_list_item_2,this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
- holder.text(android.R.id.text2, model.name);
+ holder.text(android.R.id.text2, model.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
@@ -79,7 +86,7 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- switch (Item.values()[position]) {
+ switch (Item.values()[position % Item.values().length]) {
case 默认主题:
mRefreshLayout.setPrimaryColorsId(android.R.color.white, android.R.color.black);
break;
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameHitBlockStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameHitBlockStyleActivity.java
index 0b6e106d..32591b5c 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameHitBlockStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameHitBlockStyleActivity.java
@@ -2,6 +2,7 @@
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
@@ -17,7 +18,9 @@
import com.scwang.refreshlayout.adapter.SmartViewHolder;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import static android.R.layout.simple_list_item_2;
import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
@@ -25,15 +28,15 @@
public class FunGameHitBlockStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private enum Item {
- 默认主题("更改为橙色默认颜色"),
- 橙色主题("更改为橙色主题颜色"),
- 红色主题("更改为红色主题颜色"),
- 绿色主题("更改为绿色主题颜色"),
- 蓝色主题("更改为蓝色主题颜色"),
+ 默认主题(R.string.item_style_theme_default_abstract),
+ 橙色主题(R.string.item_style_theme_orange_abstract),
+ 红色主题(R.string.item_style_theme_red_abstract),
+ 绿色主题(R.string.item_style_theme_green_abstract),
+ 蓝色主题(R.string.item_style_theme_blue_abstract),
;
- public String name;
- Item(String name) {
- this.name = name;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
}
}
@@ -46,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_style_fungame_hitblock);
- mToolbar = (Toolbar)findViewById(R.id.toolbar);
+ mToolbar = findViewById(R.id.toolbar);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -54,7 +57,7 @@ public void onClick(View v) {
}
});
- mRefreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
mRefreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
@@ -66,20 +69,25 @@ public void onClick(View v) {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2,this) {
+ List
- items = new ArrayList<>();
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ recyclerView.setAdapter(new BaseRecyclerAdapter
- (items, simple_list_item_2,this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
- holder.text(android.R.id.text2, model.name);
+ holder.text(android.R.id.text2, model.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
}
+
}
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- switch (Item.values()[position]) {
+ switch (Item.values()[position % Item.values().length]) {
case 默认主题:
mRefreshLayout.setPrimaryColorsId(android.R.color.white, android.R.color.black);
break;
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/MaterialStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/MaterialStyleActivity.java
index 0e115dcd..895ae767 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/MaterialStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/MaterialStyleActivity.java
@@ -2,6 +2,7 @@
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
@@ -18,28 +19,28 @@
import com.scwang.smartrefresh.header.MaterialHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import static android.R.layout.simple_list_item_2;
import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
public class MaterialStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
-
-
private enum Item {
- 内容不偏移("下拉的时候列表内容停留在原位不动"),
- 内容跟随偏移("下拉的时候列表内容跟随向下偏移"),
- 打开背景("下拉的时候绘制贝塞尔曲线背景"),
- 关闭背景("下拉的时候不绘制贝塞尔曲线背景"),
- 橙色主题("更改为橙色主题颜色"),
- 红色主题("更改为红色主题颜色"),
- 绿色主题("更改为绿色主题颜色"),
- 蓝色主题("更改为蓝色主题颜色"),
+ 打开背景(R.string.item_style_bezier_on),
+ 关闭背景(R.string.item_style_bezier_off),
+ 内容不偏移(R.string.item_style_content_translation_off),
+ 内容跟随偏移(R.string.item_style_content_translation_on),
+ 橙色主题(R.string.item_style_theme_orange_abstract),
+ 红色主题(R.string.item_style_theme_red_abstract),
+ 绿色主题(R.string.item_style_theme_green_abstract),
+ 蓝色主题(R.string.item_style_theme_blue_abstract),
;
- public String name;
- Item(String name) {
- this.name = name;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
}
}
@@ -53,15 +54,10 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_style_material);
- mToolbar = (Toolbar)findViewById(R.id.toolbar);
- mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
+ mToolbar = findViewById(R.id.toolbar);
+ mToolbar.setNavigationOnClickListener(v -> finish());
- mRefreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
mRefreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
@@ -75,11 +71,14 @@ public void onClick(View v) {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2,this) {
+ List
- items = new ArrayList<>();
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ recyclerView.setAdapter(new BaseRecyclerAdapter
- (items, simple_list_item_2,this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
- holder.text(android.R.id.text2, model.name);
+ holder.text(android.R.id.text2, model.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
@@ -88,7 +87,7 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- switch (Item.values()[position]) {
+ switch (Item.values()[position % Item.values().length]) {
case 内容不偏移:
mRefreshLayout.setEnableHeaderTranslationContent(false);
break;
@@ -120,6 +119,8 @@ public void onItemClick(AdapterView> parent, View view, int position, long id)
private void setThemeColor(int colorPrimary, int colorPrimaryDark) {
mToolbar.setBackgroundResource(colorPrimary);
mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white);
+ mMaterialHeader.setProgressBackgroundColorSchemeResource(colorPrimary);
+ mMaterialHeader.setColorSchemeResources(android.R.color.white);
if (Build.VERSION.SDK_INT >= 21) {
getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark));
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/PhoenixStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/PhoenixStyleActivity.java
index 1b4ab3fb..96989fdd 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/PhoenixStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/PhoenixStyleActivity.java
@@ -3,6 +3,7 @@
import android.content.res.ColorStateList;
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
@@ -21,7 +22,9 @@
import com.scwang.refreshlayout.adapter.SmartViewHolder;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import static android.R.layout.simple_list_item_2;
import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
@@ -29,16 +32,16 @@
public class PhoenixStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private enum Item {
- 折叠("折叠AppBarLayout,变成正常的列表页面"),
- 展开("展开AppBarLayout,变成可伸展头部的页面"),
- 橙色主题("更改为橙色主题颜色"),
- 红色主题("更改为红色主题颜色"),
- 绿色主题("更改为绿色主题颜色"),
- 蓝色主题("更改为蓝色主题颜色"),
+ 折叠(R.string.item_style_app_bar_collapse),
+ 展开(R.string.item_style_app_bar_expand),
+ 橙色主题(R.string.item_style_theme_orange_abstract),
+ 红色主题(R.string.item_style_theme_red_abstract),
+ 绿色主题(R.string.item_style_theme_green_abstract),
+ 蓝色主题(R.string.item_style_theme_blue_abstract),
;
- public String name;
- Item(String name) {
- this.name = name;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
}
}
@@ -55,7 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_style_phoenix);
- mToolbar = (Toolbar)findViewById(R.id.toolbar);
+ mToolbar = findViewById(R.id.toolbar);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -63,14 +66,14 @@ public void onClick(View v) {
}
});
- mRefreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
mRefreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
}
- mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
- mToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
+ mAppBarLayout = findViewById(R.id.appbar);
+ mToolbarLayout = findViewById(R.id.toolbarLayout);
View view = findViewById(R.id.recyclerView);
if (view instanceof RecyclerView) {
@@ -78,21 +81,24 @@ public void onClick(View v) {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2,this) {
+ List
- items = new ArrayList<>();
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ recyclerView.setAdapter(new BaseRecyclerAdapter
- (items, simple_list_item_2,this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
- holder.text(android.R.id.text2, model.name);
+ holder.text(android.R.id.text2, model.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
mRecyclerView = recyclerView;
}
- /**
- * 监听 AppBarLayout 的关闭和开启 给 FlyView(纸飞机) 和 ActionButton 设置关闭隐藏动画
+ /*
+ * 监听 AppBarLayout 的关闭和开启 ActionButton 设置关闭隐藏动画
*/
- mActionButton = (FloatingActionButton) findViewById(R.id.fab);
+ mActionButton = findViewById(R.id.fab);
mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
boolean misAppbarExpand = true;
View fab = findViewById(R.id.fab);
@@ -114,7 +120,7 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- switch (Item.values()[position]) {
+ switch (Item.values()[position % Item.values().length]) {
case 折叠:
mAppBarLayout.setExpanded(false, true);
mAppBarLayout.setEnabled(false);
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/StoreHouseStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/StoreHouseStyleActivity.java
index d0a64724..74a1814b 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/StoreHouseStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/StoreHouseStyleActivity.java
@@ -1,7 +1,9 @@
package com.scwang.refreshlayout.activity.style;
+import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
@@ -15,9 +17,13 @@
import com.scwang.refreshlayout.R;
import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
import com.scwang.refreshlayout.adapter.SmartViewHolder;
+import com.scwang.smartrefresh.header.StoreHouseHeader;
+import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import static android.R.layout.simple_list_item_2;
import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
@@ -25,14 +31,18 @@
public class StoreHouseStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private enum Item {
- 橙色主题("更改为橙色主题颜色"),
- 红色主题("更改为红色主题颜色"),
- 绿色主题("更改为绿色主题颜色"),
- 蓝色主题("更改为蓝色主题颜色"),
+ 显示商标(R.string.item_style_store_house_brand),
+ 显示图标(R.string.item_style_store_house_icon),
+ 显示中文(R.string.item_style_store_house_chinese),
+ 显示英文(R.string.item_style_store_house_english),
+ 橙色主题(R.string.item_style_theme_orange_abstract),
+ 红色主题(R.string.item_style_theme_red_abstract),
+ 绿色主题(R.string.item_style_theme_green_abstract),
+ 蓝色主题(R.string.item_style_theme_blue_abstract),
;
- public String name;
- Item(String name) {
- this.name = name;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
}
}
@@ -45,7 +55,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_style_storehouse);
- mToolbar = (Toolbar)findViewById(R.id.toolbar);
+ mToolbar = findViewById(R.id.toolbar);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -53,7 +63,7 @@ public void onClick(View v) {
}
});
- mRefreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
mRefreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
@@ -65,11 +75,14 @@ public void onClick(View v) {
recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2,this) {
+ List
- items = new ArrayList<>();
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ recyclerView.setAdapter(new BaseRecyclerAdapter
- (items, simple_list_item_2,this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
- holder.text(android.R.id.text2, model.name);
+ holder.text(android.R.id.text2, model.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
@@ -78,7 +91,35 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- switch (Item.values()[position]) {
+ switch (Item.values()[position % Item.values().length]) {
+ case 显示中文: {
+ RefreshHeader refreshHeader = mRefreshLayout.getRefreshHeader();
+ if (refreshHeader instanceof StoreHouseHeader) {
+ ((StoreHouseHeader) refreshHeader).initWithPointList(getPointList());
+ }
+ break;
+ }
+ case 显示英文: {
+ RefreshHeader refreshHeader = mRefreshLayout.getRefreshHeader();
+ if (refreshHeader instanceof StoreHouseHeader) {
+ ((StoreHouseHeader) refreshHeader).initWithString("SmartRefresh");
+ }
+ break;
+ }
+ case 显示图标: {
+ RefreshHeader refreshHeader = mRefreshLayout.getRefreshHeader();
+ if (refreshHeader instanceof StoreHouseHeader) {
+ ((StoreHouseHeader) refreshHeader).initWithStringArray(R.array.storehouse);
+ }
+ break;
+ }
+ case 显示商标: {
+ RefreshHeader refreshHeader = mRefreshLayout.getRefreshHeader();
+ if (refreshHeader instanceof StoreHouseHeader) {
+ ((StoreHouseHeader) refreshHeader).initWithStringArray(R.array.akta);
+ }
+ break;
+ }
case 蓝色主题:
setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark);
break;
@@ -103,4 +144,80 @@ private void setThemeColor(int colorPrimary, int colorPrimaryDark) {
}
}
+ private List getPointList() {
+ // this point is taken from https://github.com/cloay/CRefreshLayout
+ List startPoints = new ArrayList<>();
+ startPoints.add(new Point(240, 80));
+ startPoints.add(new Point(270, 80));
+ startPoints.add(new Point(265, 103));
+ startPoints.add(new Point(255, 65));
+ startPoints.add(new Point(275, 80));
+ startPoints.add(new Point(275, 80));
+ startPoints.add(new Point(302, 80));
+ startPoints.add(new Point(275, 107));
+
+ startPoints.add(new Point(320, 70));
+ startPoints.add(new Point(313, 80));
+ startPoints.add(new Point(330, 63));
+ startPoints.add(new Point(315, 87));
+ startPoints.add(new Point(330, 80));
+ startPoints.add(new Point(315, 100));
+ startPoints.add(new Point(330, 90));
+ startPoints.add(new Point(315, 110));
+ startPoints.add(new Point(345, 65));
+ startPoints.add(new Point(357, 67));
+ startPoints.add(new Point(363, 103));
+
+ startPoints.add(new Point(375, 80));
+ startPoints.add(new Point(375, 80));
+ startPoints.add(new Point(425, 80));
+ startPoints.add(new Point(380, 95));
+ startPoints.add(new Point(400, 63));
+
+ List endPoints = new ArrayList<>();
+ endPoints.add(new Point(270, 80));
+ endPoints.add(new Point(270, 110));
+ endPoints.add(new Point(270, 110));
+ endPoints.add(new Point(250, 110));
+ endPoints.add(new Point(275, 107));
+ endPoints.add(new Point(302, 80));
+ endPoints.add(new Point(302, 107));
+ endPoints.add(new Point(302, 107));
+
+ endPoints.add(new Point(340, 70));
+ endPoints.add(new Point(360, 80));
+ endPoints.add(new Point(330, 80));
+ endPoints.add(new Point(340, 87));
+ endPoints.add(new Point(315, 100));
+ endPoints.add(new Point(345, 98));
+ endPoints.add(new Point(330, 120));
+ endPoints.add(new Point(345, 108));
+ endPoints.add(new Point(360, 120));
+ endPoints.add(new Point(363, 75));
+ endPoints.add(new Point(345, 117));
+
+ endPoints.add(new Point(380, 95));
+ endPoints.add(new Point(425, 80));
+ endPoints.add(new Point(420, 95));
+ endPoints.add(new Point(420, 95));
+ endPoints.add(new Point(400, 120));
+ List list = new ArrayList<>();
+
+ int offsetX = Integer.MAX_VALUE;
+ int offsetY = Integer.MAX_VALUE;
+
+ for (int i = 0; i < startPoints.size(); i++) {
+ offsetX = Math.min(startPoints.get(i).x, offsetX);
+ offsetY = Math.min(startPoints.get(i).y, offsetY);
+ }
+ for (int i = 0; i < endPoints.size(); i++) {
+ float[] point = new float[4];
+ point[0] = startPoints.get(i).x - offsetX;
+ point[1] = startPoints.get(i).y - offsetY;
+ point[2] = endPoints.get(i).x - offsetX;
+ point[3] = endPoints.get(i).y - offsetY;
+ list.add(point);
+ }
+ return list;
+ }
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/TaurusStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/TaurusStyleActivity.java
index 986dbe3c..e3026a1b 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/TaurusStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/TaurusStyleActivity.java
@@ -3,6 +3,7 @@
import android.content.res.ColorStateList;
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
@@ -21,7 +22,9 @@
import com.scwang.refreshlayout.adapter.SmartViewHolder;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import static android.R.layout.simple_list_item_2;
import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
@@ -29,16 +32,16 @@
public class TaurusStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private enum Item {
- 折叠("折叠AppBarLayout,变成正常的列表页面"),
- 展开("展开AppBarLayout,变成可伸展头部的页面"),
- 橙色主题("更改为橙色主题颜色"),
- 红色主题("更改为红色主题颜色"),
- 绿色主题("更改为绿色主题颜色"),
- 蓝色主题("更改为蓝色主题颜色"),
+ 折叠(R.string.item_style_app_bar_collapse),
+ 展开(R.string.item_style_app_bar_expand),
+ 橙色主题(R.string.item_style_theme_orange_abstract),
+ 红色主题(R.string.item_style_theme_red_abstract),
+ 绿色主题(R.string.item_style_theme_green_abstract),
+ 蓝色主题(R.string.item_style_theme_blue_abstract),
;
- public String name;
- Item(String name) {
- this.name = name;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
}
}
@@ -55,7 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_style_taurus);
- mToolbar = (Toolbar)findViewById(R.id.toolbar);
+ mToolbar = findViewById(R.id.toolbar);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -63,14 +66,14 @@ public void onClick(View v) {
}
});
- mRefreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
mRefreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
}
- mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
- mToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
+ mAppBarLayout = findViewById(R.id.appbar);
+ mToolbarLayout = findViewById(R.id.toolbarLayout);
View view = findViewById(R.id.recyclerView);
if (view instanceof RecyclerView) {
@@ -78,21 +81,24 @@ public void onClick(View v) {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2,this) {
+ List
- items = new ArrayList<>();
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ recyclerView.setAdapter(new BaseRecyclerAdapter
- (items, simple_list_item_2,this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
- holder.text(android.R.id.text2, model.name);
+ holder.text(android.R.id.text2, model.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
mRecyclerView = recyclerView;
}
- /**
- * 监听 AppBarLayout 的关闭和开启 给 FlyView(纸飞机) 和 ActionButton 设置关闭隐藏动画
+ /*
+ * 监听 AppBarLayout 的关闭和开启 给 ActionButton 设置关闭隐藏动画
*/
- mActionButton = (FloatingActionButton) findViewById(R.id.fab);
+ mActionButton = findViewById(R.id.fab);
mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
boolean misAppbarExpand = true;
View fab = findViewById(R.id.fab);
@@ -114,7 +120,7 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- switch (Item.values()[position]) {
+ switch (Item.values()[position % Item.values().length]) {
case 折叠:
mAppBarLayout.setExpanded(false, true);
mAppBarLayout.setEnabled(false);
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/WaterDropStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/WaterDropStyleActivity.java
index 41b30a60..01be31fd 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/WaterDropStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/WaterDropStyleActivity.java
@@ -2,6 +2,7 @@
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
@@ -17,7 +18,9 @@
import com.scwang.refreshlayout.adapter.SmartViewHolder;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import static android.R.layout.simple_list_item_2;
import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
@@ -25,17 +28,17 @@
public class WaterDropStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private enum Item {
- 内容不偏移("下拉的时候列表内容停留在原位不动"),
- 内容跟随偏移("下拉的时候列表内容跟随向下偏移"),
- 默认主题("更改为默认主题颜色"),
- 橙色主题("更改为橙色主题颜色"),
- 红色主题("更改为红色主题颜色"),
- 绿色主题("更改为绿色主题颜色"),
- 蓝色主题("更改为蓝色主题颜色"),
+ 内容不偏移(R.string.item_style_content_translation_off),
+ 内容跟随偏移(R.string.item_style_content_translation_on),
+ 默认主题(R.string.item_style_theme_default_abstract),
+ 橙色主题(R.string.item_style_theme_orange_abstract),
+ 红色主题(R.string.item_style_theme_red_abstract),
+ 绿色主题(R.string.item_style_theme_green_abstract),
+ 蓝色主题(R.string.item_style_theme_blue_abstract),
;
- public String name;
- Item(String name) {
- this.name = name;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
}
}
@@ -48,7 +51,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_style_water_drop);
- mToolbar = (Toolbar)findViewById(R.id.toolbar);
+ mToolbar = findViewById(R.id.toolbar);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -56,7 +59,7 @@ public void onClick(View v) {
}
});
- mRefreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
mRefreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
@@ -68,11 +71,14 @@ public void onClick(View v) {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2,this) {
+ List
- items = new ArrayList<>();
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ recyclerView.setAdapter(new BaseRecyclerAdapter
- (items, simple_list_item_2,this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
- holder.text(android.R.id.text2, model.name);
+ holder.text(android.R.id.text2, model.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
@@ -81,7 +87,7 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- switch (Item.values()[position]) {
+ switch (Item.values()[position % Item.values().length]) {
case 内容不偏移:
mRefreshLayout.setEnableHeaderTranslationContent(false);
break;
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/BezierStyleActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/style/WaveSwipeStyleActivity.java
similarity index 74%
rename from app/src/main/java/com/scwang/refreshlayout/activity/style/BezierStyleActivity.java
rename to app/src/main/java/com/scwang/refreshlayout/activity/style/WaveSwipeStyleActivity.java
index a0dd47c3..a0825f0f 100644
--- a/app/src/main/java/com/scwang/refreshlayout/activity/style/BezierStyleActivity.java
+++ b/app/src/main/java/com/scwang/refreshlayout/activity/style/WaveSwipeStyleActivity.java
@@ -2,6 +2,7 @@
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
@@ -17,24 +18,26 @@
import com.scwang.refreshlayout.adapter.SmartViewHolder;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import static android.R.layout.simple_list_item_2;
import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
-public class BezierStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
+public class WaveSwipeStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private enum Item {
- 内容不偏移("下拉的时候列表内容停留在原位不动"),
- 内容跟随偏移("下拉的时候列表内容跟随向下偏移"),
- 橙色主题("更改为橙色主题颜色"),
- 红色主题("更改为红色主题颜色"),
- 绿色主题("更改为绿色主题颜色"),
- 蓝色主题("更改为蓝色主题颜色"),
+ 内容不偏移(R.string.item_style_content_translation_off),
+ 内容跟随偏移(R.string.item_style_content_translation_on),
+ 橙色主题(R.string.item_style_theme_orange_abstract),
+ 红色主题(R.string.item_style_theme_red_abstract),
+ 绿色主题(R.string.item_style_theme_green_abstract),
+ 蓝色主题(R.string.item_style_theme_blue_abstract),
;
- public String name;
- Item(String name) {
- this.name = name;
+ public int nameId;
+ Item(@StringRes int nameId) {
+ this.nameId = nameId;
}
}
@@ -45,9 +48,9 @@ private enum Item {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_style_bezier);
+ setContentView(R.layout.activity_style_wave_swipe);
- mToolbar = (Toolbar)findViewById(R.id.toolbar);
+ mToolbar = findViewById(R.id.toolbar);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -55,7 +58,7 @@ public void onClick(View v) {
}
});
- mRefreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
+ mRefreshLayout = findViewById(R.id.refreshLayout);
if (isFirstEnter) {
isFirstEnter = false;
mRefreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
@@ -67,11 +70,15 @@ public void onClick(View v) {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2,this) {
+ List
- items = new ArrayList<>();
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ items.addAll(Arrays.asList(Item.values()));
+ recyclerView.setAdapter(new BaseRecyclerAdapter
- (items, simple_list_item_2,this) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
holder.text(android.R.id.text1, model.name());
- holder.text(android.R.id.text2, model.name);
+ holder.text(android.R.id.text2, model.nameId);
holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
}
});
@@ -80,7 +87,7 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- switch (Item.values()[position]) {
+ switch (Item.values()[position % Item.values().length]) {
case 内容不偏移:
mRefreshLayout.setEnableHeaderTranslationContent(false);
break;
@@ -111,5 +118,4 @@ private void setThemeColor(int colorPrimary, int colorPrimaryDark) {
}
}
-
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/using/AssignDefaultUsingActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/using/AssignDefaultUsingActivity.java
deleted file mode 100644
index 724f2490..00000000
--- a/app/src/main/java/com/scwang/refreshlayout/activity/using/AssignDefaultUsingActivity.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package com.scwang.refreshlayout.activity.using;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.Toolbar;
-import android.view.View;
-
-import com.scwang.refreshlayout.R;
-import com.scwang.smartrefresh.layout.SmartRefreshLayout;
-import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreater;
-import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreater;
-import com.scwang.smartrefresh.layout.api.RefreshFooter;
-import com.scwang.smartrefresh.layout.api.RefreshHeader;
-import com.scwang.smartrefresh.layout.api.RefreshLayout;
-import com.scwang.smartrefresh.layout.constant.RefreshState;
-import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
-import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
-import com.scwang.smartrefresh.layout.header.ClassicsHeader;
-import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;
-
-/**
- * 全局指定默认的Header和Footer
- */
-public class AssignDefaultUsingActivity extends AppCompatActivity {
-
- private static boolean isFirstEnter = true;
-
- /**
- * 关键代码,需要在布局生成之前设置,建议代码放在 Application.onCreate 中
- */
- public AssignDefaultUsingActivity() {
- //设置全局的Header构建器
- SmartRefreshLayout.setDefaultRefreshHeaderCreater(new DefaultRefreshHeaderCreater() {
- @NonNull
- @Override
- public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
- layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);//创建同时可以先设置主题颜色
- ((View) layout).setBackgroundResource(R.color.colorPrimary);//设置刷新布局的背景融合Header主题色
- return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.FixedBehind);//指定为经典Header,默认是 贝塞尔雷达Header
- }
- });
- //设置全局的Footer构建器
- SmartRefreshLayout.setDefaultRefreshFooterCreater(new DefaultRefreshFooterCreater() {
- @NonNull
- @Override
- public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
- ClassicsFooter footer = new ClassicsFooter(context);
- footer.setBackgroundResource(android.R.color.white);
- footer.setSpinnerStyle(SpinnerStyle.Scale);//设置为拉伸模式
- return footer;//指定为经典Footer,默认是 BallPulseFooter
- }
- });
- }
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_using_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(RefreshLayout refreshLayout, RefreshState oldState, RefreshState newState) {
- if (oldState == RefreshState.LoadingFinish
- && newState == RefreshState.None) {
- refreshLayout.autoRefresh();
- refreshLayout.setOnMultiPurposeListener(null);
- }
- }
- });
- }
- }
-
-}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/using/BasicUsingActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/using/BasicUsingActivity.java
deleted file mode 100644
index 5eb05f7f..00000000
--- a/app/src/main/java/com/scwang/refreshlayout/activity/using/BasicUsingActivity.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package com.scwang.refreshlayout.activity.using;
-
-import android.os.Bundle;
-import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.Toolbar;
-import android.view.View;
-import android.widget.ListView;
-import android.widget.Toast;
-
-import com.scwang.refreshlayout.R;
-import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
-import com.scwang.refreshlayout.adapter.SmartViewHolder;
-import com.scwang.smartrefresh.layout.api.RefreshLayout;
-import com.scwang.smartrefresh.layout.listener.OnLoadmoreListener;
-import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Locale;
-
-import static android.R.layout.simple_list_item_2;
-
-/**
- * 基本的功能使用
- */
-public class BasicUsingActivity extends AppCompatActivity {
-
- private BaseRecyclerAdapter mAdapter;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_using_basic);
-
- 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(simple_list_item_2) {
- @Override
- protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) {
- holder.text(android.R.id.text1, String.format(Locale.CHINA, "第%02d条数据", position));
- holder.text(android.R.id.text2, String.format(Locale.CHINA, "这是测试的第%02d条数据", position));
- holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
- }
- });
-
- final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
- refreshLayout.setEnableAutoLoadmore(true);//开启自动加载功能(非必须)
- refreshLayout.setOnRefreshListener(new OnRefreshListener() {
- @Override
- public void onRefresh(final RefreshLayout refreshlayout) {
- ((View) refreshlayout).postDelayed(new Runnable() {
- @Override
- public void run() {
- mAdapter.refresh(initData());
- refreshlayout.finishRefresh();
- }
- }, 2000);
- }
- });
- refreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {
- @Override
- public void onLoadmore(final RefreshLayout refreshlayout) {
- ((View) refreshlayout).postDelayed(new Runnable() {
- @Override
- public void run() {
- mAdapter.loadmore(initData());
- refreshlayout.finishLoadmore();
- if (mAdapter.getItemCount() > 60) {
- Toast.makeText(getApplication(), "数据全部加载完毕", Toast.LENGTH_SHORT).show();
- refreshlayout.setLoadmoreFinished(true);//将不会再次触发加载更多事件
- }
- }
- }, 2000);
- }
- });
-
- //触发自动刷新
- refreshLayout.autoRefresh();
-
- }
-
- private Collection initData() {
- return Arrays.asList(null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
- }
-}
diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/using/ListenerUsingActivity.java b/app/src/main/java/com/scwang/refreshlayout/activity/using/ListenerUsingActivity.java
deleted file mode 100644
index 1f7d87b6..00000000
--- a/app/src/main/java/com/scwang/refreshlayout/activity/using/ListenerUsingActivity.java
+++ /dev/null
@@ -1,177 +0,0 @@
-package com.scwang.refreshlayout.activity.using;
-
-import android.os.Bundle;
-import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.Toolbar;
-import android.view.View;
-import android.widget.TextView;
-
-import com.scwang.refreshlayout.R;
-import com.scwang.smartrefresh.layout.api.RefreshFooter;
-import com.scwang.smartrefresh.layout.api.RefreshHeader;
-import com.scwang.smartrefresh.layout.api.RefreshLayout;
-import com.scwang.smartrefresh.layout.constant.RefreshState;
-import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-
-/**
- * 多功能监听器的使用
- */
-public class ListenerUsingActivity extends AppCompatActivity {
-
-
- private static DateFormat FORMAT = new SimpleDateFormat("HH:mm sss", Locale.CHINA);
-
- private TextView mTvContent;
- private static boolean isFirstEnter = true;
- private String mHeaderPulling;
- private String mHeaderReleasing;
- private String mFooterPulling;
- private String mFooterReleasing;
- private String mFooterStartAnimator;
- private String mHeaderStartAnimator;
- private String mFooterFinish;
- private String mHeaderFinish;
- private String mRefresh;
- private String mLoadmore;
- private String mStateChanged;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_using_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);
-
- final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
- refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
- @Override
- public void onHeaderPulling(RefreshHeader header, float percent, int offset, int headerHeight, int extendHeight) {
- mHeaderPulling = String.format(Locale.CHINA, "%s\npercent=%.02f offset=%03d\nheight=%03d extend=%03d",
- FORMAT.format(new Date()),
- percent,offset,headerHeight,extendHeight);
- updateContent();
- }
-
- @Override
- public void onHeaderReleasing(RefreshHeader header, float percent, int offset, int headerHeight, int extendHeight) {
- mHeaderReleasing = String.format(Locale.CHINA, "%s\npercent=%.02f offset=%03d\nheight=%03d extend=%03d",
- FORMAT.format(new Date()),
- percent,offset,headerHeight,extendHeight);
- updateContent();
- }
-
- @Override
- public void onHeaderStartAnimator(RefreshHeader header, int headerHeight, int extendHeight) {
- mHeaderStartAnimator = String.format(Locale.CHINA, "%s\nheight=%03d extend=%03d",
- FORMAT.format(new Date()),
- headerHeight,extendHeight);
- updateContent();
- }
-
- @Override
- public void onHeaderFinish(RefreshHeader header, boolean success) {
- mHeaderFinish = String.format(Locale.CHINA, "%s - " + success,FORMAT.format(new Date()));
- updateContent();
- }
-
- @Override
- public void onFooterPulling(RefreshFooter footer, float percent, int offset, int footerHeight, int extendHeight) {
- mFooterPulling = String.format(Locale.CHINA, "%s\npercent=%.02f\noffset=%03d height=%03d\nextend=%03d",
- FORMAT.format(new Date()),
- percent,offset,footerHeight,extendHeight);
- updateContent();
- }
-
- @Override
- public void onFooterReleasing(RefreshFooter footer, float percent, int offset, int footerHeight, int extendHeight) {
- mFooterReleasing = String.format(Locale.CHINA, "%s\npercent=%.02f\noffset=%03d height=%03d\nextend=%03d",
- FORMAT.format(new Date()),
- percent,offset,footerHeight,extendHeight);
- updateContent();
- }
-
- @Override
- public void onFooterStartAnimator(RefreshFooter footer, int footerHeight, int extendHeight) {
- mFooterStartAnimator = String.format(Locale.CHINA, "%s\nheight=%03d extend=%03d",
- FORMAT.format(new Date()),
- footerHeight,extendHeight);
- updateContent();
- }
-
- @Override
- public void onFooterFinish(RefreshFooter footer, boolean success) {
- mFooterFinish = String.format(Locale.CHINA, "%s - " + success,FORMAT.format(new Date()));
- updateContent();
- }
-
- @Override
- public void onRefresh(RefreshLayout refreshlayout) {
- mRefresh = String.format(Locale.CHINA, "%s",FORMAT.format(new Date()));
- updateContent();
- }
-
- @Override
- public void onLoadmore(RefreshLayout refreshlayout) {
- mLoadmore = String.format(Locale.CHINA, "%s",FORMAT.format(new Date()));
- updateContent();
- }
-
- @Override
- public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, 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();
- }
-
- }
-
- private void updateContent() {
- mTvContent.setText(String.format(Locale.CHINA,
- "onStateChanged:%s\n\n" +
- "onHeaderPulling:%s\n\n" +
- "onHeaderReleasing:%s\n\n" +
- "onHeaderStartAnimator:%s\n\n" +
- "onHeaderFinish:%s\n\n" +
- "onFooterPulling:%s\n\n" +
- "onFooterReleasing:%s\n\n" +
- "onFooterStartAnimator:%s\n\n" +
- "onFooterFinish:%s\n\n" +
- "onRefresh:%s\n\n" +
- "onLoadmore:%s\n\n",
- mStateChanged,
- mHeaderPulling,
- mHeaderReleasing,
- mHeaderStartAnimator,
- mHeaderFinish,
- mFooterPulling,
- mFooterReleasing,
- mFooterStartAnimator,
- mFooterFinish,
- mRefresh,
- mLoadmore));
- }
-
-}
diff --git a/app/src/main/java/com/scwang/refreshlayout/adapter/BaseRecyclerAdapter.java b/app/src/main/java/com/scwang/refreshlayout/adapter/BaseRecyclerAdapter.java
index 88af8c20..85e83a7a 100644
--- a/app/src/main/java/com/scwang/refreshlayout/adapter/BaseRecyclerAdapter.java
+++ b/app/src/main/java/com/scwang/refreshlayout/adapter/BaseRecyclerAdapter.java
@@ -16,17 +16,18 @@
/**
*
- * Created by SCWANG on 2017/6/11.
+ * Created by scwang on 2017/6/11.
*/
-
+@SuppressWarnings({"UnusedReturnValue", "unused"})
public abstract class BaseRecyclerAdapter extends RecyclerView.Adapter implements ListAdapter {
//
-
private final int mLayoutId;
private final List mList;
- private AdapterView.OnItemClickListener mListener;
+ private int mLastPosition = -1;
+ private boolean mOpenAnimationEnable = true;
+ protected AdapterView.OnItemClickListener mListener;
public BaseRecyclerAdapter(@LayoutRes int layoutId) {
setHasStableIds(false);
@@ -48,6 +49,14 @@ public BaseRecyclerAdapter(Collection collection, @LayoutRes int layoutId, Ad
}
//
+ private void addAnimate(SmartViewHolder holder, int postion) {
+ if (mOpenAnimationEnable && mLastPosition < postion) {
+ holder.itemView.setAlpha(0);
+ holder.itemView.animate().alpha(1).start();
+ mLastPosition = postion;
+ }
+ }
+
//
@Override
public SmartViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
@@ -65,32 +74,18 @@ public void onBindViewHolder(SmartViewHolder holder, int position) {
public int getItemCount() {
return mList.size();
}
- //
-
- //
-
- public BaseRecyclerAdapter setOnItemClickListener(AdapterView.OnItemClickListener listener) {
- mListener = listener;
- return this;
- }
- public BaseRecyclerAdapter refresh(Collection collection) {
- mList.clear();
- mList.addAll(collection);
- notifyDataSetChanged();
- notifyListDataSetChanged();
- return this;
+ @Override
+ public void onViewAttachedToWindow(SmartViewHolder holder) {
+ super.onViewAttachedToWindow(holder);
+ addAnimate(holder, holder.getLayoutPosition());
}
- public BaseRecyclerAdapter loadmore(Collection collection) {
- mList.addAll(collection);
- notifyDataSetChanged();
- notifyListDataSetChanged();
- return this;
+ public void setOpenAnimationEnable(boolean enabled) {
+ this.mOpenAnimationEnable = enabled;
}
//
-
//
private final DataSetObservable mDataSetObservable = new DataSetObservable();
@@ -141,7 +136,9 @@ public View getView(int position, View convertView, ViewGroup parent) {
convertView = holder.itemView;
convertView.setTag(holder);
}
+ holder.setPosition(position);
onBindViewHolder(holder, position);
+ addAnimate(holder, position);
return convertView;
}
@@ -166,6 +163,40 @@ public Object getItem(int position) {
public int getCount() {
return mList.size();
}
+ //
+
+ //
+ public T get(int index) {
+ return mList.get(index);
+ }
+
+ public BaseRecyclerAdapter setOnItemClickListener(AdapterView.OnItemClickListener listener) {
+ mListener = listener;
+ return this;
+ }
+
+ public BaseRecyclerAdapter refresh(Collection collection) {
+ mList.clear();
+ mList.addAll(collection);
+ notifyDataSetChanged();
+ notifyListDataSetChanged();
+ mLastPosition = -1;
+ return this;
+ }
+ public BaseRecyclerAdapter loadMore(Collection collection) {
+ mList.addAll(collection);
+ notifyDataSetChanged();
+ notifyListDataSetChanged();
+ return this;
+ }
+
+ public BaseRecyclerAdapter insert(Collection collection) {
+ mList.addAll(0, collection);
+ notifyItemRangeInserted(0, collection.size());
+ notifyListDataSetChanged();
+ return this;
+ }
//
+
}
diff --git a/app/src/main/java/com/scwang/refreshlayout/adapter/SmartViewHolder.java b/app/src/main/java/com/scwang/refreshlayout/adapter/SmartViewHolder.java
index 66b69c26..57cb17f2 100644
--- a/app/src/main/java/com/scwang/refreshlayout/adapter/SmartViewHolder.java
+++ b/app/src/main/java/com/scwang/refreshlayout/adapter/SmartViewHolder.java
@@ -13,13 +13,14 @@
public class SmartViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private final AdapterView.OnItemClickListener mListener;
+ private int mPosition = -1;
public SmartViewHolder(View itemView, AdapterView.OnItemClickListener mListener) {
super(itemView);
this.mListener = mListener;
itemView.setOnClickListener(this);
- /**
+ /*
* 设置水波纹背景
*/
if (itemView.getBackground() == null) {
@@ -36,12 +37,18 @@ public SmartViewHolder(View itemView, AdapterView.OnItemClickListener mListener)
}
}
+ public void setPosition(int position) {
+ mPosition = position;
+ }
+
@Override
public void onClick(View v) {
if (mListener != null) {
int position = getAdapterPosition();
if(position >= 0){
mListener.onItemClick(null, v, position, getItemId());
+ } else if (mPosition > -1) {
+ mListener.onItemClick(null, v, mPosition, getItemId());
}
}
}
@@ -81,4 +88,20 @@ public SmartViewHolder image(int id, int imageId) {
}
return this;
}
+
+ public SmartViewHolder gone(int id) {
+ View view = findViewById(id);
+ if (view != null) {
+ view.setVisibility(View.GONE);
+ }
+ return this;
+ }
+
+ public SmartViewHolder visible(int id) {
+ View view = findViewById(id);
+ if (view != null) {
+ view.setVisibility(View.VISIBLE);
+ }
+ return this;
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/RefreshStylesFragment.java b/app/src/main/java/com/scwang/refreshlayout/fragment/RefreshStylesFragment.java
deleted file mode 100644
index 2b056cd4..00000000
--- a/app/src/main/java/com/scwang/refreshlayout/fragment/RefreshStylesFragment.java
+++ /dev/null
@@ -1,134 +0,0 @@
-package com.scwang.refreshlayout.fragment;
-
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.support.annotation.StringRes;
-import android.support.v4.app.Fragment;
-import android.support.v7.widget.DefaultItemAnimator;
-import android.support.v7.widget.DividerItemDecoration;
-import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.RecyclerView;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-
-import com.scwang.refreshlayout.R;
-import com.scwang.refreshlayout.activity.ExperimentActivity;
-import com.scwang.refreshlayout.activity.style.BezierStyleActivity;
-import com.scwang.refreshlayout.activity.style.CircleStyleActivity;
-import com.scwang.refreshlayout.activity.style.ClassicsStyleActivity;
-import com.scwang.refreshlayout.activity.style.DeliveryStyleActivity;
-import com.scwang.refreshlayout.activity.style.DropboxStyleActivity;
-import com.scwang.refreshlayout.activity.style.FlyRefreshStyleActivity;
-import com.scwang.refreshlayout.activity.style.FunGameBattleCityStyleActivity;
-import com.scwang.refreshlayout.activity.style.FunGameHitBlockStyleActivity;
-import com.scwang.refreshlayout.activity.style.MaterialStyleActivity;
-import com.scwang.refreshlayout.activity.style.PhoenixStyleActivity;
-import com.scwang.refreshlayout.activity.style.StoreHouseStyleActivity;
-import com.scwang.refreshlayout.activity.style.TaurusStyleActivity;
-import com.scwang.refreshlayout.activity.style.WaterDropStyleActivity;
-import com.scwang.refreshlayout.activity.style.WaveSwipStyleActivity;
-import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
-import com.scwang.refreshlayout.adapter.SmartViewHolder;
-import com.scwang.smartrefresh.layout.api.RefreshHeader;
-import com.scwang.smartrefresh.layout.api.RefreshLayout;
-import com.scwang.smartrefresh.layout.header.ClassicsHeader;
-
-import java.lang.reflect.Constructor;
-import java.util.Arrays;
-
-import static android.R.layout.simple_list_item_2;
-import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
-import static com.scwang.refreshlayout.R.id.recyclerView;
-
-/**
- * 风格展示
- * A simple {@link Fragment} subclass.
- */
-public class RefreshStylesFragment extends Fragment implements AdapterView.OnItemClickListener {
-
- private enum Item {
- Delivery(R.string.title_activity_style_delivery,DeliveryStyleActivity.class),
- Dropbox(R.string.title_activity_style_dropbox, DropboxStyleActivity.class),
- FlyRefresh(R.string.title_activity_style_flyrefresh, FlyRefreshStyleActivity.class),
- WaveSwipe(R.string.title_activity_style_wave_swip, WaveSwipStyleActivity.class),
- WaterDrop(R.string.title_activity_style_water_drop, WaterDropStyleActivity.class),
- Material(R.string.title_activity_style_material, MaterialStyleActivity.class),
- Phoenix(R.string.title_activity_style_phoenix, PhoenixStyleActivity.class),
- Taurus(R.string.title_activity_style_taurus, TaurusStyleActivity.class),
- Bezier(R.string.title_activity_style_bezier, BezierStyleActivity.class),
- Circle(R.string.title_activity_style_circle, CircleStyleActivity.class),
- FunGameHitBlock(R.string.title_activity_style_fungame_hitblock, FunGameHitBlockStyleActivity.class),
- FunGameBattleCity(R.string.title_activity_style_fungame_battlecity, FunGameBattleCityStyleActivity.class),
- StoreHouse(R.string.title_activity_style_storehouse, StoreHouseStyleActivity.class),
- Classics(R.string.title_activity_style_classics, ClassicsStyleActivity.class),
- ;
- public int nameId;
- public Class> clazz;
- Item(@StringRes int nameId, Class> clazz) {
- this.nameId = nameId;
- this.clazz = clazz;
- }
-
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- return inflater.inflate(R.layout.fragment_refresh_styles, container, false);
- }
-
- @Override
- public void onViewCreated(View root, @Nullable Bundle savedInstanceState) {
- super.onViewCreated(root, savedInstanceState);
-
- View view = root.findViewById(recyclerView);
- if (view instanceof RecyclerView) {
- RecyclerView recyclerView = (RecyclerView) view;
- recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
- recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
- recyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2,this) {
- @Override
- protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
- holder.text(android.R.id.text1, model.name());
- holder.text(android.R.id.text2, model.nameId);
- holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
- }
- });
- }
-
- root.findViewById(R.id.toolbar).setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- startActivity(new Intent(getContext(), ExperimentActivity.class));
- return false;
- }
- });
- }
-
- @Override
- public void onItemClick(AdapterView> parent, View view, int position, long id) {
- Item item = Item.values()[position];
- if (Activity.class.isAssignableFrom(item.clazz)) {
- startActivity(new Intent(getContext(), item.clazz));
- } else if (RefreshHeader.class.isAssignableFrom(item.clazz)) {
- try {
- Constructor> constructor = item.clazz.getConstructor(Context.class);
- RefreshHeader header = (RefreshHeader) constructor.newInstance(getContext());
- RefreshLayout layout = (RefreshLayout) getView().findViewById(R.id.refreshLayout);
- layout.setRefreshHeader(header);
- if (!(header instanceof ClassicsHeader)) {
- layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);
- }
- layout.autoRefresh();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-}
diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/BottomSheetExampleFragment.java b/app/src/main/java/com/scwang/refreshlayout/fragment/example/BottomSheetExampleFragment.java
new file mode 100644
index 00000000..01ca93f0
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/fragment/example/BottomSheetExampleFragment.java
@@ -0,0 +1,104 @@
+package com.scwang.refreshlayout.fragment.example;
+
+
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.design.widget.BottomSheetDialog;
+import android.support.v4.app.Fragment;
+import android.support.v7.widget.DefaultItemAnimator;
+import android.support.v7.widget.DividerItemDecoration;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.Toolbar;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.scwang.refreshlayout.R;
+import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
+import com.scwang.refreshlayout.adapter.SmartViewHolder;
+import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
+import com.scwang.smartrefresh.layout.header.ClassicsHeader;
+import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import static android.R.layout.simple_list_item_2;
+import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
+
+/**
+ * 使用示例-BottomSheet
+ * A simple {@link Fragment} subclass.
+ */
+public class BottomSheetExampleFragment extends Fragment {
+
+ private BaseRecyclerAdapter mAdapter;
+
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.fragment_example_bottom_sheet, container, false);
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(root, savedInstanceState);
+
+ root = onCreateView(LayoutInflater.from(getContext()), null, null);
+
+ final Toolbar toolbar = root.findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ getActivity().finish();
+ }
+ });
+
+ RefreshLayout refreshLayout = root.findViewById(R.id.refreshLayout);
+ refreshLayout.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white));
+ refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
+ @Override
+ public void onLoadMore(@NonNull final RefreshLayout refreshLayout) {
+ refreshLayout.getLayout().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ mAdapter.loadMore(initData());
+ refreshLayout.finishLoadMore();
+ }
+ },2000);
+ }
+ });
+
+ RecyclerView recyclerView = root.findViewById(R.id.recyclerView);
+ recyclerView.setItemAnimator(new DefaultItemAnimator());
+ recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
+ recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
+
+ recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter(initData(),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);
+ }
+ });
+
+ BottomSheetDialog dialog = new BottomSheetDialog(getContext());
+ dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ getActivity().finish();
+ }
+ });
+ dialog.setContentView(root);
+ dialog.setCancelable(false);
+ dialog.show();
+ }
+
+ private Collection initData() {
+ return Arrays.asList(null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
+ }
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/DisallowInterceptExampleFragment.java b/app/src/main/java/com/scwang/refreshlayout/fragment/example/DisallowInterceptExampleFragment.java
new file mode 100644
index 00000000..aa002b27
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/fragment/example/DisallowInterceptExampleFragment.java
@@ -0,0 +1,114 @@
+package com.scwang.refreshlayout.fragment.example;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.support.v7.widget.AppCompatTextView;
+import android.support.v7.widget.Toolbar;
+import android.util.AttributeSet;
+import android.view.*;
+import com.scwang.refreshlayout.R;
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class DisallowInterceptExampleFragment extends Fragment {
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_example_disallow_intercept, container, false);
+ }
+
+
+ @Override
+ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(root, savedInstanceState);
+
+ final Toolbar toolbar = root.findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ getActivity().finish();
+ }
+ });
+ }
+
+ public static class MoveView extends AppCompatTextView {
+
+
+ //移动的阈值
+ private static final int TOUCH_SLOP = 20;
+ /**
+ * 点击按下事件 X坐标记录
+ */
+ private float mLastMotionX;
+ /**
+ * 点击按下事件 Y坐标记录
+ */
+ private float mLastMotionY;
+
+ private boolean mDelay;
+
+ /**
+ * 长按模式的标记位
+ */
+ private boolean isLongPress;
+
+ /**
+ * 长按的runnable
+ */
+ private Runnable mLongPressRunnable = new Runnable() {
+ @Override
+ public void run() {
+ isLongPress = true;
+ mDelay = false;
+ getParent().requestDisallowInterceptTouchEvent(true);
+ }
+ };
+
+ public MoveView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ float x = event.getX();
+ float y = event.getY();
+
+ switch (event.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ mLastMotionX = x;
+ mLastMotionY = y;
+ postDelayed(mLongPressRunnable, ViewConfiguration.getLongPressTimeout());
+ mDelay = true;
+ break;
+ case MotionEvent.ACTION_MOVE:
+ if (isLongPress) {
+ //长按状态下.绘制时间和轴线
+ setText("x=" + x + ";y=" + y);
+ } else if (mDelay && (Math.abs(mLastMotionX - x) > TOUCH_SLOP
+ || Math.abs(mLastMotionY - y) > TOUCH_SLOP)) {
+ //移动超过阈值,则表示移动了
+ removeCallbacks(mLongPressRunnable);
+ mDelay = false;
+ }
+ break;
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ default:
+ //释放了
+ removeCallbacks(mLongPressRunnable);
+ isLongPress = false;
+ mDelay = false;
+ invalidate();
+ break;
+ }
+ return true;
+ }
+
+ }
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragment.java b/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragment.java
new file mode 100644
index 00000000..35bd1e13
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragment.java
@@ -0,0 +1,144 @@
+package com.scwang.refreshlayout.fragment.example;
+
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.support.v7.widget.DefaultItemAnimator;
+import android.support.v7.widget.DividerItemDecoration;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.Toolbar;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+
+import com.scwang.refreshlayout.R;
+import com.scwang.refreshlayout.activity.FragmentActivity;
+import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
+import com.scwang.refreshlayout.adapter.SmartViewHolder;
+import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import com.scwang.smartrefresh.layout.constant.RefreshState;
+import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
+import com.scwang.smartrefresh.layout.header.ClassicsHeader;
+import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
+import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;
+
+import java.util.Arrays;
+
+import ezy.ui.layout.LoadingLayout;
+
+import static android.R.layout.simple_list_item_2;
+import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
+import static com.scwang.refreshlayout.R.id.recyclerView;
+import static com.scwang.refreshlayout.R.id.refreshLayout;
+
+/**
+ * 使用示例-空布页面
+ * A simple {@link Fragment} subclass.
+ */
+public class EmptyLayoutExampleFragment extends Fragment implements AdapterView.OnItemClickListener, OnRefreshListener {
+
+ public enum Item {
+ ThirdParty("集成第三方控件", EmptyLayoutExampleFragment.class),
+ NestedInner("内部嵌套", EmptyLayoutExampleFragmentInner.class),
+ NestedOuter("外部嵌套", EmptyLayoutExampleFragmentOuter.class),
+ ;
+ public String name;
+ public Class> clazz;
+ Item(String name, Class> clazz) {
+ this.name = name;
+ this.clazz = clazz;
+ }
+ }
+
+ private RecyclerView mRecyclerView;
+ private RefreshLayout mRefreshLayout;
+ private LoadingLayout mLoadingLayout;
+ private static boolean mIsNeedDemo = true;
+
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.fragment_example_emptylayout, container, false);
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(root, savedInstanceState);
+
+ final Toolbar toolbar = root.findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ getActivity().finish();
+ }
+ });
+
+ mRefreshLayout = root.findViewById(refreshLayout);
+ mRefreshLayout.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white));
+ mRefreshLayout.setOnRefreshListener(this);
+
+ mRecyclerView = root.findViewById(recyclerView);
+ mRecyclerView.setItemAnimator(new DefaultItemAnimator());
+ mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
+ mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
+
+ mLoadingLayout = 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;
+ }
+ @Override
+ public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
+ refreshLayout.finishLoadMore(2000);
+ }
+ });
+ }
+ }
+
+ @Override
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
+ mRefreshLayout.getLayout().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ mRecyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2,EmptyLayoutExampleFragment.this) {
+ @Override
+ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
+ holder.text(android.R.id.text1, model.name());
+ holder.text(android.R.id.text2, model.name);
+ holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
+ }
+ });
+ mRefreshLayout.finishRefresh();
+ mLoadingLayout.showContent();
+ }
+ }, 2000);
+ }
+
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ Item item = Item.values()[position];
+ if (Activity.class.isAssignableFrom(item.clazz)) {
+ startActivity(new Intent(getContext(), item.clazz));
+ } else if (Fragment.class.isAssignableFrom(item.clazz)) {
+ FragmentActivity.start(this, item.clazz);
+ }
+ }
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragmentInner.java b/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragmentInner.java
new file mode 100644
index 00000000..17d114e2
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragmentInner.java
@@ -0,0 +1,140 @@
+package com.scwang.refreshlayout.fragment.example;
+
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.support.v7.widget.DefaultItemAnimator;
+import android.support.v7.widget.DividerItemDecoration;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.Toolbar;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.scwang.refreshlayout.R;
+import com.scwang.refreshlayout.activity.FragmentActivity;
+import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
+import com.scwang.refreshlayout.adapter.SmartViewHolder;
+import com.scwang.refreshlayout.fragment.example.EmptyLayoutExampleFragment.Item;
+import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import com.scwang.smartrefresh.layout.constant.RefreshState;
+import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
+import com.scwang.smartrefresh.layout.header.ClassicsHeader;
+import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
+import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import static android.R.layout.simple_list_item_2;
+import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
+import static com.scwang.refreshlayout.R.id.recyclerView;
+import static com.scwang.refreshlayout.R.id.refreshLayout;
+
+/**
+ * 使用示例-空布页面
+ * A simple {@link Fragment} subclass.
+ */
+public class EmptyLayoutExampleFragmentInner extends Fragment implements AdapterView.OnItemClickListener, OnRefreshListener {
+
+ private View mEmptyLayout;
+ private RecyclerView mRecyclerView;
+ private RefreshLayout mRefreshLayout;
+ private static boolean mIsNeedDemo = true;
+ private BaseRecyclerAdapter
- mAdapter;
+
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.fragment_example_emptylayout_inner, container, false);
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(root, savedInstanceState);
+
+ final Toolbar toolbar = root.findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ getActivity().finish();
+ }
+ });
+
+ mRefreshLayout = root.findViewById(refreshLayout);
+ mRefreshLayout.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white));
+ mRefreshLayout.setOnRefreshListener(this);
+
+ mRecyclerView = root.findViewById(recyclerView);
+ mRecyclerView.setItemAnimator(new DefaultItemAnimator());
+ mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
+ mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
+ mRecyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter
- (new ArrayList
- (), simple_list_item_2,EmptyLayoutExampleFragmentInner.this) {
+ @Override
+ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
+ holder.text(android.R.id.text1, model.name());
+ holder.text(android.R.id.text2, model.name);
+ holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
+ }
+ });
+
+ mEmptyLayout = root.findViewById(R.id.empty);
+
+ ImageView image = root.findViewById(R.id.empty_image);
+ image.setImageResource(R.drawable.ic_empty);
+
+ TextView empty = 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;
+ }
+ @Override
+ public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
+ refreshLayout.finishLoadMore(2000);
+ }
+ });
+ }
+ }
+
+ @Override
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
+ mRefreshLayout.getLayout().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ mAdapter.refresh(Arrays.asList(Item.values()));
+ mRefreshLayout.finishRefresh();
+ mEmptyLayout.setVisibility(View.GONE);
+ }
+ }, 2000);
+ }
+
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ Item item = Item.values()[position];
+ if (Activity.class.isAssignableFrom(item.clazz)) {
+ startActivity(new Intent(getContext(), item.clazz));
+ } else if (Fragment.class.isAssignableFrom(item.clazz)) {
+ FragmentActivity.start(this, item.clazz);
+ }
+ }
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragmentOuter.java b/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragmentOuter.java
new file mode 100644
index 00000000..8a6ed357
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragmentOuter.java
@@ -0,0 +1,124 @@
+package com.scwang.refreshlayout.fragment.example;
+
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.support.v7.widget.DefaultItemAnimator;
+import android.support.v7.widget.DividerItemDecoration;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.Toolbar;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.scwang.refreshlayout.R;
+import com.scwang.refreshlayout.activity.FragmentActivity;
+import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
+import com.scwang.refreshlayout.adapter.SmartViewHolder;
+import com.scwang.refreshlayout.fragment.example.EmptyLayoutExampleFragment.Item;
+import com.scwang.smartrefresh.layout.api.RefreshLayout;
+import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
+import com.scwang.smartrefresh.layout.header.ClassicsHeader;
+import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
+
+import java.util.Arrays;
+
+import static android.R.layout.simple_list_item_2;
+import static android.support.v7.widget.DividerItemDecoration.VERTICAL;
+import static com.scwang.refreshlayout.R.id.recyclerView;
+import static com.scwang.refreshlayout.R.id.refreshLayout;
+
+/**
+ * 使用示例-空布页面
+ * A simple {@link Fragment} subclass.
+ */
+public class EmptyLayoutExampleFragmentOuter extends Fragment implements AdapterView.OnItemClickListener, OnRefreshListener {
+
+ private View mEmptyLayout;
+ private RecyclerView mRecyclerView;
+ private RefreshLayout mRefreshLayout;
+
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.fragment_example_emptylayout_outer, container, false);
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(root, savedInstanceState);
+
+ final Toolbar toolbar = root.findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ getActivity().finish();
+ }
+ });
+
+ mRefreshLayout = root.findViewById(refreshLayout);
+ mRefreshLayout.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white));
+ mRefreshLayout.setOnRefreshListener(this);
+
+ mRecyclerView = 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 = root.findViewById(R.id.empty_image);
+ image.setImageResource(R.drawable.ic_empty);
+
+ TextView empty = root.findViewById(R.id.empty_text);
+ empty.setText("暂无数据点击刷新");
+
+ ((View)empty.getParent()).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ doRefresh(0);
+ }
+ });
+
+ }
+
+ @Override
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
+ doRefresh(2000);
+ }
+
+ protected void doRefresh(int delayed) {
+ mRefreshLayout.getLayout().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ mRecyclerView.setAdapter(new BaseRecyclerAdapter
- (Arrays.asList(Item.values()), simple_list_item_2, EmptyLayoutExampleFragmentOuter.this) {
+ @Override
+ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
+ holder.text(android.R.id.text1, model.name());
+ holder.text(android.R.id.text2, model.name);
+ holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
+ }
+ });
+ mRefreshLayout.finishRefresh();
+ mEmptyLayout.setVisibility(View.GONE);
+ }
+ }, delayed);
+ }
+
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ Item item = Item.values()[position];
+ if (Activity.class.isAssignableFrom(item.clazz)) {
+ startActivity(new Intent(getContext(), item.clazz));
+ } else if (Fragment.class.isAssignableFrom(item.clazz)) {
+ FragmentActivity.start(this, item.clazz);
+ }
+ }
+}
diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/FlexBoxLayoutManagerFragment.java b/app/src/main/java/com/scwang/refreshlayout/fragment/example/FlexBoxLayoutManagerFragment.java
new file mode 100644
index 00000000..d3c68e66
--- /dev/null
+++ b/app/src/main/java/com/scwang/refreshlayout/fragment/example/FlexBoxLayoutManagerFragment.java
@@ -0,0 +1,98 @@
+package com.scwang.refreshlayout.fragment.example;
+
+
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.Toolbar;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+
+import com.google.android.flexbox.AlignItems;
+import com.google.android.flexbox.FlexDirection;
+import com.google.android.flexbox.FlexWrap;
+import com.google.android.flexbox.FlexboxLayoutManager;
+import com.scwang.refreshlayout.R;
+import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter;
+import com.scwang.refreshlayout.adapter.SmartViewHolder;
+import com.scwang.smartrefresh.layout.util.SmartUtil;
+
+import java.util.Arrays;
+import java.util.Random;
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class FlexBoxLayoutManagerFragment extends Fragment {
+
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.fragment_flexbox_layout_manager, container, false);
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(root, savedInstanceState);
+
+
+ final Toolbar toolbar = root.findViewById(R.id.toolbar);
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ getActivity().finish();
+ }
+ });
+
+ FlexboxLayoutManager manager = new FlexboxLayoutManager(root.getContext());
+ //设置主轴排列方式
+ manager.setFlexDirection(FlexDirection.ROW);
+ //设置是否换行
+ manager.setFlexWrap(FlexWrap.WRAP);
+ manager.setAlignItems(AlignItems.STRETCH);
+
+ RecyclerView recyclerView = root.findViewById(R.id.recyclerView);
+ recyclerView.setLayoutManager(manager);
+ recyclerView.setClipToPadding(false);
+ recyclerView.setPadding(SmartUtil.dp2px(2.5f),SmartUtil.dp2px(2.5f),SmartUtil.dp2px(2.5f),SmartUtil.dp2px(2.5f));
+
+ recyclerView.setAdapter(new BaseRecyclerAdapter