├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── cn │ │ └── jianke │ │ └── lbaizxfpulltorefresh │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── cn │ │ │ └── jianke │ │ │ └── lbaizxfpulltorefresh │ │ │ ├── common │ │ │ └── ImageLoader.java │ │ │ ├── module │ │ │ ├── HomeActivity.java │ │ │ ├── JdActivity.java │ │ │ ├── JkActivity.java │ │ │ └── TmallActivity.java │ │ │ └── widget │ │ │ ├── JkPullToRefreshScrollView.java │ │ │ ├── ObservableScrollView.java │ │ │ ├── TweenAnimLoadingLayout.java │ │ │ ├── jd │ │ │ ├── JdRefreshHeader.java │ │ │ └── JdRefreshLayout.java │ │ │ └── tmall │ │ │ ├── TmallRefreshHeader.java │ │ │ └── TmallRefreshLayout.java │ └── res │ │ ├── drawable-hdpi │ │ └── start_bg.png │ │ ├── drawable-xhdpi │ │ ├── a29.png │ │ ├── a2a.png │ │ ├── a2b.png │ │ ├── a2c.png │ │ ├── a2d.png │ │ ├── jd.png │ │ ├── refresh_gif0000.png │ │ ├── refresh_gif0001.png │ │ ├── refresh_gif0002.png │ │ ├── refresh_gif0003.png │ │ ├── refresh_gif0004.png │ │ ├── refresh_gif0005.png │ │ ├── refresh_gif0006.png │ │ ├── refresh_gif0007.png │ │ ├── refresh_gif0008.png │ │ └── tm.png │ │ ├── drawable │ │ ├── jd_refresh_header_anim.xml │ │ ├── pull_to_refresh_loading.xml │ │ └── tm_mui_bike.gif │ │ ├── layout │ │ ├── activity_home.xml │ │ ├── activity_jd.xml │ │ ├── activity_main.xml │ │ ├── activity_tmall.xml │ │ ├── jd_refresh_header_view.xml │ │ └── tmall_refresh_header_view.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── cn │ └── jianke │ └── lbaizxfpulltorefresh │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── handmark │ │ └── pulltorefresh │ │ └── library │ │ ├── ILoadingLayout.java │ │ ├── IPullToRefresh.java │ │ ├── LoadingLayoutProxy.java │ │ ├── OverscrollHelper.java │ │ ├── PullToRefreshAdapterViewBase.java │ │ ├── PullToRefreshBase.java │ │ ├── PullToRefreshExpandableListView.java │ │ ├── PullToRefreshGridView.java │ │ ├── PullToRefreshHorizontalScrollView.java │ │ ├── PullToRefreshListView.java │ │ ├── PullToRefreshScrollView.java │ │ ├── PullToRefreshWebView.java │ │ ├── extras │ │ ├── PullToRefreshWebView2.java │ │ └── SoundPullEventListener.java │ │ └── internal │ │ ├── EmptyViewMethodAccessor.java │ │ ├── FlipLoadingLayout.java │ │ ├── IndicatorLayout.java │ │ ├── LoadingLayout.java │ │ ├── RotateLoadingLayout.java │ │ ├── Utils.java │ │ └── ViewCompat.java │ └── res │ ├── anim │ ├── slide_in_from_bottom.xml │ ├── slide_in_from_top.xml │ ├── slide_out_to_bottom.xml │ └── slide_out_to_top.xml │ ├── drawable-hdpi │ ├── default_ptr_flip.png │ ├── default_ptr_rotate.png │ └── indicator_arrow.png │ ├── drawable-mdpi │ ├── default_ptr_flip.png │ ├── default_ptr_rotate.png │ └── indicator_arrow.png │ ├── drawable-xhdpi │ ├── default_ptr_flip.png │ ├── default_ptr_rotate.png │ └── indicator_arrow.png │ ├── drawable │ ├── indicator_bg_bottom.xml │ └── indicator_bg_top.xml │ ├── layout │ ├── pull_to_refresh_header_horizontal.xml │ └── pull_to_refresh_header_vertical.xml │ ├── values-ar │ └── pull_refresh_strings.xml │ ├── values-cs │ └── pull_refresh_strings.xml │ ├── values-de │ └── pull_refresh_strings.xml │ ├── values-es │ └── pull_refresh_strings.xml │ ├── values-fi │ └── pull_refresh_strings.xml │ ├── values-fr │ └── pull_refresh_strings.xml │ ├── values-he │ └── pull_refresh_strings.xml │ ├── values-it │ └── pull_refresh_strings.xml │ ├── values-iw │ └── pull_refresh_strings.xml │ ├── values-ja │ └── pull_refresh_strings.xml │ ├── values-ko │ └── pull_refresh_strings.xml │ ├── values-nl │ └── pull_refresh_strings.xml │ ├── values-pl │ └── pull_refresh_strings.xml │ ├── values-pt-rBR │ └── pull_refresh_strings.xml │ ├── values-pt │ └── pull_refresh_strings.xml │ ├── values-ro │ └── pull_refresh_strings.xml │ ├── values-ru │ └── pull_refresh_strings.xml │ ├── values-zh │ └── pull_refresh_strings.xml │ └── values │ ├── attrs.xml │ ├── dimens.xml │ ├── ids.xml │ └── pull_refresh_strings.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | 39 | # Keystore files 40 | *.jks 41 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /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 | 效果图: 2 | 3 | ![pull_up_anim.gif](http://upload-images.jianshu.io/upload_images/2412932-174e10f7965fed67.gif?imageMogr2/auto-orient/strip) 4 | 5 | # 实现 6 | ### 健客 7 | * com.handmark.pulltorefresh.library库 8 | * AnimationDrawable动画 9 | 10 | ### 京东 11 | * 下拉刷新PtrFrameLayout组件 12 | * AnimationDrawable动画 13 | 14 | ### 天猫 15 | * 下拉刷新PtrFrameLayout组件 16 | * glide播放gif图 -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.2" 6 | defaultConfig { 7 | applicationId "cn.jianke.lbaizxfpulltorefresh" 8 | minSdkVersion 15 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:24.2.1' 28 | testCompile 'junit:junit:4.12' 29 | // 图片加载库采用Glide框架 30 | compile 'com.github.bumptech.glide:glide:3.7.0' 31 | compile 'jp.wasabeef:glide-transformations:2.0.1' 32 | // use base library 33 | compile project(':library') 34 | // 依赖下拉刷新PtrFrameLayout组件 35 | compile 'in.srain.cube:ultra-ptr:1.0.11' 36 | } 37 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/cn/jianke/lbaizxfpulltorefresh/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package cn.jianke.lbaizxfpulltorefresh; 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 | * Instrumentation 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() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("cn.jianke.lbaizxfpulltorefresh", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 14 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 35 | 36 | 42 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jianke/lbaizxfpulltorefresh/module/HomeActivity.java: -------------------------------------------------------------------------------- 1 | package cn.jianke.lbaizxfpulltorefresh.module; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.app.Activity; 6 | import android.view.View; 7 | import cn.jianke.lbaizxfpulltorefresh.R; 8 | 9 | /** 10 | * @className: HomeActivity 11 | * @classDescription: 首页 12 | * @author: leibing 13 | * @createTime: 2016/12/16 14 | */ 15 | public class HomeActivity extends Activity implements View.OnClickListener{ 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_home); 21 | // onClick 22 | findViewById(R.id.btn_jk).setOnClickListener(this); 23 | findViewById(R.id.btn_jd).setOnClickListener(this); 24 | findViewById(R.id.btn_tmall).setOnClickListener(this); 25 | } 26 | 27 | @Override 28 | public void onClick(View view) { 29 | switch (view.getId()){ 30 | case R.id.btn_jk: 31 | // 仿健客页 32 | turnToNewPage(JkActivity.class); 33 | break; 34 | case R.id.btn_jd: 35 | // 仿京东页 36 | turnToNewPage(JdActivity.class); 37 | break; 38 | case R.id.btn_tmall: 39 | // 仿天猫页 40 | turnToNewPage(TmallActivity.class); 41 | break; 42 | default: 43 | break; 44 | } 45 | } 46 | 47 | /** 48 | * 跳转新页面 49 | * @author leibing 50 | * @createTime 2016/12/16 51 | * @lastModify 2016/12/16 52 | * @param newCls 页面类名 53 | * @return 54 | */ 55 | private void turnToNewPage(Class newCls){ 56 | Intent intent = new Intent(); 57 | intent.setClass(this, newCls); 58 | startActivity(intent); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jianke/lbaizxfpulltorefresh/module/JdActivity.java: -------------------------------------------------------------------------------- 1 | package cn.jianke.lbaizxfpulltorefresh.module; 2 | 3 | import android.os.Bundle; 4 | import android.app.Activity; 5 | import android.os.Handler; 6 | import cn.jianke.lbaizxfpulltorefresh.R; 7 | import cn.jianke.lbaizxfpulltorefresh.widget.jd.JdRefreshLayout; 8 | import in.srain.cube.views.ptr.PtrDefaultHandler; 9 | import in.srain.cube.views.ptr.PtrFrameLayout; 10 | 11 | /** 12 | * @className: JdActivity 13 | * @classDescription: 仿京东页面 14 | * @author: leibing 15 | * @createTime: 2016/12/16 16 | */ 17 | public class JdActivity extends Activity { 18 | // 下拉刷新 19 | private JdRefreshLayout mPullUpJdly; 20 | // 自定义Handler 21 | private Handler mHandler = new Handler(); 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_jd); 27 | // findView 28 | mPullUpJdly = (JdRefreshLayout) findViewById(R.id.jdly_pull_up); 29 | // 设置刷新监听 30 | mPullUpJdly.setPtrHandler(new PtrDefaultHandler() { 31 | @Override 32 | public void onRefreshBegin(PtrFrameLayout frame) { 33 | // 刷新操作 34 | if (mHandler != null) 35 | mHandler.postDelayed(new Runnable() { 36 | @Override 37 | public void run() { 38 | // 刷新完毕 39 | if (mPullUpJdly != null) 40 | mPullUpJdly.refreshComplete(); 41 | } 42 | }, 1500); 43 | } 44 | }); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jianke/lbaizxfpulltorefresh/module/JkActivity.java: -------------------------------------------------------------------------------- 1 | package cn.jianke.lbaizxfpulltorefresh.module; 2 | 3 | import android.app.Activity; 4 | import android.os.Handler; 5 | import android.os.Bundle; 6 | import android.view.Gravity; 7 | import android.widget.Toast; 8 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 9 | import cn.jianke.lbaizxfpulltorefresh.R; 10 | import cn.jianke.lbaizxfpulltorefresh.widget.JkPullToRefreshScrollView; 11 | import cn.jianke.lbaizxfpulltorefresh.widget.ObservableScrollView; 12 | 13 | /** 14 | * @className: JkActivity 15 | * @classDescription: 仿健客页 16 | * @author: leibing 17 | * @createTime: 2016/12/15 18 | */ 19 | public class JkActivity extends Activity implements ObservableScrollView.ScrollViewListener{ 20 | // 下拉刷新滑动布局实例 21 | private JkPullToRefreshScrollView pullUpSv; 22 | // 自定义Handler 23 | private Handler mHandler = new Handler(); 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_main); 29 | // findView 30 | pullUpSv = (JkPullToRefreshScrollView) findViewById(R.id.sv_pull_up); 31 | // 设置居中 32 | pullUpSv.setGravity(Gravity.CENTER); 33 | // 设置下拉刷新方式 34 | pullUpSv.setMode(PullToRefreshBase.Mode.PULL_FROM_START); 35 | // 设置滑动监听 36 | pullUpSv.getRefreshableView().setScrollViewListener(this); 37 | // 设置下拉事件监听 38 | pullUpSv.setOnPullEventListener(new PullToRefreshBase.OnPullEventListener() { 39 | @Override 40 | public void onPullEvent(PullToRefreshBase refreshView, 41 | PullToRefreshBase.State state, PullToRefreshBase.Mode direction) { 42 | if (state == PullToRefreshBase.State.PULL_TO_REFRESH) { 43 | // 刷新中 44 | } else if (state == PullToRefreshBase.State.RESET) { 45 | // 刷新完毕 46 | } 47 | } 48 | }); 49 | // 设置刷新事件 50 | pullUpSv.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener() { 51 | 52 | @Override 53 | public void onRefresh(PullToRefreshBase refreshView) { 54 | // 刷新事件 55 | if (mHandler != null){ 56 | mHandler.postDelayed(new Runnable() { 57 | @Override 58 | public void run() { 59 | // 刷新完毕 60 | if (pullUpSv != null) 61 | pullUpSv.onRefreshComplete(); 62 | } 63 | }, 1500); 64 | } 65 | } 66 | }); 67 | } 68 | 69 | @Override 70 | public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) { 71 | 72 | } 73 | 74 | @Override 75 | public void onScrollToBottom() { 76 | Toast.makeText(JkActivity.this, "已经滑动到底部!",Toast.LENGTH_SHORT).show(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jianke/lbaizxfpulltorefresh/module/TmallActivity.java: -------------------------------------------------------------------------------- 1 | package cn.jianke.lbaizxfpulltorefresh.module; 2 | 3 | import android.os.Bundle; 4 | import android.app.Activity; 5 | import android.os.Handler; 6 | import cn.jianke.lbaizxfpulltorefresh.R; 7 | import cn.jianke.lbaizxfpulltorefresh.widget.tmall.TmallRefreshLayout; 8 | import in.srain.cube.views.ptr.PtrDefaultHandler; 9 | import in.srain.cube.views.ptr.PtrFrameLayout; 10 | 11 | /** 12 | * @className: TmallActivity 13 | * @classDescription:仿天猫页面 14 | * @author: leibing 15 | * @createTime: 2016/12/16 16 | */ 17 | public class TmallActivity extends Activity { 18 | // 下拉刷新 19 | private TmallRefreshLayout mPullUpTmly; 20 | // 自定义Handler 21 | private Handler mHandler = new Handler(); 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_tmall); 27 | // findView 28 | mPullUpTmly = (TmallRefreshLayout) findViewById(R.id.tmly_pull_up); 29 | // 设置刷新监听 30 | mPullUpTmly.setPtrHandler(new PtrDefaultHandler() { 31 | @Override 32 | public void onRefreshBegin(PtrFrameLayout frame) { 33 | // 刷新操作 34 | if (mHandler != null) 35 | mHandler.postDelayed(new Runnable() { 36 | @Override 37 | public void run() { 38 | // 刷新完毕 39 | if (mPullUpTmly != null) 40 | mPullUpTmly.refreshComplete(); 41 | } 42 | }, 1500); 43 | } 44 | }); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jianke/lbaizxfpulltorefresh/widget/JkPullToRefreshScrollView.java: -------------------------------------------------------------------------------- 1 | package cn.jianke.lbaizxfpulltorefresh.widget; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.os.Build; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | import com.handmark.pulltorefresh.library.OverscrollHelper; 10 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 11 | import com.handmark.pulltorefresh.library.internal.LoadingLayout; 12 | 13 | /** 14 | * @className: JKPullToRefreshScrollView 15 | * @classDescription: 健客网上药店首页下拉刷新滑动布局 16 | * @author: leibing 17 | * @createTime: 2016/12/15 18 | */ 19 | public class JkPullToRefreshScrollView extends PullToRefreshBase { 20 | 21 | public JkPullToRefreshScrollView(Context context) { 22 | super(context); 23 | } 24 | 25 | public JkPullToRefreshScrollView(Context context, AttributeSet attrs) { 26 | super(context, attrs); 27 | } 28 | 29 | public JkPullToRefreshScrollView(Context context, Mode mode) { 30 | super(context, mode); 31 | } 32 | 33 | public JkPullToRefreshScrollView(Context context, Mode mode, AnimationStyle animStyle) { 34 | super(context, mode, animStyle); 35 | } 36 | 37 | @Override 38 | public Orientation getPullToRefreshScrollDirection() { 39 | // 横直滑动 40 | return Orientation.VERTICAL; 41 | } 42 | 43 | @Override 44 | protected LoadingLayout createLoadingLayout(Context context, Mode mode, TypedArray attrs) { 45 | // 触发下拉刷新操作 46 | if(mode == Mode.PULL_FROM_START){ 47 | LoadingLayout layout = 48 | new TweenAnimLoadingLayout(context,mode, 49 | getPullToRefreshScrollDirection(),attrs); 50 | layout.setVisibility(View.INVISIBLE); 51 | return layout; 52 | }else{ 53 | return super.createLoadingLayout(context, mode, attrs); 54 | } 55 | } 56 | 57 | @Override 58 | protected ObservableScrollView createRefreshableView(Context context, AttributeSet attrs) { 59 | ObservableScrollView scrollView; 60 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { 61 | scrollView = new InternalScrollViewSDK9(context, attrs); 62 | } else { 63 | scrollView = new ObservableScrollView(context, attrs); 64 | } 65 | 66 | scrollView.setId(com.handmark.pulltorefresh.library.R.id.scrollview); 67 | return scrollView; 68 | } 69 | 70 | @Override 71 | protected boolean isReadyForPullEnd() { 72 | View scrollViewChild = mRefreshableView.getChildAt(0); 73 | if (null != scrollViewChild) { 74 | return mRefreshableView.getScrollY() >= (scrollViewChild.getHeight() - getHeight()); 75 | } 76 | return false; 77 | } 78 | 79 | @Override 80 | protected boolean isReadyForPullStart() { 81 | return mRefreshableView.getScrollY() == 0; 82 | } 83 | 84 | @TargetApi(9) 85 | final class InternalScrollViewSDK9 extends ObservableScrollView { 86 | 87 | public InternalScrollViewSDK9(Context context, AttributeSet attrs) { 88 | super(context, attrs); 89 | } 90 | 91 | @Override 92 | protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, 93 | int scrollRangeX, int scrollRangeY, int maxOverScrollX, 94 | int maxOverScrollY, boolean isTouchEvent) { 95 | final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, 96 | scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent); 97 | 98 | // Does all of the hard work... 99 | OverscrollHelper.overScrollBy(JkPullToRefreshScrollView.this, deltaX, scrollX, deltaY, scrollY, 100 | getScrollRange(), isTouchEvent); 101 | 102 | return returnValue; 103 | } 104 | 105 | // Taken from the AOSP ScrollView source 106 | private int getScrollRange() { 107 | int scrollRange = 0; 108 | if (getChildCount() > 0) { 109 | View child = getChildAt(0); 110 | scrollRange = Math.max(0, child.getHeight() - (getHeight() - getPaddingBottom() - getPaddingTop())); 111 | } 112 | return scrollRange; 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jianke/lbaizxfpulltorefresh/widget/ObservableScrollView.java: -------------------------------------------------------------------------------- 1 | package cn.jianke.lbaizxfpulltorefresh.widget; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.util.AttributeSet; 6 | import android.view.MotionEvent; 7 | import android.widget.ScrollView; 8 | 9 | /** 10 | * @className: ObservableScrollView 11 | * @classDescription: 自定义ScrollView(监听滑动状态) 12 | * @author: leibing 13 | * @createTime: 2016/12/15 14 | */ 15 | public class ObservableScrollView extends ScrollView { 16 | // 监听是否滑动底部检测时间间隔 17 | private final static int BOTTOM_DETECT_TIME_DIV = 100; 18 | // 滑动监听 19 | private ScrollViewListener mScrollViewListener; 20 | // 监听是否滑动到底部 21 | private Handler mHandler = new Handler(); 22 | private Runnable mDetectYRunnable = new Runnable() { 23 | @Override 24 | public void run() { 25 | if (getChildAt(0) != null 26 | && getChildAt(0) .getMeasuredHeight() <= getScrollY() + getHeight()) { 27 | // 滑动到顶部 28 | if(mScrollViewListener != null){ 29 | mScrollViewListener.onScrollToBottom(); 30 | } 31 | if (mHandler != null && mDetectYRunnable != null){ 32 | mHandler.removeCallbacks(mDetectYRunnable); 33 | return; 34 | } 35 | } 36 | // 每过100ms检测一次是否滑动到底部 37 | if (mHandler != null) 38 | mHandler.postDelayed(mDetectYRunnable, BOTTOM_DETECT_TIME_DIV); 39 | } 40 | }; 41 | 42 | public ObservableScrollView(Context context) { 43 | super(context); 44 | } 45 | 46 | public ObservableScrollView(Context context, AttributeSet attrs) { 47 | super(context, attrs); 48 | } 49 | 50 | public ObservableScrollView(Context context, AttributeSet attrs, int defStyle) { 51 | super(context, attrs, defStyle); 52 | } 53 | 54 | /** 55 | * 设置滑动监听 56 | * @author leibing 57 | * @createTime 2016/12/15 58 | * @lastModify 2016/12/15 59 | * @param mScrollViewListener 滑动监听 60 | * @return 61 | */ 62 | public void setScrollViewListener(ScrollViewListener mScrollViewListener) { 63 | this.mScrollViewListener = mScrollViewListener; 64 | } 65 | 66 | @Override 67 | protected void onScrollChanged(int x, int y, int oldx, int oldy) { 68 | super.onScrollChanged(x, y, oldx, oldy); 69 | // 滑动变化监听 70 | if (mScrollViewListener != null) { 71 | mScrollViewListener.onScrollChanged(this, x, y, oldx, oldy); 72 | } 73 | } 74 | 75 | @Override 76 | public boolean onTouchEvent(MotionEvent ev) { 77 | switch (ev.getAction()){ 78 | case MotionEvent.ACTION_UP: 79 | if (getChildAt(0) != null && getChildAt(0) .getMeasuredHeight() <= getScrollY() + getHeight()) { 80 | // 滑动到底部 81 | if(mScrollViewListener != null){ 82 | mScrollViewListener.onScrollToBottom(); 83 | } 84 | }else if(getChildAt(0) != null && getChildAt(0) .getMeasuredHeight() > getScrollY() + getHeight()){ 85 | // 检测是否滑动到底部 86 | if (mHandler != null){ 87 | mHandler.post(mDetectYRunnable); 88 | } 89 | } 90 | break; 91 | } 92 | return super.onTouchEvent(ev); 93 | } 94 | 95 | /** 96 | * @interfaceName: ScrollViewListener 97 | * @interfaceDescription: 滑动监听 98 | * @author: leibing 99 | * @createTime: 2016/12/15 100 | */ 101 | public interface ScrollViewListener { 102 | // 滑动变化监听 103 | void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy); 104 | // 监听是否滑动到底部 105 | void onScrollToBottom(); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jianke/lbaizxfpulltorefresh/widget/TweenAnimLoadingLayout.java: -------------------------------------------------------------------------------- 1 | package cn.jianke.lbaizxfpulltorefresh.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.drawable.AnimationDrawable; 6 | import android.graphics.drawable.Drawable; 7 | import android.view.View; 8 | import android.widget.FrameLayout; 9 | import android.widget.TextView; 10 | import com.handmark.pulltorefresh.library.PullToRefreshBase; 11 | import com.handmark.pulltorefresh.library.internal.LoadingLayout; 12 | import cn.jianke.lbaizxfpulltorefresh.R; 13 | 14 | /** 15 | * @className: TweenAnimLoadingLayout 16 | * @classDescription: Tween动画加载布局 17 | * @author: leibing 18 | * @createTime: 2016/12/15 19 | */ 20 | public class TweenAnimLoadingLayout extends LoadingLayout { 21 | // 名称 22 | private final TextView mSubHeaderText; 23 | // 动画 24 | private AnimationDrawable animationDrawable; 25 | 26 | /** 27 | * constructor 28 | * @author leibing 29 | * @createTime 2016/12/15 30 | * @lastModify 2016/12/15 31 | * @param context 上下文 32 | * @param mode 模式 33 | * @param scrollDirection 滑动方向 34 | * @param attrs 样式 35 | * @return 36 | */ 37 | public TweenAnimLoadingLayout(Context context, PullToRefreshBase.Mode mode, 38 | PullToRefreshBase.Orientation scrollDirection, TypedArray attrs) { 39 | super(context, mode, scrollDirection, attrs); 40 | // 设置动画 41 | mHeaderImage.setImageResource(R.drawable.pull_to_refresh_loading); 42 | animationDrawable = (AnimationDrawable) mHeaderImage.getDrawable(); 43 | // 设置动画布局 44 | FrameLayout mInnerLayout = (FrameLayout) findViewById(com.handmark.pulltorefresh.library.R.id.fl_inner); 45 | mInnerLayout.setPadding(24, 0 , 24, 0); 46 | // 设置动画文字提示 47 | mSubHeaderText = (TextView) mInnerLayout.findViewById(com.handmark.pulltorefresh.library.R.id.pull_to_refresh_subtext); 48 | mSubHeaderText.setText("正在加载"); 49 | } 50 | 51 | @Override 52 | protected int getDefaultDrawableResId() { 53 | // 默认图片 54 | return R.drawable.refresh_gif0000; 55 | } 56 | 57 | @Override 58 | protected void onLoadingDrawableSet(Drawable imageDrawable) { 59 | } 60 | 61 | @Override 62 | protected void onPullImpl(float scaleOfLayout) { 63 | } 64 | 65 | @Override 66 | protected void pullToRefreshImpl() { 67 | // 下拉以刷新 68 | mHeaderImage.setVisibility(View.VISIBLE); 69 | mSubHeaderText.setVisibility(View.GONE); 70 | } 71 | 72 | @Override 73 | protected void refreshingImpl() { 74 | // 正在刷新时回调 75 | // 播放帧动画 76 | animationDrawable.start(); 77 | mSubHeaderText.setVisibility(View.VISIBLE); 78 | } 79 | 80 | @Override 81 | protected void releaseToRefreshImpl() { 82 | // 释放以刷新 83 | mSubHeaderText.setVisibility(View.GONE); 84 | } 85 | 86 | @Override 87 | protected void resetImpl() { 88 | // 重新设置 89 | mHeaderImage.clearAnimation(); 90 | mHeaderImage.setVisibility(View.GONE); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jianke/lbaizxfpulltorefresh/widget/jd/JdRefreshHeader.java: -------------------------------------------------------------------------------- 1 | package cn.jianke.lbaizxfpulltorefresh.widget.jd; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.AnimationDrawable; 5 | import android.util.AttributeSet; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.widget.FrameLayout; 9 | import android.widget.ImageView; 10 | import android.widget.RelativeLayout; 11 | import android.widget.TextView; 12 | import cn.jianke.lbaizxfpulltorefresh.R; 13 | import in.srain.cube.views.ptr.PtrFrameLayout; 14 | import in.srain.cube.views.ptr.PtrUIHandler; 15 | import in.srain.cube.views.ptr.indicator.PtrIndicator; 16 | 17 | /** 18 | * @className: 仿京东下拉刷新Header 19 | * @classDescription: 20 | * @author: leibing 21 | * @createTime: 2016/12/16 22 | */ 23 | public class JdRefreshHeader extends FrameLayout implements PtrUIHandler { 24 | // 重置 25 | public static final int STATE_RESET = -1; 26 | 27 | // 准备刷新 28 | public static final int STATE_PREPARE = 0; 29 | 30 | // 开始刷新 31 | public static final int STATE_BEGIN = 1; 32 | 33 | // 结束刷新 34 | public static final int STATE_FINISH = 2; 35 | 36 | // 右外边距 37 | public static final int MARGIN_RIGHT = 100; 38 | 39 | // 刷新布局容器 40 | private RelativeLayout jdRefreshRly; 41 | 42 | // 提醒文本 43 | private TextView mRemindTv; 44 | 45 | // 快递员logo 46 | private ImageView mManIv; 47 | 48 | // 商品logo 49 | private ImageView mGoodsIv; 50 | 51 | // 状态识别 52 | private int mState; 53 | 54 | // 动画 55 | private AnimationDrawable mAnimation; 56 | 57 | /** 58 | * Constructor 59 | * @author leibing 60 | * @createTime 2016/12/16 61 | * @lastModify 2016/12/16 62 | * @param context 页面实例 63 | * @return 64 | */ 65 | public JdRefreshHeader(Context context) { 66 | super(context); 67 | initView(context); 68 | } 69 | 70 | /** 71 | * Constructor 72 | * @author leibing 73 | * @createTime 2016/12/16 74 | * @lastModify 2016/12/16 75 | * @param context 页面实例 76 | * @param attrs 77 | * @return 78 | */ 79 | public JdRefreshHeader(Context context, AttributeSet attrs) { 80 | super(context, attrs); 81 | initView(context); 82 | } 83 | 84 | /** 85 | * Constructor 86 | * @author leibing 87 | * @createTime 2016/12/16 88 | * @lastModify 2016/12/16 89 | * @param context 页面实例 90 | * @param attrs 91 | * @param defStyleAttr 92 | * @return 93 | */ 94 | public JdRefreshHeader(Context context, AttributeSet attrs, int defStyleAttr) { 95 | super(context, attrs, defStyleAttr); 96 | initView(context); 97 | } 98 | 99 | /** 100 | * 初始化view 101 | * @author leibing 102 | * @createTime 2016/12/16 103 | * @lastModify 2016/12/16 104 | * @param mContext 页面实例 105 | * @return 106 | */ 107 | private void initView(Context mContext) { 108 | // 构建布局 109 | View view = LayoutInflater.from(mContext).inflate( 110 | R.layout.jd_refresh_header_view, this, false); 111 | // 初始化刷新布局容器 112 | jdRefreshRly = (RelativeLayout) view.findViewById(R.id.rly_jd_refresh); 113 | // 初始化提醒文本 114 | mRemindTv = (TextView) view.findViewById(R.id.tv_remain); 115 | // 初始化快递员 116 | mManIv = (ImageView) view.findViewById(R.id.iv_man); 117 | // 初始化货物 118 | mGoodsIv = (ImageView) view.findViewById(R.id.iv_goods); 119 | // 添加布局到当前控件 120 | addView(view); 121 | } 122 | 123 | @Override 124 | public void onUIReset(PtrFrameLayout frame) { 125 | // 状态重置 126 | mState = STATE_RESET; 127 | // 设置刷新布局容器不可见 128 | if (jdRefreshRly != null) 129 | jdRefreshRly.setVisibility(GONE); 130 | } 131 | 132 | @Override 133 | public void onUIRefreshPrepare(PtrFrameLayout frame) { 134 | // 准备刷新 135 | mState = STATE_PREPARE; 136 | // 设置刷新布局容器可见 137 | if (jdRefreshRly != null) 138 | jdRefreshRly.setVisibility(VISIBLE); 139 | } 140 | 141 | @Override 142 | public void onUIRefreshBegin(PtrFrameLayout frame) { 143 | // 开始刷新 144 | mState = STATE_BEGIN; 145 | // 隐藏商品logo 146 | mGoodsIv.setVisibility(View.GONE); 147 | // 开启跑步动画 148 | mManIv.setBackgroundResource(R.drawable.jd_refresh_header_anim); 149 | mAnimation = (AnimationDrawable) mManIv.getBackground(); 150 | if (!mAnimation.isRunning()) { 151 | mAnimation.start(); 152 | } 153 | } 154 | 155 | @Override 156 | public void onUIRefreshComplete(PtrFrameLayout frame) { 157 | // 结束刷新 158 | mState = STATE_FINISH; 159 | // 显示商品Logo 160 | mGoodsIv.setVisibility(View.VISIBLE); 161 | // 停止跑步动画 162 | if (mAnimation.isRunning()) { 163 | mAnimation.stop(); 164 | } 165 | // 显示跑步完快递员 166 | mManIv.setBackgroundResource(R.drawable.a2a); 167 | // 设置刷新布局容器不可见 168 | if (jdRefreshRly != null) 169 | jdRefreshRly.setVisibility(GONE); 170 | } 171 | 172 | @Override 173 | public void onUIPositionChange(PtrFrameLayout frame, boolean isUnderTouch, byte status, PtrIndicator ptrIndicator) { 174 | // 处理提醒字体 175 | switch (mState) { 176 | case STATE_PREPARE: 177 | // 准备刷新 178 | mManIv.setAlpha(ptrIndicator.getCurrentPercent()); 179 | mGoodsIv.setAlpha(ptrIndicator.getCurrentPercent()); 180 | LayoutParams mIvManLayoutParams = (LayoutParams) mManIv.getLayoutParams(); 181 | if (ptrIndicator.getCurrentPercent() <= 1) { 182 | mManIv.setScaleX(ptrIndicator.getCurrentPercent()); 183 | mManIv.setScaleY(ptrIndicator.getCurrentPercent()); 184 | mGoodsIv.setScaleX(ptrIndicator.getCurrentPercent()); 185 | mGoodsIv.setScaleY(ptrIndicator.getCurrentPercent()); 186 | int marginRight = (int) (MARGIN_RIGHT - MARGIN_RIGHT * ptrIndicator.getCurrentPercent()); 187 | mIvManLayoutParams.setMargins(0, 0, marginRight, 0); 188 | mManIv.setLayoutParams(mIvManLayoutParams); 189 | } 190 | if (ptrIndicator.getCurrentPercent() < 1.2) { 191 | mRemindTv.setText("下拉刷新..."); 192 | } else { 193 | mRemindTv.setText("松开刷新..."); 194 | } 195 | break; 196 | case STATE_BEGIN: 197 | // 开始刷新 198 | mRemindTv.setText("更新中..."); 199 | break; 200 | case STATE_FINISH: 201 | // 结束刷新 202 | mRemindTv.setText("加载完成..."); 203 | break; 204 | } 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jianke/lbaizxfpulltorefresh/widget/jd/JdRefreshLayout.java: -------------------------------------------------------------------------------- 1 | package cn.jianke.lbaizxfpulltorefresh.widget.jd; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import in.srain.cube.views.ptr.PtrFrameLayout; 6 | 7 | /** 8 | * @className: JdRefreshLayout 9 | * @classDescription: 仿京东下拉刷新View 10 | * @author: leibing 11 | * @createTime: 2016/12/16 12 | */ 13 | public class JdRefreshLayout extends PtrFrameLayout { 14 | // HeaderView 15 | private JdRefreshHeader mHeaderView; 16 | 17 | /** 18 | * Constructor 19 | * @author leibing 20 | * @createTime 2016/12/16 21 | * @lastModify 2016/12/16 22 | * @param context 页面实例 23 | * @return 24 | */ 25 | public JdRefreshLayout(Context context) { 26 | super(context); 27 | initView(context); 28 | } 29 | 30 | /** 31 | * Constructor 32 | * @author leibing 33 | * @createTime 2016/12/16 34 | * @lastModify 2016/12/16 35 | * @param context 页面实例 36 | * @param attrs 37 | * @return 38 | */ 39 | public JdRefreshLayout(Context context, AttributeSet attrs) { 40 | super(context, attrs); 41 | initView(context); 42 | } 43 | 44 | /** 45 | * Constructor 46 | * @author leibing 47 | * @createTime 2016/12/16 48 | * @lastModify 2016/12/16 49 | * @param context 页面实例 50 | * @param attrs 51 | * @param defStyle 52 | * @return 53 | */ 54 | public JdRefreshLayout(Context context, AttributeSet attrs, int defStyle) { 55 | super(context, attrs, defStyle); 56 | initView(context); 57 | } 58 | 59 | /** 60 | * 初始化view 61 | * @author leibing 62 | * @createTime 2016/12/16 63 | * @lastModify 2016/12/16 64 | * @param 65 | * @return 66 | */ 67 | private void initView(Context mContext) { 68 | // 初始化Header 69 | mHeaderView = new JdRefreshHeader(mContext); 70 | // 设置Header 71 | setHeaderView(mHeaderView); 72 | // 添加PtrUIHandler实例 73 | addPtrUIHandler(mHeaderView); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jianke/lbaizxfpulltorefresh/widget/tmall/TmallRefreshHeader.java: -------------------------------------------------------------------------------- 1 | package cn.jianke.lbaizxfpulltorefresh.widget.tmall; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.widget.FrameLayout; 8 | import android.widget.ImageView; 9 | import android.widget.LinearLayout; 10 | import android.widget.TextView; 11 | import cn.jianke.lbaizxfpulltorefresh.R; 12 | import cn.jianke.lbaizxfpulltorefresh.common.ImageLoader; 13 | import in.srain.cube.views.ptr.PtrFrameLayout; 14 | import in.srain.cube.views.ptr.PtrUIHandler; 15 | import in.srain.cube.views.ptr.indicator.PtrIndicator; 16 | 17 | /** 18 | * @className: TmallRefreshHeader 19 | * @classDescription:仿天猫下拉刷新Header 20 | * @author: leibing 21 | * @createTime: 2016/12/16 22 | */ 23 | public class TmallRefreshHeader extends FrameLayout implements PtrUIHandler { 24 | // 重置 25 | public static final int STATE_RESET = -1; 26 | 27 | // 准备刷新 28 | public static final int STATE_PREPARE = 0; 29 | 30 | // 开始刷新 31 | public static final int STATE_BEGIN = 1; 32 | 33 | // 结束刷新 34 | public static final int STATE_FINISH = 2; 35 | 36 | // 刷新布局容器 37 | private LinearLayout tmRefreshLy; 38 | 39 | // 提醒文本 40 | private TextView mRemindTv; 41 | 42 | // 状态识别 43 | private int mState; 44 | 45 | /** 46 | * Constructor 47 | * @author leibing 48 | * @createTime 2016/12/16 49 | * @lastModify 2016/12/16 50 | * @param context 页面实例 51 | * @return 52 | */ 53 | public TmallRefreshHeader(Context context) { 54 | super(context); 55 | initView(context); 56 | } 57 | 58 | 59 | /** 60 | * Constructor 61 | * @author leibing 62 | * @createTime 2016/12/16 63 | * @lastModify 2016/12/16 64 | * @param context 页面实例 65 | * @param attrs 66 | * @return 67 | */ 68 | public TmallRefreshHeader(Context context, AttributeSet attrs) { 69 | super(context, attrs); 70 | initView(context); 71 | } 72 | 73 | /** 74 | * Constructor 75 | * @author leibing 76 | * @createTime 2016/12/16 77 | * @lastModify 2016/12/16 78 | * @param context 页面实例 79 | * @param attrs 80 | * @param defStyleAttr 81 | * @return 82 | */ 83 | public TmallRefreshHeader(Context context, AttributeSet attrs, int defStyleAttr) { 84 | super(context, attrs, defStyleAttr); 85 | initView(context); 86 | } 87 | 88 | /** 89 | * 初始化view 90 | * @author leibing 91 | * @createTime 2016/12/16 92 | * @lastModify 2016/12/16 93 | * @param mContext 页面实例 94 | * @return 95 | */ 96 | private void initView(Context mContext) { 97 | // 构建布局 98 | View view = LayoutInflater.from(mContext).inflate( 99 | R.layout.tmall_refresh_header_view, this, false); 100 | // 初始化刷新布局容器 101 | tmRefreshLy = (LinearLayout) view.findViewById(R.id.ly_tm_refresh); 102 | // 初始化提醒文本 103 | mRemindTv = (TextView) view.findViewById(R.id.tv_remind); 104 | // 初始化logo 105 | ImageView logoIv = (ImageView) view.findViewById(R.id.iv_logo); 106 | // 设置ImageView ScaleType 107 | logoIv.setScaleType(ImageView.ScaleType.FIT_CENTER); 108 | // 加载Logo资源 109 | ImageLoader.getInstance().loadGif(mContext, logoIv, 110 | ImageLoader.getDrawableSource(mContext, R.drawable.tm_mui_bike)); 111 | // 添加布局到当前控件 112 | addView(view); 113 | } 114 | 115 | @Override 116 | public void onUIReset(PtrFrameLayout frame) { 117 | // 状态重置 118 | mState = STATE_RESET; 119 | // 设置刷新布局容器不可见 120 | if (tmRefreshLy != null) 121 | tmRefreshLy.setVisibility(GONE); 122 | } 123 | 124 | @Override 125 | public void onUIRefreshPrepare(PtrFrameLayout frame) { 126 | // 准备刷新 127 | mState = STATE_PREPARE; 128 | // 设置刷新布局容器不可见 129 | if (tmRefreshLy != null) 130 | tmRefreshLy.setVisibility(VISIBLE); 131 | } 132 | 133 | @Override 134 | public void onUIRefreshBegin(PtrFrameLayout frame) { 135 | // 开始刷新 136 | mState = STATE_BEGIN; 137 | } 138 | 139 | @Override 140 | public void onUIRefreshComplete(PtrFrameLayout frame) { 141 | // 结束刷新 142 | mState = STATE_FINISH; 143 | // 设置刷新布局容器不可见 144 | if (tmRefreshLy != null) 145 | tmRefreshLy.setVisibility(GONE); 146 | } 147 | 148 | @Override 149 | public void onUIPositionChange(PtrFrameLayout frame, boolean isUnderTouch, byte status, PtrIndicator ptrIndicator) { 150 | // 处理提醒文本 151 | switch (mState) { 152 | case STATE_PREPARE: 153 | if (ptrIndicator.getCurrentPercent() < 1) { 154 | mRemindTv.setText("下拉刷新"); 155 | } else { 156 | mRemindTv.setText("松开立即刷新"); 157 | } 158 | break; 159 | case STATE_BEGIN: 160 | mRemindTv.setText("正在刷新..."); 161 | break; 162 | case STATE_FINISH: 163 | mRemindTv.setText("加载完成..."); 164 | break; 165 | } 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jianke/lbaizxfpulltorefresh/widget/tmall/TmallRefreshLayout.java: -------------------------------------------------------------------------------- 1 | package cn.jianke.lbaizxfpulltorefresh.widget.tmall; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import in.srain.cube.views.ptr.PtrFrameLayout; 6 | 7 | /** 8 | * @className: TmallRefreshLayout 9 | * @classDescription: 仿天猫下拉刷新view 10 | * @author: leibing 11 | * @createTime: 2016/12/16 12 | */ 13 | 14 | public class TmallRefreshLayout extends PtrFrameLayout { 15 | // HeaderView 16 | private TmallRefreshHeader mHeaderView; 17 | 18 | /** 19 | * Constructor 20 | * @author leibing 21 | * @createTime 2016/12/16 22 | * @lastModify 2016/12/16 23 | * @param context 页面实例 24 | * @return 25 | */ 26 | public TmallRefreshLayout(Context context) { 27 | super(context); 28 | initView(context); 29 | } 30 | 31 | /** 32 | * Constructor 33 | * @author leibing 34 | * @createTime 2016/12/16 35 | * @lastModify 2016/12/16 36 | * @param context 页面实例 37 | * @param attrs 38 | * @return 39 | */ 40 | public TmallRefreshLayout(Context context, AttributeSet attrs) { 41 | super(context, attrs); 42 | initView(context); 43 | } 44 | 45 | /** 46 | * Constructor 47 | * @author leibing 48 | * @createTime 2016/12/16 49 | * @lastModify 2016/12/16 50 | * @param context 页面实例 51 | * @param attrs 52 | * @param defStyle 53 | * @return 54 | */ 55 | public TmallRefreshLayout(Context context, AttributeSet attrs, int defStyle) { 56 | super(context, attrs, defStyle); 57 | initView(context); 58 | } 59 | 60 | /** 61 | * 初始化view 62 | * @author leibing 63 | * @createTime 2016/12/16 64 | * @lastModify 2016/12/16 65 | * @param mContext 页面实例 66 | * @return 67 | */ 68 | private void initView(Context mContext) { 69 | // 初始化Header 70 | mHeaderView = new TmallRefreshHeader(mContext); 71 | // 设置Header 72 | setHeaderView(mHeaderView); 73 | // 添加PtrUIHandler实例 74 | addPtrUIHandler(mHeaderView); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/start_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-hdpi/start_bg.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/a29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/a29.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/a2a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/a2a.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/a2b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/a2b.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/a2c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/a2c.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/a2d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/a2d.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/jd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/jd.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/refresh_gif0000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/refresh_gif0000.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/refresh_gif0001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/refresh_gif0001.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/refresh_gif0002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/refresh_gif0002.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/refresh_gif0003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/refresh_gif0003.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/refresh_gif0004.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/refresh_gif0004.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/refresh_gif0005.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/refresh_gif0005.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/refresh_gif0006.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/refresh_gif0006.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/refresh_gif0007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/refresh_gif0007.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/refresh_gif0008.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/refresh_gif0008.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/tm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable-xhdpi/tm.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/jd_refresh_header_anim.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 9 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/pull_to_refresh_loading.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 11 | 14 | 17 | 20 | 23 | 26 | 29 | 30 | 33 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/tm_mui_bike.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leibing8912/LbaizxfPulltoRefresh/f7ffe9451624316a03a02da2f5a7332b3ee47a88/app/src/main/res/drawable/tm_mui_bike.gif -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 13 |