├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── canyinghao │ │ └── caneffect │ │ └── demo │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── canyinghao │ │ │ └── caneffect │ │ │ └── demo │ │ │ ├── App.java │ │ │ ├── model │ │ │ └── MainBean.java │ │ │ ├── ui │ │ │ ├── MainActivity.java │ │ │ ├── RippleActivity.java │ │ │ ├── ShadowActivity.java │ │ │ ├── ShapeActivity.java │ │ │ ├── WaterActivity.java │ │ │ └── XmlActivity.java │ │ │ └── view │ │ │ └── GameView.java │ └── res │ │ ├── drawable │ │ ├── gary_ball_shape.xml │ │ ├── red_ball_selector.xml │ │ ├── red_border_ball_shape.xml │ │ ├── round_shape.xml │ │ └── waterwave.xml │ │ ├── layout │ │ ├── activity_base.xml │ │ ├── activity_main.xml │ │ └── activity_xml.xml │ │ ├── menu │ │ └── menu_main.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 │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── canyinghao │ └── caneffect │ └── demo │ └── ExampleUnitTest.java ├── build.gradle ├── caneffect ├── .gitignore ├── bintray.gradle ├── build.gradle ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── canyinghao │ │ │ └── caneffect │ │ │ ├── CanCircularRevealLayout.java │ │ │ ├── CanRippleLayout.java │ │ │ ├── CanShadowDrawable.java │ │ │ ├── CanWaterWaveLayout.java │ │ │ └── ViewAnimationUtils.java │ └── res │ │ └── values │ │ ├── attrs_canripple.xml │ │ └── attrs_canwaterwave.xml │ └── test │ └── java │ └── com │ └── canyinghao │ └── caneffect │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pic └── CanEffect.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | /*/build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Eclipse project files 30 | .classpath 31 | .project 32 | .settings/ 33 | 34 | # Intellij project files 35 | *.iml 36 | *.ipr 37 | *.iws 38 | .idea/ 39 | 40 | # Mac system files 41 | .DS_Store 42 | -------------------------------------------------------------------------------- /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 | # CanEffect 2 | android效果库,阴影效果、水纹效果、波纹效果、圆形显示过渡效果等。 3 | 4 | 5 | ![](./pic/CanEffect.gif) 6 | 7 | ##添加依赖 8 | ```JAVA 9 | compile 'com.canyinghao:caneffect:1.0.3' 10 | ``` 11 | 12 | ## 使用方式 13 | **1. 实现方法** 14 | CanEffect是一个效果库,兼容至sdk11。很多效果都是继承FrameLayout,通过重写draw方法,画图绘制的。圆形显示过渡的效果,在sdk21及以上可使用系统自带的效果,以下是通过drawChild绘制的,但包装成了与系统相似的方法,用法一致。 15 | ```JAVA 16 | public final class ViewAnimationUtils { 17 | 18 | 19 | public static Animator createCircularReveal(View view, int centerX, int centerY, float startRadius, float endRadius) { 20 | 21 | 22 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 23 | return android.view.ViewAnimationUtils 24 | .createCircularReveal(view, centerX, centerY, startRadius, endRadius); 25 | } else { 26 | 27 | return CanCircularRevealLayout.Builder.on(view) 28 | .centerX(centerX) 29 | .centerY(centerY) 30 | .startRadius(startRadius) 31 | .endRadius(endRadius) 32 | .create(); 33 | 34 | 35 | } 36 | 37 | 38 | } 39 | 40 | 41 | } 42 | ``` 43 | **2. 使用方法** 44 | 其它的阴影效果、水纹效果、波纹效果,使用方法如出一辙。 45 | 一些使用中的坑: 46 | 1.不要给CanRippleLayout、CanWaterWaveLayout添加点击或长按事件,不然它的子view接受不到事件。 47 | 2.如果使用了CanAdapter库,并且使用的是CanRVAdapter类,不要将CanRippleLayout、CanWaterWaveLayout放在item的最外层,CanRVAdapter的item的最外层view默认给了一个点击一个长按事件。 48 | ```JAVA 49 | public class MainActivity extends AppCompatActivity { 50 | 51 | @Override 52 | protected void onCreate(Bundle savedInstanceState) { 53 | super.onCreate(savedInstanceState); 54 | setContentView(R.layout.activity_main); 55 | 56 | 57 | View view1 = findViewById(R.id.view1); 58 | View fl1 = findViewById(R.id.fl1); 59 | View view2 = findViewById(R.id.view2); 60 | View fl2 = findViewById(R.id.fl2); 61 | 62 | 63 | final View view3 = findViewById(R.id.view3); 64 | final View view4 = findViewById(R.id.view4); 65 | 66 | 67 | CanShadowDrawable.Builder.on(fl1) 68 | 69 | .radius(dp2Px(5)) 70 | .shadowColor(Color.parseColor("#333333")) 71 | 72 | .shadowRange(dp2Px(5)) 73 | .offsetTop(dp2Px(5)) 74 | .offsetBottom(dp2Px(5)) 75 | .offsetLeft(dp2Px(5)) 76 | .offsetRight(dp2Px(5)) 77 | .create(); 78 | 79 | CanRippleLayout.Builder.on(view1).rippleCorner(dp2Px(5)).create(); 80 | 81 | view1.setOnClickListener(new View.OnClickListener() { 82 | @Override 83 | public void onClick(View view) { 84 | Toast.makeText(getApplicationContext(), "onClick", Toast.LENGTH_SHORT).show(); 85 | } 86 | }); 87 | 88 | 89 | CanShadowDrawable.Builder.on(fl2) 90 | 91 | .radius(dp2Px(10)) 92 | .shadowColor(Color.parseColor("#333333")) 93 | 94 | .shadowRange(dp2Px(5)) 95 | // .offsetTop(dp2Px(5)) 96 | .offsetBottom(dp2Px(5)) 97 | .offsetLeft(dp2Px(5)) 98 | .offsetRight(dp2Px(5)) 99 | .create(); 100 | 101 | CanWaterWaveLayout.Builder.on(view2).create(); 102 | 103 | view2.setOnClickListener(new View.OnClickListener() { 104 | @Override 105 | public void onClick(View view) { 106 | Toast.makeText(getApplicationContext(), "onClick", Toast.LENGTH_SHORT).show(); 107 | } 108 | }); 109 | 110 | 111 | view3.setVisibility(View.GONE); 112 | view4.setOnClickListener(new View.OnClickListener() { 113 | @Override 114 | public void onClick(View view) { 115 | view4.setVisibility(View.GONE); 116 | view3.setVisibility(View.VISIBLE); 117 | 118 | 119 | Animator c1a = ViewAnimationUtils 120 | .createCircularReveal(view3, 0, 0, (int) dp2Px(100), 1000); 121 | 122 | 123 | c1a.setDuration(1000); 124 | c1a.setInterpolator(new AccelerateDecelerateInterpolator()); 125 | c1a.start(); 126 | 127 | } 128 | }); 129 | 130 | view3.setOnClickListener(new View.OnClickListener() { 131 | @Override 132 | public void onClick(View view) { 133 | 134 | 135 | Animator c1a = ViewAnimationUtils 136 | .createCircularReveal(view3, 0, 0, 1000, (int) dp2Px(100)); 137 | 138 | 139 | c1a.setDuration(1000); 140 | c1a.setInterpolator(new AccelerateDecelerateInterpolator()); 141 | c1a.start(); 142 | 143 | c1a.addListener(new Animator.AnimatorListener() { 144 | @Override 145 | public void onAnimationStart(Animator animator) { 146 | 147 | } 148 | 149 | @Override 150 | public void onAnimationEnd(Animator animator) { 151 | view3.setVisibility(View.GONE); 152 | view4.setVisibility(View.VISIBLE); 153 | } 154 | 155 | @Override 156 | public void onAnimationCancel(Animator animator) { 157 | 158 | } 159 | 160 | @Override 161 | public void onAnimationRepeat(Animator animator) { 162 | 163 | } 164 | }); 165 | } 166 | }); 167 | 168 | } 169 | 170 | 171 | float dp2Px(float dp) { 172 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()); 173 | } 174 | 175 | 176 | @Override 177 | public boolean onCreateOptionsMenu(Menu menu) { 178 | // Inflate the menu; this adds items to the action bar if it is present. 179 | getMenuInflater().inflate(R.menu.menu_main, menu); 180 | return true; 181 | } 182 | 183 | @Override 184 | public boolean onOptionsItemSelected(MenuItem item) { 185 | 186 | int id = item.getItemId(); 187 | 188 | 189 | switch (id) { 190 | 191 | case R.id.action_1: 192 | 193 | 194 | startActivity(new Intent(MainActivity.this, ShadowActivity.class)); 195 | 196 | break; 197 | case R.id.action_2: 198 | startActivity(new Intent(MainActivity.this, WaterActivity.class)); 199 | 200 | 201 | break; 202 | case R.id.action_3: 203 | startActivity(new Intent(MainActivity.this, RippleActivity.class)); 204 | break; 205 | case R.id.action_4: 206 | startActivity(new Intent(MainActivity.this, ShapeActivity.class)); 207 | break; 208 | 209 | case R.id.action_5: 210 | startActivity(new Intent(MainActivity.this, XmlActivity.class)); 211 | break; 212 | 213 | 214 | } 215 | 216 | return super.onOptionsItemSelected(item); 217 | } 218 | } 219 | ``` 220 | 221 | 222 | 223 | 224 | ### 开发者 225 | 226 | ![](https://avatars3.githubusercontent.com/u/12572840?v=3&s=460) 227 | 228 | canyinghao: 229 | 230 | 231 | 232 | [新浪微博](http://weibo.com/u/5670978460) 233 | 234 | [google+](https://plus.google.com/u/0/109542533436298291853) 235 | 236 | ### License 237 | 238 | Copyright 2016 canyinghao 239 | 240 | Licensed under the Apache License, Version 2.0 (the "License"); 241 | you may not use this file except in compliance with the License. 242 | You may obtain a copy of the License at 243 | 244 | http://www.apache.org/licenses/LICENSE-2.0 245 | 246 | Unless required by applicable law or agreed to in writing, software 247 | distributed under the License is distributed on an "AS IS" BASIS, 248 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 249 | See the License for the specific language governing permissions and 250 | limitations under the License. 251 | 252 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | buildToolsVersion "28.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.canyinghao.caneffect.demo" 9 | minSdkVersion 14 10 | targetSdkVersion 26 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 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | 25 | implementation 'androidx.appcompat:appcompat:1.1.0' 26 | implementation project(':caneffect') 27 | } 28 | -------------------------------------------------------------------------------- /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/yangjian/Documents/program/android-sdk-macosx/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/canyinghao/caneffect/demo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect.demo; 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 | 3 | 4 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/canyinghao/caneffect/demo/App.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect.demo; 2 | 3 | import android.app.Application; 4 | import android.widget.Toast; 5 | 6 | 7 | public class App extends Application { 8 | private static App sInstance; 9 | 10 | 11 | @Override 12 | public void onCreate() { 13 | super.onCreate(); 14 | 15 | sInstance = this; 16 | 17 | 18 | } 19 | 20 | public static App getInstance() { 21 | 22 | if (sInstance == null) { 23 | sInstance = new App(); 24 | } 25 | return sInstance; 26 | } 27 | 28 | 29 | public void show(String msg){ 30 | 31 | 32 | Toast.makeText(getApplicationContext(),msg,Toast.LENGTH_SHORT).show(); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /app/src/main/java/com/canyinghao/caneffect/demo/model/MainBean.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect.demo.model; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by yangjian on 16/1/21. 8 | */ 9 | public class MainBean { 10 | 11 | 12 | public String title ; 13 | public String content ; 14 | 15 | 16 | public static List getList(){ 17 | 18 | List list = new ArrayList<>(); 19 | 20 | 21 | for (int i = 0; i < 50; i++) { 22 | 23 | MainBean bean = new MainBean(); 24 | 25 | bean.title = "this is a canadapter title "+i; 26 | bean.content = "this is a canadapter content "+i; 27 | 28 | list.add(bean); 29 | 30 | } 31 | 32 | return list; 33 | 34 | } 35 | 36 | public static List getMainList(){ 37 | 38 | List list = new ArrayList<>(); 39 | 40 | 41 | MainBean bean1 = new MainBean(); 42 | bean1.title = "不可滚动的视图"; 43 | bean1.content = "TextView ImageView FrameLayout 等"; 44 | 45 | MainBean bean2 = new MainBean(); 46 | bean2.title = "可滚动的视图"; 47 | bean2.content = "ListView ScrollView GridView 等"; 48 | 49 | MainBean bean3 = new MainBean(); 50 | bean3.title = "RecyclerView"; 51 | bean3.content = "RecyclerView的各种刷新方式"; 52 | 53 | // MainBean bean4 = new MainBean(); 54 | // bean4.title = "自定义"; 55 | // bean4.content = "自定义刷新方式"; 56 | 57 | 58 | list.add(bean1); 59 | list.add(bean2); 60 | list.add(bean3); 61 | // list.add(bean4); 62 | 63 | 64 | return list; 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/canyinghao/caneffect/demo/ui/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect.demo.ui; 2 | 3 | 4 | import android.animation.Animator; 5 | import android.content.Intent; 6 | import android.graphics.Color; 7 | import android.os.Bundle; 8 | import android.util.TypedValue; 9 | import android.view.Menu; 10 | import android.view.MenuItem; 11 | import android.view.View; 12 | import android.view.animation.AccelerateDecelerateInterpolator; 13 | import android.widget.Toast; 14 | 15 | import com.canyinghao.caneffect.CanRippleLayout; 16 | import com.canyinghao.caneffect.CanShadowDrawable; 17 | import com.canyinghao.caneffect.CanWaterWaveLayout; 18 | import com.canyinghao.caneffect.ViewAnimationUtils; 19 | import com.canyinghao.caneffect.demo.R; 20 | 21 | import androidx.appcompat.app.AppCompatActivity; 22 | 23 | 24 | /** 25 | * Created by yangjian on 16/1/25. 26 | */ 27 | public class MainActivity extends AppCompatActivity { 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_main); 33 | 34 | 35 | 36 | View view1 = findViewById(R.id.view1); 37 | View fl1 = findViewById(R.id.fl1); 38 | View view2 = findViewById(R.id.view2); 39 | View fl2 = findViewById(R.id.fl2); 40 | 41 | 42 | final View view3 = findViewById(R.id.view3); 43 | final View view4 = findViewById(R.id.view4); 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | CanShadowDrawable.Builder.on(fl1) 52 | 53 | .radius(dp2Px(5)) 54 | .shadowColor(Color.parseColor("#333333")) 55 | 56 | .shadowRange(dp2Px(5)) 57 | .offsetTop(dp2Px(5)) 58 | .offsetBottom(dp2Px(5)) 59 | .offsetLeft(dp2Px(5)) 60 | .offsetRight(dp2Px(5)) 61 | .create(); 62 | 63 | CanRippleLayout.Builder.on(view1).rippleCorner(dp2Px(5)).create(); 64 | 65 | view1.setOnClickListener(new View.OnClickListener() { 66 | @Override 67 | public void onClick(View view) { 68 | Toast.makeText(getApplicationContext(), "onClick", Toast.LENGTH_SHORT).show(); 69 | } 70 | }); 71 | 72 | 73 | CanShadowDrawable.Builder.on(fl2) 74 | 75 | .radius(dp2Px(10)) 76 | .shadowColor(Color.parseColor("#333333")) 77 | 78 | .shadowRange(dp2Px(5)) 79 | // .offsetTop(dp2Px(5)) 80 | .offsetBottom(dp2Px(5)) 81 | .offsetLeft(dp2Px(5)) 82 | .offsetRight(dp2Px(5)) 83 | .create(); 84 | 85 | CanWaterWaveLayout.Builder.on(view2).create(); 86 | 87 | view2.setOnClickListener(new View.OnClickListener() { 88 | @Override 89 | public void onClick(View view) { 90 | Toast.makeText(getApplicationContext(), "onClick", Toast.LENGTH_SHORT).show(); 91 | } 92 | }); 93 | 94 | 95 | view3.setVisibility(View.GONE); 96 | view4.setOnClickListener(new View.OnClickListener() { 97 | @Override 98 | public void onClick(View view) { 99 | view4.setVisibility(View.GONE); 100 | view3.setVisibility(View.VISIBLE); 101 | 102 | 103 | 104 | Animator c1a = ViewAnimationUtils 105 | .createCircularReveal(view3, 0, 0, (int) dp2Px(100), 1000); 106 | 107 | 108 | 109 | c1a.setDuration(1000); 110 | c1a.setInterpolator(new AccelerateDecelerateInterpolator()); 111 | c1a.start(); 112 | 113 | } 114 | }); 115 | 116 | view3.setOnClickListener(new View.OnClickListener() { 117 | @Override 118 | public void onClick(View view) { 119 | 120 | 121 | 122 | 123 | Animator c1a = ViewAnimationUtils 124 | .createCircularReveal(view3, 0, 0, 1000, (int) dp2Px(100)); 125 | 126 | 127 | 128 | c1a.setDuration(1000); 129 | c1a.setInterpolator(new AccelerateDecelerateInterpolator()); 130 | c1a.start(); 131 | 132 | c1a.addListener(new Animator.AnimatorListener() { 133 | @Override 134 | public void onAnimationStart(Animator animator) { 135 | 136 | } 137 | 138 | @Override 139 | public void onAnimationEnd(Animator animator) { 140 | view3.setVisibility(View.GONE); 141 | view4.setVisibility(View.VISIBLE); 142 | } 143 | 144 | @Override 145 | public void onAnimationCancel(Animator animator) { 146 | 147 | } 148 | 149 | @Override 150 | public void onAnimationRepeat(Animator animator) { 151 | 152 | } 153 | }); 154 | } 155 | }); 156 | 157 | } 158 | 159 | 160 | float dp2Px(float dp) { 161 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()); 162 | } 163 | 164 | 165 | 166 | @Override 167 | public boolean onCreateOptionsMenu(Menu menu) { 168 | // Inflate the menu; this adds items to the action bar if it is present. 169 | getMenuInflater().inflate(R.menu.menu_main, menu); 170 | return true; 171 | } 172 | 173 | @Override 174 | public boolean onOptionsItemSelected(MenuItem item) { 175 | 176 | int id = item.getItemId(); 177 | 178 | 179 | switch (id) { 180 | 181 | case R.id.action_1: 182 | 183 | 184 | startActivity(new Intent(MainActivity.this,ShadowActivity.class)); 185 | 186 | break; 187 | case R.id.action_2: 188 | startActivity(new Intent(MainActivity.this,WaterActivity.class)); 189 | 190 | 191 | break; 192 | case R.id.action_3: 193 | startActivity(new Intent(MainActivity.this,RippleActivity.class)); 194 | break; 195 | case R.id.action_4: 196 | startActivity(new Intent(MainActivity.this,ShapeActivity.class)); 197 | break; 198 | 199 | case R.id.action_5: 200 | startActivity(new Intent(MainActivity.this,XmlActivity.class)); 201 | break; 202 | 203 | 204 | } 205 | 206 | return super.onOptionsItemSelected(item); 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /app/src/main/java/com/canyinghao/caneffect/demo/ui/RippleActivity.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect.demo.ui; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | import android.widget.Toast; 6 | 7 | import com.canyinghao.caneffect.CanRippleLayout; 8 | import com.canyinghao.caneffect.demo.R; 9 | 10 | import androidx.appcompat.app.AppCompatActivity; 11 | 12 | /** 13 | * Created by yangjian on 16/2/2. 14 | */ 15 | public class RippleActivity extends AppCompatActivity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_base); 21 | View view1 = findViewById(R.id.view1); 22 | View view2 = findViewById(R.id.view2); 23 | View view3 = findViewById(R.id.view3); 24 | View view4 = findViewById(R.id.view4); 25 | View fl1 = findViewById(R.id.fl1); 26 | 27 | 28 | CanRippleLayout.Builder.on(view1).create(); 29 | CanRippleLayout.Builder.on(view2).rippleCorner(dp2Px(5)).create(); 30 | CanRippleLayout.Builder.on(fl1).create(); 31 | 32 | 33 | view1.setOnClickListener(new View.OnClickListener() { 34 | @Override 35 | public void onClick(View view) { 36 | Toast.makeText(getApplicationContext(), "onClick", Toast.LENGTH_SHORT).show(); 37 | } 38 | }); 39 | view1.setOnLongClickListener(new View.OnLongClickListener() { 40 | @Override 41 | public boolean onLongClick(View view) { 42 | 43 | Toast.makeText(getApplicationContext(), "OnLongClick", Toast.LENGTH_SHORT).show(); 44 | 45 | return true; 46 | } 47 | }); 48 | 49 | view2.setOnClickListener(new View.OnClickListener() { 50 | @Override 51 | public void onClick(View view) { 52 | Toast.makeText(getApplicationContext(), "onClick", Toast.LENGTH_SHORT).show(); 53 | } 54 | }); 55 | 56 | view3.setOnClickListener(new View.OnClickListener() { 57 | @Override 58 | public void onClick(View view) { 59 | Toast.makeText(getApplicationContext(), "onClick", Toast.LENGTH_SHORT).show(); 60 | } 61 | }); 62 | 63 | view4.setOnClickListener(new View.OnClickListener() { 64 | @Override 65 | public void onClick(View view) { 66 | Toast.makeText(getApplicationContext(), "have clickListener", Toast.LENGTH_SHORT).show(); 67 | } 68 | }); 69 | 70 | 71 | 72 | } 73 | 74 | 75 | public int dp2Px(float dpValue) { 76 | final float scale = getResources().getDisplayMetrics().density; 77 | return (int) (dpValue * scale + 0.5f); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/canyinghao/caneffect/demo/ui/ShadowActivity.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect.demo.ui; 2 | 3 | import android.graphics.Color; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | 7 | import com.canyinghao.caneffect.CanShadowDrawable; 8 | import com.canyinghao.caneffect.demo.R; 9 | 10 | import androidx.appcompat.app.AppCompatActivity; 11 | 12 | /** 13 | * Created by yangjian on 16/2/2. 14 | */ 15 | public class ShadowActivity extends AppCompatActivity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_base); 21 | View view1 = findViewById(R.id.view1); 22 | View view2 = findViewById(R.id.view2); 23 | 24 | findViewById(R.id.fl1).setVisibility(View.GONE); 25 | 26 | 27 | 28 | 29 | CanShadowDrawable.Builder.on(view1) 30 | .bgColor(getResources().getColor(R.color.colorPrimaryDark)) 31 | 32 | .shadowColor(Color.parseColor("#000000")) 33 | 34 | .shadowRange(dp2Px(5)) 35 | 36 | .offsetBottom(dp2Px(5)) 37 | .offsetLeft(dp2Px(5)) 38 | .offsetRight(dp2Px(5)) 39 | .create(); 40 | 41 | 42 | CanShadowDrawable.Builder.on(view2) 43 | .bgColor(getResources().getColor(R.color.colorPrimaryDark)) 44 | .radius(dp2Px(5)) 45 | .shadowColor(Color.parseColor("#aa000000")) 46 | 47 | .corners(CanShadowDrawable.CORNER_TOP_RIGHT|CanShadowDrawable.CORNER_TOP_LEFT) 48 | .shadowRange(dp2Px(5)) 49 | .offsetTop(dp2Px(5)) 50 | .offsetBottom(dp2Px(5)) 51 | .offsetLeft(dp2Px(5)) 52 | .offsetRight(dp2Px(5)) 53 | .create(); 54 | 55 | 56 | } 57 | 58 | public int dp2Px(float dpValue) { 59 | final float scale = getResources().getDisplayMetrics().density; 60 | return (int) (dpValue * scale + 0.5f); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/canyinghao/caneffect/demo/ui/ShapeActivity.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect.demo.ui; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.canyinghao.caneffect.demo.view.GameView; 6 | 7 | import androidx.appcompat.app.AppCompatActivity; 8 | 9 | /** 10 | * Created by yangjian on 16/2/2. 11 | */ 12 | public class ShapeActivity extends AppCompatActivity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | GameView gv = new GameView(this); 18 | 19 | setContentView(gv); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/canyinghao/caneffect/demo/ui/WaterActivity.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect.demo.ui; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | import android.widget.Toast; 6 | 7 | import com.canyinghao.caneffect.CanWaterWaveLayout; 8 | import com.canyinghao.caneffect.demo.R; 9 | 10 | import androidx.appcompat.app.AppCompatActivity; 11 | 12 | /** 13 | * Created by yangjian on 16/2/2. 14 | */ 15 | public class WaterActivity extends AppCompatActivity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_base); 21 | View view1 = findViewById(R.id.view1); 22 | View view2 = findViewById(R.id.view2); 23 | View view3 = findViewById(R.id.view3); 24 | View view4 = findViewById(R.id.view4); 25 | View fl1 = findViewById(R.id.fl1); 26 | 27 | 28 | CanWaterWaveLayout.Builder.on(view1).create(); 29 | CanWaterWaveLayout.Builder.on(view2).waterRadius(dp2Px(5)).create(); 30 | CanWaterWaveLayout.Builder.on(fl1).create(); 31 | 32 | 33 | view1.setOnClickListener(new View.OnClickListener() { 34 | @Override 35 | public void onClick(View view) { 36 | Toast.makeText(getApplicationContext(), "onClick", Toast.LENGTH_SHORT).show(); 37 | } 38 | }); 39 | view1.setOnLongClickListener(new View.OnLongClickListener() { 40 | @Override 41 | public boolean onLongClick(View view) { 42 | 43 | Toast.makeText(getApplicationContext(), "OnLongClick", Toast.LENGTH_SHORT).show(); 44 | 45 | return true; 46 | } 47 | }); 48 | 49 | view2.setOnClickListener(new View.OnClickListener() { 50 | @Override 51 | public void onClick(View view) { 52 | Toast.makeText(getApplicationContext(), "onClick", Toast.LENGTH_SHORT).show(); 53 | } 54 | }); 55 | 56 | view3.setOnClickListener(new View.OnClickListener() { 57 | @Override 58 | public void onClick(View view) { 59 | Toast.makeText(getApplicationContext(), "onClick", Toast.LENGTH_SHORT).show(); 60 | } 61 | }); 62 | 63 | view4.setOnClickListener(new View.OnClickListener() { 64 | @Override 65 | public void onClick(View view) { 66 | Toast.makeText(getApplicationContext(), "have clickListener", Toast.LENGTH_SHORT).show(); 67 | } 68 | }); 69 | 70 | 71 | 72 | } 73 | 74 | 75 | public int dp2Px(float dpValue) { 76 | final float scale = getResources().getDisplayMetrics().density; 77 | return (int) (dpValue * scale + 0.5f); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/canyinghao/caneffect/demo/ui/XmlActivity.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect.demo.ui; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.canyinghao.caneffect.demo.R; 6 | 7 | import androidx.appcompat.app.AppCompatActivity; 8 | 9 | /** 10 | * Created by yangjian on 16/2/2. 11 | */ 12 | public class XmlActivity extends AppCompatActivity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_xml); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/canyinghao/caneffect/demo/view/GameView.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect.demo.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapShader; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.ComposeShader; 9 | import android.graphics.LinearGradient; 10 | import android.graphics.Paint; 11 | import android.graphics.PorterDuff; 12 | import android.graphics.RadialGradient; 13 | import android.graphics.Shader; 14 | import android.graphics.SweepGradient; 15 | import android.graphics.drawable.BitmapDrawable; 16 | import android.graphics.drawable.ShapeDrawable; 17 | import android.graphics.drawable.shapes.OvalShape; 18 | import android.util.AttributeSet; 19 | import android.view.KeyEvent; 20 | import android.view.MotionEvent; 21 | import android.view.View; 22 | 23 | import com.canyinghao.caneffect.demo.R; 24 | 25 | public class GameView extends View implements Runnable 26 | { 27 | /* 声明Bitmap对象 */ 28 | Bitmap mBitQQ = null; 29 | int BitQQwidth = 0; 30 | int BitQQheight = 0; 31 | 32 | Paint mPaint = null; 33 | 34 | /* Bitmap渲染 */ 35 | Shader mBitmapShader = null; 36 | 37 | /* 线性渐变渲染 */ 38 | Shader mLinearGradient = null; 39 | 40 | /* 混合渲染 */ 41 | Shader mComposeShader = null; 42 | 43 | /* 唤醒渐变渲染 */ 44 | Shader mRadialGradient = null; 45 | 46 | /* 梯度渲染 */ 47 | Shader mSweepGradient = null; 48 | 49 | 50 | ShapeDrawable mShapeDrawableQQ = null; 51 | 52 | 53 | public GameView(Context context) 54 | { 55 | this(context,null); 56 | 57 | 58 | } 59 | 60 | public GameView(Context context, AttributeSet attrs) { 61 | this(context, attrs,0); 62 | } 63 | 64 | public GameView(Context context, AttributeSet attrs, int defStyleAttr) { 65 | super(context, attrs, defStyleAttr); 66 | 67 | /* 装载资源 */ 68 | mBitQQ = ((BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap(); 69 | 70 | /* 得到图片的宽度和高度 */ 71 | BitQQwidth = mBitQQ.getWidth(); 72 | BitQQheight = mBitQQ.getHeight(); 73 | 74 | /* 创建BitmapShader对象 */ 75 | mBitmapShader = new BitmapShader(mBitQQ,Shader.TileMode.REPEAT,Shader.TileMode.MIRROR); 76 | 77 | /* 创建LinearGradient并设置渐变的颜色数组 说明一下这几天参数 78 | * 第一个 起始的x坐标 79 | * 第二个 起始的y坐标 80 | * 第三个 结束的x坐标 81 | * 第四个 结束的y坐标 82 | * 第五个 颜色数组 83 | * 第六个 这个也是一个数组用来指定颜色数组的相对位置 如果为null 就沿坡度线均匀分布 84 | * 第七个 渲染模式 85 | * */ 86 | mLinearGradient = new LinearGradient(0,0,100,100, 87 | new int[]{Color.RED,Color.GREEN,Color.BLUE,Color.WHITE}, 88 | null,Shader.TileMode.REPEAT); 89 | /* 这里理解为混合渲染*/ 90 | mComposeShader = new ComposeShader(mBitmapShader,mLinearGradient,PorterDuff.Mode.DARKEN); 91 | 92 | /* 构建RadialGradient对象,设置半径的属性 */ 93 | //这里使用了BitmapShader和LinearGradient进行混合 94 | //当然也可以使用其他的组合 95 | //混合渲染的模式很多,可以根据自己需要来选择 96 | mRadialGradient = new RadialGradient(50,200,50, 97 | new int[]{Color.GREEN,Color.RED,Color.BLUE,Color.WHITE}, 98 | null,Shader.TileMode.REPEAT); 99 | /* 构建SweepGradient对象 */ 100 | mSweepGradient = new SweepGradient(30,30,new int[]{Color.GREEN,Color.RED,Color.BLUE,Color.WHITE},null); 101 | 102 | mPaint = new Paint(); 103 | 104 | /* 开启线程 */ 105 | new Thread(this).start(); 106 | } 107 | 108 | public void onDraw(Canvas canvas) 109 | { 110 | super.onDraw(canvas); 111 | 112 | //将图片裁剪为椭圆形 113 | /* 构建ShapeDrawable对象并定义形状为椭圆 */ 114 | mShapeDrawableQQ = new ShapeDrawable(new OvalShape()); 115 | 116 | /* 设置要绘制的椭圆形的东西为ShapeDrawable图片 */ 117 | mShapeDrawableQQ.getPaint().setShader(mBitmapShader); 118 | 119 | /* 设置显示区域 */ 120 | mShapeDrawableQQ.setBounds(0,0, BitQQwidth, BitQQheight); 121 | 122 | /* 绘制ShapeDrawableQQ */ 123 | mShapeDrawableQQ.draw(canvas); 124 | 125 | //绘制渐变的矩形 126 | mPaint.setShader(mLinearGradient); 127 | canvas.drawRect(BitQQwidth, 0, 320, 156, mPaint); 128 | 129 | //显示混合渲染效果 130 | mPaint.setShader(mComposeShader); 131 | canvas.drawRect(0, 300, BitQQwidth, 300+BitQQheight, mPaint); 132 | 133 | //绘制环形渐变 134 | mPaint.setShader(mRadialGradient); 135 | canvas.drawCircle(50, 200, 50, mPaint); 136 | 137 | //绘制梯度渐变 138 | mPaint.setShader(mSweepGradient); 139 | canvas.drawRect(150, 160, 300, 300, mPaint); 140 | 141 | } 142 | 143 | // 触笔事件 144 | public boolean onTouchEvent(MotionEvent event) 145 | { 146 | return true; 147 | } 148 | 149 | 150 | // 按键按下事件 151 | public boolean onKeyDown(int keyCode, KeyEvent event) 152 | { 153 | return true; 154 | } 155 | 156 | 157 | // 按键弹起事件 158 | public boolean onKeyUp(int keyCode, KeyEvent event) 159 | { 160 | return false; 161 | } 162 | 163 | 164 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) 165 | { 166 | return true; 167 | } 168 | 169 | 170 | /** 171 | * 线程处理 172 | */ 173 | public void run() 174 | { 175 | while (!Thread.currentThread().isInterrupted()) 176 | { 177 | try 178 | { 179 | Thread.sleep(100); 180 | } 181 | catch (InterruptedException e) 182 | { 183 | Thread.currentThread().interrupt(); 184 | } 185 | //使用postInvalidate可以直接在线程中更新界面 186 | postInvalidate(); 187 | } 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/gary_ball_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 14 | 15 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 32 | 35 | 36 | 37 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/red_ball_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/red_border_ball_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 10 | 11 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/round_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/waterwave.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | 13 | 14 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_base.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 11 | 12 | 13 | 18 | 19 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 38 | 39 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 60 | 61 | 69 | 70 | 71 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 14 | 15 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 31 | 32 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 48 | 49 | 55 | 56 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_xml.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 18 | 19 | 20 | 25 | 26 | 27 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 10 | 11 | 12 | 17 | 18 | 23 | 24 | 29 | 30 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/canyinghao/CanEffect/db6610b19021e0e0288d0cdc7e44cd580a3c451a/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/canyinghao/CanEffect/db6610b19021e0e0288d0cdc7e44cd580a3c451a/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/canyinghao/CanEffect/db6610b19021e0e0288d0cdc7e44cd580a3c451a/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/canyinghao/CanEffect/db6610b19021e0e0288d0cdc7e44cd580a3c451a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/canyinghao/CanEffect/db6610b19021e0e0288d0cdc7e44cd580a3c451a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #00000000 7 | #ff0000 8 | #ffffff 9 | #777777 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CanEffectDemo 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/canyinghao/caneffect/demo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect.demo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:4.1.1' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | google() 20 | jcenter() 21 | 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /caneffect/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /caneffect/bintray.gradle: -------------------------------------------------------------------------------- 1 | group = PROJ_GROUP 2 | version = PROJ_VERSION 3 | project.archivesBaseName = PROJ_ARTIFACTID 4 | 5 | apply plugin: 'com.jfrog.bintray' 6 | apply plugin: 'com.github.dcendents.android-maven' 7 | 8 | task sourcesJar(type: Jar) { 9 | from android.sourceSets.main.java.srcDirs 10 | classifier = 'sources' 11 | } 12 | 13 | task javadoc(type: Javadoc) { 14 | source = android.sourceSets.main.java.srcDirs 15 | classpath += configurations.compile 16 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 17 | } 18 | 19 | task javadocJar(type: Jar, dependsOn: javadoc) { 20 | classifier = 'javadoc' 21 | from javadoc.destinationDir 22 | } 23 | 24 | javadoc { 25 | options{ 26 | encoding "UTF-8" 27 | charSet 'UTF-8' 28 | author true 29 | version true 30 | links "http://docs.oracle.com/javase/7/docs/api" 31 | title PROJ_ARTIFACTID 32 | } 33 | } 34 | 35 | artifacts { 36 | archives sourcesJar 37 | archives javadocJar 38 | } 39 | 40 | install { 41 | repositories.mavenInstaller { 42 | pom.project { 43 | name PROJ_NAME 44 | description PROJ_DESCRIPTION 45 | url PROJ_WEBSITEURL 46 | inceptionYear '2016' 47 | 48 | packaging 'aar' 49 | groupId PROJ_GROUP 50 | artifactId PROJ_ARTIFACTID 51 | version PROJ_VERSION 52 | 53 | licenses { 54 | license { 55 | name 'The Apache Software License, Version 2.0' 56 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 57 | distribution 'repo' 58 | } 59 | } 60 | scm { 61 | connection PROJ_VCSURL 62 | url PROJ_WEBSITEURL 63 | 64 | } 65 | developers { 66 | developer { 67 | id DEVELOPER_ID 68 | name DEVELOPER_NAME 69 | email DEVELOPER_EMAIL 70 | } 71 | } 72 | } 73 | } 74 | } 75 | 76 | bintray { 77 | user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : project.property('BINTRAY_USER') 78 | key = project.hasProperty('bintrayKey') ? project.property('bintrayKey') : project.property('BINTRAY_KEY') 79 | 80 | configurations = ['archives'] 81 | 82 | dryRun = false 83 | publish = true 84 | 85 | pkg { 86 | repo = 'maven' 87 | name = PROJ_NAME 88 | licenses = ['Apache-2.0'] 89 | vcsUrl = PROJ_VCSURL 90 | websiteUrl = PROJ_WEBSITEURL 91 | issueTrackerUrl = PROJ_ISSUETRACKERURL 92 | publicDownloadNumbers = true 93 | version { 94 | name = PROJ_VERSION 95 | desc = PROJ_DESCRIPTION 96 | vcsTag = PROJ_VERSION 97 | 98 | gpg { 99 | sign = true 100 | } 101 | 102 | mavenCentralSync { 103 | sync = project.hasProperty('SONATYPE_USER') && project.hasProperty('SONATYPE_KEY') 104 | user = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : "" 105 | password = project.hasProperty('SONATYPE_PASS') ? project.property('SONATYPE_PASS') : "" 106 | close = '1' 107 | } 108 | } 109 | } 110 | } 111 | 112 | //以下内容用于发布SNAPSHOT版本,如果不需要可以移除。 113 | //参考自:https://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin 114 | 115 | //apply plugin: "com.jfrog.artifactory" 116 | //artifactory { 117 | // contextUrl = 'http://oss.jfrog.org/artifactory' //The base Artifactory URL if not overridden by the publisher/resolver 118 | // resolve { 119 | // repository { 120 | // repoKey = 'libs-release' 121 | // } 122 | // } 123 | // publish { 124 | // repository { 125 | // repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to 126 | // username = bintray.user 127 | // password = bintray.key 128 | // maven = true 129 | // } 130 | // defaults { 131 | // //这里的名字和前面bintray.configurations的值一致即可,会将其包含的输出上传到jfrog上去 132 | // publishConfigs('archives') 133 | // } 134 | // } 135 | //} -------------------------------------------------------------------------------- /caneffect/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | buildToolsVersion "28.0.3" 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 26 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | 24 | } 25 | 26 | //buildscript { 27 | // repositories { 28 | // jcenter() 29 | // } 30 | // dependencies { 31 | // classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2' 32 | // classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1" 33 | // classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' 34 | // } 35 | //} 36 | //apply from: 'bintray.gradle' -------------------------------------------------------------------------------- /caneffect/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/yangjian/Documents/program/android-sdk-macosx/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 | -------------------------------------------------------------------------------- /caneffect/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /caneffect/src/main/java/com/canyinghao/caneffect/CanCircularRevealLayout.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect; 2 | 3 | 4 | import android.animation.Animator; 5 | import android.animation.ObjectAnimator; 6 | import android.content.Context; 7 | import android.graphics.Canvas; 8 | import android.graphics.Path; 9 | import android.os.Build; 10 | import android.util.AttributeSet; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.FrameLayout; 14 | 15 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; 16 | 17 | /** 18 | * Created by canyinghao on 16/2/4. 19 | */ 20 | public class CanCircularRevealLayout extends FrameLayout { 21 | 22 | private Path path; 23 | private float centerX; 24 | private float centerY; 25 | private float revealRadius; 26 | private boolean isRunning; 27 | private View childView; 28 | private float startRadius; 29 | private float endRadius; 30 | 31 | public CanCircularRevealLayout(Context context) { 32 | this(context, null); 33 | } 34 | 35 | public CanCircularRevealLayout(Context context, AttributeSet attrs) { 36 | this(context, attrs, 0); 37 | } 38 | 39 | public CanCircularRevealLayout(Context context, AttributeSet attrs, int defStyleAttr) { 40 | super(context, attrs, defStyleAttr); 41 | 42 | path = new Path(); 43 | 44 | 45 | } 46 | 47 | 48 | public void setChildView(View childView) { 49 | this.childView = childView; 50 | } 51 | 52 | public void setCenterX(float centerX) { 53 | this.centerX = centerX; 54 | } 55 | 56 | public void setCenterY(float centerY) { 57 | this.centerY = centerY; 58 | } 59 | 60 | public void setStartRadius(float startRadius) { 61 | this.startRadius = startRadius; 62 | } 63 | 64 | public void setEndRadius(float endRadius) { 65 | this.endRadius = endRadius; 66 | } 67 | 68 | public void setRevealRadius(float revealRadius) { 69 | this.revealRadius = revealRadius; 70 | 71 | invalidate(); 72 | 73 | } 74 | 75 | 76 | public Animator getAnimator() { 77 | ObjectAnimator reveal = ObjectAnimator.ofFloat(this, "revealRadius", startRadius, endRadius); 78 | 79 | reveal.addListener(new Animator.AnimatorListener() { 80 | @Override 81 | public void onAnimationStart(Animator animator) { 82 | animationStart(); 83 | } 84 | 85 | @Override 86 | public void onAnimationEnd(Animator animator) { 87 | animationEnd(); 88 | } 89 | 90 | @Override 91 | public void onAnimationCancel(Animator animator) { 92 | animationEnd(); 93 | } 94 | 95 | @Override 96 | public void onAnimationRepeat(Animator animator) { 97 | 98 | } 99 | }); 100 | 101 | return reveal; 102 | } 103 | 104 | private void animationStart() { 105 | isRunning = true; 106 | 107 | } 108 | 109 | private void animationEnd() { 110 | isRunning = false; 111 | } 112 | 113 | @Override 114 | protected boolean drawChild(Canvas canvas, View child, long drawingTime) { 115 | if (isRunning && childView == child) { 116 | final int state = canvas.save(); 117 | 118 | path.reset(); 119 | path.addCircle(centerX, centerY, revealRadius, Path.Direction.CW); 120 | 121 | canvas.clipPath(path); 122 | 123 | boolean isInvalided = super.drawChild(canvas, child, drawingTime); 124 | 125 | canvas.restoreToCount(state); 126 | 127 | return isInvalided; 128 | } 129 | 130 | return super.drawChild(canvas, child, drawingTime); 131 | } 132 | 133 | 134 | public static class Builder { 135 | 136 | 137 | private View view; 138 | private float centerX; 139 | private float centerY; 140 | private float startRadius; 141 | private float endRadius; 142 | 143 | public Builder(View view) { 144 | this.view = view; 145 | } 146 | 147 | 148 | public static Builder on(View view) { 149 | return new Builder(view); 150 | } 151 | 152 | 153 | public Builder centerX(float centerX) { 154 | this.centerX = centerX; 155 | return this; 156 | } 157 | 158 | public Builder centerY(float centerY) { 159 | this.centerY = centerY; 160 | return this; 161 | } 162 | 163 | public Builder startRadius(float startRadius) { 164 | this.startRadius = startRadius; 165 | return this; 166 | } 167 | 168 | public Builder endRadius(float endRadius) { 169 | this.endRadius = endRadius; 170 | return this; 171 | } 172 | 173 | private void setParameter(CanCircularRevealLayout layout) { 174 | layout.setCenterX(centerX); 175 | layout.setCenterY(centerY); 176 | layout.setStartRadius(startRadius); 177 | layout.setEndRadius(endRadius); 178 | layout.setChildView(view); 179 | 180 | } 181 | 182 | 183 | public Animator create() { 184 | 185 | if (view.getParent() != null && view.getParent() instanceof CanCircularRevealLayout) { 186 | 187 | CanCircularRevealLayout layout = ((CanCircularRevealLayout) view.getParent()); 188 | 189 | setParameter(layout); 190 | 191 | return layout.getAnimator(); 192 | } 193 | 194 | CanCircularRevealLayout layout = new CanCircularRevealLayout(view.getContext()); 195 | 196 | 197 | if(Build.VERSION.SDK_INT>=11){ 198 | layout.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 199 | } 200 | 201 | 202 | 203 | setParameter(layout); 204 | 205 | 206 | ViewGroup.LayoutParams params = view.getLayoutParams(); 207 | ViewGroup parent = (ViewGroup) view.getParent(); 208 | int index = 0; 209 | 210 | 211 | if (parent != null) { 212 | index = parent.indexOfChild(view); 213 | parent.removeView(view); 214 | } 215 | 216 | layout.addView(view, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); 217 | 218 | if (parent != null) { 219 | parent.addView(layout, index, params); 220 | } 221 | 222 | 223 | return layout.getAnimator(); 224 | 225 | } 226 | 227 | 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /caneffect/src/main/java/com/canyinghao/caneffect/CanRippleLayout.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect; 2 | 3 | 4 | import android.animation.ObjectAnimator; 5 | import android.content.Context; 6 | import android.content.res.TypedArray; 7 | import android.graphics.Canvas; 8 | import android.graphics.Color; 9 | import android.graphics.Paint; 10 | import android.graphics.Path; 11 | import android.graphics.Rect; 12 | import android.graphics.RectF; 13 | import android.util.AttributeSet; 14 | import android.view.MotionEvent; 15 | import android.view.View; 16 | import android.view.ViewGroup; 17 | import android.view.animation.OvershootInterpolator; 18 | import android.widget.FrameLayout; 19 | import android.widget.RelativeLayout; 20 | 21 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; 22 | 23 | /** 24 | * Created by canyinghao on 16/2/3. 25 | */ 26 | public class CanRippleLayout extends FrameLayout { 27 | 28 | 29 | private float radius; 30 | private Paint paint; 31 | 32 | private float centerX; 33 | private float centerY; 34 | 35 | private ObjectAnimator ripple; 36 | 37 | private boolean isAnime; 38 | 39 | private View childView; 40 | 41 | private float radiusMax; 42 | 43 | 44 | private float rippleCorner; 45 | private int rippleColor = Color.parseColor("#77000000"); 46 | private int rippleAlpha = 20; 47 | private float rippleSpeed = 0.5f; 48 | 49 | 50 | public CanRippleLayout(Context context) { 51 | this(context, null); 52 | } 53 | 54 | public CanRippleLayout(Context context, AttributeSet attrs) { 55 | this(context, attrs, 0); 56 | } 57 | 58 | public CanRippleLayout(Context context, AttributeSet attrs, int defStyleAttr) { 59 | super(context, attrs, defStyleAttr); 60 | 61 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CanRippleLayout, defStyleAttr, 0); 62 | 63 | try { 64 | final int N = a.getIndexCount(); 65 | for (int i = 0; i < N; i++) { 66 | int attr = a.getIndex(i); 67 | if (attr == R.styleable.CanRippleLayout_can_ripple_corner) { 68 | 69 | setRippleCorner(a.getDimension(attr, 0)); 70 | 71 | } else if (attr == R.styleable.CanRippleLayout_can_ripple_alpha) { 72 | setRippleAlpha(a.getInt(attr, 20)); 73 | 74 | } else if (attr == R.styleable.CanRippleLayout_can_ripple_speed) { 75 | setRippleSpeed(a.getFloat(attr, 0.5f)); 76 | 77 | } else if (attr == R.styleable.CanRippleLayout_can_ripple_color) { 78 | setRippleColor(a.getColor(attr, Color.parseColor("#77000000"))); 79 | 80 | } 81 | } 82 | 83 | 84 | } finally { 85 | a.recycle(); 86 | } 87 | 88 | paint = new Paint(Paint.ANTI_ALIAS_FLAG); 89 | 90 | paint.setColor(rippleColor); 91 | paint.setAlpha(rippleAlpha); 92 | 93 | 94 | setWillNotDraw(false); 95 | 96 | } 97 | 98 | public void setRadius(float radius) { 99 | this.radius = radius; 100 | 101 | 102 | invalidate(); 103 | } 104 | 105 | 106 | public void setRippleSpeed( float rippleSpeed) { 107 | this.rippleSpeed = rippleSpeed; 108 | } 109 | 110 | public void setRippleAlpha(int rippleAlpha) { 111 | this.rippleAlpha = rippleAlpha; 112 | } 113 | 114 | public void setRippleColor(int rippleColor) { 115 | this.rippleColor = rippleColor; 116 | } 117 | 118 | public void setRippleCorner(float rippleCorner) { 119 | this.rippleCorner = rippleCorner; 120 | } 121 | 122 | public void startAnimator(float x, float y) { 123 | 124 | 125 | float maxX = Math.max(x, getWidth() - x); 126 | float maxY = Math.max(y, getHeight() - y); 127 | 128 | radiusMax = (float) Math.sqrt(Math.pow(maxX, 2) + Math.pow(maxY, 2)); 129 | 130 | 131 | ripple = ObjectAnimator.ofFloat(this, "radius", 0, radiusMax); 132 | ripple.setDuration((long) (radiusMax + radiusMax * 10 * (1 - rippleSpeed))); 133 | 134 | 135 | ripple.setInterpolator(new OvershootInterpolator()); 136 | ripple.start(); 137 | 138 | 139 | } 140 | 141 | 142 | 143 | @Override 144 | public boolean dispatchTouchEvent(MotionEvent ev) { 145 | 146 | if (isAnime){ 147 | stopAnime(); 148 | } 149 | 150 | return super.dispatchTouchEvent(ev); 151 | } 152 | 153 | @Override 154 | public boolean onInterceptTouchEvent(MotionEvent e) { 155 | 156 | 157 | return true; 158 | 159 | } 160 | 161 | @Override 162 | public boolean onTouchEvent(MotionEvent e) { 163 | if (!isChildViewClick(this, (int) e.getX(), (int) e.getY())) { 164 | return super.onTouchEvent(e); 165 | } 166 | 167 | if (childView!=this){ 168 | childView.onTouchEvent(e); 169 | } 170 | 171 | 172 | switch (e.getAction()) { 173 | 174 | case MotionEvent.ACTION_DOWN: 175 | 176 | centerY = e.getY(); 177 | centerX = e.getX(); 178 | isAnime = true; 179 | startAnimator(e.getX(), e.getY()); 180 | return true; 181 | 182 | case MotionEvent.ACTION_MOVE: 183 | 184 | return super.onTouchEvent(e); 185 | case MotionEvent.ACTION_CANCEL: 186 | case MotionEvent.ACTION_UP: 187 | 188 | stopAnime(); 189 | 190 | break; 191 | 192 | 193 | } 194 | 195 | 196 | return super.onTouchEvent(e); 197 | } 198 | 199 | private void stopAnime() { 200 | if (ripple != null && ripple.isRunning()) { 201 | postDelayed(new Runnable() { 202 | @Override 203 | public void run() { 204 | 205 | if (ripple.isRunning()) { 206 | ripple.cancel(); 207 | 208 | } 209 | isAnime = false; 210 | 211 | setRadius(0); 212 | } 213 | }, 500); 214 | } else { 215 | isAnime = false; 216 | setRadius(0); 217 | } 218 | } 219 | 220 | 221 | private boolean isChildViewClick(View view, int x, int y) { 222 | 223 | 224 | if (view.isEnabled() && (view.isClickable() || view.isLongClickable())){ 225 | 226 | childView = view; 227 | return true; 228 | } 229 | 230 | if (view instanceof ViewGroup) { 231 | ViewGroup viewGroup = (ViewGroup) view; 232 | 233 | if (view instanceof FrameLayout || view instanceof RelativeLayout) { 234 | 235 | 236 | for (int i = viewGroup.getChildCount() - 1; i >= 0; i--) { 237 | View child = viewGroup.getChildAt(i); 238 | final Rect rect = new Rect(); 239 | child.getHitRect(rect); 240 | 241 | final boolean contains = rect.contains(x, y); 242 | if (contains) { 243 | return isChildViewClick(child, x - rect.left, y - rect.top); 244 | } 245 | } 246 | } else { 247 | 248 | for (int i = 0; i < viewGroup.getChildCount(); i++) { 249 | View child = viewGroup.getChildAt(i); 250 | final Rect rect = new Rect(); 251 | child.getHitRect(rect); 252 | 253 | final boolean contains = rect.contains(x, y); 254 | if (contains) { 255 | return isChildViewClick(child, x - rect.left, y - rect.top); 256 | } 257 | } 258 | } 259 | 260 | 261 | } 262 | 263 | childView = view; 264 | 265 | 266 | return view.isEnabled() && (view.isClickable() || view.isLongClickable()); 267 | } 268 | 269 | 270 | @Override 271 | public void draw(Canvas canvas) { 272 | super.draw(canvas); 273 | 274 | 275 | if (isAnime) { 276 | 277 | Path clipPath = new Path(); 278 | RectF rect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight()); 279 | clipPath.addRoundRect(rect, rippleCorner, rippleCorner, Path.Direction.CW); 280 | canvas.clipPath(clipPath); 281 | canvas.drawCircle(centerX, centerY, radiusMax, paint); 282 | canvas.drawCircle(centerX, centerY, radius, paint); 283 | } 284 | 285 | 286 | } 287 | 288 | 289 | 290 | 291 | public static class Builder { 292 | 293 | 294 | private View view; 295 | private float rippleCorner; 296 | private int rippleColor = Color.parseColor("#77000000"); 297 | private int rippleAlpha = 20; 298 | private float rippleSpeed = 0.5f; 299 | 300 | public Builder(View view) { 301 | this.view = view; 302 | } 303 | 304 | 305 | public static Builder on(View view) { 306 | return new Builder(view); 307 | } 308 | 309 | 310 | public Builder rippleCorner(float rippleCorner) { 311 | this.rippleCorner = rippleCorner; 312 | return this; 313 | } 314 | 315 | public Builder rippleColor(int rippleColor) { 316 | this.rippleColor = rippleColor; 317 | return this; 318 | } 319 | public Builder rippleAlpha(int rippleAlpha) { 320 | this.rippleAlpha = rippleAlpha; 321 | return this; 322 | } 323 | public Builder rippleSpeed(float rippleSpeed) { 324 | this.rippleSpeed = rippleSpeed; 325 | return this; 326 | } 327 | 328 | 329 | 330 | 331 | public CanRippleLayout create() { 332 | 333 | if (view.getParent() != null && view.getParent() instanceof CanRippleLayout) { 334 | return (CanRippleLayout) view.getParent(); 335 | } 336 | 337 | CanRippleLayout layout = new CanRippleLayout(view.getContext()); 338 | 339 | layout.setRippleColor(rippleColor); 340 | layout.setRippleSpeed(rippleSpeed); 341 | layout.setRippleAlpha(rippleAlpha); 342 | layout.setRippleCorner(rippleCorner); 343 | 344 | 345 | 346 | ViewGroup.LayoutParams params = view.getLayoutParams(); 347 | ViewGroup parent = (ViewGroup) view.getParent(); 348 | int index = 0; 349 | 350 | 351 | if (parent != null) { 352 | index = parent.indexOfChild(view); 353 | parent.removeView(view); 354 | } 355 | 356 | layout.addView(view, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); 357 | 358 | if (parent != null) { 359 | parent.addView(layout, index, params); 360 | } 361 | 362 | 363 | return layout; 364 | 365 | } 366 | 367 | 368 | } 369 | } 370 | -------------------------------------------------------------------------------- /caneffect/src/main/java/com/canyinghao/caneffect/CanShadowDrawable.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Color; 5 | import android.graphics.ColorFilter; 6 | import android.graphics.Paint; 7 | import android.graphics.PixelFormat; 8 | import android.graphics.Rect; 9 | import android.graphics.RectF; 10 | import android.graphics.drawable.Drawable; 11 | import android.os.Build; 12 | import android.view.View; 13 | import android.view.ViewTreeObserver; 14 | 15 | /** 16 | * Created by canyinghao on 16/2/1. 17 | */ 18 | public class CanShadowDrawable extends Drawable { 19 | 20 | 21 | private Paint paint; 22 | private Paint paintNoShadow; 23 | 24 | 25 | private RectF drawRect; 26 | // 圆角半径 27 | private float radius; 28 | private int corners ; 29 | 30 | private float offsetLeft; 31 | private float offsetTop; 32 | private float offsetRight; 33 | private float offsetBottom; 34 | 35 | 36 | 37 | public static final int CORNER_TOP_LEFT = 1; 38 | public static final int CORNER_TOP_RIGHT = 1 << 1; 39 | public static final int CORNER_BOTTOM_LEFT = 1 << 2; 40 | public static final int CORNER_BOTTOM_RIGHT = 1 << 3; 41 | public static final int CORNER_ALL = CORNER_TOP_LEFT | CORNER_TOP_RIGHT | CORNER_BOTTOM_LEFT | CORNER_BOTTOM_RIGHT; 42 | 43 | 44 | public CanShadowDrawable(int bgColor, float shadowRange, float shadowDx, float shadowDy, int shadowColor) { 45 | 46 | 47 | paint = new Paint(); 48 | paint.setAntiAlias(true); 49 | 50 | paint.setFilterBitmap(true); 51 | paint.setDither(true); 52 | paint.setStyle(Paint.Style.FILL); 53 | paint.setColor(bgColor); 54 | // 设置阴影 55 | paint.setShadowLayer(shadowRange, shadowDx, shadowDy, shadowColor); 56 | 57 | paintNoShadow = new Paint(); 58 | paintNoShadow.setAntiAlias(true); 59 | 60 | paintNoShadow.setFilterBitmap(true); 61 | paintNoShadow.setDither(true); 62 | paintNoShadow.setStyle(Paint.Style.FILL); 63 | paintNoShadow.setColor(bgColor); 64 | 65 | 66 | drawRect = new RectF(); 67 | } 68 | 69 | 70 | @Override 71 | protected void onBoundsChange(Rect bounds) { 72 | super.onBoundsChange(bounds); 73 | 74 | 75 | if (bounds.right - bounds.left > 0 && bounds.bottom - bounds.top > 0) { 76 | 77 | int width = bounds.right - bounds.left; 78 | int height = bounds.bottom - bounds.top; 79 | 80 | drawRect = new RectF(offsetLeft, offsetTop, width - offsetRight, height - offsetBottom); 81 | 82 | 83 | invalidateSelf(); 84 | 85 | } 86 | } 87 | 88 | 89 | public void setCorners(int corners) { 90 | this.corners = corners; 91 | } 92 | 93 | @Override 94 | public void draw(Canvas canvas) { 95 | canvas.drawRoundRect( 96 | drawRect, 97 | radius, radius, 98 | paint 99 | ); 100 | 101 | if(corners==0){ 102 | corners = CORNER_ALL; 103 | } 104 | int notRoundedCorners = corners ^ CORNER_ALL; 105 | //哪个角不是圆角我再把你用矩形画出来 106 | if ((notRoundedCorners & CORNER_TOP_LEFT) != 0) { 107 | canvas.drawRect(offsetLeft, offsetTop, radius+offsetLeft, radius+offsetTop, paintNoShadow); 108 | } 109 | if ((notRoundedCorners & CORNER_TOP_RIGHT) != 0) { 110 | canvas.drawRect(drawRect.right - radius , offsetTop, drawRect.right , radius+offsetTop, paintNoShadow); 111 | } 112 | if ((notRoundedCorners & CORNER_BOTTOM_LEFT) != 0) { 113 | canvas.drawRect(offsetLeft, drawRect.bottom - radius, radius+offsetLeft, drawRect.bottom, paintNoShadow); 114 | } 115 | if ((notRoundedCorners & CORNER_BOTTOM_RIGHT) != 0) { 116 | canvas.drawRect(drawRect.right - radius, drawRect.bottom - radius, drawRect.right, drawRect.bottom, paintNoShadow); 117 | } 118 | } 119 | 120 | 121 | public float getOffsetLeft() { 122 | return offsetLeft; 123 | } 124 | 125 | public void setOffsetLeft(float offsetLeft) { 126 | this.offsetLeft = offsetLeft; 127 | } 128 | 129 | public float getOffsetTop() { 130 | return offsetTop; 131 | } 132 | 133 | public void setOffsetTop(float offsetTop) { 134 | this.offsetTop = offsetTop; 135 | } 136 | 137 | public float getOffsetRight() { 138 | return offsetRight; 139 | } 140 | 141 | public void setOffsetRight(float offsetRight) { 142 | this.offsetRight = offsetRight; 143 | } 144 | 145 | public float getOffsetBottom() { 146 | return offsetBottom; 147 | } 148 | 149 | public void setOffsetBottom(float offsetBottom) { 150 | this.offsetBottom = offsetBottom; 151 | } 152 | 153 | public float getRadius() { 154 | return radius; 155 | } 156 | 157 | public void setRadius(float radius) { 158 | this.radius = radius; 159 | } 160 | 161 | public CanShadowDrawable setColor(int color) { 162 | paint.setColor(color); 163 | return this; 164 | } 165 | 166 | @Override 167 | public void setAlpha(int i) { 168 | 169 | } 170 | 171 | @Override 172 | public void setColorFilter(ColorFilter colorFilter) { 173 | 174 | } 175 | 176 | @Override 177 | public int getOpacity() { 178 | return PixelFormat.TRANSLUCENT; 179 | } 180 | 181 | 182 | public static class Builder { 183 | 184 | 185 | private View view; 186 | // paddingLeft 187 | private float offsetLeft; 188 | // paddingTop 189 | private float offsetTop; 190 | // paddingRight 191 | private float offsetRight; 192 | // paddingBottom 193 | private float offsetBottom; 194 | // 圆角半径 195 | private float radius; 196 | private int corners; 197 | // 阴影范围 198 | private float shadowRange; 199 | // 阴影x轴偏移 200 | private float shadowDx; 201 | // 阴影y轴偏移 202 | private float shadowDy; 203 | // 阴影颜色 204 | private int shadowColor = Color.BLACK; 205 | // 背景颜色 206 | private int bgColor = Color.WHITE; 207 | 208 | public Builder(View view) { 209 | this.view = view; 210 | } 211 | 212 | 213 | public static Builder on(View view) { 214 | return new Builder(view); 215 | } 216 | 217 | 218 | /** 219 | * PaddingLeft 220 | * @param offsetLeft 221 | * @return 222 | */ 223 | public Builder offsetLeft(float offsetLeft) { 224 | this.offsetLeft = offsetLeft; 225 | return this; 226 | } 227 | 228 | /** 229 | * PaddingTop 230 | * @param offsetTop 231 | * @return 232 | */ 233 | public Builder offsetTop(float offsetTop) { 234 | this.offsetTop = offsetTop; 235 | return this; 236 | } 237 | 238 | /** 239 | * PaddingRight 240 | * @param offsetRight 241 | * @return 242 | */ 243 | public Builder offsetRight(float offsetRight) { 244 | this.offsetRight = offsetRight; 245 | return this; 246 | } 247 | 248 | /** 249 | * PaddingBottom 250 | * @param offsetBottom 251 | * @return 252 | */ 253 | public Builder offsetBottom(float offsetBottom) { 254 | this.offsetBottom = offsetBottom; 255 | return this; 256 | } 257 | 258 | /** 259 | * 指定圆角 260 | * @param corners 261 | * @return 262 | */ 263 | public Builder corners(int corners) { 264 | this.corners = corners; 265 | return this; 266 | } 267 | 268 | 269 | /** 270 | * 圆角半径 271 | * @param radius 272 | * @return 273 | */ 274 | public Builder radius(float radius) { 275 | this.radius = radius; 276 | return this; 277 | } 278 | 279 | 280 | /** 281 | * 阴影范围 282 | * @param shadowRange 283 | * @return 284 | */ 285 | public Builder shadowRange(float shadowRange) { 286 | this.shadowRange = shadowRange; 287 | return this; 288 | } 289 | 290 | 291 | /** 292 | * 阴影x轴偏移 293 | * @param shadowDx 294 | * @return 295 | */ 296 | public Builder shadowDx(float shadowDx) { 297 | this.shadowDx = shadowDx; 298 | return this; 299 | } 300 | 301 | /** 302 | * 阴影y轴偏移 303 | * @param shadowDy 304 | * @return 305 | */ 306 | public Builder shadowDy(float shadowDy) { 307 | this.shadowDy = shadowDy; 308 | return this; 309 | } 310 | 311 | /** 312 | * 阴影颜色 313 | * @param shadowColor 314 | * @return 315 | */ 316 | public Builder shadowColor(int shadowColor) { 317 | this.shadowColor = shadowColor; 318 | return this; 319 | } 320 | 321 | /** 322 | * 背景颜色 323 | * @param bgColor 324 | * @return 325 | */ 326 | public Builder bgColor(int bgColor) { 327 | this.bgColor = bgColor; 328 | return this; 329 | } 330 | 331 | 332 | public CanShadowDrawable create() { 333 | 334 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { 335 | view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 336 | } 337 | 338 | final CanShadowDrawable shadowViewDrawable = new CanShadowDrawable(bgColor, shadowRange, shadowDx, shadowDy, shadowColor); 339 | 340 | 341 | view.setPadding(view.getPaddingLeft() + (int) offsetLeft, view.getPaddingTop() + (int) offsetTop, view.getPaddingRight() + (int) offsetRight, view.getPaddingBottom() + (int) offsetBottom); 342 | 343 | view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 344 | @Override 345 | public void onGlobalLayout() { 346 | 347 | 348 | shadowViewDrawable.setOffsetLeft(offsetLeft); 349 | shadowViewDrawable.setOffsetTop(offsetTop); 350 | shadowViewDrawable.setOffsetBottom(offsetBottom); 351 | shadowViewDrawable.setOffsetRight(offsetRight); 352 | shadowViewDrawable.setRadius(radius); 353 | shadowViewDrawable.setCorners(corners); 354 | 355 | shadowViewDrawable.setBounds(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); 356 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 357 | view.getViewTreeObserver().removeOnGlobalLayoutListener(this); 358 | } else { 359 | view.getViewTreeObserver().removeGlobalOnLayoutListener(this); 360 | } 361 | } 362 | }); 363 | 364 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { 365 | view.setBackgroundDrawable(shadowViewDrawable); 366 | } else { 367 | view.setBackground(shadowViewDrawable); 368 | } 369 | 370 | 371 | return shadowViewDrawable; 372 | 373 | 374 | } 375 | } 376 | } 377 | -------------------------------------------------------------------------------- /caneffect/src/main/java/com/canyinghao/caneffect/CanWaterWaveLayout.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect; 2 | 3 | import android.animation.ObjectAnimator; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.Paint; 9 | import android.graphics.RadialGradient; 10 | import android.graphics.Rect; 11 | import android.graphics.Shader; 12 | import android.util.AttributeSet; 13 | import android.view.MotionEvent; 14 | import android.view.View; 15 | import android.view.ViewGroup; 16 | import android.view.animation.DecelerateInterpolator; 17 | import android.widget.FrameLayout; 18 | import android.widget.RelativeLayout; 19 | 20 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; 21 | 22 | /** 23 | * Created by canyinghao on 16/1/25. 24 | */ 25 | public class CanWaterWaveLayout extends FrameLayout { 26 | 27 | private Paint paint; 28 | 29 | private float centerDownX; 30 | private float centerDownY; 31 | 32 | 33 | private float centerUpX; 34 | private float centerUpY; 35 | 36 | private int alphaDown; 37 | private int alphaUp; 38 | 39 | 40 | private float radiusDown; 41 | 42 | private float radiusUp; 43 | 44 | private float maxDown; 45 | private float maxUp; 46 | 47 | private boolean isAnimeDowning; 48 | private boolean isAnimeUping; 49 | 50 | 51 | private long startTime; 52 | 53 | 54 | private float waterSpeed = 0.5f; 55 | private int waterRadius = 100; 56 | private int waterThickness = 50; 57 | 58 | private int colorStart = Color.TRANSPARENT; 59 | private int colorCenter = Color.WHITE; 60 | private int colorEnd = Color.TRANSPARENT; 61 | 62 | 63 | private int[] colors; 64 | 65 | private View childView; 66 | 67 | 68 | public CanWaterWaveLayout(Context context) { 69 | this(context, null); 70 | } 71 | 72 | public CanWaterWaveLayout(Context context, AttributeSet attrs) { 73 | this(context, attrs, 0); 74 | } 75 | 76 | public CanWaterWaveLayout(Context context, AttributeSet attrs, int defStyleAttr) { 77 | super(context, attrs, defStyleAttr); 78 | 79 | 80 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CanWaterWaveLayout, defStyleAttr, 0); 81 | 82 | try { 83 | final int N = a.getIndexCount(); 84 | for (int i = 0; i < N; i++) { 85 | int attr = a.getIndex(i); 86 | if (attr == R.styleable.CanWaterWaveLayout_can_water_radius) { 87 | 88 | setWaterRadius((int) a.getDimension(attr, 100)); 89 | 90 | } else if (attr == R.styleable.CanWaterWaveLayout_can_water_thickness) { 91 | setWaterThickness((int) a.getDimension(attr, 50)); 92 | 93 | } else if (attr == R.styleable.CanWaterWaveLayout_can_water_speed) { 94 | setWaterSpeed(a.getFloat(attr, 0.5f)); 95 | 96 | } else if (attr == R.styleable.CanWaterWaveLayout_can_color_start) { 97 | colorStart = a.getColor(attr, Color.TRANSPARENT); 98 | 99 | } else if (attr == R.styleable.CanWaterWaveLayout_can_color_center) { 100 | colorCenter = a.getColor(attr, Color.WHITE); 101 | 102 | } else if (attr == R.styleable.CanWaterWaveLayout_can_color_end) { 103 | colorEnd = a.getColor(attr, Color.TRANSPARENT); 104 | 105 | } 106 | } 107 | 108 | 109 | } finally { 110 | a.recycle(); 111 | } 112 | 113 | 114 | colors = new int[]{colorStart, colorCenter, colorEnd}; 115 | paint = new Paint(); 116 | paint.setAntiAlias(true); //消除锯齿 117 | paint.setStyle(Paint.Style.STROKE); //绘制空心圆或 空心矩形 118 | paint.setColor(Color.WHITE); 119 | 120 | setWillNotDraw(false); 121 | } 122 | 123 | public void setWaterThickness(int waterThickness) { 124 | this.waterThickness = waterThickness; 125 | } 126 | 127 | public void setWaterRadius(int waterRadius) { 128 | this.waterRadius = waterRadius; 129 | } 130 | 131 | public void setWaterSpeed( float waterSpeed) { 132 | this.waterSpeed = waterSpeed; 133 | } 134 | 135 | 136 | public void setColors(int... colors) { 137 | if (colors != null) { 138 | this.colors = colors; 139 | } 140 | 141 | } 142 | 143 | 144 | @Override 145 | protected void onFinishInflate() { 146 | super.onFinishInflate(); 147 | 148 | if (getChildCount() == 0) { 149 | throw new IllegalStateException("ChildCount = 0 "); 150 | } 151 | 152 | childView = getChildAt(0); 153 | 154 | } 155 | 156 | @Override 157 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 158 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 159 | 160 | centerDownX = getWidth() / 2; 161 | centerDownY = getHeight() / 2; 162 | 163 | } 164 | 165 | 166 | public float startAnimator(float centerX, float centerY, String radiusStr) { 167 | 168 | 169 | float maxX = Math.max(centerX, getWidth() - centerX); 170 | float maxY = Math.max(centerY, getHeight() - centerY); 171 | 172 | float max = Math.max(maxX, maxY); 173 | 174 | ObjectAnimator ripple = ObjectAnimator.ofFloat(this, radiusStr, 0, max); 175 | ripple.setDuration((long) (max + max * 10 * (1 - waterSpeed))); 176 | 177 | 178 | ripple.setInterpolator(new DecelerateInterpolator()); 179 | ripple.start(); 180 | 181 | return max; 182 | 183 | } 184 | 185 | 186 | public void setRadiusDown(float radiusDown) { 187 | this.radiusDown = radiusDown; 188 | 189 | alphaDown = (int) ((1 - (radiusDown / maxDown)) * 255); 190 | 191 | invalidate(); 192 | } 193 | 194 | public void setRadiusUp(float radiusUp) { 195 | this.radiusUp = radiusUp; 196 | 197 | alphaUp = (int) ((1 - (radiusUp / maxUp)) * 255); 198 | 199 | invalidate(); 200 | } 201 | 202 | 203 | @Override 204 | public boolean onInterceptTouchEvent(MotionEvent e) { 205 | 206 | return true; 207 | 208 | } 209 | 210 | @Override 211 | public boolean onTouchEvent(MotionEvent e) { 212 | if (!isChildViewClick(this, (int) e.getX(), (int) e.getY())) { 213 | return super.onTouchEvent(e); 214 | } 215 | 216 | if (childView != this) { 217 | childView.onTouchEvent(e); 218 | } 219 | 220 | 221 | switch (e.getAction()) { 222 | 223 | case MotionEvent.ACTION_DOWN: 224 | 225 | startTime = System.currentTimeMillis(); 226 | centerDownY = e.getY(); 227 | centerDownX = e.getX(); 228 | 229 | isAnimeDowning = true; 230 | maxDown = startAnimator(centerDownX, centerDownY, "radiusDown"); 231 | return true; 232 | 233 | case MotionEvent.ACTION_MOVE: 234 | 235 | return true; 236 | 237 | case MotionEvent.ACTION_UP: 238 | case MotionEvent.ACTION_CANCEL: 239 | 240 | 241 | long endTime = System.currentTimeMillis(); 242 | 243 | long time = endTime - startTime; 244 | 245 | 246 | if (time > 500) { 247 | 248 | centerUpY = e.getY(); 249 | centerUpX = e.getX(); 250 | 251 | isAnimeUping = true; 252 | maxUp = startAnimator(centerUpX, centerUpY, "radiusUp"); 253 | 254 | 255 | } 256 | 257 | 258 | break; 259 | 260 | 261 | } 262 | 263 | 264 | return super.onTouchEvent(e); 265 | } 266 | 267 | 268 | private boolean isChildViewClick(View view, int x, int y) { 269 | 270 | if (view.isEnabled() && (view.isClickable() || view.isLongClickable())) { 271 | 272 | childView = view; 273 | return true; 274 | } 275 | 276 | if (view instanceof ViewGroup) { 277 | ViewGroup viewGroup = (ViewGroup) view; 278 | 279 | if (view instanceof FrameLayout || view instanceof RelativeLayout) { 280 | 281 | 282 | for (int i = viewGroup.getChildCount() - 1; i >= 0; i--) { 283 | View child = viewGroup.getChildAt(i); 284 | final Rect rect = new Rect(); 285 | child.getHitRect(rect); 286 | 287 | final boolean contains = rect.contains(x, y); 288 | if (contains) { 289 | return isChildViewClick(child, x - rect.left, y - rect.top); 290 | } 291 | } 292 | } else { 293 | 294 | for (int i = 0; i < viewGroup.getChildCount(); i++) { 295 | View child = viewGroup.getChildAt(i); 296 | final Rect rect = new Rect(); 297 | child.getHitRect(rect); 298 | 299 | final boolean contains = rect.contains(x, y); 300 | if (contains) { 301 | return isChildViewClick(child, x - rect.left, y - rect.top); 302 | } 303 | } 304 | } 305 | 306 | 307 | } 308 | 309 | childView = view; 310 | 311 | 312 | return view.isEnabled() && (view.isClickable() || view.isLongClickable()); 313 | } 314 | 315 | 316 | @Override 317 | public void draw(Canvas canvas) { 318 | 319 | super.draw(canvas); 320 | 321 | if (isAnimeDowning) { 322 | 323 | drawWater(canvas, centerDownX, centerDownY, radiusDown, alphaDown); 324 | if (alphaDown <= 5) { 325 | 326 | isAnimeDowning = false; 327 | } 328 | } 329 | 330 | if (isAnimeUping) { 331 | 332 | drawWater(canvas, centerUpX, centerUpY, radiusUp, alphaUp); 333 | 334 | if (alphaUp <= 5) { 335 | 336 | isAnimeUping = false; 337 | } 338 | } 339 | 340 | 341 | } 342 | 343 | 344 | private void drawWater(Canvas canvas, float centerX, float centerY, float radius, int alpha) { 345 | 346 | 347 | Shader mShader = new RadialGradient(centerX, centerY, waterRadius + radius + waterThickness / 2, 348 | colors, 349 | null, Shader.TileMode.REPEAT); 350 | 351 | paint.setAlpha(alpha); 352 | paint.setShader(mShader); 353 | 354 | paint.setStrokeWidth(waterThickness + radius / 5); 355 | canvas.drawCircle(centerX, centerY, waterRadius + radius, paint); 356 | } 357 | 358 | 359 | public static class Builder { 360 | 361 | 362 | private View view; 363 | private float waterSpeed = 0.5f; 364 | private int waterRadius = 100; 365 | private int waterThickness = 50; 366 | private int[] colors; 367 | 368 | public Builder(View view) { 369 | this.view = view; 370 | } 371 | 372 | 373 | public static Builder on(View view) { 374 | return new Builder(view); 375 | } 376 | 377 | 378 | public Builder waterSpeed(float waterSpeed) { 379 | this.waterSpeed = waterSpeed; 380 | return this; 381 | } 382 | 383 | public Builder waterRadius(int waterRadius) { 384 | this.waterRadius = waterRadius; 385 | return this; 386 | } 387 | 388 | public Builder waterThickness(int waterThickness) { 389 | this.waterThickness = waterThickness; 390 | return this; 391 | } 392 | 393 | public Builder colors(int... colors) { 394 | this.colors = colors; 395 | return this; 396 | } 397 | 398 | 399 | public CanWaterWaveLayout create() { 400 | 401 | if (view.getParent() != null && view.getParent() instanceof CanWaterWaveLayout) { 402 | return (CanWaterWaveLayout) view.getParent(); 403 | } 404 | 405 | CanWaterWaveLayout layout = new CanWaterWaveLayout(view.getContext()); 406 | 407 | layout.setColors(colors); 408 | layout.setWaterSpeed(waterSpeed); 409 | layout.setWaterThickness(waterThickness); 410 | layout.setWaterRadius(waterRadius); 411 | 412 | 413 | ViewGroup.LayoutParams params = view.getLayoutParams(); 414 | ViewGroup parent = (ViewGroup) view.getParent(); 415 | int index = 0; 416 | 417 | 418 | if (parent != null) { 419 | index = parent.indexOfChild(view); 420 | parent.removeView(view); 421 | } 422 | 423 | layout.addView(view, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); 424 | 425 | if (parent != null) { 426 | parent.addView(layout, index, params); 427 | } 428 | 429 | 430 | return layout; 431 | 432 | } 433 | 434 | 435 | } 436 | 437 | 438 | } 439 | -------------------------------------------------------------------------------- /caneffect/src/main/java/com/canyinghao/caneffect/ViewAnimationUtils.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect; 2 | 3 | 4 | import android.animation.Animator; 5 | import android.view.View; 6 | 7 | 8 | /** 9 | * Created by canyinghao on 16/2/3. 10 | */ 11 | public final class ViewAnimationUtils { 12 | 13 | 14 | public static Animator createCircularReveal(View view, int centerX, int centerY, float startRadius, float endRadius) { 15 | 16 | 17 | return CanCircularRevealLayout.Builder.on(view) 18 | .centerX(centerX) 19 | .centerY(centerY) 20 | .startRadius(startRadius) 21 | .endRadius(endRadius) 22 | .create(); 23 | 24 | 25 | } 26 | 27 | 28 | // public static android.animation.Animator createCircularReveal(View view, int centerX, int centerY, float startRadius, float endRadius) { 29 | // 30 | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 31 | // 32 | // return android.view.ViewAnimationUtils 33 | // .createCircularReveal(view, centerX, centerY, startRadius, endRadius); 34 | // } 35 | // 36 | // 37 | // return null; 38 | // 39 | // } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /caneffect/src/main/res/values/attrs_canripple.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /caneffect/src/main/res/values/attrs_canwaterwave.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /caneffect/src/test/java/com/canyinghao/caneffect/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.canyinghao.caneffect; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | android.enableD8=true 15 | android.useAndroidX=true 16 | android.enableJetifier=true 17 | android.enableR8=false 18 | # When configured, Gradle will run in incubating parallel mode. 19 | # This option should only be used with decoupled projects. More details, visit 20 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 21 | # org.gradle.parallel=true 22 | # ./gradlew bintrayUpload 23 | 24 | 25 | PROJ_GROUP=com.canyinghao 26 | PROJ_VERSION=5.0.0 27 | PROJ_NAME=caneffect 28 | PROJ_WEBSITEURL=https://github.com/canyinghao/CanEffect 29 | PROJ_ISSUETRACKERURL= 30 | PROJ_VCSURL=git@github.com:canyinghao/CanEffect.git 31 | PROJ_DESCRIPTION=android caneffect helper 32 | PROJ_ARTIFACTID=caneffect 33 | 34 | DEVELOPER_ID=canyinghao 35 | DEVELOPER_NAME=canyinghao 36 | DEVELOPER_EMAIL=canyinghao@hotmail.com -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/canyinghao/CanEffect/db6610b19021e0e0288d0cdc7e44cd580a3c451a/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 07 11:49:41 CST 2020 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-6.5-bin.zip 7 | 8 | -------------------------------------------------------------------------------- /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 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pic/CanEffect.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/canyinghao/CanEffect/db6610b19021e0e0288d0cdc7e44cd580a3c451a/pic/CanEffect.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':caneffect' 2 | --------------------------------------------------------------------------------