├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── markdown-exported-files.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── cn │ │ └── ittiger │ │ └── uc │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── cn │ │ │ └── ittiger │ │ │ └── uc │ │ │ ├── MainActivity.java │ │ │ ├── adapter │ │ │ ├── ContentAdapter.java │ │ │ └── ContentFragmentAdapter.java │ │ │ ├── fragment │ │ │ └── ContentFragment.java │ │ │ └── view │ │ │ └── behavior │ │ │ ├── UCViewContentBehavior.java │ │ │ ├── UCViewHeaderBehavior.java │ │ │ ├── UCViewTabBehavior.java │ │ │ ├── UCViewTitleBehavior.java │ │ │ └── base │ │ │ ├── HeaderScrollingViewBehavior.java │ │ │ ├── MathUtils.java │ │ │ ├── ViewOffsetBehavior.java │ │ │ └── ViewOffsetHelper.java │ └── res │ │ ├── layout │ │ ├── fragment_content.xml │ │ └── uc_main_view_layout.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 │ └── ittiger │ └── uc │ └── ExampleUnitTest.java ├── build.gradle ├── gif └── uc-main-view-behavior.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.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/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/markdown-exported-files.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 34 | 35 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Abstraction issuesJava 39 | 40 | 41 | Android 42 | 43 | 44 | Android Lint 45 | 46 | 47 | Assignment issuesGroovy 48 | 49 | 50 | Assignment issuesJava 51 | 52 | 53 | Bitwise operation issuesJava 54 | 55 | 56 | C/C++ 57 | 58 | 59 | Class metricsJava 60 | 61 | 62 | Class structureJava 63 | 64 | 65 | Cloning issuesJava 66 | 67 | 68 | Code maturity issuesJava 69 | 70 | 71 | Code style issuesJava 72 | 73 | 74 | Compiler issuesJava 75 | 76 | 77 | Concurrency annotation issuesJava 78 | 79 | 80 | Control FlowGroovy 81 | 82 | 83 | Control flow issuesJava 84 | 85 | 86 | CorrectnessLintAndroid 87 | 88 | 89 | Data flow analysisC/C++ 90 | 91 | 92 | Data flow issuesGroovy 93 | 94 | 95 | Data flow issuesJava 96 | 97 | 98 | Declaration orderC/C++ 99 | 100 | 101 | Declaration redundancyGroovy 102 | 103 | 104 | Declaration redundancyJava 105 | 106 | 107 | Dependency issuesJava 108 | 109 | 110 | Encapsulation issuesJava 111 | 112 | 113 | Error handlingGroovy 114 | 115 | 116 | Error handlingJava 117 | 118 | 119 | Finalization issuesJava 120 | 121 | 122 | FunctionsC/C++ 123 | 124 | 125 | GPath inspectionsGroovy 126 | 127 | 128 | General 129 | 130 | 131 | GeneralC/C++ 132 | 133 | 134 | GeneralJava 135 | 136 | 137 | Google Cloud Endpoints 138 | 139 | 140 | Gradle 141 | 142 | 143 | Groovy 144 | 145 | 146 | HTML 147 | 148 | 149 | ImportsJava 150 | 151 | 152 | Inheritance issuesJava 153 | 154 | 155 | Initialization issuesJava 156 | 157 | 158 | Internationalization issues 159 | 160 | 161 | Internationalization issuesJava 162 | 163 | 164 | J2ME issuesJava 165 | 166 | 167 | JUnit issues 168 | 169 | 170 | JUnit issuesJava 171 | 172 | 173 | Java 174 | 175 | 176 | Java language level issuesJava 177 | 178 | 179 | Java language level migration aidsJava 180 | 181 | 182 | JavaBeans issuesJava 183 | 184 | 185 | Javadoc issuesJava 186 | 187 | 188 | Language Injection 189 | 190 | 191 | LintAndroid 192 | 193 | 194 | Logging issuesJava 195 | 196 | 197 | Manifest 198 | 199 | 200 | Maven 201 | 202 | 203 | Memory issuesJava 204 | 205 | 206 | Method MetricsGroovy 207 | 208 | 209 | Method metricsJava 210 | 211 | 212 | Modularization issuesJava 213 | 214 | 215 | Naming ConventionsGroovy 216 | 217 | 218 | Naming conventionsJava 219 | 220 | 221 | Numeric issuesJava 222 | 223 | 224 | OtherGroovy 225 | 226 | 227 | Packaging issuesJava 228 | 229 | 230 | Performance issuesJava 231 | 232 | 233 | Portability issuesJava 234 | 235 | 236 | Potentially confusing code constructsGroovy 237 | 238 | 239 | Probable bugsGradle 240 | 241 | 242 | Probable bugsGroovy 243 | 244 | 245 | Probable bugsJava 246 | 247 | 248 | Properties Files 249 | 250 | 251 | RELAX NG 252 | 253 | 254 | Resource management issuesJava 255 | 256 | 257 | Security issuesJava 258 | 259 | 260 | Serialization issuesJava 261 | 262 | 263 | TestNG 264 | 265 | 266 | Threading issuesGroovy 267 | 268 | 269 | Threading issuesJava 270 | 271 | 272 | Type checksC/C++ 273 | 274 | 275 | Unused codeC/C++ 276 | 277 | 278 | Validity issuesGroovy 279 | 280 | 281 | Verbose or redundant code constructsJava 282 | 283 | 284 | Visibility issuesJava 285 | 286 | 287 | XML 288 | 289 | 290 | toString() issuesJava 291 | 292 | 293 | 294 | 295 | Android 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 317 | 318 | 319 | 320 | 321 | 322 | 327 | 328 | 329 | 330 | 331 | 332 | -------------------------------------------------------------------------------- /.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 | # UCMainViewForBehavior 2 | 3 | ## 使用[Behavior高仿实现UC浏览器首页上下滑动效果](http://ittiger.cn/Behavior-UC-Main-Page.html) 4 | 5 | ### 之前使用自定义View的方式实现过这个效果,感兴趣的可以看看[UCIndexAnimation](https://github.com/huyongli/UCIndexAnimation) 6 | 7 | ### 有想法要交流?[欢迎戳这里](http://ittiger.cn/about/) 8 | 9 | ### 个人微信公众号 10 | 欢迎扫码关注交流: 11 | ![](https://img-blog.csdnimg.cn/2019052410035231.jpg) 12 | 13 | ## 最终效果如下 14 | 15 | 图片名称 16 | -------------------------------------------------------------------------------- /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.ittiger.ucview" 8 | minSdkVersion 14 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 | compile 'com.android.support:design:24.2.1' 29 | testCompile 'junit:junit:4.12' 30 | } 31 | -------------------------------------------------------------------------------- /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 /home/baina/ylhu/program/android-sdk-linux/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/ittiger/uc/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc; 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.ittiger.ucview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/cn/ittiger/uc/MainActivity.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc; 2 | 3 | import cn.ittiger.uc.adapter.ContentFragmentAdapter; 4 | import cn.ittiger.uc.fragment.ContentFragment; 5 | import cn.ittiger.uc.view.behavior.UCViewHeaderBehavior; 6 | 7 | import android.support.design.widget.CoordinatorLayout; 8 | import android.support.design.widget.TabLayout; 9 | import android.support.v4.view.ViewPager; 10 | import android.support.v7.app.AppCompatActivity; 11 | import android.os.Bundle; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class MainActivity extends AppCompatActivity { 17 | private TabLayout mTabLayout; 18 | private ViewPager mViewPager; 19 | private UCViewHeaderBehavior mUCViewHeaderBehavior; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.uc_main_view_layout); 26 | mTabLayout = (TabLayout) findViewById(R.id.news_view_tab_layout); 27 | mViewPager = (ViewPager) findViewById(R.id.news_view_content_layout); 28 | 29 | mUCViewHeaderBehavior = (UCViewHeaderBehavior) ((CoordinatorLayout.LayoutParams)findViewById(R.id.news_view_header_layout).getLayoutParams()).getBehavior(); 30 | initViewData(); 31 | } 32 | 33 | private void initViewData() { 34 | 35 | List fragments = new ArrayList<>(); 36 | for(int i = 0; i < 5; i++) { 37 | fragments.add(ContentFragment.newInstance(i)); 38 | } 39 | mTabLayout.setTabMode(TabLayout.MODE_FIXED); 40 | 41 | ContentFragmentAdapter adapter = new ContentFragmentAdapter(fragments, getSupportFragmentManager()); 42 | mViewPager.setAdapter(adapter); 43 | mTabLayout.setupWithViewPager(mViewPager); 44 | } 45 | 46 | @Override 47 | public void onBackPressed() { 48 | 49 | if(mUCViewHeaderBehavior.isClosed()) { 50 | mUCViewHeaderBehavior.openPager(); 51 | } else { 52 | super.onBackPressed(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/cn/ittiger/uc/adapter/ContentAdapter.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * Created by ylhu on 17-2-23. 14 | */ 15 | public class ContentAdapter extends RecyclerView.Adapter { 16 | private List mList; 17 | private Context mContext; 18 | 19 | public ContentAdapter(Context context, List list) { 20 | 21 | mContext = context; 22 | mList = list; 23 | } 24 | 25 | @Override 26 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 27 | 28 | View view = LayoutInflater.from(mContext).inflate(android.R.layout.simple_list_item_1, parent, false); 29 | return new ContentViewHolder(view); 30 | } 31 | 32 | @Override 33 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 34 | 35 | ContentViewHolder viewHolder = (ContentViewHolder) holder; 36 | viewHolder.mTextView.setText(mList.get(position)); 37 | } 38 | 39 | @Override 40 | public int getItemCount() { 41 | 42 | return mList.size(); 43 | } 44 | 45 | public String getItem(int position) { 46 | 47 | return mList.get(position); 48 | } 49 | 50 | class ContentViewHolder extends RecyclerView.ViewHolder { 51 | TextView mTextView; 52 | public ContentViewHolder(View itemView) { 53 | 54 | super(itemView); 55 | mTextView = (TextView) itemView; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/cn/ittiger/uc/adapter/ContentFragmentAdapter.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc.adapter; 2 | 3 | import cn.ittiger.uc.fragment.ContentFragment; 4 | 5 | import android.support.v4.app.Fragment; 6 | import android.support.v4.app.FragmentManager; 7 | import android.support.v4.app.FragmentPagerAdapter; 8 | 9 | import java.util.List; 10 | 11 | public class ContentFragmentAdapter extends FragmentPagerAdapter { 12 | List mFragments; 13 | 14 | 15 | public ContentFragmentAdapter(List fragments, FragmentManager fm) { 16 | super(fm); 17 | this.mFragments = fragments; 18 | } 19 | 20 | @Override 21 | public Fragment getItem(int position) { 22 | return mFragments.get(position); 23 | } 24 | 25 | @Override 26 | public int getCount() { 27 | return mFragments == null ? 0 : mFragments.size(); 28 | } 29 | 30 | @Override 31 | public CharSequence getPageTitle(int position) { 32 | 33 | return mFragments.get(position).getName(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/cn/ittiger/uc/fragment/ContentFragment.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc.fragment; 2 | 3 | import cn.ittiger.uc.R; 4 | import cn.ittiger.uc.adapter.ContentAdapter; 5 | 6 | import android.os.Bundle; 7 | import android.support.annotation.Nullable; 8 | import android.support.v4.app.Fragment; 9 | import android.support.v7.widget.DefaultItemAnimator; 10 | import android.support.v7.widget.LinearLayoutManager; 11 | import android.support.v7.widget.RecyclerView; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * Created by ylhu on 17-2-23. 21 | */ 22 | public class ContentFragment extends Fragment { 23 | private RecyclerView mRecyclerView; 24 | private ContentAdapter mAdapter; 25 | private int mFragmentIndex; 26 | 27 | public String getName() { 28 | 29 | return "Tab" + (getArguments().getInt("fragmentIndex") + 1); 30 | } 31 | 32 | public static ContentFragment newInstance(int fragmentIndex) { 33 | 34 | ContentFragment fragment = new ContentFragment(); 35 | Bundle bundle = new Bundle(); 36 | bundle.putInt("fragmentIndex", fragmentIndex); 37 | fragment.setArguments(bundle); 38 | return fragment; 39 | } 40 | 41 | @Nullable 42 | @Override 43 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 44 | 45 | Bundle bundle = getArguments(); 46 | mFragmentIndex = bundle.getInt("fragmentIndex"); 47 | 48 | View view = inflater.inflate(R.layout.fragment_content, null); 49 | mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView); 50 | initRecyclerView(); 51 | return view; 52 | } 53 | 54 | private void initRecyclerView() { 55 | 56 | mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); 57 | mRecyclerView.setItemAnimator(new DefaultItemAnimator()); 58 | 59 | List list = new ArrayList<>(); 60 | for(int i = 0; i < 30; i++) { 61 | list.add("Fragment " + mFragmentIndex + ", 第" + i + "条数据"); 62 | } 63 | 64 | mAdapter = new ContentAdapter(getContext(), list); 65 | mRecyclerView.setAdapter(mAdapter); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/cn/ittiger/uc/view/behavior/UCViewContentBehavior.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc.view.behavior; 2 | 3 | import cn.ittiger.uc.R; 4 | import cn.ittiger.uc.view.behavior.base.HeaderScrollingViewBehavior; 5 | 6 | import android.content.Context; 7 | import android.support.design.widget.CoordinatorLayout; 8 | import android.util.AttributeSet; 9 | import android.view.View; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by ylhu on 17-2-22. 15 | */ 16 | public class UCViewContentBehavior extends HeaderScrollingViewBehavior { 17 | private int mTitleViewHeight = 0; 18 | private int mTabViewHeight = 0; 19 | 20 | public UCViewContentBehavior() { 21 | 22 | super(); 23 | } 24 | 25 | public UCViewContentBehavior(Context context, AttributeSet attrs) { 26 | 27 | super(context, attrs); 28 | } 29 | 30 | @Override 31 | public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) { 32 | 33 | return isDependency(dependency); 34 | } 35 | 36 | @Override 37 | protected void layoutChild(CoordinatorLayout parent, View child, int layoutDirection) { 38 | 39 | mTitleViewHeight = parent.findViewById(R.id.news_view_title_layout).getMeasuredHeight(); 40 | mTabViewHeight = parent.findViewById(R.id.news_view_tab_layout).getMeasuredHeight(); 41 | super.layoutChild(parent, child, layoutDirection); 42 | } 43 | 44 | @Override 45 | public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) { 46 | 47 | int headerOffsetRange = -mTitleViewHeight; 48 | //因为UCViewContent与依赖UCViewHeader为同向滑动 49 | //所以UCViewHeader向上滑即translationY为负数时,UCViewContent也向上滑其translationY也为负数 50 | //所以UCViewHeader向上滑即translationY为正数时,UCViewContent也向上滑其translationY也为正数 51 | //而headerOffsetRange为负数,getScrollRange(dependency)为正数,所以最前面要加上一个负号 52 | 53 | //计算方式与UCViewTab的计算方式一样 54 | child.setTranslationY(-dependency.getTranslationY() / (headerOffsetRange * 1.0f) * getScrollRange(dependency)); 55 | return false; 56 | } 57 | 58 | @Override 59 | protected int getScrollRange(View dependency) { 60 | 61 | if(isDependency(dependency)) { 62 | //UCViewHeader的高度,减去UCViewTab和UCViewTitle的高度就是UCViewContent要滑动的高度 63 | return dependency.getMeasuredHeight() - mTitleViewHeight - mTabViewHeight; 64 | } 65 | return super.getScrollRange(dependency); 66 | } 67 | 68 | @Override 69 | public View findFirstDependency(List views) { 70 | 71 | for(int i = 0; i < views.size(); i++) { 72 | if(isDependency(views.get(i))) { 73 | return views.get(i); 74 | } 75 | } 76 | return null; 77 | } 78 | 79 | private boolean isDependency(View dependency) { 80 | 81 | return dependency != null && dependency.getId() == R.id.news_view_header_layout; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/java/cn/ittiger/uc/view/behavior/UCViewHeaderBehavior.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc.view.behavior; 2 | 3 | import cn.ittiger.uc.R; 4 | import cn.ittiger.uc.view.behavior.base.ViewOffsetBehavior; 5 | 6 | import android.content.Context; 7 | import android.support.design.widget.CoordinatorLayout; 8 | import android.support.v4.view.ViewCompat; 9 | import android.util.AttributeSet; 10 | import android.view.MotionEvent; 11 | import android.view.View; 12 | import android.widget.OverScroller; 13 | 14 | import java.lang.ref.WeakReference; 15 | 16 | /** 17 | * Created by ylhu on 17-2-23. 18 | */ 19 | public class UCViewHeaderBehavior extends ViewOffsetBehavior { 20 | private int mTitleViewHeight = 0; 21 | private OverScroller mOverScroller; 22 | private WeakReference mChild; 23 | 24 | public static final int STATE_OPENED = 0; 25 | public static final int STATE_CLOSED = 1; 26 | public static final int DURATION_SHORT = 300; 27 | public static final int DURATION_LONG = 600; 28 | 29 | private int mCurState = STATE_OPENED; 30 | 31 | public UCViewHeaderBehavior() { 32 | 33 | super(); 34 | } 35 | 36 | public UCViewHeaderBehavior(Context context, AttributeSet attrs) { 37 | 38 | super(context, attrs); 39 | mOverScroller = new OverScroller(context); 40 | } 41 | 42 | @Override 43 | protected void layoutChild(CoordinatorLayout parent, View child, int layoutDirection) { 44 | 45 | super.layoutChild(parent, child, layoutDirection); 46 | mTitleViewHeight = parent.findViewById(R.id.news_view_title_layout).getMeasuredHeight(); 47 | mChild = new WeakReference<>(child); 48 | } 49 | 50 | @Override 51 | public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) { 52 | 53 | //开始滑动的条件,垂直方向滑动,滑动未结束 54 | return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL && canScroll(child, 0) && !isClosed(child); 55 | } 56 | 57 | /** 58 | * 当前是否可以滑动 59 | * @param child 60 | * @param pendingDy Y轴方向滑动的translationY 61 | * @return 62 | */ 63 | private boolean canScroll(View child, float pendingDy) { 64 | 65 | int pendingTranslationY = (int) (child.getTranslationY() - pendingDy); 66 | if (pendingTranslationY >= getHeaderOffsetRange() && pendingTranslationY <= 0) { 67 | return true; 68 | } 69 | return false; 70 | } 71 | 72 | @Override 73 | public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) { 74 | 75 | super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed); 76 | //开始滑动之前的逻辑处理 77 | 78 | //dy>0 向上滑 79 | //dy<0 向下滑 80 | float halfOfDis = dy / 4.0f; 81 | if (!canScroll(child, halfOfDis)) {//滑动结束 82 | if(halfOfDis > 0) { 83 | child.setVisibility(View.GONE);//滑动结束后,隐藏此视图 84 | child.setTranslationY(getHeaderOffsetRange()); 85 | } else { 86 | child.setTranslationY(0); 87 | } 88 | } else {//滑动未结束 89 | if(halfOfDis <= 0) { 90 | child.setVisibility(View.VISIBLE); 91 | } 92 | //滑动 93 | child.setTranslationY(child.getTranslationY() - halfOfDis); 94 | } 95 | //消耗掉当前垂直方向上的滑动距离 96 | consumed[1] = dy; 97 | } 98 | 99 | /** 100 | * 向上滑动过程时translationY的最小值 101 | * @return 102 | */ 103 | private int getHeaderOffsetRange() { 104 | 105 | return -mTitleViewHeight; 106 | } 107 | 108 | @Override 109 | public boolean onInterceptTouchEvent(CoordinatorLayout parent, View child, MotionEvent ev) { 110 | 111 | if(ev.getAction() == MotionEvent.ACTION_UP) { 112 | //对松开手指时进行处理,如果松开时滑动滑动了1/4则自动滑动到结束,否则则回归原位 113 | handlerActionUp(child); 114 | } 115 | return super.onInterceptTouchEvent(parent, child, ev); 116 | } 117 | 118 | private void handlerActionUp(View child) { 119 | if (mFlingRunnable != null) { 120 | child.removeCallbacks(mFlingRunnable); 121 | mFlingRunnable = null; 122 | } 123 | mFlingRunnable = new FlingRunnable(child); 124 | if (child.getTranslationY() < getHeaderOffsetRange() / 4.0f) { 125 | mFlingRunnable.scrollToClosed(DURATION_SHORT); 126 | } else { 127 | mFlingRunnable.scrollToOpen(DURATION_SHORT); 128 | } 129 | } 130 | 131 | private void onFlingFinished(View layout) { 132 | 133 | boolean isClosed = isClosed(layout); 134 | mCurState = isClosed ? STATE_CLOSED : STATE_OPENED; 135 | if(isClosed) { 136 | layout.setVisibility(View.GONE); 137 | } 138 | } 139 | 140 | /** 141 | * 是否滑动结束 142 | * @param child 143 | * @return 144 | */ 145 | private boolean isClosed(View child) { 146 | 147 | return child.getTranslationY() == getHeaderOffsetRange(); 148 | } 149 | 150 | public boolean isClosed() { 151 | return mCurState == STATE_CLOSED; 152 | } 153 | 154 | public void openPager() { 155 | openPager(DURATION_LONG); 156 | } 157 | 158 | /** 159 | * @param duration open animation duration 160 | */ 161 | public void openPager(int duration) { 162 | View child = mChild.get(); 163 | if (isClosed() && child != null) { 164 | if(child.getVisibility() == View.GONE) { 165 | child.setVisibility(View.VISIBLE); 166 | } 167 | if (mFlingRunnable != null) { 168 | child.removeCallbacks(mFlingRunnable); 169 | mFlingRunnable = null; 170 | } 171 | mFlingRunnable = new FlingRunnable(child); 172 | mFlingRunnable.scrollToOpen(duration); 173 | } 174 | } 175 | 176 | public void closePager() { 177 | closePager(DURATION_LONG); 178 | } 179 | 180 | /** 181 | * @param duration close animation duration 182 | */ 183 | public void closePager(int duration) { 184 | View child = mChild.get(); 185 | if (!isClosed()) { 186 | if (mFlingRunnable != null) { 187 | child.removeCallbacks(mFlingRunnable); 188 | mFlingRunnable = null; 189 | } 190 | mFlingRunnable = new FlingRunnable(child); 191 | mFlingRunnable.scrollToClosed(duration); 192 | } 193 | } 194 | 195 | 196 | private FlingRunnable mFlingRunnable; 197 | private class FlingRunnable implements Runnable { 198 | private final View mLayout; 199 | 200 | FlingRunnable(View layout) { 201 | mLayout = layout; 202 | } 203 | 204 | public void scrollToClosed(int duration) { 205 | float curTranslationY = ViewCompat.getTranslationY(mLayout); 206 | float dy = getHeaderOffsetRange() - curTranslationY; 207 | mOverScroller.startScroll(0, Math.round(curTranslationY - 0.1f), 0, Math.round(dy + 0.1f), duration); 208 | start(); 209 | } 210 | 211 | public void scrollToOpen(int duration) { 212 | float curTranslationY = ViewCompat.getTranslationY(mLayout); 213 | mOverScroller.startScroll(0, (int) curTranslationY, 0, (int) -curTranslationY, duration); 214 | start(); 215 | } 216 | 217 | private void start() { 218 | if (mOverScroller.computeScrollOffset()) { 219 | mFlingRunnable = new FlingRunnable(mLayout); 220 | ViewCompat.postOnAnimation(mLayout, mFlingRunnable); 221 | } else { 222 | onFlingFinished(mLayout); 223 | } 224 | } 225 | 226 | 227 | @Override 228 | public void run() { 229 | if (mLayout != null && mOverScroller != null) { 230 | if (mOverScroller.computeScrollOffset()) { 231 | ViewCompat.setTranslationY(mLayout, mOverScroller.getCurrY()); 232 | ViewCompat.postOnAnimation(mLayout, this); 233 | } else { 234 | onFlingFinished(mLayout); 235 | } 236 | } 237 | } 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /app/src/main/java/cn/ittiger/uc/view/behavior/UCViewTabBehavior.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc.view.behavior; 2 | 3 | import cn.ittiger.uc.R; 4 | import cn.ittiger.uc.view.behavior.base.HeaderScrollingViewBehavior; 5 | 6 | import android.content.Context; 7 | import android.support.design.widget.CoordinatorLayout; 8 | import android.util.AttributeSet; 9 | import android.view.View; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by ylhu on 17-2-23. 15 | */ 16 | public class UCViewTabBehavior extends HeaderScrollingViewBehavior { 17 | private int mTitleViewHeight = 0; 18 | 19 | public UCViewTabBehavior() { 20 | 21 | super(); 22 | } 23 | 24 | public UCViewTabBehavior(Context context, AttributeSet attrs) { 25 | 26 | super(context, attrs); 27 | } 28 | 29 | @Override 30 | public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) { 31 | 32 | return isDependency(dependency); 33 | } 34 | 35 | @Override 36 | protected void layoutChild(CoordinatorLayout parent, View child, int layoutDirection) { 37 | 38 | mTitleViewHeight = parent.findViewById(R.id.news_view_title_layout).getMeasuredHeight(); 39 | super.layoutChild(parent, child, layoutDirection); 40 | } 41 | 42 | @Override 43 | public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) { 44 | 45 | //UCViewTab要滑动的距离为Header的高度减去TitleView的高度 46 | float offsetRange = mTitleViewHeight - dependency.getMeasuredHeight(); 47 | //当Header向上滑动mTitleViewHeight高度后,即滑动完成 48 | int headerOffsetRange = -mTitleViewHeight; 49 | 50 | if(dependency.getTranslationY() == headerOffsetRange) {//Header已经上滑结束 51 | child.setTranslationY(offsetRange); 52 | } else if(dependency.getTranslationY() == 0) {//下滑结束,也是初始化的状态 53 | child.setTranslationY(0); 54 | } else { 55 | //UCViewTab与UCViewHeader为同向滑动 56 | //根据依赖UCViewHeader的滑动比例计算当前UCViewTab应该要滑动的值translationY 57 | child.setTranslationY(dependency.getTranslationY() / (headerOffsetRange * 1.0f) * offsetRange); 58 | } 59 | return false; 60 | } 61 | 62 | private boolean isDependency(View dependency) { 63 | 64 | return dependency != null && dependency.getId() == R.id.news_view_header_layout; 65 | } 66 | 67 | @Override 68 | public View findFirstDependency(List views) { 69 | 70 | for(int i = 0; i < views.size(); i++) { 71 | if(isDependency(views.get(i))) { 72 | return views.get(i); 73 | } 74 | } 75 | return null; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/cn/ittiger/uc/view/behavior/UCViewTitleBehavior.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc.view.behavior; 2 | 3 | import cn.ittiger.uc.R; 4 | import cn.ittiger.uc.view.behavior.base.ViewOffsetBehavior; 5 | 6 | import android.content.Context; 7 | import android.support.design.widget.CoordinatorLayout; 8 | import android.util.AttributeSet; 9 | import android.view.View; 10 | 11 | /** 12 | * Created by ylhu on 17-2-23. 13 | */ 14 | public class UCViewTitleBehavior extends ViewOffsetBehavior { 15 | 16 | public UCViewTitleBehavior() { 17 | 18 | super(); 19 | } 20 | 21 | public UCViewTitleBehavior(Context context, AttributeSet attrs) { 22 | 23 | super(context, attrs); 24 | } 25 | 26 | @Override 27 | public boolean onLayoutChild(CoordinatorLayout parent, View child, int layoutDirection) { 28 | 29 | //因为UCViewTitle默认是在屏幕外不可见,所以在UCViewTitle进行布局的时候设置其topMargin让其不可见 30 | ((CoordinatorLayout.LayoutParams) child.getLayoutParams()).topMargin = -child.getMeasuredHeight(); 31 | return super.onLayoutChild(parent, child, layoutDirection); 32 | } 33 | 34 | @Override 35 | public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) { 36 | 37 | return isDependOn(dependency); 38 | } 39 | 40 | @Override 41 | public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) { 42 | 43 | //因为UCViewTitle与UCViewHeader的滑动方向相反 44 | //所以当依赖UCViewHeader发生变化时,只需要时设置反向的translationY即可 45 | child.setTranslationY(-dependency.getTranslationY()); 46 | return false; 47 | } 48 | 49 | private boolean isDependOn(View dependency) { 50 | return dependency != null && dependency.getId() == R.id.news_view_header_layout; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/cn/ittiger/uc/view/behavior/base/HeaderScrollingViewBehavior.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc.view.behavior.base; 2 | 3 | import android.content.Context; 4 | import android.graphics.Rect; 5 | import android.support.design.widget.*; 6 | import android.support.v4.view.GravityCompat; 7 | import android.support.v4.view.ViewCompat; 8 | import android.util.AttributeSet; 9 | import android.view.Gravity; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * this class code copy from android framework 17 | * 18 | * The {@link CoordinatorLayout.Behavior} for a scrolling view that is positioned vertically below another view. 19 | * See {@link HeaderBehavior}. 20 | */ 21 | public abstract class HeaderScrollingViewBehavior extends ViewOffsetBehavior { 22 | 23 | final Rect mTempRect1 = new Rect(); 24 | final Rect mTempRect2 = new Rect(); 25 | 26 | private int mVerticalLayoutGap = 0; 27 | private int mOverlayTop; 28 | 29 | public HeaderScrollingViewBehavior() {} 30 | 31 | public HeaderScrollingViewBehavior(Context context, AttributeSet attrs) { 32 | super(context, attrs); 33 | } 34 | 35 | @Override 36 | public boolean onMeasureChild(CoordinatorLayout parent, View child, 37 | int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, 38 | int heightUsed) { 39 | final int childLpHeight = child.getLayoutParams().height; 40 | if (childLpHeight == ViewGroup.LayoutParams.MATCH_PARENT 41 | || childLpHeight == ViewGroup.LayoutParams.WRAP_CONTENT) { 42 | // If the menu's height is set to match_parent/wrap_content then measure it 43 | // with the maximum visible height 44 | 45 | final List dependencies = parent.getDependencies(child); 46 | final View header = findFirstDependency(dependencies); 47 | if (header != null) { 48 | if (ViewCompat.getFitsSystemWindows(header) 49 | && !ViewCompat.getFitsSystemWindows(child)) { 50 | // If the header is fitting system windows then we need to also, 51 | // otherwise we'll get CoL's compatible measuring 52 | ViewCompat.setFitsSystemWindows(child, true); 53 | 54 | if (ViewCompat.getFitsSystemWindows(child)) { 55 | // If the set succeeded, trigger a new layout and return true 56 | child.requestLayout(); 57 | return true; 58 | } 59 | } 60 | 61 | int availableHeight = View.MeasureSpec.getSize(parentHeightMeasureSpec); 62 | if (availableHeight == 0) { 63 | // If the measure spec doesn't specify a size, use the current height 64 | availableHeight = parent.getHeight(); 65 | } 66 | 67 | final int height = availableHeight - header.getMeasuredHeight() 68 | + getScrollRange(header); 69 | final int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(height, 70 | childLpHeight == ViewGroup.LayoutParams.MATCH_PARENT 71 | ? View.MeasureSpec.EXACTLY 72 | : View.MeasureSpec.AT_MOST); 73 | 74 | // Now measure the scrolling view with the correct height 75 | parent.onMeasureChild(child, parentWidthMeasureSpec, 76 | widthUsed, heightMeasureSpec, heightUsed); 77 | 78 | return true; 79 | } 80 | } 81 | return false; 82 | } 83 | 84 | @Override 85 | protected void layoutChild(final CoordinatorLayout parent, final View child, 86 | final int layoutDirection) { 87 | final List dependencies = parent.getDependencies(child); 88 | final View header = findFirstDependency(dependencies); 89 | 90 | if (header != null) { 91 | final CoordinatorLayout.LayoutParams lp = 92 | (CoordinatorLayout.LayoutParams) child.getLayoutParams(); 93 | final Rect available = mTempRect1; 94 | available.set(parent.getPaddingLeft() + lp.leftMargin, 95 | header.getBottom() + lp.topMargin, 96 | parent.getWidth() - parent.getPaddingRight() - lp.rightMargin, 97 | parent.getHeight() + header.getBottom() 98 | - parent.getPaddingBottom() - lp.bottomMargin); 99 | 100 | /*final WindowInsetsCompat parentInsets = parent.getLastWindowInsets(); 101 | if (parentInsets != null && ViewCompat.getFitsSystemWindows(parent) 102 | && !ViewCompat.getFitsSystemWindows(child)) { 103 | // If we're set to handle insets but this child isn't, then it has been measured as 104 | // if there are no insets. We need to lay it out to match horizontally. 105 | // Top and bottom and already handled in the logic above 106 | available.left += parentInsets.getSystemWindowInsetLeft(); 107 | available.right -= parentInsets.getSystemWindowInsetRight(); 108 | }*/ 109 | 110 | final Rect out = mTempRect2; 111 | GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), 112 | child.getMeasuredHeight(), available, out, layoutDirection); 113 | 114 | final int overlap = getOverlapPixelsForOffset(header); 115 | 116 | child.layout(out.left, out.top - overlap, out.right, out.bottom - overlap); 117 | mVerticalLayoutGap = out.top - header.getBottom(); 118 | } else { 119 | // If we don't have a dependency, let super handle it 120 | super.layoutChild(parent, child, layoutDirection); 121 | mVerticalLayoutGap = 0; 122 | } 123 | } 124 | 125 | float getOverlapRatioForOffset(final View header) { 126 | return 1f; 127 | } 128 | 129 | final int getOverlapPixelsForOffset(final View header) { 130 | return mOverlayTop == 0 ? 0 : MathUtils.constrain( 131 | (int) (getOverlapRatioForOffset(header) * mOverlayTop), 0, mOverlayTop); 132 | } 133 | 134 | private static int resolveGravity(int gravity) { 135 | return gravity == Gravity.NO_GRAVITY ? GravityCompat.START | Gravity.TOP : gravity; 136 | } 137 | 138 | public abstract View findFirstDependency(List views); 139 | 140 | protected int getScrollRange(View v) { 141 | return v.getMeasuredHeight(); 142 | } 143 | 144 | /** 145 | * The gap between the top of the scrolling view and the bottom of the header layout in pixels. 146 | */ 147 | final int getVerticalLayoutGap() { 148 | return mVerticalLayoutGap; 149 | } 150 | 151 | /** 152 | * Set the distance that this view should overlap any {@link AppBarLayout}. 153 | * 154 | * @param overlayTop the distance in px 155 | */ 156 | public final void setOverlayTop(int overlayTop) { 157 | mOverlayTop = overlayTop; 158 | } 159 | 160 | /** 161 | * Returns the distance that this view should overlap any {@link AppBarLayout}. 162 | */ 163 | public final int getOverlayTop() { 164 | return mOverlayTop; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /app/src/main/java/cn/ittiger/uc/view/behavior/base/MathUtils.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc.view.behavior.base; 2 | 3 | /** 4 | * Created by ylhu on 17-2-23. 5 | */ 6 | public class MathUtils { 7 | 8 | static int constrain(int amount, int low, int high) { 9 | return amount < low ? low : (amount > high ? high : amount); 10 | } 11 | 12 | static float constrain(float amount, float low, float high) { 13 | return amount < low ? low : (amount > high ? high : amount); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/cn/ittiger/uc/view/behavior/base/ViewOffsetBehavior.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc.view.behavior.base; 2 | 3 | import android.content.Context; 4 | import android.support.design.widget.CoordinatorLayout; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | 8 | /** 9 | * this class code copy from android framework 10 | * 11 | * Behavior will automatically sets up a {@link ViewOffsetHelper} on a {@link View}. 12 | */ 13 | public class ViewOffsetBehavior extends CoordinatorLayout.Behavior { 14 | 15 | private ViewOffsetHelper mViewOffsetHelper; 16 | 17 | private int mTempTopBottomOffset = 0; 18 | private int mTempLeftRightOffset = 0; 19 | 20 | public ViewOffsetBehavior() {} 21 | 22 | public ViewOffsetBehavior(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | @Override 27 | public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) { 28 | // First let lay the child out 29 | layoutChild(parent, child, layoutDirection); 30 | 31 | if (mViewOffsetHelper == null) { 32 | mViewOffsetHelper = new ViewOffsetHelper(child); 33 | } 34 | mViewOffsetHelper.onViewLayout(); 35 | 36 | if (mTempTopBottomOffset != 0) { 37 | mViewOffsetHelper.setTopAndBottomOffset(mTempTopBottomOffset); 38 | mTempTopBottomOffset = 0; 39 | } 40 | if (mTempLeftRightOffset != 0) { 41 | mViewOffsetHelper.setLeftAndRightOffset(mTempLeftRightOffset); 42 | mTempLeftRightOffset = 0; 43 | } 44 | 45 | return true; 46 | } 47 | 48 | protected void layoutChild(CoordinatorLayout parent, V child, int layoutDirection) { 49 | // Let the parent lay it out by default 50 | parent.onLayoutChild(child, layoutDirection); 51 | } 52 | 53 | public boolean setTopAndBottomOffset(int offset) { 54 | if (mViewOffsetHelper != null) { 55 | return mViewOffsetHelper.setTopAndBottomOffset(offset); 56 | } else { 57 | mTempTopBottomOffset = offset; 58 | } 59 | return false; 60 | } 61 | 62 | public boolean setLeftAndRightOffset(int offset) { 63 | if (mViewOffsetHelper != null) { 64 | return mViewOffsetHelper.setLeftAndRightOffset(offset); 65 | } else { 66 | mTempLeftRightOffset = offset; 67 | } 68 | return false; 69 | } 70 | 71 | public int getTopAndBottomOffset() { 72 | return mViewOffsetHelper != null ? mViewOffsetHelper.getTopAndBottomOffset() : 0; 73 | } 74 | 75 | public int getLeftAndRightOffset() { 76 | return mViewOffsetHelper != null ? mViewOffsetHelper.getLeftAndRightOffset() : 0; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/cn/ittiger/uc/view/behavior/base/ViewOffsetHelper.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc.view.behavior.base; 2 | 3 | import android.support.v4.view.ViewCompat; 4 | import android.view.View; 5 | 6 | /** 7 | * this class code copy from android framework 8 | * 9 | * 10 | * Utility helper for moving a {@link android.view.View} around using 11 | * {@link android.view.View#offsetLeftAndRight(int)} and 12 | * {@link android.view.View#offsetTopAndBottom(int)}. 13 | *

14 | * Also the setting of absolute offsets (similar to translationX/Y), rather than additive 15 | * offsets. 16 | */ 17 | public class ViewOffsetHelper { 18 | 19 | private final View mView; 20 | 21 | private int mLayoutTop; 22 | private int mLayoutLeft; 23 | private int mOffsetTop; 24 | private int mOffsetLeft; 25 | 26 | public ViewOffsetHelper(View view) { 27 | mView = view; 28 | } 29 | 30 | public void onViewLayout() { 31 | // Now grab the intended top 32 | mLayoutTop = mView.getTop(); 33 | mLayoutLeft = mView.getLeft(); 34 | 35 | // And offset it as needed 36 | updateOffsets(); 37 | } 38 | 39 | private void updateOffsets() { 40 | ViewCompat.offsetTopAndBottom(mView, mOffsetTop - (mView.getTop() - mLayoutTop)); 41 | ViewCompat.offsetLeftAndRight(mView, mOffsetLeft - (mView.getLeft() - mLayoutLeft)); 42 | } 43 | 44 | /** 45 | * Set the top and bottom offset for this {@link android.support.design.widget.ViewOffsetHelper}'s view. 46 | * 47 | * @param offset the offset in px. 48 | * @return true if the offset has changed 49 | */ 50 | public boolean setTopAndBottomOffset(int offset) { 51 | if (mOffsetTop != offset) { 52 | mOffsetTop = offset; 53 | updateOffsets(); 54 | return true; 55 | } 56 | return false; 57 | } 58 | 59 | /** 60 | * Set the left and right offset for this {@link android.support.design.widget.ViewOffsetHelper}'s view. 61 | * 62 | * @param offset the offset in px. 63 | * @return true if the offset has changed 64 | */ 65 | public boolean setLeftAndRightOffset(int offset) { 66 | if (mOffsetLeft != offset) { 67 | mOffsetLeft = offset; 68 | updateOffsets(); 69 | return true; 70 | } 71 | return false; 72 | } 73 | 74 | public int getTopAndBottomOffset() { 75 | return mOffsetTop; 76 | } 77 | 78 | public int getLeftAndRightOffset() { 79 | return mOffsetLeft; 80 | } 81 | 82 | public int getLayoutTop() { 83 | return mLayoutTop; 84 | } 85 | 86 | public int getLayoutLeft() { 87 | return mLayoutLeft; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_content.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/uc_main_view_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 21 | 22 | 23 | 24 | 29 | 32 | 37 | 38 | 39 | 40 | 41 | 42 | 54 | 55 | 64 | 65 | 71 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyongli/UCMainViewForBehavior/a043073602997a72922a0fddf21f361661a031e7/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyongli/UCMainViewForBehavior/a043073602997a72922a0fddf21f361661a031e7/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyongli/UCMainViewForBehavior/a043073602997a72922a0fddf21f361661a031e7/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyongli/UCMainViewForBehavior/a043073602997a72922a0fddf21f361661a031e7/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyongli/UCMainViewForBehavior/a043073602997a72922a0fddf21f361661a031e7/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 40dp 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | UCMainViewForBehavior 3 | 4 | cn.ittiger.uc.view.behavior.UCViewContentBehavior 5 | cn.ittiger.uc.view.behavior.UCViewTabBehavior 6 | cn.ittiger.uc.view.behavior.UCViewTitleBehavior 7 | cn.ittiger.uc.view.behavior.UCViewHeaderBehavior 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/cn/ittiger/uc/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package cn.ittiger.uc; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | 16 | assertEquals(4, 2 + 2); 17 | } 18 | } -------------------------------------------------------------------------------- /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 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.2' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gif/uc-main-view-behavior.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyongli/UCMainViewForBehavior/a043073602997a72922a0fddf21f361661a031e7/gif/uc-main-view-behavior.gif -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyongli/UCMainViewForBehavior/a043073602997a72922a0fddf21f361661a031e7/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 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-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 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 Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------