├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── AndroidSweetBehavior.iml ├── LICENSE.txt ├── README.md ├── app-1.1.2.apk ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── mingle │ │ └── androidsweetbehavior │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── mingle │ │ ├── androidsweetbehavior │ │ ├── InstagramActivity.java │ │ ├── MainActivity.java │ │ ├── SecondActivity.java │ │ ├── WebActivity.java │ │ ├── adapter │ │ │ └── ImageRVAdapter.java │ │ └── entity │ │ │ └── ImageEntity.java │ │ └── widget │ │ ├── BakedBezierInterpolator.java │ │ ├── LoadingToolBar.java │ │ ├── PopupIndicator.java │ │ ├── SwipeProgressBar.java │ │ └── SwipeProgressView.java │ └── res │ ├── layout │ ├── activity_instagram.xml │ ├── activity_main.xml │ ├── activity_second.xml │ ├── activity_webctivity.xml │ └── item_image.xml │ ├── menu │ ├── menu_instagram.xml │ ├── menu_main.xml │ └── menu_second.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ ├── ic_01.jpg │ ├── ic_03.jpg │ ├── ic_06.png │ ├── ic_08.jpg │ ├── ic_09.jpg │ ├── ic_10.jpg │ ├── ic_11.jpg │ ├── ic_7.jpg │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── app0.1.1.apk ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── sweetbehavior ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── src ├── androidTest │ └── java │ │ └── com │ │ └── mingle │ │ └── sweetbehavior │ │ └── ApplicationTest.java └── main │ ├── AndroidManifest.xml │ ├── java │ └── android │ │ └── support │ │ └── design │ │ └── widget │ │ ├── InAppBarBehavior.java │ │ ├── InNestChildBehavior.java │ │ └── SheetBehavior.java │ └── res │ └── values │ ├── behavior_strings.xml │ └── sweet_behavior_attr.xml └── sweetbehavior.iml /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | AndroidSweetBehavior -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 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 | 25 | 26 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Android Lint 39 | 40 | 41 | Assignment issuesGroovy 42 | 43 | 44 | Assignment issuesJava 45 | 46 | 47 | C/C++ 48 | 49 | 50 | Class metricsJava 51 | 52 | 53 | Class structureJava 54 | 55 | 56 | Code style issuesJava 57 | 58 | 59 | Control FlowGroovy 60 | 61 | 62 | Control flow issuesJava 63 | 64 | 65 | Declaration orderC/C++ 66 | 67 | 68 | Declaration redundancyJava 69 | 70 | 71 | Error handlingJava 72 | 73 | 74 | Finalization issuesJava 75 | 76 | 77 | FunctionsC/C++ 78 | 79 | 80 | General 81 | 82 | 83 | GeneralC/C++ 84 | 85 | 86 | Gradle 87 | 88 | 89 | Groovy 90 | 91 | 92 | Inheritance issuesJava 93 | 94 | 95 | Internationalization issuesJava 96 | 97 | 98 | J2ME issuesJava 99 | 100 | 101 | JSON 102 | 103 | 104 | JUnit issuesJava 105 | 106 | 107 | Java 108 | 109 | 110 | Java language level migration aidsJava 111 | 112 | 113 | Javadoc issuesJava 114 | 115 | 116 | Language Injection 117 | 118 | 119 | Logging issuesJava 120 | 121 | 122 | Maven 123 | 124 | 125 | Method MetricsGroovy 126 | 127 | 128 | Method metricsJava 129 | 130 | 131 | Numeric issuesJava 132 | 133 | 134 | Packaging issuesJava 135 | 136 | 137 | Pattern Validation 138 | 139 | 140 | Performance issuesJava 141 | 142 | 143 | Potentially confusing code constructsGroovy 144 | 145 | 146 | Probable bugsGradle 147 | 148 | 149 | Probable bugsJava 150 | 151 | 152 | Properties Files 153 | 154 | 155 | Serialization issuesJava 156 | 157 | 158 | Threading issuesGroovy 159 | 160 | 161 | Threading issuesJava 162 | 163 | 164 | Type checksC/C++ 165 | 166 | 167 | Validity issuesGroovy 168 | 169 | 170 | XML 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 192 | 193 | 194 | 195 | 196 | 1.7 197 | 198 | 203 | 204 | 205 | 206 | 207 | 208 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AndroidSweetBehavior.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidSweetBehavior 2 | Android support Behavior 实践 3 | ###实践1: 4 | 5 | 6 | ![效果图.gif](http://upload-images.jianshu.io/upload_images/166866-b243d27707cc6d4b.gif?imageMogr2/auto-orient/strip) 7 | 8 | 9 | 通过自定义Behavior 和 Nest 事件,达到 instagram 选择照片的的效果. 10 | 使用方法:http://www.jianshu.com/p/5081c6a0113b 11 | 12 | 存在的问题: 13 | 里面有一块使用了setPadding的方法.导致有点顿,后期使用自定LayoutManager 来实现; 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | ##实践2 23 | ![效果.gif](http://upload-images.jianshu.io/upload_images/166866-89cd7f9f19bf12bf.gif?imageMogr2/auto-orient/strip) 24 | SheetBehavior :扩展自BottomSheetBehavior ,可以下拉的SheetBehavior 25 | 使用方法:http://www.jianshu.com/p/d338695d4fd8 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app-1.1.2.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzz40500/AndroidSweetBehavior/bc5ffbf7c8186d2f2941227868e3f5ef64f9849a/app-1.1.2.apk -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 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 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.0" 6 | 7 | defaultConfig { 8 | applicationId "com.mingle.androidsweetbehavior" 9 | minSdkVersion 14 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 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 'com.github.zzz40500:ScaleLayout:0.1' 24 | compile 'com.android.support:appcompat-v7:23.2.0' 25 | compile 'com.android.support:recyclerview-v7:23.2.0' 26 | compile 'com.github.bumptech.glide:glide:3.5.2' 27 | compile project(':sweetbehavior') 28 | } 29 | -------------------------------------------------------------------------------- /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 /Users/zzz40500/Documents/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/mingle/androidsweetbehavior/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.mingle.androidsweetbehavior; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingle/androidsweetbehavior/InstagramActivity.java: -------------------------------------------------------------------------------- 1 | package com.mingle.androidsweetbehavior; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.support.design.widget.AppBarLayout; 6 | import android.support.design.widget.CoordinatorLayout; 7 | import android.support.design.widget.InAppBarBehavior; 8 | import android.support.design.widget.InNestChildBehavior; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.os.Bundle; 11 | import android.support.v7.widget.GridLayoutManager; 12 | import android.support.v7.widget.RecyclerView; 13 | import android.view.Menu; 14 | import android.view.MenuItem; 15 | import android.view.View; 16 | import android.view.WindowManager; 17 | import android.widget.ImageView; 18 | import android.widget.Toast; 19 | 20 | import com.bumptech.glide.Glide; 21 | import com.mingle.androidsweetbehavior.adapter.ImageRVAdapter; 22 | import com.mingle.androidsweetbehavior.entity.ImageEntity; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | import java.util.Random; 27 | 28 | public class InstagramActivity extends AppCompatActivity implements View.OnClickListener, ImageRVAdapter.OnRvItemClickListener { 29 | 30 | 31 | private RecyclerView mRV; 32 | 33 | private ImageView mContentIv; 34 | 35 | private AppBarLayout mAppBarLayout; 36 | private CoordinatorLayout mCoordinatorLayout; 37 | private GridLayoutManager gridLayoutManager; 38 | private int totalScroll; 39 | 40 | public static void startActivity(Context ctx) { 41 | ctx.startActivity(new Intent(ctx, InstagramActivity.class)); 42 | } 43 | 44 | private int[] randomIntArray = new int[]{R.mipmap.ic_01, R.mipmap.ic_03, 45 | 46 | R.mipmap.ic_06, R.mipmap.ic_7, 47 | R.mipmap.ic_08, R.mipmap.ic_10, 48 | R.mipmap.ic_11, R.mipmap.ic_01, 49 | 50 | }; 51 | 52 | @Override 53 | protected void onCreate(Bundle savedInstanceState) { 54 | this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 55 | super.onCreate(savedInstanceState); 56 | setContentView(R.layout.activity_instagram); 57 | mRV = (RecyclerView) findViewById(R.id.rv); 58 | mAppBarLayout = (AppBarLayout) findViewById(R.id.appBarLayout); 59 | mContentIv = (ImageView) findViewById(R.id.contentIv); 60 | mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLY); 61 | mContentIv.setOnClickListener(this); 62 | 63 | 64 | List list = new ArrayList<>(); 65 | list.add(new ImageEntity(randomIntArray[0])); 66 | for (int i = 0; i < 78; i++) { 67 | ImageEntity item = new ImageEntity(); 68 | item.resId = randomIntArray[new Random().nextInt(8)]; 69 | list.add(item); 70 | } 71 | 72 | gridLayoutManager = new GridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false); 73 | 74 | mRV.setLayoutManager(gridLayoutManager); 75 | 76 | 77 | mRV.setAdapter(new ImageRVAdapter(list, this)); 78 | } 79 | 80 | @Override 81 | public boolean onCreateOptionsMenu(Menu menu) { 82 | // Inflate the menu; this adds items to the action bar if it is present. 83 | getMenuInflater().inflate(R.menu.menu_instagram, menu); 84 | return true; 85 | } 86 | 87 | @Override 88 | public boolean onOptionsItemSelected(MenuItem item) { 89 | int id = item.getItemId(); 90 | if (id == R.id.action_settings) { 91 | return true; 92 | } 93 | 94 | return super.onOptionsItemSelected(item); 95 | } 96 | 97 | @Override 98 | public void onClick(View v) { 99 | Toast.makeText(this, "小样,点击了图片", Toast.LENGTH_LONG).show(); 100 | 101 | } 102 | 103 | @Override 104 | public void onRvItemClick(View view, Object o, int position) { 105 | 106 | ImageEntity imageEntity = (ImageEntity) o; 107 | Glide.with(this).load(imageEntity.resId).into(mContentIv); 108 | InAppBarBehavior appBarBehavior = (InAppBarBehavior) ((CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams()).getBehavior(); 109 | appBarBehavior.setExpanded(true, true); 110 | 111 | InNestChildBehavior inNestChildBehavior= (InNestChildBehavior) ((CoordinatorLayout.LayoutParams)mRV.getLayoutParams()).getBehavior(); 112 | inNestChildBehavior.smoothScrollToView(view, mRV); 113 | } 114 | 115 | 116 | } 117 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingle/androidsweetbehavior/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.mingle.androidsweetbehavior; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.Menu; 8 | import android.view.MenuItem; 9 | import android.view.View; 10 | import android.widget.Toast; 11 | 12 | public class MainActivity extends AppCompatActivity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | } 19 | 20 | @Override 21 | public boolean onCreateOptionsMenu(Menu menu) { 22 | getMenuInflater().inflate(R.menu.menu_main, menu); 23 | return true; 24 | } 25 | 26 | @Override 27 | public boolean onOptionsItemSelected(MenuItem item) { 28 | // Handle action bar item clicks here. The action bar will 29 | // automatically handle clicks on the Home/Up button, so long 30 | // as you specify a parent activity in AndroidManifest.xml. 31 | int id = item.getItemId(); 32 | 33 | //noinspection SimplifiableIfStatement 34 | if (id == R.id.action_github) { 35 | Uri uri = Uri.parse("https://github.com/zzz40500/AndroidSweetBehavior"); 36 | startActivity(new Intent(Intent.ACTION_VIEW,uri)); 37 | return true; 38 | } 39 | 40 | return super.onOptionsItemSelected(item); 41 | } 42 | 43 | public void instagramAction(View view) { 44 | 45 | InstagramActivity.startActivity(this); 46 | } 47 | 48 | public void studyNotesAction(View view) { 49 | 50 | WebActivity.startActivity(this,"http://www.jianshu.com/p/99adaad8d55c"); 51 | } 52 | 53 | public void secondClick(View view) { 54 | SecondActivity.startActivity(this); 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingle/androidsweetbehavior/SecondActivity.java: -------------------------------------------------------------------------------- 1 | package com.mingle.androidsweetbehavior; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.support.annotation.NonNull; 6 | import android.support.design.widget.SheetBehavior; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.os.Bundle; 9 | import android.util.Log; 10 | import android.view.Menu; 11 | import android.view.MenuItem; 12 | import android.view.View; 13 | 14 | public class SecondActivity extends AppCompatActivity { 15 | 16 | private SheetBehavior mSheetBehavior; 17 | 18 | public static void startActivity(Context ctx) { 19 | ctx.startActivity(new Intent(ctx, SecondActivity.class)); 20 | } 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_second); 25 | View view=findViewById(R.id.design_bottom_sheet); 26 | 27 | 28 | mSheetBehavior =SheetBehavior.from(view); 29 | // mSheetBehavior.setHideable(true); 30 | mSheetBehavior.setBottomSheetCallback(new SheetBehavior.SheetCallback() { 31 | @Override 32 | public void onStateChanged(@NonNull View bottomSheet, @SheetBehavior.State int newState) { 33 | 34 | } 35 | 36 | @Override 37 | public void onSlide(@NonNull View bottomSheet, float slideOffset) { 38 | 39 | Log.e("dim",slideOffset+""); 40 | } 41 | }); 42 | 43 | } 44 | @Override 45 | public boolean onCreateOptionsMenu(Menu menu) { 46 | getMenuInflater().inflate(R.menu.menu_second, menu); 47 | return true; 48 | } 49 | 50 | @Override 51 | public boolean onOptionsItemSelected(MenuItem item) { 52 | // Handle action bar item clicks here. The action bar will 53 | // automatically handle clicks on the Home/Up button, so long 54 | // as you specify a parent activity in AndroidManifest.xml. 55 | int id = item.getItemId(); 56 | 57 | //noinspection SimplifiableIfStatement 58 | if (id == R.id.action_switch) { 59 | if( mSheetBehavior.getSlideModel()== SheetBehavior.TOP_SHEET){ 60 | mSheetBehavior.setSlideModel(SheetBehavior.BOTTOM_SHEET); 61 | }else { 62 | mSheetBehavior.setSlideModel(SheetBehavior.TOP_SHEET); 63 | } 64 | return true; 65 | } 66 | 67 | return super.onOptionsItemSelected(item); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingle/androidsweetbehavior/WebActivity.java: -------------------------------------------------------------------------------- 1 | package com.mingle.androidsweetbehavior; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.graphics.Bitmap; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.os.Bundle; 8 | import android.webkit.WebChromeClient; 9 | import android.webkit.WebResourceError; 10 | import android.webkit.WebResourceRequest; 11 | import android.webkit.WebView; 12 | import android.webkit.WebViewClient; 13 | 14 | import com.mingle.widget.LoadingToolBar; 15 | 16 | /** 17 | * 内部网页加载器 18 | */ 19 | public class WebActivity extends AppCompatActivity { 20 | 21 | 22 | 23 | 24 | 25 | public static final String KEY_URL="key_url"; 26 | 27 | private WebView mWebView; 28 | private String mUrl; 29 | 30 | private LoadingToolBar mLoadingToolBar; 31 | 32 | public static void startActivity(Context ctx, String url){ 33 | Intent intent=new Intent(ctx,WebActivity.class); 34 | intent.putExtra(KEY_URL, url); 35 | ctx.startActivity(intent); 36 | } 37 | 38 | 39 | @Override 40 | protected void onCreate(Bundle savedInstanceState) { 41 | super.onCreate(savedInstanceState); 42 | setContentView(R.layout.activity_webctivity); 43 | 44 | if(getIntent().hasExtra(KEY_URL)){ 45 | handIntentExtra(); 46 | } 47 | initView(); 48 | 49 | 50 | } 51 | 52 | private void initView() { 53 | mWebView= (WebView) findViewById(R.id.webView); 54 | mWebView.setWebChromeClient(new WebChromeClient()); 55 | mLoadingToolBar= (LoadingToolBar) findViewById(R.id.toolbar); 56 | mLoadingToolBar.setColorScheme(R.color.triangle, R.color.rect, R.color.circle, R.color.rect); 57 | 58 | setSupportActionBar(mLoadingToolBar); 59 | mWebView.setWebViewClient(new WebViewClient() { 60 | @Override 61 | public void onPageStarted(WebView view, String url, Bitmap favicon) { 62 | super.onPageStarted(view, url, favicon); 63 | mLoadingToolBar.setRefreshing(true); 64 | } 65 | 66 | @Override 67 | public void onPageFinished(WebView view, String url) { 68 | super.onPageFinished(view, url); 69 | mLoadingToolBar.setRefreshing(false); 70 | 71 | } 72 | 73 | @Override 74 | public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { 75 | super.onReceivedError(view, request, error); 76 | } 77 | }); 78 | mWebView.loadUrl(mUrl); 79 | 80 | } 81 | 82 | private void handIntentExtra() { 83 | 84 | mUrl=getIntent().getStringExtra(KEY_URL); 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingle/androidsweetbehavior/adapter/ImageRVAdapter.java: -------------------------------------------------------------------------------- 1 | package com.mingle.androidsweetbehavior.adapter; 2 | 3 | import android.support.annotation.NonNull; 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.ImageView; 9 | 10 | import com.bumptech.glide.Glide; 11 | import com.mingle.androidsweetbehavior.R; 12 | import com.mingle.androidsweetbehavior.entity.ImageEntity; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * Created by zzz40500 on 15/11/16. 18 | */ 19 | public class ImageRVAdapter extends RecyclerView.Adapter { 20 | 21 | 22 | private OnRvItemClickListener mOnRvItemClickListener; 23 | 24 | private List mData; 25 | 26 | public ImageRVAdapter(@NonNull List data,OnRvItemClickListener onRvItemClickListener) { 27 | mData=data; 28 | mOnRvItemClickListener=onRvItemClickListener; 29 | } 30 | 31 | 32 | 33 | @Override 34 | public VH onCreateViewHolder(ViewGroup parent, int viewType) { 35 | return new VH(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_image,parent,false)); 36 | } 37 | 38 | @Override 39 | public void onBindViewHolder(VH holder, final int position) { 40 | Glide.with(holder.itemView.getContext()).load(mData.get(position).resId).into(holder.mIv); 41 | holder.itemView.setOnClickListener(new View.OnClickListener() { 42 | @Override 43 | public void onClick(View v) { 44 | mOnRvItemClickListener.onRvItemClick(v,mData.get(position),position); 45 | } 46 | }); 47 | } 48 | 49 | @Override 50 | public int getItemCount() { 51 | return mData.size(); 52 | } 53 | 54 | 55 | public interface OnRvItemClickListener { 56 | void onRvItemClick(View view,Object o,int position); 57 | } 58 | public static class VH extends RecyclerView.ViewHolder { 59 | 60 | ImageView mIv; 61 | public VH(View itemView) { 62 | super(itemView); 63 | mIv= (ImageView) itemView.findViewById(R.id.imageIv); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingle/androidsweetbehavior/entity/ImageEntity.java: -------------------------------------------------------------------------------- 1 | package com.mingle.androidsweetbehavior.entity; 2 | 3 | /** 4 | * 类: 5 | * Created by zwm on 15/11/16. 6 | */ 7 | public class ImageEntity { 8 | 9 | public int resId; 10 | 11 | public ImageEntity(int resId) { 12 | this.resId = resId; 13 | } 14 | 15 | public ImageEntity() { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingle/widget/BakedBezierInterpolator.java: -------------------------------------------------------------------------------- 1 | package com.mingle.widget; 2 | 3 | import android.view.animation.Interpolator; 4 | 5 | /** 6 | * A pre-baked bezier-curved interpolator for indeterminate progress animations. 7 | */ 8 | final class BakedBezierInterpolator implements Interpolator { 9 | private static final BakedBezierInterpolator INSTANCE = new BakedBezierInterpolator(); 10 | 11 | public final static BakedBezierInterpolator getInstance() { 12 | return INSTANCE; 13 | } 14 | 15 | /** 16 | * Use getInstance instead of instantiating. 17 | */ 18 | private BakedBezierInterpolator() { 19 | super(); 20 | } 21 | 22 | /** 23 | * Lookup table values. 24 | * Generated using a Bezier curve from (0,0) to (1,1) with control points: 25 | * P0 (0,0) 26 | * P1 (0.4, 0) 27 | * P2 (0.2, 1.0) 28 | * P3 (1.0, 1.0) 29 | * 30 | * Values sampled with x at regular intervals between 0 and 1. 31 | */ 32 | private static final float[] VALUES = new float[] { 33 | 0.0f, 0.0002f, 0.0009f, 0.0019f, 0.0036f, 0.0059f, 0.0086f, 0.0119f, 0.0157f, 0.0209f, 34 | 0.0257f, 0.0321f, 0.0392f, 0.0469f, 0.0566f, 0.0656f, 0.0768f, 0.0887f, 0.1033f, 0.1186f, 35 | 0.1349f, 0.1519f, 0.1696f, 0.1928f, 0.2121f, 0.237f, 0.2627f, 0.2892f, 0.3109f, 0.3386f, 36 | 0.3667f, 0.3952f, 0.4241f, 0.4474f, 0.4766f, 0.5f, 0.5234f, 0.5468f, 0.5701f, 0.5933f, 37 | 0.6134f, 0.6333f, 0.6531f, 0.6698f, 0.6891f, 0.7054f, 0.7214f, 0.7346f, 0.7502f, 0.763f, 38 | 0.7756f, 0.7879f, 0.8f, 0.8107f, 0.8212f, 0.8326f, 0.8415f, 0.8503f, 0.8588f, 0.8672f, 39 | 0.8754f, 0.8833f, 0.8911f, 0.8977f, 0.9041f, 0.9113f, 0.9165f, 0.9232f, 0.9281f, 0.9328f, 40 | 0.9382f, 0.9434f, 0.9476f, 0.9518f, 0.9557f, 0.9596f, 0.9632f, 0.9662f, 0.9695f, 0.9722f, 41 | 0.9753f, 0.9777f, 0.9805f, 0.9826f, 0.9847f, 0.9866f, 0.9884f, 0.9901f, 0.9917f, 0.9931f, 42 | 0.9944f, 0.9955f, 0.9964f, 0.9973f, 0.9981f, 0.9986f, 0.9992f, 0.9995f, 0.9998f, 1.0f, 1.0f 43 | }; 44 | 45 | private static final float STEP_SIZE = 1.0f / (VALUES.length - 1); 46 | 47 | @Override 48 | public float getInterpolation(float input) { 49 | if (input >= 1.0f) { 50 | return 1.0f; 51 | } 52 | 53 | if (input <= 0f) { 54 | return 0f; 55 | } 56 | 57 | int position = Math.min( 58 | (int)(input * (VALUES.length - 1)), 59 | VALUES.length - 2); 60 | 61 | float quantized = position * STEP_SIZE; 62 | float difference = input - quantized; 63 | float weight = difference / STEP_SIZE; 64 | 65 | return VALUES[position] + weight * (VALUES[position + 1] - VALUES[position]); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingle/widget/LoadingToolBar.java: -------------------------------------------------------------------------------- 1 | package com.mingle.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.Canvas; 6 | import android.support.v7.widget.Toolbar; 7 | import android.util.AttributeSet; 8 | import android.util.DisplayMetrics; 9 | 10 | /** 11 | * Created by zzz40500 on 15/9/21. 12 | */ 13 | public class LoadingToolBar extends Toolbar { 14 | 15 | 16 | private SwipeProgressBar mProgressBar; 17 | private int mProgressBarHeight; 18 | private static final float PROGRESS_BAR_HEIGHT = 4; 19 | private boolean mRefreshing; 20 | private PopupIndicator mPopupIndicator; 21 | 22 | 23 | public LoadingToolBar(Context context) { 24 | super(context); 25 | init(); 26 | } 27 | 28 | 29 | 30 | public LoadingToolBar(Context context, AttributeSet attrs) { 31 | super(context, attrs); 32 | init(); 33 | } 34 | 35 | public LoadingToolBar(Context context, AttributeSet attrs, int defStyleAttr) { 36 | super(context, attrs, defStyleAttr); 37 | init(); 38 | } 39 | 40 | private void init() { 41 | setWillNotDraw(false); 42 | //progressbar 生成 43 | mProgressBar = new SwipeProgressBar(this); 44 | final DisplayMetrics metrics = getResources().getDisplayMetrics(); 45 | 46 | //bar 的高度 47 | mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT); 48 | mPopupIndicator=new PopupIndicator(getContext()); 49 | } 50 | 51 | 52 | 53 | /** 54 | * Notify the widget that refresh state has changed. Do not call this when 55 | * refresh is triggered by a swipe gesture. 56 | * 57 | * @param refreshing Whether or not the view should show refresh progress. 58 | */ 59 | public void setRefreshing(boolean refreshing) { 60 | if (mRefreshing != refreshing) { 61 | mRefreshing = refreshing; 62 | if (mRefreshing) { 63 | mPopupIndicator.showIndicator(this); 64 | // mProgressBar.start(); 65 | } else { 66 | mPopupIndicator.dismissIndicator(); 67 | // mProgressBar.stop(); 68 | } 69 | } 70 | } 71 | 72 | 73 | /** 74 | * Set the four colors used in the progress animation. The first color will 75 | * also be the color of the bar that grows in response to a user swipe 76 | * gesture. 77 | * 78 | * @param colorRes1 Color resource. 79 | * @param colorRes2 Color resource. 80 | * @param colorRes3 Color resource. 81 | * @param colorRes4 Color resource. 82 | */ 83 | public void setColorScheme(int colorRes1, int colorRes2, int colorRes3, int colorRes4) { 84 | final Resources res = getResources(); 85 | final int color1 = res.getColor(colorRes1); 86 | final int color2 = res.getColor(colorRes2); 87 | final int color3 = res.getColor(colorRes3); 88 | final int color4 = res.getColor(colorRes4); 89 | mProgressBar.setColorScheme(color1, color2, color3, color4); 90 | mPopupIndicator.setColorScheme(color1, color2, color3, color4); 91 | } 92 | public void draw(Canvas canvas) { 93 | super.draw(canvas); 94 | mProgressBar.draw(canvas); 95 | } 96 | @Override 97 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 98 | final int width = getMeasuredWidth(); 99 | final int height = getMeasuredHeight(); 100 | mProgressBar.setBounds(0, height-mProgressBarHeight, width, height); 101 | super.onLayout(changed,left,top,right,bottom); 102 | } 103 | 104 | 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingle/widget/PopupIndicator.java: -------------------------------------------------------------------------------- 1 | package com.mingle.widget; 2 | 3 | import android.content.Context; 4 | import android.graphics.PixelFormat; 5 | import android.graphics.Point; 6 | import android.os.IBinder; 7 | import android.support.v4.view.GravityCompat; 8 | import android.util.DisplayMetrics; 9 | import android.view.Gravity; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.view.WindowManager; 13 | 14 | /** 15 | * Created by zzz40500 on 15/9/25. 16 | */ 17 | public class PopupIndicator implements SwipeProgressBar.AnimListener { 18 | 19 | 20 | 21 | private final WindowManager mWindowManager; 22 | private boolean mShowing; 23 | Point screenSize = new Point(); 24 | private int[] mDrawingLocation = new int[2]; 25 | 26 | private SwipeProgressView mSwipeProgressView; 27 | 28 | 29 | 30 | public PopupIndicator(Context context) { 31 | mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 32 | DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); 33 | screenSize.set(displayMetrics.widthPixels, displayMetrics.heightPixels); 34 | mSwipeProgressView=new SwipeProgressView(context); 35 | mSwipeProgressView.setOnAnimListener(this); 36 | } 37 | public boolean isShowing() { 38 | return mShowing; 39 | } 40 | 41 | 42 | public void showIndicator(View parent) { 43 | if (isShowing()) { 44 | // mPopupView.mMarker.animateOpen(); 45 | return; 46 | } 47 | 48 | IBinder windowToken = parent.getWindowToken(); 49 | 50 | if (windowToken != null) { 51 | WindowManager.LayoutParams p = createPopupLayout(windowToken); 52 | 53 | p.gravity = Gravity.TOP | GravityCompat.START; 54 | updateLayoutParamsForPosiion(parent, p); 55 | mShowing = true; 56 | invokePopup(p); 57 | } 58 | 59 | } 60 | 61 | public void dismissIndicator(){ 62 | 63 | mSwipeProgressView. 64 | setRefreshing(false); 65 | 66 | } 67 | 68 | 69 | private void measureFloater() { 70 | int specWidth = View.MeasureSpec.makeMeasureSpec(screenSize.x, View.MeasureSpec.EXACTLY); 71 | int specHeight = View.MeasureSpec.makeMeasureSpec(screenSize.y, View.MeasureSpec.AT_MOST); 72 | mSwipeProgressView.measure(specWidth, specHeight); 73 | } 74 | 75 | private void invokePopup(WindowManager.LayoutParams p) { 76 | mWindowManager.addView(mSwipeProgressView, p); 77 | mSwipeProgressView. 78 | setRefreshing(true); 79 | } 80 | private void updateLayoutParamsForPosiion(View anchor, WindowManager.LayoutParams p) { 81 | // measureFloater(); 82 | int measuredHeight = mSwipeProgressView.getMeasuredHeight(); 83 | anchor.getLocationInWindow(mDrawingLocation); 84 | p.x = 0; 85 | p.y = mDrawingLocation[1]+anchor.getMeasuredHeight() ; 86 | p.width = screenSize.x; 87 | p.height = 12; 88 | 89 | 90 | } 91 | 92 | 93 | private WindowManager.LayoutParams createPopupLayout(IBinder token) { 94 | WindowManager.LayoutParams p = new WindowManager.LayoutParams(); 95 | p.gravity = Gravity.START | Gravity.TOP; 96 | p.width = ViewGroup.LayoutParams.MATCH_PARENT; 97 | p.height = ViewGroup.LayoutParams.MATCH_PARENT; 98 | p.format = PixelFormat.TRANSLUCENT; 99 | p.flags = computeFlags(p.flags); 100 | p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; 101 | p.token = token; 102 | p.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN; 103 | return p; 104 | } 105 | 106 | /** 107 | * I'm NOT completely sure how all this bitwise things work... 108 | * 109 | * @param curFlags 110 | * @return 111 | */ 112 | private int computeFlags(int curFlags) { 113 | curFlags &= ~( 114 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES | 115 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | 116 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | 117 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | 118 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | 119 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 120 | curFlags |= WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES; 121 | curFlags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 122 | curFlags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; 123 | curFlags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; 124 | return curFlags; 125 | } 126 | 127 | 128 | @Override 129 | public void onStart() { 130 | 131 | } 132 | 133 | @Override 134 | public void onStop() { 135 | mShowing = false; 136 | if(mSwipeProgressView.getParent()!= null) { 137 | mWindowManager.removeView(mSwipeProgressView); 138 | } 139 | } 140 | 141 | void setColorScheme(int color1, int color2, int color3, int color4) { 142 | mSwipeProgressView.setColorScheme(color1, color2, color3, color4); 143 | 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingle/widget/SwipeProgressBar.java: -------------------------------------------------------------------------------- 1 | package com.mingle.widget; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Color; 5 | import android.graphics.Paint; 6 | import android.graphics.Rect; 7 | import android.graphics.RectF; 8 | import android.support.v4.view.ViewCompat; 9 | import android.view.View; 10 | import android.view.animation.AnimationUtils; 11 | import android.view.animation.Interpolator; 12 | 13 | 14 | /** 15 | * Custom progress bar that shows a cycle of colors as widening circles that 16 | * overdraw each other. When finished, the bar is cleared from the inside out as 17 | * the main cycle continues. Before running, this can also indicate how close 18 | * the user is to triggering something (e.g. how far they need to pull down to 19 | * trigger a refresh). 20 | */ 21 | public class SwipeProgressBar { 22 | 23 | // Default progress animation colors are grays. 24 | private final static int COLOR1 = 0xB3000000; 25 | private final static int COLOR2 = 0x80000000; 26 | private final static int COLOR3 = 0x4d000000; 27 | private final static int COLOR4 = 0x1a000000; 28 | 29 | // The duration of the animation cycle. 30 | private static final int ANIMATION_DURATION_MS = 2000; 31 | 32 | // The duration of the animation to clear the bar. 33 | private static final int FINISH_ANIMATION_DURATION_MS = 1000; 34 | 35 | // Interpolator for varying the speed of the animation. 36 | private static final Interpolator INTERPOLATOR = BakedBezierInterpolator.getInstance(); 37 | 38 | private final Paint mPaint = new Paint(); 39 | private final RectF mClipRect = new RectF(); 40 | private float mTriggerPercentage; 41 | private long mStartTime; 42 | private long mFinishTime; 43 | private boolean mRunning; 44 | private AnimListener mAnimListener; 45 | 46 | // Colors used when rendering the animation, 47 | private int mColor1; 48 | private int mColor2; 49 | private int mColor3; 50 | private int mColor4; 51 | private View mParent; 52 | 53 | private Rect mBounds = new Rect(); 54 | 55 | public SwipeProgressBar(View parent) { 56 | mParent = parent; 57 | mColor1 = COLOR1; 58 | mColor2 = COLOR2; 59 | mColor3 = COLOR3; 60 | mColor4 = COLOR4; 61 | } 62 | 63 | /** 64 | * Set the four colors used in the progress animation. The first color will 65 | * also be the color of the bar that grows in response to a user swipe 66 | * gesture. 67 | * 68 | * @param color1 Integer representation of a color. 69 | * @param color2 Integer representation of a color. 70 | * @param color3 Integer representation of a color. 71 | * @param color4 Integer representation of a color. 72 | */ 73 | void setColorScheme(int color1, int color2, int color3, int color4) { 74 | mColor1 = color1; 75 | mColor2 = color2; 76 | mColor3 = color3; 77 | mColor4 = color4; 78 | } 79 | 80 | /** 81 | * Update the progress the user has made toward triggering the swipe 82 | * gesture. and use this value to update the percentage of the trigger that 83 | * is shown. 84 | */ 85 | void setTriggerPercentage(float triggerPercentage) { 86 | mTriggerPercentage = triggerPercentage; 87 | mStartTime = 0; 88 | ViewCompat.postInvalidateOnAnimation(mParent); 89 | } 90 | 91 | /** 92 | * Start showing the progress animation. 93 | */ 94 | void start() { 95 | if (!mRunning) { 96 | mTriggerPercentage = 0; 97 | mStartTime = AnimationUtils.currentAnimationTimeMillis(); 98 | mRunning = true; 99 | if(mAnimListener != null){ 100 | mAnimListener.onStart(); 101 | } 102 | mParent.postInvalidate(); 103 | } 104 | } 105 | 106 | /** 107 | * Stop showing the progress animation. 108 | */ 109 | void stop() { 110 | if (mRunning) { 111 | mTriggerPercentage = 0; 112 | mFinishTime = AnimationUtils.currentAnimationTimeMillis(); 113 | mRunning = false; 114 | mParent.postInvalidate(); 115 | } 116 | } 117 | 118 | /** 119 | * @return Return whether the progress animation is currently running. 120 | */ 121 | boolean isRunning() { 122 | return mRunning || mFinishTime > 0; 123 | } 124 | 125 | void draw(Canvas canvas) { 126 | final int width = mBounds.width(); 127 | final int height = mBounds.height(); 128 | final int cx = width / 2; 129 | final int cy = mBounds.top+height / 2; 130 | boolean drawTriggerWhileFinishing = false; 131 | int restoreCount = canvas.save(); 132 | canvas.clipRect(mBounds); 133 | 134 | if (mRunning || (mFinishTime > 0)) { 135 | long now = AnimationUtils.currentAnimationTimeMillis(); 136 | long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS; 137 | long iterations = (now - mStartTime) / ANIMATION_DURATION_MS; 138 | float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f)); 139 | 140 | // If we're not running anymore, that means we're running through 141 | // the finish animation. 142 | if (!mRunning) { 143 | // If the finish animation is done, don't draw anything, and 144 | // don't repost. 145 | if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) { 146 | mFinishTime = 0; 147 | if(mAnimListener != null){ 148 | mAnimListener.onStop(); 149 | } 150 | return; 151 | } 152 | 153 | // Otherwise, use a 0 opacity alpha layer to clear the animation 154 | // from the inside out. This layer will prevent the circles from 155 | // drawing within its bounds. 156 | long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS; 157 | float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f)); 158 | float pct = (finishProgress / 100f); 159 | // Radius of the circle is half of the screen. 160 | float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct); 161 | mClipRect.set(cx - clearRadius, mBounds.top, cx + clearRadius, mBounds.bottom); 162 | canvas.saveLayerAlpha(mClipRect, 0, 0); 163 | 164 | // Only draw the trigger if there is a space in the center of 165 | // this refreshing view that needs to be filled in by the 166 | // trigger. If the progress view is just still animating, let it 167 | // continue animating. 168 | drawTriggerWhileFinishing = true; 169 | } 170 | 171 | // First fill in with the last color that would have finished drawing. 172 | if (iterations == 0) { 173 | canvas.drawColor(mColor1); 174 | } else { 175 | if (rawProgress >= 0 && rawProgress < 25) { 176 | canvas.drawColor(mColor4); 177 | } else if (rawProgress >= 25 && rawProgress < 50) { 178 | canvas.drawColor(mColor1); 179 | } else if (rawProgress >= 50 && rawProgress < 75) { 180 | canvas.drawColor(mColor2); 181 | } else { 182 | canvas.drawColor(mColor3); 183 | } 184 | } 185 | 186 | // Then draw up to 4 overlapping concentric circles of varying radii, based on how far 187 | // along we are in the cycle. 188 | // progress 0-50 draw mColor2 189 | // progress 25-75 draw mColor3 190 | // progress 50-100 draw mColor4 191 | // progress 75 (wrap to 25) draw mColor1 192 | if ((rawProgress >= 0 && rawProgress <= 25)) { 193 | float pct = (((rawProgress + 25) * 2) / 100f); 194 | drawCircle(canvas, cx, cy, mColor1, pct); 195 | } 196 | if (rawProgress >= 0 && rawProgress <= 50) { 197 | float pct = ((rawProgress * 2) / 100f); 198 | drawCircle(canvas, cx, cy, mColor2, pct); 199 | } 200 | if (rawProgress >= 25 && rawProgress <= 75) { 201 | float pct = (((rawProgress - 25) * 2) / 100f); 202 | drawCircle(canvas, cx, cy, mColor3, pct); 203 | } 204 | if (rawProgress >= 50 && rawProgress <= 100) { 205 | float pct = (((rawProgress - 50) * 2) / 100f); 206 | drawCircle(canvas, cx, cy, mColor4, pct); 207 | } 208 | if ((rawProgress >= 75 && rawProgress <= 100)) { 209 | float pct = (((rawProgress - 75) * 2) / 100f); 210 | drawCircle(canvas, cx, cy, mColor1, pct); 211 | } 212 | if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) { 213 | // There is some portion of trigger to draw. Restore the canvas, 214 | // then draw the trigger. Otherwise, the trigger does not appear 215 | // until after the bar has finished animating and appears to 216 | // just jump in at a larger width than expected. 217 | canvas.restoreToCount(restoreCount); 218 | restoreCount = canvas.save(); 219 | canvas.clipRect(mBounds); 220 | drawTrigger(canvas, cx, cy); 221 | } 222 | // Keep running until we finish out the last cycle. 223 | ViewCompat.postInvalidateOnAnimation(mParent); 224 | } else { 225 | // Otherwise if we're in the middle of a trigger, draw that. 226 | if (mTriggerPercentage > 0 227 | && mTriggerPercentage <= 1.0 228 | ) { 229 | mPaint.setColor(mColor1); 230 | drawTrigger(canvas, cx, cy); 231 | } else if (mTriggerPercentage > 1) { 232 | 233 | mPaint.setColor(deepColor(mColor1)); 234 | drawTrigger(canvas, cx, cy); 235 | } 236 | } 237 | canvas.restoreToCount(restoreCount); 238 | } 239 | 240 | private void drawTrigger(Canvas canvas, int cx, int cy) { 241 | mPaint.setColor(mColor1); 242 | canvas.drawCircle(cx, cy, cx * mTriggerPercentage, mPaint); 243 | } 244 | 245 | private int deepColor(int color) { 246 | int red = Color.red(color); 247 | int nextRed = (int) (red + 99 * (mTriggerPercentage - 1)); 248 | if (nextRed > 0xff) { 249 | red = 0xff; 250 | } else { 251 | red = nextRed; 252 | } 253 | int green = Color.green(color); 254 | int nextGreen = (int) (green + 99 * (mTriggerPercentage - 1)); 255 | if (nextRed > 0xff) { 256 | green = 0xff; 257 | } else { 258 | green = nextGreen; 259 | } 260 | 261 | int blue = Color.blue(color); 262 | int nextBlue = (int) (blue + 99 * (mTriggerPercentage - 1)); 263 | if (nextRed > 0xff) { 264 | blue = 0xff; 265 | } else { 266 | blue = nextBlue; 267 | } 268 | 269 | 270 | return Color.argb(Color.alpha(color), red, green, blue); 271 | } 272 | 273 | 274 | /** 275 | * Draws a circle centered in the view. 276 | * 277 | * @param canvas the canvas to draw on 278 | * @param cx the center x coordinate 279 | * @param cy the center y coordinate 280 | * @param color the color to draw 281 | * @param pct the percentage of the view that the circle should cover 282 | */ 283 | private void drawCircle(Canvas canvas, float cx, float cy, int color, float pct) { 284 | mPaint.setColor(color); 285 | canvas.save(); 286 | canvas.translate(cx, cy); 287 | float radiusScale = INTERPOLATOR.getInterpolation(pct); 288 | canvas.scale(radiusScale, radiusScale); 289 | canvas.drawCircle(0, 0, cx, mPaint); 290 | canvas.restore(); 291 | } 292 | 293 | /** 294 | * Set the drawing bounds of this SwipeProgressBar. 295 | */ 296 | void setBounds(int left, int top, int right, int bottom) { 297 | mBounds.left = left; 298 | mBounds.top = top; 299 | mBounds.right = right; 300 | mBounds.bottom = bottom; 301 | } 302 | 303 | 304 | public void setOnAnimListener(AnimListener animListener) { 305 | mAnimListener = animListener; 306 | } 307 | 308 | public interface AnimListener{ 309 | void onStart(); 310 | void onStop(); 311 | } 312 | } -------------------------------------------------------------------------------- /app/src/main/java/com/mingle/widget/SwipeProgressView.java: -------------------------------------------------------------------------------- 1 | package com.mingle.widget; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.graphics.Canvas; 6 | import android.os.Build; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | 10 | /** 11 | * Created by zzz40500 on 15/9/24. 12 | */ 13 | public class SwipeProgressView extends View { 14 | 15 | 16 | private SwipeProgressBar mProgressBar; 17 | private boolean mRefreshing; 18 | public SwipeProgressView(Context context) { 19 | super(context); 20 | init(); 21 | } 22 | 23 | private void init() { 24 | setWillNotDraw(false); 25 | mProgressBar = new SwipeProgressBar(this); 26 | } 27 | 28 | public SwipeProgressView(Context context, AttributeSet attrs) { 29 | super(context, attrs); 30 | init(); 31 | } 32 | 33 | public SwipeProgressView(Context context, AttributeSet attrs, int defStyleAttr) { 34 | super(context, attrs, defStyleAttr); 35 | init(); 36 | } 37 | 38 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 39 | public SwipeProgressView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 40 | super(context, attrs, defStyleAttr, defStyleRes); 41 | init(); 42 | } 43 | 44 | 45 | @Override 46 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 47 | 48 | 49 | MeasureSpec.getMode(heightMeasureSpec); 50 | 51 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 52 | } 53 | 54 | @Override 55 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 56 | super.onSizeChanged(w, h, oldw, oldh); 57 | mProgressBar.setBounds(0, 0, w, h); 58 | } 59 | 60 | public void draw(Canvas canvas) { 61 | super.draw(canvas); 62 | mProgressBar.draw(canvas); 63 | } 64 | 65 | /** 66 | * Notify the widget that refresh state has changed. Do not call this when 67 | * refresh is triggered by a swipe gesture. 68 | * 69 | * @param refreshing Whether or not the view should show refresh progress. 70 | */ 71 | public void setRefreshing(boolean refreshing) { 72 | if (mRefreshing != refreshing) { 73 | mRefreshing = refreshing; 74 | if (mRefreshing) { 75 | mProgressBar.start(); 76 | } else { 77 | mProgressBar.stop(); 78 | } 79 | } 80 | } 81 | 82 | /** 83 | * Set the four colors used in the progress animation. The first color will 84 | * also be the color of the bar that grows in response to a user swipe 85 | * gesture. 86 | * 87 | * @param colorRes1 Color resource. 88 | * @param colorRes2 Color resource. 89 | * @param colorRes3 Color resource. 90 | * @param colorRes4 Color resource. 91 | */ 92 | public void setColorScheme(int colorRes1, int colorRes2, int colorRes3, int colorRes4) { 93 | mProgressBar.setColorScheme(colorRes1, colorRes2, colorRes3, colorRes4); 94 | } 95 | 96 | 97 | public void setOnAnimListener(SwipeProgressBar.AnimListener animListener) { 98 | mProgressBar.setOnAnimListener(animListener); 99 | } 100 | 101 | 102 | } 103 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_instagram.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 17 | 18 | 27 | 28 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 |