├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── markdown-navigator.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── secondfloorbehavior ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── wuyr │ │ └── secondfloorbehavior │ │ ├── OnBeforeEnterSecondFloorListener.java │ │ ├── OnEnterSecondFloorListener.java │ │ ├── OnExitSecondFloorListener.java │ │ ├── OnStateChangeListener.java │ │ └── SecondFloorBehavior.java │ └── res │ └── values │ ├── attrs.xml │ └── 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 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/assetWizardSettings.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | .idea/caches 44 | 45 | # Keystore files 46 | # Uncomment the following line if you do not want to check your keystore files in. 47 | #*.jks 48 | 49 | # External native build folder generated in Android Studio 2.2 and later 50 | .externalNativeBuild 51 | 52 | # Google Services (e.g. APIs or Firebase) 53 | google-services.json 54 | 55 | # Freeline 56 | freeline.py 57 | freeline/ 58 | freeline_project_description.json 59 | 60 | # fastlane 61 | fastlane/report.xml 62 | fastlane/Preview.html 63 | fastlane/screenshots 64 | fastlane/test_output 65 | fastlane/readme.md 66 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | xmlns:android 11 | 12 | ^$ 13 | 14 | 15 | 16 |
17 |
18 | 19 | 20 | 21 | xmlns:.* 22 | 23 | ^$ 24 | 25 | 26 | BY_NAME 27 | 28 |
29 |
30 | 31 | 32 | 33 | .*:id 34 | 35 | http://schemas.android.com/apk/res/android 36 | 37 | 38 | 39 |
40 |
41 | 42 | 43 | 44 | .*:name 45 | 46 | http://schemas.android.com/apk/res/android 47 | 48 | 49 | 50 |
51 |
52 | 53 | 54 | 55 | name 56 | 57 | ^$ 58 | 59 | 60 | 61 |
62 |
63 | 64 | 65 | 66 | style 67 | 68 | ^$ 69 | 70 | 71 | 72 |
73 |
74 | 75 | 76 | 77 | .* 78 | 79 | ^$ 80 | 81 | 82 | BY_NAME 83 | 84 |
85 |
86 | 87 | 88 | 89 | .* 90 | 91 | http://schemas.android.com/apk/res/android 92 | 93 | 94 | ANDROID_ATTRIBUTE_ORDER 95 | 96 |
97 |
98 | 99 | 100 | 101 | .* 102 | 103 | .* 104 | 105 | 106 | BY_NAME 107 | 108 |
109 |
110 |
111 |
112 |
113 |
-------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Android 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 31 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /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 | ## 只需一个Behavior就能实现“二楼”效果,兼容所有下拉刷新控件。 2 | ### 博客详情: 3 | 4 | 5 | ### 使用方式: 6 | #### 添加依赖: 7 | ``` 8 | implementation 'com.wuyr:secondfloorbehavior:1.0.4' 9 | ``` 10 | 11 | ### APIs: 12 | |Method|Description| 13 | |---------|-------------| 14 | |enterSecondFloor()|主动进入二楼| 15 | |leaveSecondFloor()|主动退出二楼| 16 | |getState()|获取当前状态:
**STATE_NORMAL**: 普通状态
**STATE_DRAGGING**: 拖动中
**STATE_PREPARED**: 符合触发进入二楼的条件
**STATE_OPENING**: 正在进入二楼
**STATE_OPENED**: 在二楼
**STATE_CLOSING**: 正在离开二楼| 17 | |setStartInterceptDistance(float distance)|设置开始拦截下拉的滑动距离
即:列表滑动到顶后,往下拉多长距离可以开始触发二楼的下拉?| 18 | |setMinTriggerDistance(float distance)|设置能够进入二楼的滑动距离(从触发上面的二楼下拉后开始计算)
即:拦截下拉后,至少还要继续往下滑动多长距离才能够触发进入二楼?| 19 | |setDampingRatio(float ratio)|设置触发下拉后的滑动距离衰减率
取值范围: **0~1**,0: 无衰减| 20 | |setRollbackDuration(long duration)|设置回退的动画时长 (默认: 200)
回退:即未能触发打开二楼| 21 | |setEnterDuration(long duration)|设置进入二楼的动画时长 (默认: 500)| 22 | |setExitDuration(long duration)|设置退出二楼的动画时长 (默认: 400)| 23 | |setOnBeforeEnterSecondFloorListener(Listener listener)|监听进入二楼之前的事件
在这里可以决定是否同意本次进入二楼,返回:
**true**: 允许进入
**false**: 拒绝进入| 24 | |setOnEnterSecondFloorListener(Listener listener)|监听打开二楼的事件| 25 | |setOnExitSecondFloorListener(Listener listener)|监听退出二楼的事件| 26 | |setOnStateChangeListener(Listener listener)|监听各种状态变化,状态见上:*getState()*| 27 | |setExitAnimationInterpolator(Interpolator interpolator)|设置退出二楼的动画插值器| 28 | |setEnterAnimationInterpolator(Interpolator interpolator)|设置进入二楼的动画插值器| 29 | 30 | ### Attributes: 31 | |Name|Format|Description| 32 | |----|-----|-----------| 33 | |layout_startInterceptDistance|dimension
默认: HeaderView的高度|开始拦截下拉的滑动距离| 34 | |layout_minTriggerOffset|dimension
默认: HeaderView高度的一半|能够进入二楼的滑动距离| 35 | |layout_dampingRatio|float (默认: 0)|触发下拉后的滑动距离衰减率
取值范围: **0~1**
0: 无衰减
0.5: 衰减一半| 36 | |layout_rollbackDuration|integer (默认: 200)|回退的动画时长| 37 | |layout_enterDuration|integer (默认: 500)|进入二楼的动画时长| 38 | |layout_exitDuration|integer (默认: 400)|退出二楼的动画时长| 39 | |layout_onEnterSecondFloor|string|进入二楼的回调方法
使用方法同**android:onClick**属性| 40 | |layout_onExitSecondFloor|string|退出二楼的回调方法
使用方法同上| 41 | 42 | ### 布局示例: 43 | ```xml 44 | 49 | 50 | 51 | 60 | 61 | 62 | 77 | 78 | 79 | 83 | 84 | 90 | 91 | 95 | 96 | 97 | 98 | 99 | ``` 100 | 101 | ### Demo下载: [app-debug.apk](https://github.com/wuyr/SecondFloorBehavior/raw/master/app-debug.apk) 102 | ### Demo源码地址: 103 | 104 | ### 效果图:(图片有点大,加载挺慢,可以安装上面的APK来预览) 105 | ![preview](https://github.com/wuyr/SecondFloorBehavior/raw/master/previews/preview1.gif) ![preview](https://github.com/wuyr/SecondFloorBehavior/raw/master/previews/preview2.gif) 106 | ![preview](https://github.com/wuyr/SecondFloorBehavior/raw/master/previews/preview3.gif) ![preview](https://github.com/wuyr/SecondFloorBehavior/raw/master/previews/preview4.gif) 107 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.5.2' 11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 12 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' 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 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /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 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | 21 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ifxcyr/SecondFloorBehavior/ab295883e3efb153e450c2fd7cc64aef76af0675/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Nov 26 17:59:32 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /secondfloorbehavior/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /secondfloorbehavior/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.jfrog.bintray' 3 | apply plugin: 'com.github.dcendents.android-maven' 4 | 5 | def siteUrl = 'https://github.com/wuyr/SecondFloorBehavior' //需要修改 6 | def gitUrl = 'https://github.com/Ifxcyr/SecondFloorBehavior.git' //需要修改 7 | 8 | version = "1.0.4" 9 | group = "com.wuyr" 10 | 11 | android { 12 | compileSdkVersion 29 13 | buildToolsVersion "29.0.1" 14 | 15 | 16 | defaultConfig { 17 | minSdkVersion 14 18 | targetSdkVersion 29 19 | versionCode 1 20 | versionName "1.0.4" 21 | 22 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 23 | consumerProguardFiles 'consumer-rules.pro' 24 | } 25 | 26 | buildTypes { 27 | release { 28 | minifyEnabled false 29 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 30 | } 31 | } 32 | } 33 | 34 | Properties properties = new Properties() 35 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 36 | bintray { 37 | user = properties.getProperty("bintray.user") 38 | key = properties.getProperty("bintray.apikey") 39 | pkg { 40 | repo = 'SecondFloorBehavior' //需要修改 41 | name = 'SecondFloorBehavior' //需要修改 42 | websiteUrl = siteUrl 43 | vcsUrl = gitUrl 44 | licenses = ['Apache-2.0'] 45 | userOrg = 'wuyr' 46 | publish = true 47 | 48 | version { 49 | name = '1.0.4' 50 | desc = '通过自定义Behavior实现“二楼”效果,兼容所有下拉刷新框架' //需要修改 51 | released = new Date() 52 | vcsTag = '1.0.4' 53 | attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin'] 54 | } 55 | } 56 | configurations = ['archives'] 57 | } 58 | 59 | install { 60 | repositories.mavenInstaller { 61 | 62 | pom { 63 | project { 64 | packaging 'aar' 65 | 66 | name '陈小缘' 67 | description '通过自定义Behavior实现“二楼”效果,兼容所有下拉刷新框架' //需要修改 68 | url siteUrl 69 | 70 | licenses { 71 | license { 72 | name 'Apache-2.0' 73 | url 'https://raw.githubusercontent.com/Ifxcyr/SecondFloorBehavior/master/LICENSE' //需要修改 74 | } 75 | } 76 | developers { 77 | developer { 78 | id 'ifxcyr' 79 | name '陈小缘' 80 | email 'ifxcyr@gmail.com' 81 | } 82 | } 83 | scm { 84 | connection gitUrl 85 | developerConnection gitUrl 86 | url siteUrl 87 | } 88 | } 89 | } 90 | } 91 | } 92 | task sourcesJar(type: Jar) { 93 | from android.sourceSets.main.java.srcDirs 94 | classifier = 'sources' 95 | } 96 | task javadoc(type: Javadoc) { 97 | failOnError false 98 | source = android.sourceSets.main.java.srcDirs 99 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 100 | } 101 | task javadocJar(type: Jar, dependsOn: javadoc) { 102 | classifier = 'javadoc' 103 | from javadoc.destinationDir 104 | } 105 | 106 | dependencies { 107 | implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0' 108 | } 109 | artifacts { 110 | archives javadocJar 111 | archives sourcesJar 112 | } 113 | javadoc { 114 | options { 115 | encoding "UTF-8" 116 | charSet 'UTF-8' 117 | author true 118 | version true 119 | links "http://docs.oracle.com/javase/8/docs/api" 120 | } 121 | } -------------------------------------------------------------------------------- /secondfloorbehavior/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ifxcyr/SecondFloorBehavior/ab295883e3efb153e450c2fd7cc64aef76af0675/secondfloorbehavior/consumer-rules.pro -------------------------------------------------------------------------------- /secondfloorbehavior/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 | -------------------------------------------------------------------------------- /secondfloorbehavior/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /secondfloorbehavior/src/main/java/com/wuyr/secondfloorbehavior/OnBeforeEnterSecondFloorListener.java: -------------------------------------------------------------------------------- 1 | package com.wuyr.secondfloorbehavior; 2 | 3 | /** 4 | * @author wuyr 5 | * @github https://github.com/wuyr/SecondFloorBehavior 6 | * @since 2019-11-29 上午1:50 7 | */ 8 | public interface OnBeforeEnterSecondFloorListener { 9 | /** 10 | * 进入二楼之前 11 | * 12 | * @return 是否允许本次进入二楼,true: 允许,false: 拒绝 13 | */ 14 | boolean onBeforeEnterSecondFloor(); 15 | } 16 | -------------------------------------------------------------------------------- /secondfloorbehavior/src/main/java/com/wuyr/secondfloorbehavior/OnEnterSecondFloorListener.java: -------------------------------------------------------------------------------- 1 | package com.wuyr.secondfloorbehavior; 2 | 3 | /** 4 | * @author wuyr 5 | * @github https://github.com/wuyr/SecondFloorBehavior 6 | * @since 2019-11-29 上午1:50 7 | */ 8 | public interface OnEnterSecondFloorListener { 9 | /** 10 | * 进入二楼 11 | */ 12 | void onEnterSecondFloor(); 13 | } 14 | -------------------------------------------------------------------------------- /secondfloorbehavior/src/main/java/com/wuyr/secondfloorbehavior/OnExitSecondFloorListener.java: -------------------------------------------------------------------------------- 1 | package com.wuyr.secondfloorbehavior; 2 | 3 | /** 4 | * @author wuyr 5 | * @github https://github.com/wuyr/SecondFloorBehavior 6 | * @since 2019-11-29 上午1:49 7 | */ 8 | public interface OnExitSecondFloorListener { 9 | /** 10 | * 退出二楼 11 | */ 12 | void onExitSecondFloor(); 13 | } 14 | -------------------------------------------------------------------------------- /secondfloorbehavior/src/main/java/com/wuyr/secondfloorbehavior/OnStateChangeListener.java: -------------------------------------------------------------------------------- 1 | package com.wuyr.secondfloorbehavior; 2 | 3 | /** 4 | * @author wuyr 5 | * @github https://github.com/wuyr/SecondFloorBehavior 6 | * @since 2019-11-29 上午1:49 7 | */ 8 | public interface OnStateChangeListener { 9 | /** 10 | * 状态变更 11 | * 12 | * @param state 新状态 13 | */ 14 | void onStateChange(int state); 15 | } 16 | -------------------------------------------------------------------------------- /secondfloorbehavior/src/main/java/com/wuyr/secondfloorbehavior/SecondFloorBehavior.java: -------------------------------------------------------------------------------- 1 | package com.wuyr.secondfloorbehavior; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.animation.ValueAnimator; 6 | import android.content.Context; 7 | import android.content.ContextWrapper; 8 | import android.content.res.TypedArray; 9 | import android.os.SystemClock; 10 | import android.text.TextUtils; 11 | import android.util.AttributeSet; 12 | import android.view.MotionEvent; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.view.animation.Interpolator; 16 | 17 | import androidx.annotation.NonNull; 18 | import androidx.annotation.Nullable; 19 | import androidx.coordinatorlayout.widget.CoordinatorLayout; 20 | 21 | import java.lang.reflect.InvocationTargetException; 22 | import java.lang.reflect.Method; 23 | 24 | /** 25 | * @author wuyr 26 | * @github https://github.com/wuyr/SecondFloorBehavior 27 | * @since 2019-11-25 下午7:59 28 | */ 29 | @SuppressWarnings({"unused", "WeakerAccess", "BooleanMethodIsAlwaysInverted"}) 30 | public class SecondFloorBehavior extends CoordinatorLayout.Behavior { 31 | 32 | /** 33 | * 普通状态 34 | */ 35 | public static final int STATE_NORMAL = 0; 36 | 37 | /** 38 | * 拖动中 39 | */ 40 | public static final int STATE_DRAGGING = 1; 41 | 42 | /** 43 | * 符合触发进入二楼的条件 44 | */ 45 | public static final int STATE_PREPARED = 2; 46 | 47 | /** 48 | * 正在进入二楼 49 | */ 50 | public static final int STATE_OPENING = 3; 51 | 52 | /** 53 | * 在二楼 54 | */ 55 | public static final int STATE_OPENED = 4; 56 | 57 | /** 58 | * 正在离开二楼 59 | */ 60 | public static final int STATE_CLOSING = 5; 61 | 62 | private int mState = STATE_NORMAL; 63 | 64 | /** 65 | * 开始拦截下拉的滑动距离 66 | * (即:列表滑动到顶后,往下拉多长距离可以开始触发二楼的下拉?) 67 | */ 68 | private float mStartInterceptDistance; 69 | 70 | /** 71 | * 能够进入二楼的滑动距离(从触发上面的二楼下拉后开始计算) 72 | * (即:拦截下拉后,至少还要继续往下滑动多长距离才能够触发进入二楼?) 73 | */ 74 | private float mMinTriggerDistance; 75 | 76 | /** 77 | * 触发下拉后的滑动距离衰减率 78 | */ 79 | private float mDampingRatio; 80 | 81 | /** 82 | * 回退的动画时长 83 | */ 84 | private long mRollbackDuration; 85 | 86 | /** 87 | * 进入二楼的动画时长 88 | */ 89 | private long mEnterDuration; 90 | 91 | /** 92 | * 退出二楼的动画时长 93 | */ 94 | private long mExitDuration; 95 | 96 | private int mActivePointerId = MotionEvent.INVALID_POINTER_ID; 97 | private int mLastDispatchPointerId = MotionEvent.INVALID_POINTER_ID; 98 | 99 | private float mLastY; 100 | private float mLastDispatchY; 101 | private float mLastDispatchX; 102 | 103 | private float mPullDownOffset; 104 | private float mLastMoveOffset; 105 | 106 | private boolean mDragging; 107 | private boolean mPullDownStarted; 108 | private boolean mNeedCheckInsertEvent; 109 | 110 | //寄主 111 | private ViewGroup mParent; 112 | 113 | private Interpolator mExitAnimationInterpolator; 114 | private Interpolator mEnterAnimationInterpolator; 115 | 116 | private OnBeforeEnterSecondFloorListener mOnBeforeEnterSecondFloorListener; 117 | private OnEnterSecondFloorListener mOnEnterSecondFloorListener; 118 | private OnExitSecondFloorListener mOnExitSecondFloorListener; 119 | private OnStateChangeListener mOnStateChangeListener; 120 | 121 | public SecondFloorBehavior(Context context, AttributeSet attrs) { 122 | super(context, attrs); 123 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CoordinatorLayout_Layout); 124 | initAttributes(a); 125 | initListener(context, a); 126 | a.recycle(); 127 | } 128 | 129 | private void initListener(final Context context, TypedArray a) { 130 | final String enterMethod = a.getString(R.styleable.CoordinatorLayout_Layout_layout_onEnterSecondFloor); 131 | final String exitMethod = a.getString(R.styleable.CoordinatorLayout_Layout_layout_onExitSecondFloor); 132 | if (!TextUtils.isEmpty(enterMethod)) { 133 | setOnEnterSecondFloorListener(new OnEnterSecondFloorListener() { 134 | 135 | private DeclaredHelper helper = new DeclaredHelper(context, enterMethod, "app:layout_onEnterSecondFloor"); 136 | 137 | @Override 138 | public void onEnterSecondFloor() { 139 | helper.invoke(); 140 | } 141 | }); 142 | } 143 | if (!TextUtils.isEmpty(exitMethod)) { 144 | setOnExitSecondFloorListener(new OnExitSecondFloorListener() { 145 | 146 | private DeclaredHelper helper = new DeclaredHelper(context, exitMethod, "app:layout_onExitSecondFloor"); 147 | 148 | @Override 149 | public void onExitSecondFloor() { 150 | helper.invoke(); 151 | } 152 | }); 153 | } 154 | } 155 | 156 | private void initAttributes(TypedArray a) { 157 | mStartInterceptDistance = a.getDimensionPixelSize(R.styleable.CoordinatorLayout_Layout_layout_startInterceptDistance, 0); 158 | mMinTriggerDistance = a.getDimensionPixelSize(R.styleable.CoordinatorLayout_Layout_layout_minTriggerOffset, 0); 159 | mDampingRatio = a.getFloat(R.styleable.CoordinatorLayout_Layout_layout_dampingRatio, 0); 160 | if (mDampingRatio > 1) { 161 | mDampingRatio = 1; 162 | } else if (mDampingRatio < 0) { 163 | mDampingRatio = 0; 164 | } 165 | mDampingRatio = 1F - mDampingRatio; 166 | mRollbackDuration = a.getInt(R.styleable.CoordinatorLayout_Layout_layout_rollbackDuration, 200); 167 | mEnterDuration = a.getInt(R.styleable.CoordinatorLayout_Layout_layout_enterDuration, 500); 168 | mExitDuration = a.getInt(R.styleable.CoordinatorLayout_Layout_layout_exitDuration, 400); 169 | } 170 | 171 | /** 172 | * 进入二楼 173 | */ 174 | public void enterSecondFloor() { 175 | if (!isAnimationPlaying() && !isOnOrGoingToSecondFloor()) { 176 | gotoSecondFloor(null, false); 177 | } 178 | } 179 | 180 | /** 181 | * 离开二楼 182 | */ 183 | public void leaveSecondFloor() { 184 | if (isAnimationPlaying() || !isOnOrGoingToSecondFloor()) { 185 | return; 186 | } 187 | onStateChange(STATE_CLOSING); 188 | 189 | smoothTranslationBy(getHeaderView(), 0, mExitDuration, mExitAnimationInterpolator, new AnimatorListenerAdapter() { 190 | @Override 191 | public void onAnimationEnd(Animator animation) { 192 | onStateChange(STATE_NORMAL); 193 | } 194 | }); 195 | smoothTranslationBy(getSecondFloorView(), 0, mExitDuration, mExitAnimationInterpolator, null); 196 | smoothTranslationBy(getFirstFloorView(), 0, mExitDuration, mExitAnimationInterpolator, null); 197 | 198 | if (mOnExitSecondFloorListener != null) { 199 | mOnExitSecondFloorListener.onExitSecondFloor(); 200 | } 201 | } 202 | 203 | @Override 204 | public boolean onInterceptTouchEvent(@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull MotionEvent ev) { 205 | //只要还没有进入二楼,就要拦截事件 206 | return mState != STATE_OPENED; 207 | } 208 | 209 | @Override 210 | public boolean onTouchEvent(@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull MotionEvent ev) { 211 | if (parent.isInEditMode()) return true; 212 | if (isAnimationPlaying()) return true; 213 | 214 | //还没有开始拖动就收到了DOWN之外的事件,不作处理 215 | if (!mDragging && ev.getActionMasked() != MotionEvent.ACTION_DOWN) { 216 | return true; 217 | } 218 | 219 | boolean handled = false; 220 | 221 | switch (ev.getActionMasked()) { 222 | case MotionEvent.ACTION_POINTER_DOWN: 223 | handled = handleActionPointerDown(ev); 224 | break; 225 | case MotionEvent.ACTION_DOWN: 226 | handleActionDown(ev); 227 | break; 228 | case MotionEvent.ACTION_MOVE: 229 | handled = handleActionMove(ev); 230 | break; 231 | case MotionEvent.ACTION_POINTER_UP: 232 | handled = handleActionPointerUp(ev); 233 | break; 234 | case MotionEvent.ACTION_UP: 235 | handled = handleActionUp(ev); 236 | break; 237 | case MotionEvent.ACTION_CANCEL: 238 | if (!mDragging) { 239 | handled = true; 240 | } 241 | break; 242 | } 243 | //判断是否要彻底拦截事件,有以下2种情况: 244 | //1. 上面处理滑动的逻辑需要拦截; 245 | //2. 收到了来自requestDisallowInterceptTouchEvent方法发出的ACTION_CANCEL事件 246 | if (handled || ev.getAction() == MotionEvent.ACTION_CANCEL && Thread.currentThread().getStackTrace()[4].getMethodName().equals("requestDisallowInterceptTouchEvent")) { 247 | return true; 248 | } 249 | return dispatchTouchEvent(ev); 250 | } 251 | 252 | private boolean dispatchTouchEvent(@NonNull MotionEvent ev) { 253 | if (mNeedCheckInsertEvent) { 254 | mNeedCheckInsertEvent = false; 255 | MotionEvent insertEvent = null; 256 | //防止距离足够触发二楼时,往回拉时换了手指,有以下几种情况: 257 | //1. 手指抬起时,原来的指针id无效; 258 | //2. 手指移动时,原来的指针id无效; 259 | //3. 手指移动时,原来的指针id无效,但当前指针id有效; 260 | //4. 手指移动时,由最开始的多指变为单指; 261 | boolean pointerIdInvalid = mLastDispatchPointerId == MotionEvent.INVALID_POINTER_ID || ev.findPointerIndex(mLastDispatchPointerId) == -1; 262 | if (ev.getAction() == MotionEvent.ACTION_UP && pointerIdInvalid || 263 | ev.getAction() == MotionEvent.ACTION_MOVE && pointerIdInvalid || mLastDispatchPointerId == mActivePointerId && ev.getPointerCount() == 1) { 264 | insertEvent = MotionEvent.obtain(ev); 265 | } 266 | //手动滑回来的时候找不到之前的手指id,所以现在要模拟新手指按下和旧手指抬起 267 | if (insertEvent != null) { 268 | insertEvent.setAction(MotionEvent.ACTION_POINTER_DOWN); 269 | getFirstFloorView().dispatchTouchEvent(insertEvent); 270 | insertEvent.recycle(); 271 | } 272 | } 273 | updateDispatchLocation(ev); 274 | return getFirstFloorView().dispatchTouchEvent(ev); 275 | } 276 | 277 | private void updateDispatchLocation(@NonNull MotionEvent ev) { 278 | int pi = findValidActionIndex(ev, mLastDispatchPointerId); 279 | mLastDispatchY = ev.getY(pi); 280 | mLastDispatchX = ev.getX(pi); 281 | } 282 | 283 | private boolean handleActionUp(@NonNull MotionEvent ev) { 284 | boolean handled = false; 285 | mActivePointerId = MotionEvent.INVALID_POINTER_ID; 286 | mLastY = 0; 287 | if (mDragging) { 288 | if (mPullDownStarted && mPullDownOffset < -mStartInterceptDistance) { 289 | //手指抬起的时候,如果滑动超过了指定距离,则进入二楼,否则回退 290 | if (getHeaderView().getTranslationY() >= mMinTriggerDistance) { 291 | enterSecondFloor(ev); 292 | handled = true; 293 | } else { 294 | rollback(); 295 | } 296 | } 297 | mPullDownOffset = 0; 298 | mLastMoveOffset = 0; 299 | mPullDownStarted = false; 300 | mDragging = false; 301 | } else { 302 | handled = true; 303 | } 304 | if (!isAnimationPlaying()) { 305 | onStateChange(STATE_NORMAL); 306 | } 307 | return handled; 308 | } 309 | 310 | private boolean handleActionPointerUp(@NonNull MotionEvent ev) { 311 | onSecondaryPointerUp(ev); 312 | //已经到了拦截的距离,就继续拦截 313 | return mPullDownStarted && mPullDownOffset < -mStartInterceptDistance; 314 | } 315 | 316 | private boolean handleActionMove(@NonNull MotionEvent ev) { 317 | boolean handled = false; 318 | if (mPullDownStarted) { 319 | if (mActivePointerId == MotionEvent.INVALID_POINTER_ID) { 320 | mActivePointerId = ev.getPointerId(ev.getActionIndex()); 321 | } 322 | int actionIndex = findValidActionIndex(ev, mActivePointerId); 323 | float offset = ev.getY(actionIndex) - mLastY; 324 | mPullDownOffset -= offset; 325 | if (mPullDownOffset > 0) { 326 | //回退到下拉前 327 | mPullDownStarted = false; 328 | mPullDownOffset = 0; 329 | mLastMoveOffset = 0; 330 | } else if (mPullDownOffset < -mStartInterceptDistance) { 331 | //计算出溢出的偏移量 332 | float overflowOffset = -mStartInterceptDistance - mPullDownOffset; 333 | if (mPullDownOffset + offset >= -mStartInterceptDistance) { 334 | //初次到达触发点,标记等下要检查是否需要插入事件 335 | mNeedCheckInsertEvent = true; 336 | //修正滑动溢出 337 | fixMoveOverflow(ev, overflowOffset); 338 | } 339 | handled = true; 340 | 341 | float moveOffset = overflowOffset - mLastMoveOffset; 342 | mLastMoveOffset = overflowOffset; 343 | moveOffset *= mDampingRatio; 344 | 345 | offsetChildren(moveOffset); 346 | } else if (mPullDownOffset + offset < -mStartInterceptDistance) { 347 | //初次回到触发点 348 | if (ev.getPointerCount() == 1) { 349 | //计算出溢出的偏移量 350 | float overflowOffset = -mStartInterceptDistance - mPullDownOffset; 351 | mPullDownOffset += overflowOffset; 352 | } 353 | 354 | translationChildrenY(0); 355 | mLastMoveOffset = 0; 356 | onStateChange(STATE_DRAGGING); 357 | } 358 | } 359 | updateLastY(ev); 360 | return handled; 361 | } 362 | 363 | private void offsetChildren(float offset) { 364 | View headerView = getHeaderView(); 365 | onStateChange(headerView.getTranslationY() + offset >= headerView.getHeight() / 2F ? STATE_PREPARED : STATE_DRAGGING); 366 | //偏移的距离还没有超过HeaderView的高度 367 | if (headerView.getTranslationY() + offset < headerView.getHeight()) { 368 | translationChildrenYBy(offset); 369 | 370 | //防止过度往下拖动后,向上滑动时一楼底部脱离屏幕底部 371 | if (headerView.getTranslationY() <= 0) { 372 | mPullDownOffset -= headerView.getTranslationY() / mDampingRatio; 373 | translationChildrenY(0); 374 | } 375 | } else { 376 | //如果滑动距离已经超出了HeaderView的高度的话,就要固定在这个高度 377 | float topOverflow = headerView.getTranslationY() + offset - headerView.getHeight(); 378 | 379 | //不增加偏移量 380 | mLastMoveOffset -= topOverflow; 381 | mPullDownOffset += topOverflow; 382 | 383 | //修正偏移距离 384 | float maxTranslationY = headerView.getHeight(); 385 | translationChildrenY(maxTranslationY); 386 | } 387 | } 388 | 389 | private void translationChildrenY(float translation) { 390 | View headerView = getHeaderView(); 391 | View secondFloorView = getSecondFloorView(); 392 | View firstFloorView = getFirstFloorView(); 393 | 394 | firstFloorView.setTranslationY(translation); 395 | headerView.setTranslationY(translation); 396 | secondFloorView.setTranslationY(translation); 397 | } 398 | 399 | private void translationChildrenYBy(float translation) { 400 | translationChildrenY(getHeaderView().getTranslationY() + translation); 401 | } 402 | 403 | private void fixMoveOverflow(@NonNull MotionEvent ev, float overflowOffset) { 404 | //因为超出了指定的触发点,所以要退回去,也就是减去超出的偏移量了 405 | MotionEvent appendEvent = reassignEventId(ev, mLastDispatchPointerId, ev.getAction(), ev.getRawX(), ev.getRawY() - overflowOffset); 406 | 407 | int pi = findValidActionIndex(ev, mLastDispatchPointerId); 408 | appendEvent.offsetLocation(ev.getX(pi) - ev.getRawX(), ev.getY(pi) - ev.getRawY()); 409 | 410 | mLastDispatchY = ev.getY(pi); 411 | mLastDispatchX = ev.getX(pi); 412 | getFirstFloorView().dispatchTouchEvent(appendEvent); 413 | appendEvent.recycle(); 414 | } 415 | 416 | private int findValidActionIndex(@NonNull MotionEvent ev, int id) { 417 | int actionIndex = ev.findPointerIndex(id); 418 | return actionIndex == -1 ? 0 : actionIndex; 419 | } 420 | 421 | private void handleActionDown(@NonNull MotionEvent ev) { 422 | mActivePointerId = ev.getPointerId(0); 423 | //有手指按下的时候,如果还没触发二楼的下拉,就更新id 424 | if (mPullDownOffset >= -mStartInterceptDistance) { 425 | mLastDispatchPointerId = mActivePointerId; 426 | } 427 | mDragging = true; 428 | mPullDownOffset = 0; 429 | mLastMoveOffset = 0; 430 | updateLastY(ev); 431 | onStateChange(STATE_DRAGGING); 432 | } 433 | 434 | private boolean handleActionPointerDown(@NonNull MotionEvent ev) { 435 | mActivePointerId = ev.getPointerId(ev.getActionIndex()); 436 | //有手指按下的时候,如果还没触发二楼的下拉,就更新id 437 | if (mPullDownOffset >= -mStartInterceptDistance) { 438 | mLastDispatchPointerId = mActivePointerId; 439 | } 440 | updateLastY(ev); 441 | return mPullDownStarted && mPullDownOffset < -mStartInterceptDistance; 442 | } 443 | 444 | private void updateLastY(MotionEvent ev) { 445 | mLastY = mActivePointerId == MotionEvent.INVALID_POINTER_ID ? 0 : ev.getY(findValidActionIndex(ev, mActivePointerId)); 446 | } 447 | 448 | private boolean isAnimationPlaying() { 449 | return mState == STATE_OPENING || mState == STATE_CLOSING; 450 | } 451 | 452 | private boolean isOnOrGoingToSecondFloor() { 453 | return mState == STATE_OPENED || mState == STATE_OPENING; 454 | } 455 | 456 | private void enterSecondFloor(MotionEvent ev) { 457 | if (!isAnimationPlaying()) { 458 | gotoSecondFloor(ev, true); 459 | } 460 | } 461 | 462 | private void gotoSecondFloor(final MotionEvent ev, final boolean fakeScroll) { 463 | if (mOnBeforeEnterSecondFloorListener == null || mOnBeforeEnterSecondFloorListener.onBeforeEnterSecondFloor()) { 464 | onStateChange(STATE_OPENING); 465 | 466 | final View headerView = getHeaderView(); 467 | final View secondFloorView = getSecondFloorView(); 468 | final View firstFloorView = getFirstFloorView(); 469 | 470 | smoothTranslationBy(headerView, firstFloorView.getHeight(), mEnterDuration, mEnterAnimationInterpolator, new AnimatorListenerAdapter() { 471 | @Override 472 | public void onAnimationEnd(Animator animation) { 473 | onStateChange(STATE_OPENED); 474 | if (fakeScroll) { 475 | fakeScroll(firstFloorView, -mStartInterceptDistance, ev); 476 | } 477 | } 478 | }); 479 | smoothTranslationBy(secondFloorView, firstFloorView.getHeight() + headerView.getHeight(), mEnterDuration, mEnterAnimationInterpolator, null); 480 | smoothTranslationBy(firstFloorView, firstFloorView.getHeight(), mEnterDuration / 2, mEnterAnimationInterpolator, null); 481 | 482 | if (mOnEnterSecondFloorListener != null) { 483 | mOnEnterSecondFloorListener.onEnterSecondFloor(); 484 | } 485 | } else { 486 | rollback(); 487 | if (ev != null) { 488 | dispatchTouchEvent(ev); 489 | } 490 | } 491 | } 492 | 493 | private void smoothTranslationBy(final View target, float translation, long duration, Interpolator interpolator, Animator.AnimatorListener listener) { 494 | ValueAnimator animator = ValueAnimator.ofFloat(target.getTranslationY(), translation).setDuration(duration); 495 | if (interpolator != null) { 496 | animator.setInterpolator(interpolator); 497 | } 498 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 499 | @Override 500 | public void onAnimationUpdate(ValueAnimator animation) { 501 | target.setTranslationY((Float) animation.getAnimatedValue()); 502 | } 503 | }); 504 | if (listener != null) { 505 | animator.addListener(listener); 506 | } 507 | animator.start(); 508 | } 509 | 510 | private void rollback() { 511 | if (isAnimationPlaying()) { 512 | return; 513 | } 514 | 515 | ValueAnimator animator = ValueAnimator.ofFloat(getHeaderView().getTranslationY(), 0); 516 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 517 | @Override 518 | public void onAnimationUpdate(ValueAnimator animation) { 519 | translationChildrenY((float) animation.getAnimatedValue()); 520 | } 521 | }); 522 | animator.setDuration(mRollbackDuration); 523 | animator.start(); 524 | } 525 | 526 | private void onSecondaryPointerUp(MotionEvent ev) { 527 | int pointerIndex = ev.getActionIndex(); 528 | int pointerId = ev.getPointerId(pointerIndex); 529 | //如果抬起的那根手指,刚好是当前活跃的手指,那么 530 | if (pointerId == mActivePointerId) { 531 | //另选一根手指,并把它标记为活跃 532 | int newPointerIndex = pointerIndex == 0 ? 1 : 0; 533 | mActivePointerId = ev.getPointerId(newPointerIndex); 534 | //还没有触发二楼下拉,就更新id 535 | if (mPullDownOffset >= -mStartInterceptDistance) { 536 | mLastDispatchPointerId = mActivePointerId; 537 | } 538 | mLastY = ev.getY(newPointerIndex); 539 | } 540 | } 541 | 542 | @Override 543 | public boolean layoutDependsOn(@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull View dependency) { 544 | //索引分别对应:0: Header、1: 二楼、2: 一楼 545 | //要监听的是一楼的各种状态变化 546 | return dependency == parent.getChildAt(2); 547 | } 548 | 549 | @Override 550 | public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull View child, @NonNull View directTargetChild, @NonNull View target, int axes, int type) { 551 | //只需要监听一楼的滚动 552 | return directTargetChild == coordinatorLayout.getChildAt(2); 553 | } 554 | 555 | @Override 556 | public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull View child, @NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) { 557 | if (dyUnconsumed < 0 && mDragging && !mPullDownStarted && mPullDownOffset >= 0) { 558 | mPullDownStarted = true; 559 | mPullDownOffset = dyUnconsumed; 560 | } 561 | } 562 | 563 | @Override 564 | public boolean onLayoutChild(@NonNull CoordinatorLayout parent, @NonNull View child, int layoutDirection) { 565 | if (mParent == null) { 566 | mParent = parent; 567 | } 568 | if (!mLayoutChangeListenerAdded) { 569 | parent.addOnLayoutChangeListener(mOnLayoutChangeListener); 570 | mLayoutChangeListenerAdded = true; 571 | } 572 | return false; 573 | } 574 | 575 | private boolean mLayoutChangeListenerAdded; 576 | private View.OnLayoutChangeListener mOnLayoutChangeListener = new View.OnLayoutChangeListener() { 577 | @SuppressWarnings("ConstantConditions") 578 | @Override 579 | public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { 580 | 581 | View headerView = getHeaderView(); 582 | View secondFloorView = getSecondFloorView(); 583 | View firstFloorView = getFirstFloorView(); 584 | 585 | if (!v.isInEditMode() && headerView.getHeight() > 0) { 586 | //滑动偏移量没有指定的话,就给一个默认的 587 | if (mMinTriggerDistance == 0) { 588 | mMinTriggerDistance = headerView.getHeight() / 2; 589 | } 590 | if (mStartInterceptDistance == 0) { 591 | mStartInterceptDistance = headerView.getHeight(); 592 | } 593 | } 594 | if (v.isInEditMode()) { 595 | //布局预览中允许为null 596 | int headerBottom = firstFloorView == null ? 0 : firstFloorView.getTop(); 597 | int headerTop = headerBottom - (headerView == null ? 0 : headerView.getHeight()); 598 | int secondFloorTop = headerTop - (secondFloorView == null ? 0 : secondFloorView.getHeight()); 599 | if (headerView != null) { 600 | headerView.layout(headerView.getLeft(), headerTop, headerView.getRight(), headerBottom); 601 | } 602 | if (secondFloorView != null) { 603 | secondFloorView.layout(secondFloorView.getLeft(), secondFloorTop, secondFloorView.getRight(), headerTop); 604 | } 605 | } else { 606 | //HeaderVIew放在一楼的顶部 607 | int headerBottom = firstFloorView.getTop(); 608 | int headerTop = headerBottom - headerView.getHeight(); 609 | headerView.layout(headerView.getLeft(), headerTop, headerView.getRight(), headerBottom); 610 | //二楼放在HeaderView的顶部 611 | int secondFloorTop = headerTop - secondFloorView.getHeight(); 612 | secondFloorView.layout(secondFloorView.getLeft(), secondFloorTop, secondFloorView.getRight(), headerTop); 613 | } 614 | } 615 | }; 616 | 617 | private void fakeScroll(View target, float verticalScrollBy, MotionEvent originEvent) { 618 | 619 | float startX = originEvent.getRawX(); 620 | //noinspection UnnecessaryLocalVariable 621 | float endX = startX; 622 | float startY = originEvent.getRawY(); 623 | float endY = startY + verticalScrollBy; 624 | 625 | MotionEvent event = reassignEventId(originEvent, mLastDispatchPointerId, MotionEvent.ACTION_MOVE, endX, endY); 626 | 627 | float offsetX = mLastDispatchX - startX; 628 | float offsetY = mLastDispatchY - startY; 629 | 630 | event.offsetLocation(offsetX, offsetY); 631 | 632 | target.dispatchTouchEvent(event); 633 | 634 | event.setAction(MotionEvent.ACTION_UP); 635 | target.dispatchTouchEvent(event); 636 | 637 | event.recycle(); 638 | } 639 | 640 | private void onStateChange(int newState) { 641 | if (mState != newState) { 642 | mState = newState; 643 | if (mOnStateChangeListener != null) { 644 | mOnStateChangeListener.onStateChange(newState); 645 | } 646 | } 647 | } 648 | 649 | private View getHeaderView() { 650 | return getChildAt(0, "HeaderView not found! Does your CoordinatorLayout have more than 1 child?"); 651 | } 652 | 653 | private View getSecondFloorView() { 654 | return getChildAt(1, "SecondFloorView not found! Does your CoordinatorLayout have more than 2 child?"); 655 | } 656 | 657 | private View getFirstFloorView() { 658 | return getChildAt(2, "FirstFloorView not found! Does your CoordinatorLayout have more than 3 child?"); 659 | } 660 | 661 | @NonNull 662 | private View getChildAt(int index, String exceptionMessage) { 663 | if (mParent == null) { 664 | throwException("SecondFloorBehavior not initialized!"); 665 | } 666 | View child = mParent.getChildAt(index); 667 | if (!mParent.isInEditMode() && child == null) { 668 | throwException(exceptionMessage); 669 | } 670 | return child; 671 | } 672 | 673 | private void throwException(String message) { 674 | throw new IllegalStateException(message); 675 | } 676 | 677 | /** 678 | * 重新分配事件id 679 | * 680 | * @param originEvent 原事件 681 | * @param newId 新id 682 | * @param action 新action 683 | * @param x 新rawX 684 | * @param y 新rawY 685 | * @return 基于原事件和指定变量重新创建的事件 686 | */ 687 | private MotionEvent reassignEventId(MotionEvent originEvent, int newId, int action, float x, float y) { 688 | 689 | MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[]{new MotionEvent.PointerProperties()}; 690 | MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[]{new MotionEvent.PointerCoords()}; 691 | 692 | pointerProperties[0].id = newId; 693 | 694 | pointerCoords[0].x = x; 695 | pointerCoords[0].y = y; 696 | pointerCoords[0].pressure = originEvent.getPressure(); 697 | pointerCoords[0].size = originEvent.getSize(); 698 | pointerCoords[0].orientation = originEvent.getOrientation(); 699 | pointerCoords[0].toolMajor = originEvent.getToolMajor(); 700 | pointerCoords[0].toolMinor = originEvent.getToolMinor(); 701 | pointerCoords[0].touchMajor = originEvent.getTouchMajor(); 702 | pointerCoords[0].touchMinor = originEvent.getTouchMinor(); 703 | 704 | return MotionEvent.obtain(originEvent.getDownTime(), SystemClock.uptimeMillis(), action, 705 | 1, pointerProperties, pointerCoords, originEvent.getMetaState(), 706 | originEvent.getButtonState(), originEvent.getXPrecision(), originEvent.getYPrecision(), 707 | originEvent.getDeviceId(), originEvent.getEdgeFlags(), originEvent.getSource(), originEvent.getFlags()); 708 | } 709 | 710 | public void setOnBeforeEnterSecondFloorListener(OnBeforeEnterSecondFloorListener listener) { 711 | mOnBeforeEnterSecondFloorListener = listener; 712 | } 713 | 714 | public void setOnEnterSecondFloorListener(OnEnterSecondFloorListener listener) { 715 | mOnEnterSecondFloorListener = listener; 716 | } 717 | 718 | public void setOnExitSecondFloorListener(OnExitSecondFloorListener listener) { 719 | mOnExitSecondFloorListener = listener; 720 | } 721 | 722 | public void setOnStateChangeListener(OnStateChangeListener listener) { 723 | mOnStateChangeListener = listener; 724 | } 725 | 726 | public void setExitAnimationInterpolator(Interpolator interpolator) { 727 | mExitAnimationInterpolator = interpolator; 728 | } 729 | 730 | public void setEnterAnimationInterpolator(Interpolator interpolator) { 731 | mEnterAnimationInterpolator = interpolator; 732 | } 733 | 734 | public float getStartInterceptDistance() { 735 | return mStartInterceptDistance; 736 | } 737 | 738 | public void setStartInterceptDistance(float distance) { 739 | mStartInterceptDistance = distance; 740 | } 741 | 742 | public float getMinTriggerDistance() { 743 | return mMinTriggerDistance; 744 | } 745 | 746 | public void setMinTriggerDistance(float distance) { 747 | mMinTriggerDistance = distance; 748 | } 749 | 750 | public float getDampingRatio() { 751 | return mDampingRatio; 752 | } 753 | 754 | public void setDampingRatio(float ratio) { 755 | mDampingRatio = ratio; 756 | } 757 | 758 | public long getRollbackDuration() { 759 | return mRollbackDuration; 760 | } 761 | 762 | public void setRollbackDuration(long duration) { 763 | mRollbackDuration = duration; 764 | } 765 | 766 | public long getEnterDuration() { 767 | return mEnterDuration; 768 | } 769 | 770 | public void setEnterDuration(long duration) { 771 | mEnterDuration = duration; 772 | } 773 | 774 | public long getExitDuration() { 775 | return mExitDuration; 776 | } 777 | 778 | public void setExitDuration(long duration) { 779 | mExitDuration = duration; 780 | } 781 | 782 | public int getState() { 783 | return mState; 784 | } 785 | 786 | /** 787 | * 参考自 {@link View.DeclaredOnClickListener} 788 | */ 789 | @SuppressWarnings("JavadocReference") 790 | private static class DeclaredHelper { 791 | 792 | private final Context mContext; 793 | private final String mMethodName; 794 | private final String mExceptionMessage; 795 | 796 | private Method mResolvedMethod; 797 | private Context mResolvedContext; 798 | 799 | public DeclaredHelper(@NonNull Context context, @NonNull String methodName, @NonNull String exceptionMessage) { 800 | mContext = context; 801 | mMethodName = methodName; 802 | mExceptionMessage = exceptionMessage; 803 | } 804 | 805 | public void invoke() { 806 | if (mResolvedMethod == null) { 807 | resolveMethod(mContext, mMethodName); 808 | } 809 | 810 | try { 811 | mResolvedMethod.invoke(mResolvedContext); 812 | } catch (IllegalAccessException e) { 813 | throw new IllegalStateException("Could not execute non-public method for " + mExceptionMessage, e); 814 | } catch (InvocationTargetException e) { 815 | throw new IllegalStateException("Could not execute method for " + mExceptionMessage, e); 816 | } 817 | } 818 | 819 | private void resolveMethod(@Nullable Context context, @NonNull String name) { 820 | while (context != null) { 821 | try { 822 | if (!context.isRestricted()) { 823 | mResolvedMethod = context.getClass().getMethod(mMethodName); 824 | mResolvedContext = context; 825 | return; 826 | } 827 | } catch (NoSuchMethodException e) { 828 | // Failed to find method, keep searching up the hierarchy. 829 | } 830 | 831 | if (context instanceof ContextWrapper) { 832 | context = ((ContextWrapper) context).getBaseContext(); 833 | } else { 834 | // Can't search up the hierarchy, null out and fail. 835 | context = null; 836 | } 837 | } 838 | throw new IllegalStateException("Could not find method " + mMethodName 839 | + " in a parent or ancestor Context for " + mExceptionMessage); 840 | } 841 | } 842 | } 843 | -------------------------------------------------------------------------------- /secondfloorbehavior/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /secondfloorbehavior/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SecondFloorBehavior 3 | 4 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':secondfloorbehavior' 2 | rootProject.name='SecondFloorBehavior' 3 | --------------------------------------------------------------------------------