├── .gitignore
├── LICENSE
├── README.md
├── README_EN.md
├── app
├── .gitignore
├── build.gradle
├── debug.keystore
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── scwang
│ │ └── smartrefresh
│ │ └── horizontal
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── scwang
│ │ │ └── smart
│ │ │ └── refresh
│ │ │ └── horizontal
│ │ │ └── demo
│ │ │ ├── App.java
│ │ │ ├── MainActivity.kt
│ │ │ ├── activity
│ │ │ └── FragmentActivity.java
│ │ │ ├── adapter
│ │ │ ├── BaseRecyclerAdapter.java
│ │ │ └── SmartViewHolder.java
│ │ │ ├── fragment
│ │ │ ├── ExampleBasicFragment.java
│ │ │ ├── PracticeGoodsFragment.kt
│ │ │ ├── PracticePagerFragment.kt
│ │ │ └── index
│ │ │ │ └── IndexHomeFragment.kt
│ │ │ ├── util
│ │ │ └── StatusBarUtil.java
│ │ │ └── widget
│ │ │ ├── DetailHorizontalFooter.java
│ │ │ └── SmartViewPager.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── bg_panel_bottom.xml
│ │ ├── bg_panel_common.xml
│ │ ├── bg_panel_top.xml
│ │ ├── bg_round_alpha.xml
│ │ ├── bg_tab_selected.xml
│ │ ├── ic_chevron_right.xml
│ │ ├── ic_chevron_right_gray.xml
│ │ ├── ic_dashboard_black_24dp.xml
│ │ ├── ic_footer_detail_gray_24dp.xml
│ │ ├── ic_home_black_24dp.xml
│ │ ├── ic_launcher_background.xml
│ │ ├── ic_more_white_24dp.xml
│ │ ├── ic_navigate_before_white_24dp.xml
│ │ ├── ic_notifications_black_24dp.xml
│ │ ├── ic_service_gray_24dp.xml
│ │ ├── ic_star_gray_24dp.xml
│ │ ├── ic_store_gray_24dp.xml
│ │ ├── ic_trolley_white_24dp.xml
│ │ └── loading_rabbit.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── fragment_example_horizontal.xml
│ │ ├── fragment_index_home.xml
│ │ ├── fragment_practice_goods.xml
│ │ ├── fragment_practice_pager.xml
│ │ └── widget_footer_detail_horizontal.xml
│ │ ├── menu
│ │ └── navigation.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_round.png
│ │ ├── ic_loading_1.png
│ │ ├── ic_loading_2.png
│ │ ├── ic_loading_3.png
│ │ ├── image_goods_banner_1.jpg
│ │ ├── image_goods_banner_2.jpg
│ │ └── image_goods_banner_3.jpg
│ │ ├── mipmap-xxhdpi
│ │ ├── card_cover1.png
│ │ ├── card_cover2.png
│ │ ├── card_cover3.png
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_round.png
│ │ ├── image_detail_comment_mi.jpg
│ │ ├── image_detail_description_mi.jpg
│ │ └── image_detail_goods_mi.jpg
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── scwang
│ └── smartrefresh
│ └── horizontal
│ └── ExampleUnitTest.kt
├── art
├── app-release.apk
├── gif_basic.gif
├── gif_goods.gif
├── gif_pager.gif
├── jpg_apk_demo.jpg
├── md_update.md
└── png_apk_rqcode.png
├── bintrayUpload.bat
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── scwang
│ │ └── smartrefresh
│ │ └── horizontal
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── scwang
│ │ │ └── smart
│ │ │ └── refresh
│ │ │ └── horizontal
│ │ │ ├── HorizontalComponent.java
│ │ │ ├── HorizontalFooter.java
│ │ │ ├── HorizontalHeader.java
│ │ │ ├── RefreshContentHorizontal.java
│ │ │ ├── ScrollBoundaryHorizontal.java
│ │ │ └── SmartRefreshHorizontal.java
│ └── res
│ │ └── values
│ │ ├── ids.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── scwang
│ └── smartrefresh
│ └── horizontal
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches/build_file_checksums.ser
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea
9 | .DS_Store
10 | /build
11 | /captures
12 | .externalNativeBuild
13 | bintrayUpload-key.bat
14 | .*
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android横向智能刷新框架-SmartRefreshHorizontal
2 |
3 | [](https://www.apache.org/licenses/LICENSE-2.0)
4 | [](https://android-arsenal.com/api?level=12)
5 | [](https://bintray.com/scwang90/maven/SmartRefreshHorizontal/_latestVersion)
6 | [](https://github.com/scwang90)
7 |
8 | ## [English](https://github.com/scwang90/SmartRefreshHorizontal/blob/master/README_EN.md) | 中文
9 |
10 | SmartRefreshHorizontal 作为 SmartRefreshLayout 的扩展库,实现了横向刷新和加载的功能,
11 | 虽然是独立的开源库,但是并没有重复做实现,
12 | 而是对 SmartRefreshLayout 做了封装和转换,使其支持横向刷新。
13 | 所以 SmartRefreshHorizontal 继承了 SmartRefreshLayout 所有的特性,只是方向改成了横向。
14 |
15 | ## 特点:
16 |
17 | - 支持 横向滚动
18 | - 支持 [SmartRefreshLayout](https://github.com/scwang90/SmartRefreshLayout) 的所有特性
19 | - 支持 AndroidX
20 |
21 | ## 由来
22 |
23 | SmartRefreshLayout 的设计灵活多样,扩展性高,我想这应该是它受欢迎的原因之一。
24 | 在 issue 区有不少人建议让 SmartRefreshLayout 支持横向刷新。
25 | 其实大家都知道横向刷新的库已经有了不少,我给他们的回复是使用其他现有的横向刷新库。
26 | 但这在 issue 引发热议,可能是那些横向刷新库的使用、功能、扩展与 SmartRefreshLayout有很大差距。
27 | 所以我自己认为要做横向刷新库也需要能够像 SmartRefreshLayout 一样的多功能与易扩展。
28 | 如果直接扩展 SmartRefreshLayout 的功能使其直接支持横向,将会增加代码量。
29 | 然而当此时它已经足够庞大,并且也有不少人抱怨它太大需要分包细化功能。所以一开始的时候我几乎没有开发横向刷新功能的想法。
30 | 因为用到横向刷新的应用场景比竖向刷新少很多,我自己也很少会用到这样的场景。
31 | 如果为了实现一个我自己不常用的功能库要花费我太多时间和精力实在划不来,仅仅实现一个简单的横向刷新又没有必要...
32 |
33 | ## 原理
34 |
35 | 终于!有一天我在开发旋转动画过程中,产生了一个奇妙的想法:如果把 SmartRefreshLayout 旋转90度会怎样?
36 | 然后开始做试验:把 SmartRefreshLayout 旋转90度,再把 Content 旋转-90度。结果竟然真的可以用!!
37 | 这样就不用让我花大量时间精力去做横向刷新代码实现,SmartRefreshLayout 原有的所有功能多可以直接使用,
38 | 之前设计的十多个 Header 和 Footer 也可以不用任何修改直接使用!这让我产生了开发横向刷新库的动力。
39 | 于是基于这个试验想法就诞生了这个 SmartRefreshHorizontal 库 !
40 |
41 | 明白了 SmartRefreshHorizontal 与 SmartRefreshLayout 的关系,那么大家在使用本库的使用同时也要依赖
42 | SmartRefreshLayout,并且版本要大于 1.1.0-beta-1 ,否则会出现找不到类的错误。
43 |
44 | ## 传送门
45 |
46 | - [属性文档](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_property.md)
47 | - [常见问题](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_faq.md)
48 | - [更新日志](https://github.com/scwang90/SmartRefreshHorizontal/blob/master/art/md_update.md)
49 | - [博客文章](https://segmentfault.com/a/1190000020038792)
50 | - [源码下载](https://github.com/scwang90/SmartRefreshHorizontal/releases)
51 | - [自定义Header](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_custom.md)
52 |
53 | ## Demo
54 | [下载 APK-Demo](https://github.com/scwang90/SmartRefreshHorizontal/raw/master/art/app-release.apk)
55 |
56 | 
57 |
58 | #### 效果演示
59 | |商品详情|ViewPager|
60 | |:---:|:---:|
61 | |||
62 |
63 | |数据演示|
64 | |:---:|
65 | ||
66 |
67 | ## 简单用例
68 |
69 | ### 1. 在 build.gradle 中添加依赖
70 | ```gradle
71 | //2.x
72 | implementation 'com.scwang.smart:refresh-layout-horizontal:2.0.0'
73 | implementation 'com.scwang.smart:refresh-layout-kernel:2.0.1'
74 | implementation 'com.scwang.smart:refresh-header-classics:2.0.1' //经典刷新头
75 | implementation 'com.scwang.smart:refresh-header-material:2.0.1' //谷歌刷新头
76 |
77 | //1.x
78 | implementation 'com.scwang.smartrefresh:SmartRefreshHorizontal:1.1.2'
79 | implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.3' //必须依赖 版本 1.1.0 以上
80 |
81 | //androidx
82 | implementation 'com.scwang.smartrefresh:SmartRefreshHorizontal:1.1.2-x'
83 | implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.3' //必须依赖 版本 1.1.0 以上
84 |
85 | ```
86 |
87 | ### 2. 在XML布局文件中添加 SmartRefreshHorizontal
88 | ```xml
89 |
90 |
94 |
101 |
102 | ```
103 | ### 3. 在 Activity 或者 Fragment 中添加代码
104 | ```java
105 | RefreshLayout refreshLayout = root.findViewById(R.id.refreshLayout);
106 | refreshLayout.setRefreshHeader(new MaterialHeader(root.getContext()));
107 | refreshLayout.setRefreshFooter(new RefreshFooterWrapper(new MaterialHeader(root.getContext())), -1, -2);
108 | ```
109 |
110 | ## 混淆
111 |
112 | SmartRefreshHorizontal 不需要添加混淆过滤代码,并且已经混淆测试通过,如果你在项目的使用中混淆之后出现问题,请及时通知我。
113 |
114 | ## 其他作品
115 | [MultiWaveHeader](https://github.com/scwang90/MultiWaveHeader)
116 | [SmartRefreshLayout](https://github.com/scwang90/SmartRefreshLayout)
117 | [诗和远方](http://android.myapp.com/myapp/detail.htm?apkName=com.poetry.kernel)
118 |
119 | License
120 | -------
121 |
122 | Copyright 2019 scwang90
123 |
124 | Licensed under the Apache License, Version 2.0 (the "License");
125 | you may not use this file except in compliance with the License.
126 | You may obtain a copy of the License at
127 |
128 | http://www.apache.org/licenses/LICENSE-2.0
129 |
130 | Unless required by applicable law or agreed to in writing, software
131 | distributed under the License is distributed on an "AS IS" BASIS,
132 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133 | See the License for the specific language governing permissions and
134 | limitations under the License.
135 |
--------------------------------------------------------------------------------
/README_EN.md:
--------------------------------------------------------------------------------
1 | # SmartRefreshHorizontal
2 |
3 | [](https://www.apache.org/licenses/LICENSE-2.0)
4 | [](https://android-arsenal.com/api?level=12)
5 | [](https://bintray.com/scwang90/maven/SmartRefreshHorizontal/_latestVersion)
6 | [](https://github.com/scwang90)
7 |
8 | ## English | [中文](README.md)
9 |
10 | As an extension library of SmartRefreshLayout, SmartRefreshHorizontal realizes the function of horizontal refresh and loading.
11 | Although it is an independent open source library, it has not been implemented repeatedly.
12 | Instead, SmartRefreshLayout is encapsulated and converted to support horizontal refresh.
13 | So SmartRefreshHorizontal inherits all the features of SmartRefreshLayout, but the direction changes to horizontal.
14 |
15 | ## Features
16 |
17 | - Support horizontal scrol.
18 | - Support all features of [SmartRefreshLayout](https://github.com/scwang90/SmartRefreshLayout).
19 | - Support AndroidX
20 |
21 | ## Gateway
22 |
23 | - [Update log](https://github.com/scwang90/SmartRefreshHorizontal/blob/master/art/md_update.md)
24 | - [Attribute method](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_property.md)
25 | - [Blog posts](https://segmentfault.com/a/1190000010066071)
26 | - [Download the source code](https://github.com/scwang90/SmartRefreshHorizontal/releases)
27 |
28 |
29 | ## Demo
30 | [Download APK-Demo](https://github.com/scwang90/SmartRefreshHorizontal/raw/master/art/app-release.apk)
31 |
32 | 
33 |
34 | #### Preview
35 |
36 | |Goods|ViewPager|
37 | |:---:|:---:|
38 | |||
39 |
40 | |LoadData|
41 | |:---:|
42 | ||
43 |
44 | ## Usage
45 | #### 1.Add a gradle dependency.
46 | ```
47 | //2.x
48 | implementation 'com.scwang.smart:refresh-layout-horizontal:2.0.0'
49 | implementation 'com.scwang.smart:refresh-layout-kernel:2.0.1'
50 | implementation 'com.scwang.smart:refresh-header-classics:2.0.1'
51 | implementation 'com.scwang.smart:refresh-header-material:2.0.1'
52 |
53 | //1.x
54 | implementation 'com.scwang.smartrefresh:SmartRefreshHorizontal:1.1.2'
55 | implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.3'
56 |
57 | //androidx
58 | implementation 'com.scwang.smartrefresh:SmartRefreshHorizontal:1.1.2-x'
59 | implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.3'
60 |
61 | ```
62 |
63 | #### 2.Add SmartRefreshLayout in the layout xml.
64 | ```xml
65 |
66 |
70 |
77 |
78 | ```
79 |
80 | #### 3.Coding in the Activity or Fragment.
81 | ```java
82 | RefreshLayout refreshLayout = root.findViewById(R.id.refreshLayout);
83 | refreshLayout.setRefreshHeader(new MaterialHeader(root.getContext()));
84 | refreshLayout.setRefreshFooter(new RefreshFooterWrapper(new MaterialHeader(root.getContext())), -1, -2);
85 | ```
86 |
87 | ## ProGuard
88 |
89 | This library 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.
90 |
91 | ## Donate
92 |
93 | If you like this library's design, feel it help to you, you can point the upper right corner "Star" support Thank you! ^ _ ^
94 | You can also click the PayPal below to ask the author to drink a cup of coffee.
95 |
96 | [](https://www.paypal.me/scwang90)
97 |
98 | ## Discuss
99 |
100 | Contact me: scwang90@hotmail.com
101 |
102 | ## Other Works
103 | [SmartRefreshLayout](https://github.com/scwang90/SmartRefreshLayout)
104 | [MultiWaveHeader](https://github.com/scwang90/MultiWaveHeader)
105 |
106 | License
107 | -------
108 |
109 | Copyright 2019 scwang90
110 |
111 | Licensed under the Apache License, Version 2.0 (the "License");
112 | you may not use this file except in compliance with the License.
113 | You may obtain a copy of the License at
114 |
115 | http://www.apache.org/licenses/LICENSE-2.0
116 |
117 | Unless required by applicable law or agreed to in writing, software
118 | distributed under the License is distributed on an "AS IS" BASIS,
119 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120 | See the License for the specific language governing permissions and
121 | limitations under the License.
122 |
123 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /release
3 | .*
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 28
7 | defaultConfig {
8 | applicationId "com.scwang.smartrefresh.horizontal.demo"
9 | minSdkVersion 16
10 | targetSdkVersion 28
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | signingConfigs {
16 | debug {
17 | storeFile file('debug.keystore')
18 | storePassword "android"
19 | keyAlias "androiddebugkey"
20 | keyPassword "android"
21 | }
22 | }
23 | buildTypes {
24 | debug {
25 | signingConfig = signingConfigs.debug
26 | }
27 | release {
28 | minifyEnabled true
29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
30 | signingConfig = signingConfigs.debug
31 | }
32 | }
33 | }
34 |
35 | repositories {
36 | maven { url "https://jitpack.io" }//BaseRecyclerViewAdapterHelper
37 | // maven { url "https://bintray.com/scwang90/maven" }
38 | }
39 |
40 | dependencies {
41 | implementation fileTree(include: ['*.jar'], dir: 'libs')
42 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
43 | implementation 'com.android.support:appcompat-v7:28.0.0'
44 | implementation 'com.android.support:design:28.0.0'
45 | implementation 'com.android.support:support-v4:28.0.0'
46 | implementation 'com.android.support:cardview-v7:28.0.0'
47 | implementation 'com.android.support:support-vector-drawable:28.0.0'
48 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
49 | testImplementation 'junit:junit:4.12'
50 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
51 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
52 | implementation project(':library')
53 |
54 | // 基础依赖包,必须要依赖
55 | implementation 'com.gyf.immersionbar:immersionbar:3.0.0-beta02'
56 | implementation 'com.jaeger.statusbarutil:library:1.5.1'
57 |
58 | // implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
59 | // implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0'
60 | implementation 'com.scwang.smart:refresh-layout-kernel:2.0.1'
61 | implementation 'com.scwang.smart:refresh-header-classics:2.0.1'
62 | implementation 'com.scwang.smart:refresh-header-material:2.0.1' //谷歌刷新头
63 | implementation 'com.scwang.smart:refresh-header-falsify:2.0.1' //虚拟刷新头
64 | // implementation 'com.scwang.smart:refresh-layout-horizontal:2.0.0-alpha-1'
65 | implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50'
66 |
67 | implementation 'com.ogaclejapan.smarttablayout:library:1.7.0@aar'
68 | implementation 'com.ogaclejapan.smarttablayout:utils-v4:1.7.0@aar'
69 | }
70 |
--------------------------------------------------------------------------------
/app/debug.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/debug.keystore
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/scwang/smartrefresh/horizontal/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.scwang.smartrefresh.horizontal
2 |
3 | import android.support.test.InstrumentationRegistry
4 | import android.support.test.runner.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("com.scwang.smartrefresh.horizontal", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/scwang/smart/refresh/horizontal/demo/App.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal.demo;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import android.support.annotation.NonNull;
6 |
7 | import com.scwang.smart.refresh.header.ClassicsHeader;
8 | import com.scwang.smart.refresh.header.MaterialHeader;
9 | import com.scwang.smart.refresh.layout.SmartRefreshLayout;
10 | import com.scwang.smart.refresh.layout.api.RefreshFooter;
11 | import com.scwang.smart.refresh.layout.api.RefreshHeader;
12 | import com.scwang.smart.refresh.layout.api.RefreshLayout;
13 | import com.scwang.smart.refresh.layout.listener.DefaultRefreshFooterCreator;
14 | import com.scwang.smart.refresh.layout.listener.DefaultRefreshHeaderCreator;
15 | import com.scwang.smart.refresh.layout.listener.DefaultRefreshInitializer;
16 | import com.scwang.smart.refresh.layout.wrapper.RefreshFooterWrapper;
17 | import com.scwang.smart.refresh.horizontal.SmartRefreshHorizontal;
18 | import com.scwang.smartrefresh.horizontal.demo.R;
19 |
20 | public class App extends Application {
21 | static {
22 | SmartRefreshLayout.setDefaultRefreshInitializer(new DefaultRefreshInitializer() {
23 | @Override
24 | public void initialize(@NonNull Context context, @NonNull RefreshLayout layout) {
25 | layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);
26 | }
27 | });
28 | SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
29 | @NonNull
30 | @Override
31 | public RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull RefreshLayout layout) {
32 | return new ClassicsHeader(context);
33 | }
34 | });
35 | SmartRefreshHorizontal.setDefaultRefreshInitializer(new DefaultRefreshInitializer() {
36 | @Override
37 | public void initialize(@NonNull Context context, @NonNull RefreshLayout layout) {
38 | layout.setEnableAutoLoadMore(false);
39 | layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);
40 | }
41 | });
42 | SmartRefreshHorizontal.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
43 | @NonNull
44 | @Override
45 | public RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull RefreshLayout layout) {
46 | layout.setEnableHeaderTranslationContent(true);
47 | return new MaterialHeader(context);
48 | }
49 | });
50 | SmartRefreshHorizontal.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
51 | @NonNull
52 | @Override
53 | public RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull RefreshLayout layout) {
54 | layout.setEnableFooterTranslationContent(true);
55 | return new RefreshFooterWrapper(new MaterialHeader(context));
56 | }
57 | });
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/scwang/smart/refresh/horizontal/demo/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal.demo
2 |
3 | import android.os.Bundle
4 | import android.support.design.widget.BottomNavigationView
5 | import android.support.v4.app.Fragment
6 | import android.support.v7.app.AppCompatActivity
7 | import android.view.View
8 | import com.scwang.smart.refresh.horizontal.demo.fragment.ExampleBasicFragment
9 | import com.scwang.smart.refresh.horizontal.demo.fragment.PracticeGoodsFragment
10 | import com.scwang.smart.refresh.horizontal.demo.fragment.index.IndexHomeFragment
11 | import com.scwang.smartrefresh.horizontal.demo.R
12 | import kotlinx.android.synthetic.main.activity_main.*
13 |
14 | class MainActivity : AppCompatActivity() {
15 |
16 | private val homeFragment: Fragment by lazy {
17 | IndexHomeFragment()
18 | }
19 |
20 | private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
21 | when (item.itemId) {
22 | R.id.navigation_home -> {
23 | message.setText(R.string.title_home)
24 | supportFragmentManager.beginTransaction().replace(R.id.fragment, homeFragment).commit()
25 | return@OnNavigationItemSelectedListener true
26 | }
27 | R.id.navigation_dashboard -> {
28 | message.setText(R.string.title_dashboard)
29 | supportFragmentManager.beginTransaction().replace(
30 | R.id.fragment,
31 | PracticeGoodsFragment()
32 | ).commit()
33 | return@OnNavigationItemSelectedListener true
34 | }
35 | R.id.navigation_notifications -> {
36 | message.setText(R.string.title_notifications)
37 | supportFragmentManager.beginTransaction().replace(
38 | R.id.fragment,
39 | ExampleBasicFragment()
40 | ).commit()
41 | return@OnNavigationItemSelectedListener true
42 | }
43 | }
44 | false
45 | }
46 |
47 | override fun onCreate(savedInstanceState: Bundle?) {
48 | super.onCreate(savedInstanceState)
49 | setContentView(R.layout.activity_main)
50 |
51 | navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
52 | navigation.visibility = View.GONE
53 |
54 | supportFragmentManager.beginTransaction().replace(
55 | R.id.fragment,
56 | IndexHomeFragment()
57 | ).commit()
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/scwang/smart/refresh/horizontal/demo/activity/FragmentActivity.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal.demo.activity;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.support.annotation.Nullable;
8 | import android.support.v4.app.Fragment;
9 | import android.support.v4.app.FragmentManager;
10 | import android.support.v4.app.FragmentTransaction;
11 | import android.support.v7.app.AppCompatActivity;
12 | import android.widget.FrameLayout;
13 |
14 | import java.util.HashMap;
15 | import java.util.Map;
16 |
17 | import static android.R.id.widget_frame;
18 |
19 | /**
20 | * Fragment 容器页面
21 | * Created by SCWANG on 2017/10/10.
22 | */
23 |
24 | @SuppressWarnings({"UnusedParameters", "unused"})
25 | public class FragmentActivity extends AppCompatActivity {
26 |
27 | protected static final String EXTRA_FRAGMENT = "EXTRA_FRAGMENT";
28 | private Fragment mFragment;
29 |
30 | //
31 | private static void start(Context context, Class> clazz, Object... params){
32 | if (context != null && Fragment.class.isAssignableFrom(clazz)) {
33 | context.startActivity(newIntent(clazz, context, params));
34 | }
35 | }
36 |
37 | public static void start(Activity activity, Class> clazz, Object... params){
38 | start((Context) activity, clazz, params);
39 | }
40 |
41 | public static void start(Fragment fragment, Class> clazz, Object... params){
42 | if (fragment != null) {
43 | start((Context) fragment.getActivity(), clazz, params);
44 | }
45 | }
46 |
47 | private static Intent newIntent(Class> clazz, Context context, Object... params) {
48 | Intent intent = new Intent(context, FragmentActivity.class);
49 | intent.putExtra(EXTRA_FRAGMENT, clazz.getName());
50 | return intent;
51 | }
52 | //
53 |
54 | //
55 |
56 | //@InjectExtra(value = EXTRA_FRAGMENT,remark = "Fragment类名")
57 | protected String mFragmentClazz = null;
58 |
59 | @Override
60 | protected void onCreate(@Nullable Bundle savedInstanceState) {
61 | super.onCreate(savedInstanceState);
62 | mFragmentClazz = getIntent().getStringExtra(EXTRA_FRAGMENT);
63 | FrameLayout frameLayout = new FrameLayout(this);
64 | frameLayout.setId(widget_frame);
65 | setContentView(frameLayout);
66 | replaceFragment();
67 | }
68 |
69 | protected void replaceFragment() {
70 | try {
71 | mFragment = (Fragment) getFragmentClass().newInstance();
72 | FragmentManager manager = getSupportFragmentManager();
73 | FragmentTransaction transaction = manager.beginTransaction();
74 | transaction.replace(widget_frame, mFragment);
75 | transaction.commit();
76 | } catch (Exception e) {
77 | e.printStackTrace();
78 | // AfExceptionHandler.handle(e, "AfFragmentActivity Fragment 类型错误:" + mFragmentClazz);
79 | }
80 | }
81 |
82 | //
83 | private static Map typeCache = new HashMap<>();
84 | private Class> getFragmentClass() throws ClassNotFoundException {
85 | Class type = typeCache.get(mFragmentClazz);
86 | if (type == null) {
87 | typeCache.put(mFragmentClazz, type = Class.forName(mFragmentClazz));
88 | }
89 | return type;
90 | }
91 | //
92 |
93 | public Fragment getFragment() {
94 | return mFragment;
95 | }
96 |
97 | //
98 |
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/app/src/main/java/com/scwang/smart/refresh/horizontal/demo/adapter/BaseRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal.demo.adapter;
2 |
3 | import android.database.DataSetObservable;
4 | import android.database.DataSetObserver;
5 | import android.support.annotation.LayoutRes;
6 | import android.support.annotation.NonNull;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.AdapterView;
12 | import android.widget.ListAdapter;
13 |
14 | import java.util.ArrayList;
15 | import java.util.Collection;
16 | import java.util.List;
17 |
18 | /**
19 | *
20 | * Created by SCWANG on 2017/6/11.
21 | */
22 |
23 | @SuppressWarnings({"UnusedReturnValue", "unused"})
24 | public abstract class BaseRecyclerAdapter extends RecyclerView.Adapter implements ListAdapter {
25 |
26 |
27 | //
28 |
29 | private final int mLayoutId;
30 | private final List mList;
31 | private int mLastPosition = -1;
32 | private boolean mOpenAnimationEnable = true;
33 | protected AdapterView.OnItemClickListener mListener;
34 |
35 | public BaseRecyclerAdapter(@LayoutRes int layoutId) {
36 | setHasStableIds(false);
37 | this.mList = new ArrayList<>();
38 | this.mLayoutId = layoutId;
39 | }
40 |
41 | public BaseRecyclerAdapter(Collection collection, @LayoutRes int layoutId) {
42 | setHasStableIds(false);
43 | this.mList = new ArrayList<>(collection);
44 | this.mLayoutId = layoutId;
45 | }
46 |
47 | public BaseRecyclerAdapter(Collection collection, @LayoutRes int layoutId, AdapterView.OnItemClickListener listener) {
48 | setHasStableIds(false);
49 | setOnItemClickListener(listener);
50 | this.mList = new ArrayList<>(collection);
51 | this.mLayoutId = layoutId;
52 | }
53 | //
54 |
55 |
56 | private void addAnimate(SmartViewHolder holder, int postion) {
57 | if (mOpenAnimationEnable && mLastPosition < postion) {
58 | holder.itemView.setAlpha(0);
59 | holder.itemView.animate().alpha(1).start();
60 | mLastPosition = postion;
61 | }
62 | }
63 |
64 |
65 | //
66 | @NonNull
67 | @Override
68 | public SmartViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
69 | return new SmartViewHolder(LayoutInflater.from(parent.getContext()).inflate(mLayoutId, parent, false),mListener);
70 | }
71 |
72 | @Override
73 | public void onBindViewHolder(@NonNull SmartViewHolder holder, int position) {
74 | onBindViewHolder(holder, position < mList.size() ? mList.get(position) : null, position);
75 | }
76 |
77 | protected abstract void onBindViewHolder(SmartViewHolder holder, T model, int position);
78 |
79 | @Override
80 | public int getItemCount() {
81 | return mList.size();
82 | }
83 |
84 | @Override
85 | public void onViewAttachedToWindow(@NonNull SmartViewHolder holder) {
86 | super.onViewAttachedToWindow(holder);
87 | addAnimate(holder, holder.getLayoutPosition());
88 | }
89 |
90 | public void setOpenAnimationEnable(boolean enabled) {
91 | this.mOpenAnimationEnable = enabled;
92 | }
93 |
94 | //
95 |
96 | //
97 |
98 | public T get(int index) {
99 | return mList.get(index);
100 | }
101 |
102 | public BaseRecyclerAdapter setOnItemClickListener(AdapterView.OnItemClickListener listener) {
103 | mListener = listener;
104 | return this;
105 | }
106 |
107 | public BaseRecyclerAdapter refresh(Collection collection) {
108 | mList.clear();
109 | mList.addAll(collection);
110 | notifyDataSetChanged();
111 | notifyListDataSetChanged();
112 | mLastPosition = -1;
113 | return this;
114 | }
115 |
116 | public BaseRecyclerAdapter loadMore(Collection collection) {
117 | mList.addAll(collection);
118 | notifyDataSetChanged();
119 | notifyListDataSetChanged();
120 | return this;
121 | }
122 |
123 | public BaseRecyclerAdapter insert(Collection collection) {
124 | mList.addAll(0, collection);
125 | notifyDataSetChanged();
126 | notifyListDataSetChanged();
127 | return this;
128 | }
129 |
130 |
131 | //
132 |
133 | //
134 | private final DataSetObservable mDataSetObservable = new DataSetObservable();
135 |
136 | // public boolean hasStableIds() {
137 | // return false;
138 | // }
139 |
140 | public void registerDataSetObserver(DataSetObserver observer) {
141 | mDataSetObservable.registerObserver(observer);
142 | }
143 |
144 | public void unregisterDataSetObserver(DataSetObserver observer) {
145 | mDataSetObservable.unregisterObserver(observer);
146 | }
147 |
148 | /**
149 | * Notifies the attached observers that the underlying data has been changed
150 | * and any View reflecting the data set should refresh itself.
151 | */
152 | public void notifyListDataSetChanged() {
153 | mDataSetObservable.notifyChanged();
154 | }
155 |
156 | /**
157 | * Notifies the attached observers that the underlying data is no longer valid
158 | * or available. Once invoked this adapter is no longer valid and should
159 | * not report further data set changes.
160 | */
161 | public void notifyDataSetInvalidated() {
162 | mDataSetObservable.notifyInvalidated();
163 | }
164 |
165 | public boolean areAllItemsEnabled() {
166 | return true;
167 | }
168 |
169 | public boolean isEnabled(int position) {
170 | return true;
171 | }
172 |
173 | @Override
174 | public View getView(int position, View convertView, ViewGroup parent) {
175 | SmartViewHolder holder;
176 | if (convertView != null) {
177 | holder = (SmartViewHolder) convertView.getTag();
178 | } else {
179 | holder = onCreateViewHolder(parent, getItemViewType(position));
180 | convertView = holder.itemView;
181 | convertView.setTag(holder);
182 | }
183 | holder.setPosition(position);
184 | onBindViewHolder(holder, position);
185 | addAnimate(holder, position);
186 | return convertView;
187 | }
188 |
189 | public int getItemViewType(int position) {
190 | return 0;
191 | }
192 |
193 | public int getViewTypeCount() {
194 | return 1;
195 | }
196 |
197 | public boolean isEmpty() {
198 | return getCount() == 0;
199 | }
200 |
201 | @Override
202 | public Object getItem(int position) {
203 | return mList.get(position);
204 | }
205 |
206 | @Override
207 | public int getCount() {
208 | return mList.size();
209 | }
210 |
211 | //
212 | }
213 |
--------------------------------------------------------------------------------
/app/src/main/java/com/scwang/smart/refresh/horizontal/demo/adapter/SmartViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal.demo.adapter;
2 |
3 | import android.content.res.Resources;
4 | import android.support.annotation.StringRes;
5 | import android.support.v4.content.ContextCompat;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.util.TypedValue;
8 | import android.view.View;
9 | import android.widget.AdapterView;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 |
13 | public class SmartViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
14 |
15 | private final AdapterView.OnItemClickListener mListener;
16 | private int mPosition = -1;
17 |
18 | public SmartViewHolder(View itemView, AdapterView.OnItemClickListener mListener) {
19 | super(itemView);
20 | this.mListener = mListener;
21 | itemView.setOnClickListener(this);
22 |
23 | /*
24 | * 设置水波纹背景
25 | */
26 | if (itemView.getBackground() == null) {
27 | TypedValue typedValue = new TypedValue();
28 | Resources.Theme theme = itemView.getContext().getTheme();
29 | int top = itemView.getPaddingTop();
30 | int bottom = itemView.getPaddingBottom();
31 | int left = itemView.getPaddingLeft();
32 | int right = itemView.getPaddingRight();
33 | if (theme.resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true)) {
34 | itemView.setBackgroundResource(typedValue.resourceId);
35 | }
36 | itemView.setPadding(left, top, right, bottom);
37 | }
38 | }
39 |
40 | public void setPosition(int position) {
41 | mPosition = position;
42 | }
43 |
44 | @Override
45 | public void onClick(View v) {
46 | if (mListener != null) {
47 | int position = getAdapterPosition();
48 | if(position >= 0){
49 | mListener.onItemClick(null, v, position, getItemId());
50 | } else if (mPosition > -1) {
51 | mListener.onItemClick(null, v, mPosition, getItemId());
52 | }
53 | }
54 | }
55 |
56 | private View findViewById(int id) {
57 | return id == 0 ? itemView : itemView.findViewById(id);
58 | }
59 |
60 | public SmartViewHolder text(int id, CharSequence sequence) {
61 | View view = findViewById(id);
62 | if (view instanceof TextView) {
63 | ((TextView) view).setText(sequence);
64 | }
65 | return this;
66 | }
67 |
68 | public SmartViewHolder text(int id,@StringRes int stringRes) {
69 | View view = findViewById(id);
70 | if (view instanceof TextView) {
71 | ((TextView) view).setText(stringRes);
72 | }
73 | return this;
74 | }
75 |
76 | public SmartViewHolder textColorId(int id, int colorId) {
77 | View view = findViewById(id);
78 | if (view instanceof TextView) {
79 | ((TextView) view).setTextColor(ContextCompat.getColor(view.getContext(), colorId));
80 | }
81 | return this;
82 | }
83 |
84 | public SmartViewHolder image(int id, int imageId) {
85 | View view = findViewById(id);
86 | if (view instanceof ImageView) {
87 | ((ImageView) view).setImageResource(imageId);
88 | }
89 | return this;
90 | }
91 |
92 | public SmartViewHolder gone(int id) {
93 | View view = findViewById(id);
94 | if (view != null) {
95 | view.setVisibility(View.GONE);
96 | }
97 | return this;
98 | }
99 |
100 | public SmartViewHolder visible(int id) {
101 | View view = findViewById(id);
102 | if (view != null) {
103 | view.setVisibility(View.VISIBLE);
104 | }
105 | return this;
106 | }
107 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/scwang/smart/refresh/horizontal/demo/fragment/ExampleBasicFragment.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal.demo.fragment;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.annotation.NonNull;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.support.v7.widget.Toolbar;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 |
14 | import com.chad.library.adapter.base.BaseQuickAdapter;
15 | import com.chad.library.adapter.base.BaseViewHolder;
16 | import com.scwang.smart.refresh.header.ClassicsHeader;
17 | import com.scwang.smart.refresh.horizontal.demo.adapter.BaseRecyclerAdapter;
18 | import com.scwang.smart.refresh.horizontal.demo.adapter.SmartViewHolder;
19 | import com.scwang.smart.refresh.layout.api.RefreshLayout;
20 | import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
21 | import com.scwang.smartrefresh.horizontal.demo.R;
22 |
23 | import java.util.Arrays;
24 | import java.util.Collection;
25 |
26 | import static android.R.layout.simple_list_item_2;
27 |
28 | /**
29 | * A simple {@link Fragment} subclass.
30 | */
31 | public class ExampleBasicFragment extends Fragment {
32 |
33 | private QuickAdapterAdapter mQuickAdapter;
34 | private BaseRecyclerAdapter mAdapter;
35 |
36 | int[] colorIds = {
37 | android.R.color.holo_blue_dark,
38 | android.R.color.holo_green_dark,
39 | android.R.color.holo_red_dark,
40 | android.R.color.holo_orange_dark,
41 | };
42 |
43 | @Override
44 | public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
45 | // Inflate the layout for this fragment
46 | return inflater.inflate(R.layout.fragment_example_horizontal, container, false);
47 | }
48 |
49 | @Override
50 | public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceState) {
51 | super.onViewCreated(root, savedInstanceState);
52 |
53 | final Toolbar toolbar = root.findViewById(R.id.toolbar);
54 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
55 | @Override
56 | public void onClick(View v) {
57 | getActivity().finish();
58 | }
59 | });
60 |
61 | final RecyclerView recyclerView = root.findViewById(R.id.recyclerView);
62 |
63 | recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter(simple_list_item_2) {
64 |
65 | @Override
66 | protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) {
67 | holder.itemView.getLayoutParams().width = -2;//DensityUtil.dp2px(100);
68 | holder.itemView.getLayoutParams().height = -1;
69 | holder.itemView.setBackgroundResource(colorIds[position%colorIds.length]);
70 | holder.text(android.R.id.text1, getString(R.string.item_example_number_title, position));
71 | holder.textColorId(android.R.id.text1, android.R.color.white);
72 |
73 | }
74 | });
75 | recyclerView.setAdapter(mQuickAdapter = new QuickAdapterAdapter());
76 |
77 |
78 | mAdapter.refresh(initData());
79 | mQuickAdapter.replaceData(initData());
80 | mQuickAdapter.openLoadAnimation(QuickAdapterAdapter.ALPHAIN);
81 |
82 | RefreshLayout refreshLayout = root.findViewById(R.id.refreshLayout);
83 | refreshLayout.setRefreshHeader(new ClassicsHeader(root.getContext()));
84 | // refreshLayout.setRefreshFooter(new RefreshFooterWrapper(new MaterialHeader(root.getContext())), -1, -2);
85 | //// refreshLayout.setEnableHeaderTranslationContent(true);
86 | // refreshLayout.setEnableFooterTranslationContent(true);
87 | // refreshLayout.setEnableAutoLoadMore(false);
88 |
89 | refreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
90 | @Override
91 | public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
92 | refreshLayout.getLayout().postDelayed(new Runnable() {
93 | @Override
94 | public void run() {
95 | mAdapter.refresh(initData());
96 | mQuickAdapter.replaceData(initData());
97 | refreshLayout.finishRefresh();
98 | }
99 | }, 1500);
100 | }
101 |
102 | @Override
103 | public void onLoadMore(@NonNull final RefreshLayout refreshLayout) {
104 | recyclerView.stopScroll();
105 | recyclerView.stopNestedScroll();
106 | refreshLayout.getLayout().postDelayed(new Runnable() {
107 | @Override
108 | public void run() {
109 | mAdapter.loadMore(initData());
110 | mQuickAdapter.addData(initData());
111 | refreshLayout.finishLoadMore();
112 | }
113 | }, 1500);
114 | }
115 | });
116 | }
117 |
118 | private Collection initData() {
119 | return Arrays.asList(null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
120 | }
121 |
122 | public class QuickAdapterAdapter extends BaseQuickAdapter {
123 | QuickAdapterAdapter() {
124 | super(simple_list_item_2);
125 | }
126 |
127 | @Override
128 | protected void convert(BaseViewHolder holder, Void item) {
129 | int position = holder.getAdapterPosition();
130 | holder.itemView.getLayoutParams().width = -2;//DensityUtil.dp2px(100);
131 | holder.itemView.getLayoutParams().height = -1;
132 | holder.itemView.setBackgroundResource(colorIds[position%colorIds.length]);
133 | holder.setText(android.R.id.text1, getString(R.string.item_example_number_title, position));
134 | holder.setTextColor(android.R.id.text1, 0xffffffff);
135 | }
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/app/src/main/java/com/scwang/smart/refresh/horizontal/demo/fragment/PracticeGoodsFragment.kt:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal.demo.fragment
2 |
3 |
4 | import android.os.Build
5 | import android.os.Bundle
6 | import android.support.v4.app.Fragment
7 | import android.support.v4.graphics.ColorUtils
8 | import android.support.v4.view.ViewPager
9 | import android.support.v4.widget.NestedScrollView
10 | import android.util.Log
11 | import android.view.LayoutInflater
12 | import android.view.View
13 | import android.view.ViewGroup
14 | import com.scwang.smartrefresh.horizontal.demo.R
15 | import com.scwang.smart.refresh.horizontal.demo.util.StatusBarUtil
16 | import kotlinx.android.synthetic.main.fragment_practice_goods.*
17 | import kotlin.math.min
18 |
19 | /**
20 | * A simple [Fragment] subclass.
21 | *
22 | */
23 | class PracticeGoodsFragment : Fragment() {
24 |
25 | var pageIndex = 0
26 | var darkMode = false
27 |
28 | override fun onCreateView(
29 | inflater: LayoutInflater, container: ViewGroup?,
30 | savedInstanceState: Bundle?
31 | ): View? {
32 | // Inflate the layout for this fragment
33 | return inflater.inflate(R.layout.fragment_practice_goods, container, false)
34 | }
35 |
36 |
37 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
38 | super.onViewCreated(view, savedInstanceState)
39 | onScrollChange(0)
40 | tabLayout.setViewPager(viewPager)
41 | viewPager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
42 | override fun onPageSelected(position: Int) {
43 | pageIndex = position
44 | onScrollChange(if (position == 0) scrollView.scrollY else banner.height)
45 | }
46 | })
47 | scrollView.setOnScrollChangeListener { _: NestedScrollView?, _: Int, scrollY: Int, _: Int, oldScrollY: Int ->
48 | Log.d("NestedScrollView", String.format("scrollY=%d oldScrollY=%d ", scrollY, oldScrollY))
49 | onScrollChange(scrollY)
50 | }
51 |
52 | refreshHorizontal.setEnableOverScrollBounce(false)
53 | refreshHorizontal.setOnLoadMoreListener {
54 | viewPager.currentItem = 1
55 | }
56 | refreshLayout.setOnLoadMoreListener {
57 | viewPager.currentItem = 1
58 | }
59 |
60 | toolbar_btn_go_back.setOnClickListener {
61 | activity?.finish()
62 | }
63 |
64 | StatusBarUtil.immersive(activity)
65 | StatusBarUtil.setHeight(activity, toolbar)
66 | StatusBarUtil.setPaddingSmart(activity, toolbar_content)
67 | StatusBarUtil.setPaddingSmart(activity, pager1)
68 | StatusBarUtil.setPaddingSmart(activity, pager2)
69 | }
70 |
71 | private fun onScrollChange(scrollY: Int) {
72 | val percent = min(1f * scrollY / (banner.height+1), 1f)
73 | tabLayout.alpha = percent
74 | tabBackground.alpha = percent
75 | Log.d("NestedScrollView", String.format("alpha=%f", percent))
76 |
77 | val dark = percent > 0.4
78 | if (dark != darkMode) {
79 | darkMode = dark
80 | StatusBarUtil.darkMode(activity, dark)
81 | }
82 |
83 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
84 | val colorFront:Int = 0xff666666.toInt()
85 | val colorBackground = 0xffffffff.toInt()
86 | val colorAlpha = ColorUtils.setAlphaComponent(colorFront, (percent * 255).toInt())
87 | val color = ColorUtils.compositeColors(colorAlpha, colorBackground)
88 | toolbar_btn_more.drawable.setTint(color)
89 | toolbar_btn_go_back.drawable.setTint(color)
90 | toolbar_btn_trolley.drawable.setTint(color)
91 |
92 | toolbar_btn_more.background.alpha = ((1-percent) * 255).toInt()
93 | toolbar_btn_go_back.background.alpha = ((1-percent) * 255).toInt()
94 | toolbar_btn_trolley.background.alpha = ((1-percent) * 255).toInt()
95 | }
96 | }
97 |
98 | }
99 |
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/scwang/smart/refresh/horizontal/demo/fragment/PracticePagerFragment.kt:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal.demo.fragment
2 |
3 |
4 | import android.graphics.drawable.Animatable
5 | import android.os.Bundle
6 | import android.support.v4.app.Fragment
7 | import android.view.LayoutInflater
8 | import android.view.View
9 | import android.view.ViewGroup
10 | import com.scwang.smart.refresh.layout.api.RefreshHeader
11 | import com.scwang.smart.refresh.layout.simple.SimpleMultiListener
12 |
13 | import com.scwang.smartrefresh.horizontal.demo.R
14 | import kotlinx.android.synthetic.main.fragment_practice_pager.*
15 | import kotlinx.android.synthetic.main.fragment_practice_pager.refreshLayout
16 |
17 | /**
18 | * A simple [Fragment] subclass.
19 | *
20 | */
21 | class PracticePagerFragment : Fragment() {
22 |
23 | override fun onCreateView(
24 | inflater: LayoutInflater, container: ViewGroup?,
25 | savedInstanceState: Bundle?
26 | ): View? {
27 | // Inflate the layout for this fragment
28 | return inflater.inflate(R.layout.fragment_practice_pager, container, false)
29 | }
30 |
31 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
32 | super.onViewCreated(view, savedInstanceState)
33 |
34 | toolbar.setNavigationOnClickListener {
35 | activity?.finish()
36 | }
37 |
38 | refreshLayout.setEnableOverScrollBounce(false)
39 | refreshLayout.setOnMultiListener(object : SimpleMultiListener() {
40 | override fun onHeaderStartAnimator(h: RefreshHeader?, footerHeight: Int, maxDragHeight: Int) {
41 | (header.drawable as? Animatable)?.start()
42 | }
43 | override fun onHeaderFinish(h: RefreshHeader?, success: Boolean) {
44 | (header.drawable as? Animatable)?.stop()
45 | }
46 | });
47 |
48 | refreshLayout.setOnRefreshListener {
49 | refreshLayout.finishRefresh(1500)
50 | }
51 | refreshLayout.setOnLoadMoreListener {
52 | refreshLayout.finishLoadMore(1000)
53 | }
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/scwang/smart/refresh/horizontal/demo/fragment/index/IndexHomeFragment.kt:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal.demo.fragment.index
2 |
3 | import android.R.layout.simple_list_item_2
4 | import android.os.Bundle
5 | import android.support.annotation.StringRes
6 | import android.support.v4.app.Fragment
7 | import android.view.LayoutInflater
8 | import android.view.View
9 | import android.view.ViewGroup
10 | import com.scwang.smartrefresh.horizontal.demo.R
11 | import com.scwang.smart.refresh.horizontal.demo.activity.FragmentActivity
12 | import com.scwang.smart.refresh.horizontal.demo.adapter.BaseRecyclerAdapter
13 | import com.scwang.smart.refresh.horizontal.demo.adapter.SmartViewHolder
14 | import com.scwang.smart.refresh.horizontal.demo.fragment.ExampleBasicFragment
15 | import com.scwang.smart.refresh.horizontal.demo.fragment.PracticeGoodsFragment
16 | import com.scwang.smart.refresh.horizontal.demo.fragment.PracticePagerFragment
17 | import kotlinx.android.synthetic.main.fragment_index_home.*
18 | import kotlin.reflect.KClass
19 |
20 | class IndexHomeFragment : Fragment() {
21 |
22 | enum class HomeItem(@StringRes val titleId: Int, @StringRes val descriptionId: Int, val fragment: KClass) {
23 | Goods(R.string.practice_goods_fragment_title, R.string.practice_goods_fragment_description, PracticeGoodsFragment::class),
24 | Pager(R.string.practice_pager_fragment_title,R.string.practice_pager_fragment_description, PracticePagerFragment::class),
25 | More(R.string.example_basic_fragment_title,R.string.example_basic_fragment_description, ExampleBasicFragment::class)
26 | }
27 |
28 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
29 | return inflater.inflate(R.layout.fragment_index_home, container, false)
30 | }
31 |
32 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
33 | super.onViewCreated(view, savedInstanceState)
34 |
35 | val adapter = object : BaseRecyclerAdapter(
36 | HomeItem.values().asList(), simple_list_item_2) {
37 | override fun onBindViewHolder(holder: SmartViewHolder, model: HomeItem, position: Int) {
38 | holder.text(android.R.id.text1, model.titleId)
39 | holder.text(android.R.id.text2, model.descriptionId)
40 | }
41 | }
42 | adapter.setOnItemClickListener { _, _, i, _ ->
43 | adapter.get(i)?.also { item->
44 | FragmentActivity.start(activity, item.fragment.java)
45 | }
46 | }
47 | recyclerView.adapter = adapter
48 | }
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/scwang/smart/refresh/horizontal/demo/util/StatusBarUtil.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal.demo.util;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.res.Resources;
6 | import android.os.Build;
7 | import android.support.annotation.FloatRange;
8 | import android.support.annotation.RequiresApi;
9 | import android.util.Log;
10 | import android.util.TypedValue;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.view.Window;
14 | import android.view.WindowManager;
15 |
16 | import java.lang.reflect.Field;
17 | import java.lang.reflect.Method;
18 | import java.util.regex.Pattern;
19 |
20 | /**
21 | * 状态栏透明
22 | * Created by SCWANG on 2016/10/26.
23 | */
24 |
25 | @SuppressWarnings("unused")
26 | public class StatusBarUtil {
27 |
28 | public static int DEFAULT_COLOR = 0;
29 | public static float DEFAULT_ALPHA = 0;//Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? 0.2f : 0.3f;
30 | public static final int MIN_API = 19;
31 |
32 | //
33 | public static void immersive(Activity activity) {
34 | immersive(activity, DEFAULT_COLOR, DEFAULT_ALPHA);
35 | }
36 |
37 | public static void immersive(Activity activity, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
38 | immersive(activity.getWindow(), color, alpha);
39 | }
40 |
41 | public static void immersive(Activity activity, int color) {
42 | immersive(activity.getWindow(), color, 1f);
43 | }
44 |
45 | public static void immersive(Window window) {
46 | immersive(window, DEFAULT_COLOR, DEFAULT_ALPHA);
47 | }
48 |
49 | public static void immersive(Window window, int color) {
50 | immersive(window, color, 1f);
51 | }
52 |
53 | public static void immersive(Window window, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
54 | if (Build.VERSION.SDK_INT >= 21) {
55 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
56 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
57 | window.setStatusBarColor(mixtureColor(color, alpha));
58 |
59 | int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
60 | systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
61 | systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
62 | window.getDecorView().setSystemUiVisibility(systemUiVisibility);
63 | } else if (Build.VERSION.SDK_INT >= 19) {
64 | window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
65 | setTranslucentView((ViewGroup) window.getDecorView(), color, alpha);
66 | } else if (Build.VERSION.SDK_INT >= MIN_API && Build.VERSION.SDK_INT > 16) {
67 | int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
68 | systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
69 | systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
70 | window.getDecorView().setSystemUiVisibility(systemUiVisibility);
71 | }
72 | }
73 |
74 | public static void color(Activity activity, int color) {
75 | if (Build.VERSION.SDK_INT >= 21) {
76 | Window window = activity.getWindow();
77 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
78 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
79 | window.setStatusBarColor(color);
80 | }
81 | }
82 | //
83 |
84 | //
85 | public static void darkMode(Activity activity, boolean dark) {
86 | if (isFlyme4Later()) {
87 | darkModeForFlyme4(activity.getWindow(), dark);
88 | } else if (isMIUI6Later()) {
89 | darkModeForMIUI6(activity.getWindow(), dark);
90 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
91 | darkModeForM(activity.getWindow(), dark);
92 | }
93 | }
94 |
95 | public static void darkModeCancel(Activity activity) {
96 | Window window = activity.getWindow();
97 | if (isFlyme4Later()) {
98 | darkModeForFlyme4(window, false);
99 | } else if (isMIUI6Later()) {
100 | darkModeForMIUI6(window, false);
101 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
102 | darkModeForM(window, false);
103 | }
104 | }
105 |
106 | /** 设置状态栏darkMode,字体颜色及icon变黑(目前支持MIUI6以上,Flyme4以上,Android M以上) */
107 | public static void darkMode(Activity activity) {
108 | darkMode(activity.getWindow(), DEFAULT_COLOR, DEFAULT_ALPHA);
109 | }
110 |
111 | public static void darkMode(Activity activity, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
112 | darkMode(activity.getWindow(), color, alpha);
113 | }
114 |
115 | public static void darkOnly(Activity activity) {
116 | Window window = activity.getWindow();
117 | if (isFlyme4Later()) {
118 | darkModeForFlyme4(window, true);
119 | } else if (isMIUI6Later()) {
120 | darkModeForMIUI6(window, true);
121 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
122 | darkModeForM(window, true);
123 | }
124 | }
125 |
126 | /** 设置状态栏darkMode,字体颜色及icon变黑(目前支持MIUI6以上,Flyme4以上,Android M以上) */
127 | public static void darkMode(Window window, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
128 | if (isFlyme4Later()) {
129 | darkModeForFlyme4(window, true);
130 | immersive(window,color,alpha);
131 | } else if (isMIUI6Later()) {
132 | darkModeForMIUI6(window, true);
133 | immersive(window,color,alpha);
134 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
135 | darkModeForM(window, true);
136 | immersive(window, color, alpha);
137 | } else if (Build.VERSION.SDK_INT >= 19) {
138 | window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
139 | setTranslucentView((ViewGroup) window.getDecorView(), color, alpha);
140 | } else {
141 | immersive(window, color, alpha);
142 | }
143 | // if (Build.VERSION.SDK_INT >= 21) {
144 | // window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
145 | // window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
146 | // window.setStatusBarColor(Color.TRANSPARENT);
147 | // } else if (Build.VERSION.SDK_INT >= 19) {
148 | // window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
149 | // }
150 |
151 | // setTranslucentView((ViewGroup) window.getDecorView(), color, alpha);
152 | }
153 |
154 | //------------------------->
155 |
156 | /** android 6.0设置字体颜色 */
157 | @RequiresApi(Build.VERSION_CODES.M)
158 | private static void darkModeForM(Window window, boolean dark) {
159 | // window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
160 | // window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
161 | // window.setStatusBarColor(Color.TRANSPARENT);
162 |
163 | int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
164 | if (dark) {
165 | systemUiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
166 | } else {
167 | systemUiVisibility &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
168 | }
169 | window.getDecorView().setSystemUiVisibility(systemUiVisibility);
170 | }
171 |
172 | /**
173 | * 设置Flyme4+的darkMode,darkMode时候字体颜色及icon变黑
174 | * http://open-wiki.flyme.cn/index.php?title=Flyme%E7%B3%BB%E7%BB%9FAPI
175 | */
176 | public static boolean darkModeForFlyme4(Window window, boolean dark) {
177 | boolean result = false;
178 | if (window != null) {
179 | try {
180 | WindowManager.LayoutParams e = window.getAttributes();
181 | Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
182 | Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
183 | darkFlag.setAccessible(true);
184 | meizuFlags.setAccessible(true);
185 | int bit = darkFlag.getInt(null);
186 | int value = meizuFlags.getInt(e);
187 | if (dark) {
188 | value |= bit;
189 | } else {
190 | value &= ~bit;
191 | }
192 |
193 | meizuFlags.setInt(e, value);
194 | window.setAttributes(e);
195 | result = true;
196 | } catch (Exception var8) {
197 | Log.e("StatusBar", "darkIcon: failed");
198 | }
199 | }
200 |
201 | return result;
202 | }
203 |
204 | /**
205 | * 设置MIUI6+的状态栏是否为darkMode,darkMode时候字体颜色及icon变黑
206 | * http://dev.xiaomi.com/doc/p=4769/
207 | */
208 | public static boolean darkModeForMIUI6(Window window, boolean dark) {
209 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
210 | darkModeForM(window, dark);
211 | }
212 | Class extends Window> clazz = window.getClass();
213 | try {
214 | int darkModeFlag = 0;
215 | Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
216 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
217 | darkModeFlag = field.getInt(layoutParams);
218 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
219 | extraFlagField.invoke(window, dark ? darkModeFlag : 0, darkModeFlag);
220 | return true;
221 | } catch (Throwable e) {
222 | e.printStackTrace();
223 | return false;
224 | }
225 | }
226 |
227 | /** 判断是否Flyme4以上 */
228 | public static boolean isFlyme4Later() {
229 | return Build.FINGERPRINT.contains("Flyme_OS_4")
230 | || Build.VERSION.INCREMENTAL.contains("Flyme_OS_4")
231 | || Pattern.compile("Flyme OS [4|5]", Pattern.CASE_INSENSITIVE).matcher(Build.DISPLAY).find();
232 | }
233 |
234 | /** 判断是否为MIUI6以上 */
235 | public static boolean isMIUI6Later() {
236 | try {
237 | Class> clz = Class.forName("android.os.SystemProperties");
238 | Method mtd = clz.getMethod("get", String.class);
239 | String val = (String) mtd.invoke(null, "ro.miui.ui.version.name");
240 | val = val.replaceAll("[vV]", "");
241 | int version = Integer.parseInt(val);
242 | return version >= 6;
243 | } catch (Throwable e) {
244 | return false;
245 | }
246 | }
247 | //
248 |
249 | public static void setHeight(Context context, View view) {
250 | if (Build.VERSION.SDK_INT >= MIN_API) {
251 | ViewGroup.LayoutParams lp = view.getLayoutParams();
252 | if (lp != null && lp.height > 0) {
253 | lp.height += getStatusBarHeight(context);//增高
254 | }
255 | }
256 | }
257 |
258 | /** 增加View的paddingTop,增加的值为状态栏高度 */
259 | public static void setPadding(Context context, View view) {
260 | if (Build.VERSION.SDK_INT >= MIN_API) {
261 | view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context),
262 | view.getPaddingRight(), view.getPaddingBottom());
263 | }
264 | }
265 | /** 增加View的paddingTop,增加的值为状态栏高度 (智能判断,并设置高度)*/
266 | public static void setPaddingSmart(Context context, View view) {
267 | if (Build.VERSION.SDK_INT >= MIN_API) {
268 | ViewGroup.LayoutParams lp = view.getLayoutParams();
269 | if (lp != null && lp.height > 0) {
270 | lp.height += getStatusBarHeight(context);//增高
271 | }
272 | view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context),
273 | view.getPaddingRight(), view.getPaddingBottom());
274 | }
275 | }
276 |
277 | /** 增加View的高度以及paddingTop,增加的值为状态栏高度.一般是在沉浸式全屏给ToolBar用的 */
278 | public static void setHeightAndPadding(Context context, View view) {
279 | if (Build.VERSION.SDK_INT >= MIN_API) {
280 | ViewGroup.LayoutParams lp = view.getLayoutParams();
281 | lp.height += getStatusBarHeight(context);//增高
282 | view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context),
283 | view.getPaddingRight(), view.getPaddingBottom());
284 | }
285 | }
286 | /** 增加View上边距(MarginTop)一般是给高度为 WARP_CONTENT 的小控件用的*/
287 | public static void setMargin(Context context, View view) {
288 | if (Build.VERSION.SDK_INT >= MIN_API) {
289 | ViewGroup.LayoutParams lp = view.getLayoutParams();
290 | if (lp instanceof ViewGroup.MarginLayoutParams) {
291 | ((ViewGroup.MarginLayoutParams) lp).topMargin += getStatusBarHeight(context);//增高
292 | }
293 | view.setLayoutParams(lp);
294 | }
295 | }
296 | /**
297 | * 创建假的透明栏
298 | */
299 | public static void setTranslucentView(ViewGroup container, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
300 | if (Build.VERSION.SDK_INT >= 19) {
301 | int mixtureColor = mixtureColor(color, alpha);
302 | View translucentView = container.findViewById(android.R.id.custom);
303 | if (translucentView == null && mixtureColor != 0) {
304 | translucentView = new View(container.getContext());
305 | translucentView.setId(android.R.id.custom);
306 | ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(
307 | ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(container.getContext()));
308 | container.addView(translucentView, lp);
309 | }
310 | if (translucentView != null) {
311 | translucentView.setBackgroundColor(mixtureColor);
312 | }
313 | }
314 | }
315 |
316 | public static int mixtureColor(int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
317 | int a = (color & 0xff000000) == 0 ? 0xff : color >>> 24;
318 | return (color & 0x00ffffff) | (((int) (a * alpha)) << 24);
319 | }
320 |
321 | /** 获取状态栏高度 */
322 | public static int getStatusBarHeight(Context context) {
323 | int result = 24;
324 | int resId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
325 | if (resId > 0) {
326 | result = context.getResources().getDimensionPixelSize(resId);
327 | } else {
328 | result = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
329 | result, Resources.getSystem().getDisplayMetrics());
330 | }
331 | return result;
332 | }
333 | }
334 |
--------------------------------------------------------------------------------
/app/src/main/java/com/scwang/smart/refresh/horizontal/demo/widget/DetailHorizontalFooter.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal.demo.widget;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.util.AttributeSet;
6 | import android.view.View;
7 | import android.widget.ImageView;
8 | import android.widget.TextView;
9 |
10 | import com.scwang.smart.refresh.horizontal.HorizontalFooter;
11 | import com.scwang.smart.refresh.layout.api.RefreshKernel;
12 | import com.scwang.smart.refresh.layout.api.RefreshLayout;
13 | import com.scwang.smart.refresh.layout.constant.RefreshState;
14 | import com.scwang.smartrefresh.horizontal.demo.R;
15 |
16 | public class DetailHorizontalFooter extends HorizontalFooter {
17 |
18 | private TextView mTvTitle;
19 | private ImageView mIvIcon;
20 | private RefreshKernel mRefreshKernel;
21 |
22 | public DetailHorizontalFooter(Context context) {
23 | this(context, null);
24 | }
25 |
26 | /**
27 | * 构造函数中 加载xml布局,并获取控件
28 | */
29 | public DetailHorizontalFooter(Context context, AttributeSet attrs) {
30 | super(context, attrs);
31 | View.inflate(context, R.layout.widget_footer_detail_horizontal, this);
32 | mIvIcon = findViewById(R.id.footer_icon);
33 | mTvTitle = findViewById(R.id.footer_title);
34 | }
35 |
36 | /**
37 | * 初始化中 保存 kernel 核心对象,并关闭自动加载功能
38 | */
39 | @Override
40 | public void onInitialized(@NonNull RefreshKernel kernel, int height, int maxDragHeight) {
41 | super.onInitialized(kernel, height, maxDragHeight);
42 | mRefreshKernel = kernel;
43 | kernel.getRefreshLayout().setEnableAutoLoadMore(false);
44 | }
45 |
46 | /**
47 | * 重写 onStartAnimator,在开始动画的时候,直接关闭刷新,
48 | * 因为本Footer不需要任何加载,仅仅触发事件之后直接关闭
49 | */
50 | @Override
51 | public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
52 | if (mRefreshKernel != null) {
53 | mRefreshKernel.setState(RefreshState.None);
54 | //onReleased 的时候 调用 setState(RefreshState.None); 并不会立刻改变成 None
55 | //而是先执行一个回弹动画,LoadFinish 是介于 Refreshing 和 None 之间的状态
56 | //LoadFinish 用于在回弹动画结束时候能顺利改变为 None
57 | mRefreshKernel.setState(RefreshState.LoadFinish);
58 | }
59 | }
60 |
61 | /**
62 | * 状态改变时 更新界面
63 | */
64 | @Override
65 | public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
66 | if (newState == RefreshState.ReleaseToLoad) {
67 | mIvIcon.animate().rotation(270);
68 | mTvTitle.setText(R.string.footer_detail_horizontal_release);
69 | } else {
70 | mIvIcon.animate().rotation(90);
71 | mTvTitle.setText(R.string.footer_detail_horizontal_pulling);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/scwang/smart/refresh/horizontal/demo/widget/SmartViewPager.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal.demo.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.support.annotation.IdRes;
6 | import android.support.annotation.NonNull;
7 | import android.support.annotation.Nullable;
8 | import android.support.v4.view.PagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import com.scwang.smartrefresh.horizontal.demo.R;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | /**
19 | * 智能分页器
20 | */
21 | public class SmartViewPager extends ViewPager {
22 |
23 |
24 | private SmartPagerAdapter mAdapter;
25 |
26 | public SmartViewPager(Context context) {
27 | super(context);
28 | }
29 |
30 | public SmartViewPager(Context context, AttributeSet attrs) {
31 | super(context, attrs);
32 | }
33 |
34 | /**
35 | * @param id the id of the view to be found
36 | * @return the view of the specified id, null if cannot be found
37 | */
38 | @SuppressWarnings({"unchecked", "unused"})
39 | protected T findViewTraversal(@IdRes int id) {
40 | if (mAdapter != null && mAdapter.views != null) {
41 | for (View view : mAdapter.views) {
42 | View find = view.findViewById(id);
43 | if (find != null) {
44 | return (T)find;
45 | }
46 | }
47 | }
48 | for (int i = 0, len = getChildCount(); i < len; i++) {
49 | View child = getChildAt(i);
50 | View find = child.findViewById(id);
51 | if (find != null) {
52 | return (T)find;
53 | }
54 | }
55 | if (getId() == id) {
56 | return (T)this;
57 | }
58 | return null;
59 | }
60 |
61 | @Override
62 | protected void onFinishInflate() {
63 | super.onFinishInflate();
64 | int childCount = getChildCount();
65 | if (getAdapter() == null) {
66 | if (childCount > 0) {
67 | setAdapter(mAdapter = new SmartPagerAdapter());
68 | removeAllViews();
69 | }
70 | } else if (childCount > 0) {
71 | removeAllViews();
72 | }
73 | }
74 |
75 | @Override
76 | protected void onAttachedToWindow() {
77 | super.onAttachedToWindow();
78 | int childCount = getChildCount();
79 | if (getAdapter() == null) {
80 | if (childCount > 0) {
81 | setAdapter(mAdapter = new SmartPagerAdapter());
82 | removeAllViews();
83 | }
84 | } else if (childCount > 0) {
85 | removeAllViews();
86 | }
87 | }
88 |
89 | @Override
90 | protected void onDetachedFromWindow() {
91 | super.onDetachedFromWindow();
92 | if (mAdapter != null) {
93 | setAdapter(null);
94 | for (View view : mAdapter.views) {
95 | addView(view);
96 | }
97 | mAdapter = null;
98 | }
99 | }
100 |
101 | //
102 | @Override
103 | public LayoutParams generateLayoutParams(AttributeSet attrs) {
104 | final View thisView = this;
105 | return new LayoutParams(thisView.getContext(), attrs);
106 | }
107 |
108 | public static class LayoutParams extends ViewPager.LayoutParams {
109 |
110 | LayoutParams(Context context, AttributeSet attrs) {
111 | super(context, attrs);
112 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SmartViewPager_Layout);
113 | title = ta.getString(R.styleable.SmartViewPager_Layout_layout_svpTitle);
114 | ta.recycle();
115 | }
116 |
117 | String title;
118 | }
119 | //
120 |
121 | class SmartPagerAdapter extends PagerAdapter {
122 |
123 | List views;
124 |
125 | SmartPagerAdapter() {
126 | int count = getChildCount();
127 | views = new ArrayList<>(count);
128 | for (int i = 0; i < count; i++) {
129 | views.add(getChildAt(i));
130 | }
131 | }
132 |
133 | @Nullable
134 | @Override
135 | public CharSequence getPageTitle(int position) {
136 | View view = views.get(position);
137 | ViewGroup.LayoutParams lp = view.getLayoutParams();
138 | if (lp instanceof LayoutParams) {
139 | if (((LayoutParams) lp).title != null) {
140 | return ((LayoutParams) lp).title;
141 | }
142 | }
143 | return super.getPageTitle(position);
144 | }
145 |
146 | @Override
147 | public int getCount() {
148 | return views.size();
149 | }
150 |
151 | @Override
152 | public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
153 | return view == o;
154 | }
155 |
156 | @NonNull
157 | @Override
158 | public Object instantiateItem(@NonNull ViewGroup container, int position) {
159 | container.addView(views.get(position));
160 | return views.get(position);
161 | }
162 |
163 | @Override
164 | public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
165 | container.removeView((View)object);
166 | }
167 | }
168 | }
169 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_panel_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_panel_common.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_panel_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_round_alpha.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 | -
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_tab_selected.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_chevron_right.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_chevron_right_gray.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_dashboard_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_footer_detail_gray_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_home_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_more_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_navigate_before_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_notifications_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_service_gray_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_star_gray_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_store_gray_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_trolley_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/loading_rabbit.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
22 |
29 |
30 |
31 |
32 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_example_horizontal.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
14 |
15 |
22 |
25 |
33 |
36 |
37 |
38 |
42 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_index_home.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
20 |
21 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_practice_goods.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
20 |
25 |
28 |
32 |
36 |
43 |
47 |
52 |
57 |
62 |
63 |
66 |
67 |
73 |
74 |
75 |
78 |
79 |
85 |
90 |
91 |
97 |
102 |
103 |
104 |
105 |
109 |
114 |
119 |
128 |
132 |
138 |
147 |
155 |
163 |
164 |
194 |
195 |
196 |
205 |
206 |
215 |
216 |
217 |
218 |
219 |
225 |
226 |
236 |
246 |
256 |
265 |
274 |
275 |
276 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_practice_pager.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
14 |
19 |
20 |
21 |
26 |
29 |
30 |
39 |
40 |
43 |
46 |
55 |
62 |
63 |
71 |
72 |
73 |
76 |
85 |
92 |
100 |
101 |
102 |
103 |
106 |
115 |
122 |
130 |
131 |
132 |
133 |
134 |
135 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/widget_footer_detail_horizontal.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
29 |
30 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/navigation.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_loading_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xhdpi/ic_loading_1.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_loading_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xhdpi/ic_loading_2.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_loading_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xhdpi/ic_loading_3.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/image_goods_banner_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xhdpi/image_goods_banner_1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/image_goods_banner_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xhdpi/image_goods_banner_2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/image_goods_banner_3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xhdpi/image_goods_banner_3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/card_cover1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xxhdpi/card_cover1.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/card_cover2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xxhdpi/card_cover2.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/card_cover3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xxhdpi/card_cover3.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/image_detail_comment_mi.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xxhdpi/image_detail_comment_mi.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/image_detail_description_mi.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xxhdpi/image_detail_description_mi.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/image_detail_goods_mi.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xxhdpi/image_detail_goods_mi.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #33aaff
4 | #2299ee
5 | #cc0094ff
6 | #FF4081
7 |
8 | #333333
9 | #444444
10 | #888888
11 |
12 | #FFFFFF
13 | #f2f2f2
14 | #33aaaaaa
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 | 2.5dp
7 | 5dp
8 | 10dp
9 | 10dp
10 | 12.5dp
11 | 15dp
12 | 20dp
13 | 25dp
14 |
15 | 0.5dp
16 | 20dp
17 |
18 | 10sp
19 | 12sp
20 | 14sp
21 | 16sp
22 | 17sp
23 | 19sp
24 | 20sp
25 | 14sp
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Horizontal
3 |
4 | Home
5 | Dashboard
6 | Notifications
7 | Item %02d
8 |
9 | Hello blank fragment
10 |
11 | 商品详情
12 | 商品详情幻灯片左右刷新拖动
13 | 商品
14 | 详情
15 | 评论
16 | 收藏
17 | 店铺
18 | 客服
19 | 立即购买
20 | 加入购物车
21 |
22 | 页面切换
23 | 页面切换左右刷新拖动
24 | Index 1
25 | Index 2
26 | Index 3
27 |
28 | 加载更多
29 | 左边刷新右边加载更多
30 |
31 | 滑动查看图文详情
32 | 释放查看图文详情
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
24 |
25 |
31 |
32 |
33 |
40 |
41 |
45 |
46 |
54 |
55 |
61 |
62 |
66 |
67 |
71 |
72 |
75 |
76 |
79 |
80 |
83 |
84 |
91 |
92 |
96 |
97 |
105 |
106 |
109 |
110 |
114 |
115 |
122 |
123 |
129 |
130 |
142 |
143 |
150 |
151 |
155 |
156 |
170 |
171 |
176 |
177 |
193 |
194 |
195 |
--------------------------------------------------------------------------------
/app/src/test/java/com/scwang/smartrefresh/horizontal/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.scwang.smartrefresh.horizontal
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/art/app-release.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/art/app-release.apk
--------------------------------------------------------------------------------
/art/gif_basic.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/art/gif_basic.gif
--------------------------------------------------------------------------------
/art/gif_goods.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/art/gif_goods.gif
--------------------------------------------------------------------------------
/art/gif_pager.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/art/gif_pager.gif
--------------------------------------------------------------------------------
/art/jpg_apk_demo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/art/jpg_apk_demo.jpg
--------------------------------------------------------------------------------
/art/md_update.md:
--------------------------------------------------------------------------------
1 | # 更新日志
2 |
3 | ## V 1.0.0
4 | > 发布:正式发布1.0版本,基于SmartRefreshLayout实现横向刷新
5 |
--------------------------------------------------------------------------------
/art/png_apk_rqcode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/art/png_apk_rqcode.png
--------------------------------------------------------------------------------
/bintrayUpload.bat:
--------------------------------------------------------------------------------
1 | gradlew clean build bintrayUpload -PdryRun=false
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.3.41'
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.4.2'
11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12 | classpath 'com.novoda:bintray-release:0.9.1'
13 |
14 | // NOTE: Do not place your application dependencies here; they belong
15 | // in the individual module build.gradle files
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | google()
22 | jcenter()
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
30 | def file = 'local.properties'
31 | if (new File(file).exists()) {
32 | Properties properties = new Properties()
33 | properties.load(new FileInputStream(file))
34 | if ('true' == properties['bintray.enable']) {
35 | subprojects {
36 | if (name == ("library")) {
37 | afterEvaluate {
38 | publish {
39 | groupId = group
40 | desc = description
41 | publishVersion = version
42 | artifactId = SMART_ARTIFACT
43 | userOrg = properties['bintray.user']
44 | bintrayKey = properties['bintray.key']
45 | bintrayUser = properties['bintray.user']
46 | dryRun = properties['bintray.dryRun']
47 | website = "https://github.com/scwang90/${rootProject.name}"
48 | }
49 | }
50 | apply plugin: 'com.novoda.bintray-release'
51 | }
52 | }
53 |
54 | }
55 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # Kotlin code style for this project: "official" or "obsolete":
15 | kotlin.code.style=official
16 |
17 | SMART_GROUP=com.scwang.smart
18 | SMART_ARTIFACT=refresh-layout-horizontal
19 | SMART_VERSION=2.0.0
20 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scwang90/SmartRefreshHorizontal/63a5193ed419bb175961e75a77ef6f1581756394/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'maven'
3 |
4 | android {
5 | compileSdkVersion 28
6 |
7 | defaultConfig {
8 | minSdkVersion 12
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | compileOnly fileTree(dir: 'libs', include: ['*.jar'])
28 |
29 | testImplementation 'junit:junit:4.12'
30 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
31 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
32 |
33 | compileOnly 'com.android.support:appcompat-v7:28.0.0'
34 | compileOnly 'com.scwang.smart:refresh-layout-kernel:2.0.1'
35 | }
36 |
37 | group = SMART_GROUP
38 | version = SMART_VERSION
39 | description = 'An intelligent refresh layout with horizontal'
40 |
41 | uploadArchives {
42 | repositories.mavenDeployer {
43 | repository(url: uri('../repo'))
44 | pom.artifactId = SMART_ARTIFACT
45 | }
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/scwang/smartrefresh/horizontal/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smartrefresh.horizontal;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.scwang.smartrefresh.horizontal.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/library/src/main/java/com/scwang/smart/refresh/horizontal/HorizontalComponent.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 |
7 | import com.scwang.smart.refresh.layout.api.RefreshComponent;
8 | import com.scwang.smart.refresh.layout.simple.SimpleComponent;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | /**
14 | * 由于 {@link SmartRefreshHorizontal} 是通过选装 90 度来达到横向效果的
15 | * 之前所有 Header Footer 虽然可以直接使用,但是他们也都被旋转了 90 度
16 | * 如果项自定义 不会被旋转的 Header 或者 Footer 可以继承 HorizontalComponent
17 | * 也可以把 HorizontalComponent 套在 普通 Header 和 Footer 外面达到效果
18 | */
19 | public abstract class HorizontalComponent extends SimpleComponent {
20 |
21 | private List views = new ArrayList<>();
22 |
23 | protected HorizontalComponent(Context context, AttributeSet attrs, int defStyleAttr) {
24 | super(context, attrs, defStyleAttr);
25 | mWrappedView = this;
26 | }
27 |
28 | @Override
29 | protected void onFinishInflate() {
30 | super.onFinishInflate();
31 | for (int i = 0; i < getChildCount(); i++) {
32 | View child = getChildAt(i);
33 | if (child instanceof RefreshComponent) {
34 | this.mWrappedInternal = (RefreshComponent)child;
35 | }
36 | }
37 | }
38 |
39 | @Override
40 | protected void onAttachedToWindow() {
41 | super.onAttachedToWindow();
42 | if (this.mWrappedInternal == null) {
43 | for (int i = 0; i < getChildCount(); i++) {
44 | View child = getChildAt(i);
45 | if (child instanceof RefreshComponent) {
46 | this.mWrappedInternal = (RefreshComponent)child;
47 | }
48 | }
49 | }
50 | }
51 |
52 | @Override
53 | public boolean isLayoutRequested() {
54 | return views.size() > 0 || super.isLayoutRequested();
55 | }
56 |
57 | @Override
58 | @SuppressWarnings("SuspiciousNameCombination")
59 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
60 | views.clear();
61 | super.onMeasure(heightMeasureSpec, widthMeasureSpec);
62 | for (int i = 0, len = getChildCount(); i < len; i++) {
63 | View view = getChildAt(i);
64 | if (view.getVisibility() == VISIBLE) {
65 | views.add(view);
66 | view.setVisibility(GONE);
67 | }
68 | }
69 | int width = getMeasuredWidth();
70 | int height = getMeasuredHeight();
71 | heightMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
72 | widthMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
73 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
74 | for (View child : views) {
75 | child.setVisibility(VISIBLE);
76 | }
77 | views.clear();
78 | }
79 |
80 | @Override
81 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
82 | int height = right - left;
83 | int width = bottom - top;
84 | super.onLayout(changed, left, top, right, bottom);
85 | for (int i = 0, len = getChildCount(); i < len; i++) {
86 | View child = getChildAt(i);
87 | if (child.getVisibility() == VISIBLE) {
88 | int childLeft = child.getLeft();
89 | int childTop = child.getTop();
90 | int childRight = child.getRight();
91 | int childBottom = child.getBottom();
92 | int childWidth = childRight - childLeft;
93 | int childHeight = childBottom - childTop;
94 | int distLeft = height - childBottom;
95 | //noinspection SuspiciousNameCombination,UnnecessaryLocalVariable,UnnecessaryLocalVariable
96 | int distTop = childLeft;
97 | int rotLeft = (distLeft + childHeight + distLeft) / 2 - childWidth / 2;
98 | int rotTop = (distTop + childWidth + distTop) / 2 - childHeight / 2;
99 | child.setRotation(90);
100 | child.layout(rotLeft, rotTop, rotLeft + childWidth, rotTop + childHeight);
101 | }
102 | }
103 |
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/library/src/main/java/com/scwang/smart/refresh/horizontal/HorizontalFooter.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 |
7 | import com.scwang.smart.refresh.layout.api.RefreshFooter;
8 |
9 | /**
10 | * 由于 {@link SmartRefreshHorizontal} 是通过选装 90 度来达到横向效果的
11 | * 之前所有 Footer 虽然可以直接使用,但是他们也都被旋转了 90 度
12 | * 如果项自定义 不会被旋转的 Footer 可以继承 HorizontalFooter
13 | * 也可以把 HorizontalFooter 套在 和 Footer 外面达到效果
14 | */
15 | public class HorizontalFooter extends HorizontalComponent implements RefreshFooter {
16 |
17 | public HorizontalFooter(View view) {
18 | this(view.getContext());
19 | this.addView(view);
20 | }
21 |
22 | public HorizontalFooter(Context context) {
23 | this(context, null);
24 | }
25 |
26 | public HorizontalFooter(Context context, AttributeSet attrs) {
27 | super(context, attrs, 0);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/library/src/main/java/com/scwang/smart/refresh/horizontal/HorizontalHeader.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 |
7 | import com.scwang.smart.refresh.layout.api.RefreshHeader;
8 |
9 | /**
10 | * 由于 {@link SmartRefreshHorizontal} 是通过选装 90 度来达到横向效果的
11 | * 之前所有 Header 虽然可以直接使用,但是他们也都被旋转了 90 度
12 | * 如果项自定义 不会被旋转的 Header 可以继承 HorizontalHeader
13 | * 也可以把 HorizontalHeader 套在 普通 Header 外面达到效果
14 | */
15 | public class HorizontalHeader extends HorizontalComponent implements RefreshHeader {
16 |
17 | public HorizontalHeader(View view) {
18 | this(view.getContext());
19 | this.addView(view);
20 | }
21 |
22 | public HorizontalHeader(Context context) {
23 | this(context, null);
24 | }
25 |
26 | public HorizontalHeader(Context context, AttributeSet attrs) {
27 | super(context, attrs, 0);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/library/src/main/java/com/scwang/smart/refresh/horizontal/RefreshContentHorizontal.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.support.annotation.NonNull;
5 | import android.view.View;
6 | import android.widget.AbsListView;
7 |
8 | import com.scwang.smart.refresh.layout.wrapper.RefreshContentWrapper;
9 |
10 | import static com.scwang.smart.refresh.layout.util.SmartUtil.scrollListBy;
11 |
12 | public class RefreshContentHorizontal extends RefreshContentWrapper {
13 |
14 | RefreshContentHorizontal(@NonNull View view) {
15 | super(view);
16 | }
17 |
18 | @Override
19 | public ValueAnimator.AnimatorUpdateListener scrollContentWhenFinished(final int spinner) {
20 | if (mScrollableView != null && spinner != 0) {
21 | if ((spinner < 0 && ScrollBoundaryHorizontal.canScrollRight(mScrollableView)) || (spinner > 0 && ScrollBoundaryHorizontal.canScrollLeft(mScrollableView))) {
22 | mLastSpinner = spinner;
23 | return this;
24 | }
25 | }
26 | return null;
27 | }
28 |
29 | @Override
30 | public void onAnimationUpdate(ValueAnimator animation) {
31 | int value = (int) animation.getAnimatedValue();
32 | try {
33 | if (mScrollableView instanceof AbsListView) {
34 | scrollListBy((AbsListView) mScrollableView, value - mLastSpinner);
35 | } else {
36 | mScrollableView.scrollBy(value - mLastSpinner, 0);
37 | }
38 | } catch (Throwable ignored) {
39 | //根据用户反馈,此处可能会有BUG
40 | }
41 | mLastSpinner = value;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/library/src/main/java/com/scwang/smart/refresh/horizontal/ScrollBoundaryHorizontal.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal;
2 |
3 | import android.graphics.PointF;
4 | import android.support.annotation.NonNull;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.AbsListView;
8 |
9 | import com.scwang.smart.refresh.layout.simple.SimpleBoundaryDecider;
10 | import com.scwang.smart.refresh.layout.util.SmartUtil;
11 |
12 | /**
13 | * 滚动边界
14 | * Created by SCWANG on 2017/7/8.
15 | */
16 | @SuppressWarnings("WeakerAccess")
17 | public class ScrollBoundaryHorizontal extends SimpleBoundaryDecider {
18 |
19 | //
20 | @Override
21 | public boolean canRefresh(View content) {
22 | return canRefresh(content, mActionEvent);
23 | }
24 | @Override
25 | public boolean canLoadMore(View content) {
26 | return canLoadMore(content, mActionEvent, mEnableLoadMoreWhenContentNotFull);
27 | }
28 | //
29 |
30 | //
31 | /**
32 | * 判断内容是否可以刷新
33 | * @param targetView 内容视图
34 | * @param touch 按压事件位置
35 | * @return 是否可以刷新
36 | */
37 | public static boolean canRefresh(@NonNull View targetView, PointF touch) {
38 | if (canScrollLeft(targetView) && targetView.getVisibility() == View.VISIBLE) {
39 | return false;
40 | }
41 | //touch == null 时 canRefresh 不会动态递归搜索
42 | if (targetView instanceof ViewGroup && touch != null) {
43 | ViewGroup viewGroup = (ViewGroup) targetView;
44 | final int childCount = viewGroup.getChildCount();
45 | PointF point = new PointF();
46 | for (int i = childCount; i > 0; i--) {
47 | View child = viewGroup.getChildAt(i - 1);
48 | if (SmartUtil.isTransformedTouchPointInView(viewGroup, child, touch.x, touch.y, point)) {
49 | if ("fixed".equals(child.getTag())) {
50 | return false;
51 | }
52 | touch.offset(point.x, point.y);
53 | boolean can = canRefresh(child, touch);
54 | touch.offset(-point.x, -point.y);
55 | return can;
56 | }
57 | }
58 | }
59 | return true;
60 | }
61 |
62 | /**
63 | * 判断内容视图是否可以加载更多
64 | * @param targetView 内容视图
65 | * @param touch 按压事件位置
66 | * @param contentFull 内容是否填满页面 (未填满时,会通过canScrollUp自动判断)
67 | * @return 是否可以刷新
68 | */
69 | public static boolean canLoadMore(@NonNull View targetView, PointF touch, boolean contentFull) {
70 | if (canScrollRight(targetView) && targetView.getVisibility() == View.VISIBLE) {
71 | return false;
72 | }
73 | //touch == null 时 canLoadMore 不会动态递归搜索
74 | if (targetView instanceof ViewGroup && touch != null && !SmartUtil.isScrollableView(targetView)) {
75 | ViewGroup viewGroup = (ViewGroup) targetView;
76 | final int childCount = viewGroup.getChildCount();
77 | PointF point = new PointF();
78 | for (int i = 0; i < childCount; i++) {
79 | View child = viewGroup.getChildAt(i);
80 | if (SmartUtil.isTransformedTouchPointInView(viewGroup, child, touch.x, touch.y, point)) {
81 | if ("fixed".equals(child.getTag())) {
82 | return false;
83 | }
84 | touch.offset(point.x, point.y);
85 | boolean can = canLoadMore(child, touch, contentFull);
86 | touch.offset(-point.x, -point.y);
87 | return can;
88 | }
89 | }
90 | }
91 | return (contentFull || canScrollLeft(targetView));
92 | }
93 |
94 | public static boolean canScrollLeft(@NonNull View targetView) {
95 | if (android.os.Build.VERSION.SDK_INT < 14) {
96 | if (targetView instanceof AbsListView) {
97 | final ViewGroup viewGroup = (ViewGroup) targetView;
98 | final AbsListView absListView = (AbsListView) targetView;
99 | return viewGroup.getChildCount() > 0
100 | && (absListView.getFirstVisiblePosition() > 0
101 | || viewGroup.getChildAt(0).getTop() < targetView.getPaddingTop());
102 | } else {
103 | return targetView.getScrollY() > 0;
104 | }
105 | } else {
106 | return targetView.canScrollHorizontally(-1);
107 | }
108 | }
109 |
110 | public static boolean canScrollRight(@NonNull View targetView) {
111 | if (android.os.Build.VERSION.SDK_INT < 14) {
112 | if (targetView instanceof AbsListView) {
113 | final ViewGroup viewGroup = (ViewGroup) targetView;
114 | final AbsListView absListView = (AbsListView) targetView;
115 | final int childCount = viewGroup.getChildCount();
116 | return childCount > 0 && (absListView.getLastVisiblePosition() < childCount - 1
117 | || viewGroup.getChildAt(childCount - 1).getBottom() > targetView.getPaddingBottom());
118 | } else {
119 | return targetView.getScrollY() < 0;
120 | }
121 | } else {
122 | return targetView.canScrollHorizontally(1);
123 | }
124 | }
125 |
126 | //
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/library/src/main/java/com/scwang/smart/refresh/horizontal/SmartRefreshHorizontal.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smart.refresh.horizontal;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.util.AttributeSet;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.scwang.smart.refresh.layout.SmartRefreshLayout;
10 | import com.scwang.smart.refresh.layout.api.RefreshComponent;
11 | import com.scwang.smart.refresh.layout.api.RefreshLayout;
12 | import com.scwang.smart.refresh.layout.listener.DefaultRefreshFooterCreator;
13 | import com.scwang.smart.refresh.layout.listener.DefaultRefreshHeaderCreator;
14 | import com.scwang.smart.refresh.layout.listener.DefaultRefreshInitializer;
15 | @SuppressWarnings("unused")
16 | public class SmartRefreshHorizontal extends SmartRefreshLayout {
17 |
18 | protected static DefaultRefreshHeaderCreator sHeaderCreator = null;
19 | protected static DefaultRefreshFooterCreator sFooterCreator = null;
20 | protected static DefaultRefreshInitializer sRefreshInitializer = null;
21 |
22 | protected boolean isInLayout = false;
23 |
24 | public SmartRefreshHorizontal(Context context) {
25 | this(context, null);
26 | }
27 |
28 | public SmartRefreshHorizontal(Context context, AttributeSet attrs) {
29 | super(wrapper(context), attrs);
30 | setScrollBoundaryDecider(new ScrollBoundaryHorizontal());
31 | }
32 |
33 | protected static Context wrapper(Context context) {
34 | DefaultRefreshInitializer old = SmartRefreshLayout.sRefreshInitializer;
35 | SmartRefreshLayout.setDefaultRefreshInitializer(new DefaultHorizontalInitializer(sRefreshInitializer, old));
36 | return context;
37 | }
38 |
39 |
40 | //
41 | /**
42 | * 设置默认 Header 构建器
43 | * @param creator Header构建器
44 | */
45 | public static void setDefaultRefreshHeaderCreator(@NonNull DefaultRefreshHeaderCreator creator) {
46 | sHeaderCreator = creator;
47 | }
48 |
49 | /**
50 | * 设置默认 Footer 构建器
51 | * @param creator Footer构建器
52 | */
53 | public static void setDefaultRefreshFooterCreator(@NonNull DefaultRefreshFooterCreator creator) {
54 | sFooterCreator = creator;
55 | }
56 |
57 | /**
58 | * 设置默认 Refresh 初始化器
59 | * @param initializer 全局初始化器
60 | */
61 | public static void setDefaultRefreshInitializer(@NonNull DefaultRefreshInitializer initializer) {
62 | sRefreshInitializer = initializer;
63 | }
64 | //
65 |
66 | //
67 |
68 | @Override
69 | protected void onAttachedToWindow() {
70 | DefaultRefreshHeaderCreator oldHeaderCreator = SmartRefreshLayout.sHeaderCreator;
71 | DefaultRefreshFooterCreator oldFooterCreator = SmartRefreshLayout.sFooterCreator;
72 | SmartRefreshLayout.setDefaultRefreshHeaderCreator(sHeaderCreator);
73 | SmartRefreshLayout.setDefaultRefreshFooterCreator(sFooterCreator);
74 | super.onAttachedToWindow();
75 | SmartRefreshLayout.setDefaultRefreshHeaderCreator(oldHeaderCreator);
76 | SmartRefreshLayout.setDefaultRefreshFooterCreator(oldFooterCreator);
77 |
78 | final View thisView = this;
79 | if (mRefreshContent != null && !(mRefreshContent instanceof RefreshContentHorizontal)) {
80 | mRefreshContent = new RefreshContentHorizontal(mRefreshContent.getView());
81 | View fixedHeaderView = mFixedHeaderViewId > 0 ? thisView.findViewById(mFixedHeaderViewId) : null;
82 | View fixedFooterView = mFixedFooterViewId > 0 ? thisView.findViewById(mFixedFooterViewId) : null;
83 |
84 | mRefreshContent.setScrollBoundaryDecider(mScrollBoundaryDecider);
85 | mRefreshContent.setEnableLoadMoreWhenContentNotFull(mEnableLoadMoreWhenContentNotFull);
86 | mRefreshContent.setUpComponent(mKernel, fixedHeaderView, fixedFooterView);
87 | }
88 |
89 | thisView.setRotation(-90);
90 | }
91 |
92 | protected boolean isRefreshComponent(View child) {
93 | RefreshComponent header = mRefreshHeader;
94 | RefreshComponent footer = mRefreshFooter;
95 | return (header != null && (child == header || child == header.getView())) ||
96 | (footer != null && (child == footer || child == footer.getView())) ;
97 | }
98 |
99 | @Override
100 | @SuppressWarnings("SuspiciousNameCombination")
101 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
102 | for (int i = 0, len = getChildCount(); i < len; i++) {
103 | View child = getChildAt(i);
104 | child.setTag(R.id.srl_tag, isRefreshComponent(child) ? "GONE" : "VISIBLE");
105 | }
106 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
107 | if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.AT_MOST) {
108 | widthMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY);
109 | }
110 | if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
111 | heightMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY);
112 | }
113 | for (int i = 0, len = getChildCount(); i < len; i++) {
114 | View child = getChildAt(i);
115 | child.setTag(R.id.srl_tag, isRefreshComponent(child) ? "VISIBLE" : "GONE");
116 | }
117 | super.onMeasure(heightMeasureSpec, widthMeasureSpec);
118 |
119 | //2020-10-13 如果,真的直接颠倒,height width 的测量值,会导致,布局外的同级控件位置发生偏移,必须纠正 测量值
120 | super.setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
121 | }
122 |
123 | @Override
124 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
125 | //2020-10-13 setMeasuredDimension 纠正之后,获取宽高值的算法要修改
126 | int width = bottom - top;
127 | int height = right - left;
128 | // int width = right - left;
129 | // int height = bottom - top;
130 | int div = (height - width) / 2;
131 | if (isInLayout) {
132 | RefreshComponent header = mRefreshHeader;
133 | RefreshComponent footer = mRefreshFooter;
134 |
135 | final View thisView = this;
136 | int paddingLeft = thisView.getPaddingLeft();
137 | int paddingRight = thisView.getPaddingRight();
138 | int paddingTop = thisView.getPaddingTop();
139 | int paddingBottom = thisView.getPaddingBottom();
140 |
141 | for (int i = 0, len = getChildCount(); i < len; i++) {
142 | View child = getChildAt(i);
143 | if (!isRefreshComponent(child) && child.getVisibility() != GONE) {
144 | int t = paddingLeft;
145 | int w = child.getMeasuredWidth();
146 | int h = child.getMeasuredHeight();
147 | //2020-10-13 setMeasuredDimension 纠正之后,宽高的取值要修改
148 | int r = height - paddingTop;
149 | // int r = width - paddingTop;
150 | //
151 | ViewGroup.LayoutParams params = child.getLayoutParams();
152 | if (params instanceof MarginLayoutParams) {
153 | MarginLayoutParams lp = (MarginLayoutParams) params;
154 | t += lp.leftMargin;
155 | r -= lp.topMargin;
156 | }
157 | //
158 | div = (h - w) / 2;
159 | t -= div;
160 | r -= div;
161 | //
162 | child.setRotation(90);
163 | child.setTag(R.id.srl_tag, "GONE");
164 | child.layout(r - w, t, r, t + h);
165 | }
166 | }
167 | super.onLayout(changed, left, top, right, bottom);
168 | } else {
169 | top -= div;
170 | left += div;
171 | isInLayout = true;
172 | super.layout(left, top, left + width, top + height);
173 | isInLayout = false;
174 | }
175 |
176 | }
177 | //
178 |
179 | // //
180 | //
181 | // /**
182 | // * 问题修复
183 | // * https://github.com/scwang90/SmartRefreshHorizontal/issues/9
184 | // * @param visibility 显示状态
185 | // */
186 | // @Override
187 | // public void setVisibility(int visibility) {
188 | // mRefreshLayout.setVisibility(visibility);
189 | // super.setVisibility(visibility);
190 | // }
191 | // //
192 |
193 | @SuppressWarnings("WeakerAccess")
194 | protected static class DefaultHorizontalInitializer implements DefaultRefreshInitializer {
195 | protected DefaultRefreshInitializer initializer;
196 | protected DefaultRefreshInitializer oldInitializer;
197 |
198 | protected DefaultHorizontalInitializer(DefaultRefreshInitializer initializer, DefaultRefreshInitializer old) {
199 | this.oldInitializer = old;
200 | this.initializer = initializer;
201 | }
202 |
203 | @Override
204 | public void initialize(@NonNull Context context, @NonNull RefreshLayout layout) {
205 | layout.setEnableLoadMore(true);
206 | if (initializer != null) {
207 | initializer.initialize(context, layout);
208 | }
209 | if (oldInitializer != null) {
210 | SmartRefreshLayout.setDefaultRefreshInitializer(oldInitializer);
211 | }
212 | }
213 | }
214 | }
215 |
--------------------------------------------------------------------------------
/library/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | %s falsify area,\n Represents the height[%.1fdp] of drag at run time,\n It does not show anything.
3 |
4 |
--------------------------------------------------------------------------------
/library/src/test/java/com/scwang/smartrefresh/horizontal/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.scwang.smartrefresh.horizontal;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------