├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── compiler.xml ├── dictionaries │ └── kaisengao.xml ├── encodings.xml ├── gradle.xml ├── inspectionProfiles │ └── Project_Default.xml ├── jarRepositories.xml ├── misc.xml ├── runConfigurations.xml ├── shelf │ ├── Uncommitted_changes_before_Update_at_8_5_21_10_09_PM_[Default_Changelist] │ │ └── shelved.patch │ └── Uncommitted_changes_before_Update_at_8_5_21_10_09_PM__Default_Changelist_.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── ksg │ │ └── likeview │ │ ├── MainActivity.java │ │ ├── NormalActivity.java │ │ ├── RecyclerActivity.java │ │ ├── Viewpager2Activity.java │ │ └── adapter │ │ ├── RecyclerAdapter.java │ │ └── Viewpager2Adapter.java │ └── res │ ├── drawable-xhdpi │ ├── heart0.png │ ├── heart1.png │ ├── heart2.png │ ├── heart3.png │ ├── heart4.png │ ├── heart5.png │ ├── heart6.png │ ├── heart7.png │ └── heart8.png │ ├── layout │ ├── activity_main.xml │ ├── activity_normal.xml │ ├── activity_recycler.xml │ ├── activity_viewpager2.xml │ ├── item_recycler.xml │ └── item_viewpager2.xml │ ├── mipmap-xhdpi │ └── logo.png │ ├── mipmap-xxhdpi │ └── logo.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── config.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images ├── like_list.gif ├── like_main.jpg ├── like_normal.gif └── like_viewpager.gif ├── lib_likeview ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── kaisengao │ │ └── likeview │ │ └── like │ │ ├── AnimationLayout.java │ │ ├── IAnimationLayout.java │ │ ├── KsgLikeView.java │ │ └── evaluator │ │ ├── CurveEvaluatorRecord.java │ │ └── ThreeCurveEvaluator.java │ └── res │ ├── drawable-xhdpi │ └── default_favor.png │ └── values │ ├── attr.xml │ └── strings.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 |
116 |
-------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/dictionaries/kaisengao.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | likeview 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/shelf/Uncommitted_changes_before_Update_at_8_5_21_10_09_PM_[Default_Changelist]/shelved.patch: -------------------------------------------------------------------------------- 1 | Index: .idea/codeStyles/Project.xml 2 | IDEA additional info: 3 | Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 4 | <+>UTF-8 5 | =================================================================== 6 | --- .idea/codeStyles/Project.xml (date 1589801046000) 7 | +++ .idea/codeStyles/Project.xml (date 1589801046000) 8 | @@ -0,0 +1,116 @@ 9 | + 10 | + 11 | + 12 | + 13 | + 15 | + 16 | + 17 | +
18 | + 19 | + 20 | + 21 | + xmlns:android 22 | + 23 | + ^$ 24 | + 25 | + 26 | + 27 | +
28 | +
29 | + 30 | + 31 | + 32 | + xmlns:.* 33 | + 34 | + ^$ 35 | + 36 | + 37 | + BY_NAME 38 | + 39 | +
40 | +
41 | + 42 | + 43 | + 44 | + .*:id 45 | + 46 | + http://schemas.android.com/apk/res/android 47 | + 48 | + 49 | + 50 | +
51 | +
52 | + 53 | + 54 | + 55 | + .*:name 56 | + 57 | + http://schemas.android.com/apk/res/android 58 | + 59 | + 60 | + 61 | +
62 | +
63 | + 64 | + 65 | + 66 | + name 67 | + 68 | + ^$ 69 | + 70 | + 71 | + 72 | +
73 | +
74 | + 75 | + 76 | + 77 | + style 78 | + 79 | + ^$ 80 | + 81 | + 82 | + 83 | +
84 | +
85 | + 86 | + 87 | + 88 | + .* 89 | + 90 | + ^$ 91 | + 92 | + 93 | + BY_NAME 94 | + 95 | +
96 | +
97 | + 98 | + 99 | + 100 | + .* 101 | + 102 | + http://schemas.android.com/apk/res/android 103 | + 104 | + 105 | + ANDROID_ATTRIBUTE_ORDER 106 | + 107 | +
108 | +
109 | + 110 | + 111 | + 112 | + .* 113 | + 114 | + .* 115 | + 116 | + 117 | + BY_NAME 118 | + 119 | +
120 | +
121 | +
122 | +
123 | +
124 | +
125 | \ No newline at end of file 126 | Index: .idea/gradle.xml 127 | IDEA additional info: 128 | Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP 129 | <+>\n\n \n \n \n 130 | Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 131 | <+>UTF-8 132 | =================================================================== 133 | --- .idea/gradle.xml (revision 3055c3c7a70645fb1be8bf408b0d29c678ffd47b) 134 | +++ .idea/gradle.xml (date 1628172507000) 135 | @@ -1,14 +1,22 @@ 136 | 137 | 138 | + 139 | 140 | 160 | 161 | Index: .idea/misc.xml 162 | IDEA additional info: 163 | Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP 164 | <+>\n\n \n \n \n \n \n 165 | Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 166 | <+>UTF-8 167 | =================================================================== 168 | --- .idea/misc.xml (revision 3055c3c7a70645fb1be8bf408b0d29c678ffd47b) 169 | +++ .idea/misc.xml (date 1628172549000) 170 | @@ -1,6 +1,6 @@ 171 | 172 | 173 | - 174 | + 175 | 176 | 177 | 178 | Index: .idea/compiler.xml 179 | IDEA additional info: 180 | Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 181 | <+>UTF-8 182 | =================================================================== 183 | --- .idea/compiler.xml (date 1628172549000) 184 | +++ .idea/compiler.xml (date 1628172549000) 185 | @@ -0,0 +1,6 @@ 186 | + 187 | + 188 | + 189 | + 190 | + 191 | + 192 | \ No newline at end of file 193 | -------------------------------------------------------------------------------- /.idea/shelf/Uncommitted_changes_before_Update_at_8_5_21_10_09_PM__Default_Changelist_.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KsgLikeView 2 | Android 贝塞尔曲线点赞飘心动画效果 3 | 4 | [![](https://jitpack.io/v/kaisengao/KsgLikeView.svg)](https://jitpack.io/#kaisengao/KsgLikeView) 5 | 6 | ### 添加依赖 7 | ``` gradle 8 | allprojects { 9 | repositories { 10 | ... 11 | maven { url 'https://jitpack.io' } 12 | } 13 | } 14 | ``` 15 | 16 | ``` gradle 17 | dependencies { 18 | implementation 'com.github.kaisengao:KsgLikeView:1.2.2' 19 | } 20 | ``` 21 | 22 | ### 效果图 23 | 24 | 25 | 26 | 27 | 28 | ### 基本使用 29 | 30 | ```java 31 | 42 | ``` 43 | ### 添加资源 44 | 45 | 添加单张图片资源 46 | ```java 47 | mLikeView.addLikeImage(R.drawable.heart0); 48 | ``` 49 | 数组形式 50 | ```java 51 | mLikeView.addLikeImages( 52 | R.drawable.heart0, R.drawable.heart1, R.drawable.heart2, 53 | R.drawable.heart3, R.drawable.heart4, R.drawable.heart5, 54 | R.drawable.heart6, R.drawable.heart7, R.drawable.heart8); 55 | ``` 56 | 集合形式 57 | ```java 58 | List images = new ArrayList<>(); 59 | images.add(R.drawable.heart0); 60 | images.add(R.drawable.heart1); 61 | mLikeView.addLikeImages(images); 62 | ``` 63 | ### 发送 64 | 65 | ```java 66 | mLikeView.addFavor(); 67 | ``` 68 | ### Xml attributes 69 | attribute | description 70 | ------------- | ------------- 71 | ksg_enter_duration | 进入动画 时长 72 | ksg_curve_duration | 路径动画 时长 73 | 74 | ### 更新内容 75 | ### 1.2.1版本:优化整体代码,加入路径缓存 76 | ### 1.2.2版本:新功能,在列表中使用该View 77 | ### (警告:在列表中使用如果调用了Notify刷新就会导致动画消失,因为Item刷新机制问题View会重新创建) 78 | ### 建议有需求的小伙伴手动刷新Item中的View较好。后续我会想想办法解决。 79 | 80 | 81 | :kissing_heart: 82 | 83 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.android.compileSdkVersion 5 | buildToolsVersion rootProject.ext.android.buildToolsVersion 6 | 7 | defaultConfig { 8 | applicationId rootProject.ext.android.applicationId 9 | minSdkVersion rootProject.ext.android.minSdkVersion 10 | targetSdkVersion rootProject.ext.android.targetSdkVersion 11 | versionCode rootProject.ext.android.versionCode 12 | versionName rootProject.ext.android.versionName 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | implementation fileTree(dir: 'libs', include: ['*.jar']) 25 | // Lib LikeView 26 | implementation project(':lib_likeview') 27 | implementation 'androidx.appcompat:appcompat:1.1.0' 28 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 29 | implementation 'androidx.viewpager2:viewpager2:1.1.0-alpha01' 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/ksg/likeview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.ksg.likeview; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | 7 | import androidx.appcompat.app.AppCompatActivity; 8 | 9 | /** 10 | * @ClassName: MainActivity 11 | * @Author: KaiSenGao 12 | * @CreateDate: 2019-09-17 14:23 13 | * @Description: 啦啦啦啦啦 德玛西亚 14 | */ 15 | public class MainActivity extends AppCompatActivity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | this.setContentView(R.layout.activity_main); 21 | } 22 | 23 | public void intentNormal(View view) { 24 | this.startActivity(new Intent(this, NormalActivity.class)); 25 | } 26 | 27 | public void intentRecycler(View view) { 28 | this.startActivity(new Intent(this, RecyclerActivity.class)); 29 | } 30 | 31 | public void intentViewpager2(View view) { 32 | this.startActivity(new Intent(this, Viewpager2Activity.class)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/ksg/likeview/NormalActivity.java: -------------------------------------------------------------------------------- 1 | package com.ksg.likeview; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.os.Looper; 6 | import android.view.View; 7 | 8 | import com.kaisengao.likeview.like.KsgLikeView; 9 | 10 | import androidx.appcompat.app.AppCompatActivity; 11 | 12 | /** 13 | * @ClassName: NormalActivity 14 | * @Author: KaiSenGao 15 | * @CreateDate: 8/5/21 10:23 PM 16 | * @Description: 普通模式 17 | */ 18 | public class NormalActivity extends AppCompatActivity { 19 | 20 | private KsgLikeView mLikeView; 21 | 22 | private final Handler mHandler = new Handler(Looper.getMainLooper()); 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | this.setContentView(R.layout.activity_normal); 28 | // InitView 29 | this.initView(); 30 | } 31 | 32 | /** 33 | * InitView 34 | */ 35 | private void initView() { 36 | this.mLikeView = findViewById(R.id.live_view); 37 | // 添加资源文件 38 | this.mLikeView.addLikeImages( 39 | R.drawable.heart0, R.drawable.heart1, R.drawable.heart2, 40 | R.drawable.heart3, R.drawable.heart4, R.drawable.heart5, 41 | R.drawable.heart6, R.drawable.heart7, R.drawable.heart8); 42 | // 单个发送 43 | this.findViewById(R.id.single).setOnClickListener(new View.OnClickListener() { 44 | @Override 45 | public void onClick(View v) { 46 | mLikeView.addFavor(); 47 | } 48 | }); 49 | // 多个发送 50 | this.findViewById(R.id.multiple).setOnClickListener(new View.OnClickListener() { 51 | @Override 52 | public void onClick(View view) { 53 | boolean selected = view.isSelected(); 54 | if (selected) { 55 | mHandler.removeCallbacks(mLikeRunnable); 56 | } else { 57 | mHandler.postDelayed(mLikeRunnable, 100); 58 | } 59 | view.setSelected(!selected); 60 | } 61 | }); 62 | } 63 | 64 | /** 65 | * LikeRunnable 66 | */ 67 | private final Runnable mLikeRunnable = new Runnable() { 68 | @Override 69 | public void run() { 70 | // 添加 发送 71 | mLikeView.addFavor(); 72 | mHandler.postDelayed(mLikeRunnable, 100); 73 | } 74 | }; 75 | 76 | @Override 77 | protected void onDestroy() { 78 | super.onDestroy(); 79 | this.mHandler.removeCallbacks(mLikeRunnable); 80 | } 81 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ksg/likeview/RecyclerActivity.java: -------------------------------------------------------------------------------- 1 | package com.ksg.likeview; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.ksg.likeview.adapter.RecyclerAdapter; 6 | 7 | import androidx.appcompat.app.AppCompatActivity; 8 | import androidx.recyclerview.widget.LinearLayoutManager; 9 | import androidx.recyclerview.widget.RecyclerView; 10 | 11 | /** 12 | * @ClassName: ListActivity 13 | * @Author: KaiSenGao 14 | * @CreateDate: 8/5/21 11:06 PM 15 | * @Description: 列表模式 16 | */ 17 | public class RecyclerActivity extends AppCompatActivity { 18 | 19 | private RecyclerView mRecyclerView; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | this.setContentView(R.layout.activity_recycler); 25 | // InitView 26 | this.initView(); 27 | } 28 | 29 | /** 30 | * InitView 31 | */ 32 | private void initView() { 33 | this.mRecyclerView = findViewById(R.id.recycler); 34 | // Init Adapter 35 | this.initAdapter(); 36 | } 37 | 38 | /** 39 | * Init Adapter 40 | */ 41 | private void initAdapter() { 42 | // Adapter 43 | RecyclerAdapter adapter = new RecyclerAdapter(); 44 | // Recycler 45 | this.mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); 46 | this.mRecyclerView.setAdapter(adapter); 47 | } 48 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ksg/likeview/Viewpager2Activity.java: -------------------------------------------------------------------------------- 1 | package com.ksg.likeview; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.ksg.likeview.adapter.Viewpager2Adapter; 6 | 7 | import androidx.appcompat.app.AppCompatActivity; 8 | import androidx.viewpager2.widget.ViewPager2; 9 | 10 | /** 11 | * @ClassName: Viewpager2Activity 12 | * @Author: KaiSenGao 13 | * @CreateDate: 8/5/21 10:25 PM 14 | * @Description: Viewpager2 列表模式 15 | */ 16 | public class Viewpager2Activity extends AppCompatActivity { 17 | 18 | private ViewPager2 mViewPager2; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | this.setContentView(R.layout.activity_viewpager2); 24 | // InitView 25 | this.initView(); 26 | } 27 | 28 | /** 29 | * InitView 30 | */ 31 | private void initView() { 32 | this.mViewPager2 = findViewById(R.id.viewPager2); 33 | // Init Adapter 34 | this.initAdapter(); 35 | } 36 | 37 | /** 38 | * Init Adapter 39 | */ 40 | private void initAdapter() { 41 | // Adapter 42 | Viewpager2Adapter adapter = new Viewpager2Adapter(); 43 | // ViewPager 44 | this.mViewPager2.setAdapter(adapter); 45 | } 46 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ksg/likeview/adapter/RecyclerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ksg.likeview.adapter; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import com.kaisengao.likeview.like.KsgLikeView; 9 | import com.ksg.likeview.R; 10 | 11 | import androidx.annotation.NonNull; 12 | import androidx.appcompat.widget.AppCompatTextView; 13 | import androidx.recyclerview.widget.RecyclerView; 14 | 15 | /** 16 | * @ClassName: ListAdapter 17 | * @Author: KaiSenGao 18 | * @CreateDate: 8/5/21 10:31 PM 19 | * @Description: RC 列表模式 Adapter 20 | */ 21 | public class RecyclerAdapter extends RecyclerView.Adapter { 22 | 23 | @NonNull 24 | @Override 25 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 26 | View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycler, parent, false); 27 | return new ViewHolder(itemView); 28 | } 29 | 30 | @Override 31 | public int getItemCount() { 32 | return 20; 33 | } 34 | 35 | @SuppressLint("SetTextI18n") 36 | @Override 37 | public void onBindViewHolder(@NonNull ViewHolder holder, int position) { 38 | holder.mItemVideo.setText("我是短视频(" + position + ")"); 39 | } 40 | 41 | public class ViewHolder extends RecyclerView.ViewHolder { 42 | 43 | private final AppCompatTextView mItemVideo; 44 | 45 | private final KsgLikeView mItemLike; 46 | 47 | public ViewHolder(@NonNull final View itemView) { 48 | super(itemView); 49 | this.mItemVideo = itemView.findViewById(R.id.item_video); 50 | this.mItemLike = itemView.findViewById(R.id.item_like); 51 | // 点赞 52 | itemView.findViewById(R.id.item_praise).setOnClickListener(new View.OnClickListener() { 53 | @Override 54 | public void onClick(View v) { 55 | mItemLike.addFavor(); 56 | } 57 | }); 58 | // 刷新Item 59 | itemView.findViewById(R.id.item_notify).setOnClickListener(new View.OnClickListener() { 60 | @Override 61 | public void onClick(View v) { 62 | notifyItemChanged(getLayoutPosition()); 63 | } 64 | }); 65 | // InitLikeView 66 | this.initLikeView(); 67 | } 68 | 69 | /** 70 | * InitLikeView 71 | */ 72 | private void initLikeView() { 73 | // 添加资源文件 74 | this.mItemLike.addLikeImages( 75 | R.drawable.heart0, R.drawable.heart1, R.drawable.heart2, 76 | R.drawable.heart3, R.drawable.heart4, R.drawable.heart5, 77 | R.drawable.heart6, R.drawable.heart7, R.drawable.heart8); 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ksg/likeview/adapter/Viewpager2Adapter.java: -------------------------------------------------------------------------------- 1 | package com.ksg.likeview.adapter; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import com.kaisengao.likeview.like.KsgLikeView; 9 | import com.ksg.likeview.R; 10 | 11 | import androidx.annotation.NonNull; 12 | import androidx.appcompat.widget.AppCompatTextView; 13 | import androidx.recyclerview.widget.RecyclerView; 14 | 15 | /** 16 | * @ClassName: Viewpager2Adapter 17 | * @Author: KaiSenGao 18 | * @CreateDate: 8/5/21 10:31 PM 19 | * @Description: Viewpager2 列表模式 Adapter 20 | */ 21 | public class Viewpager2Adapter extends RecyclerView.Adapter { 22 | 23 | 24 | 25 | @NonNull 26 | @Override 27 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 28 | View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_viewpager2, parent, false); 29 | return new ViewHolder(itemView); 30 | } 31 | 32 | @Override 33 | public int getItemCount() { 34 | return 20; 35 | } 36 | 37 | @SuppressLint("SetTextI18n") 38 | @Override 39 | public void onBindViewHolder(@NonNull ViewHolder holder, int position) { 40 | holder.mItemVideo.setText("我是短视频(" + position + ")"); 41 | } 42 | 43 | public class ViewHolder extends RecyclerView.ViewHolder { 44 | 45 | private final AppCompatTextView mItemVideo; 46 | 47 | private final KsgLikeView mItemLike; 48 | 49 | public ViewHolder(@NonNull final View itemView) { 50 | super(itemView); 51 | this.mItemVideo = itemView.findViewById(R.id.item_video); 52 | this.mItemLike = itemView.findViewById(R.id.item_like); 53 | // 点赞 54 | itemView.findViewById(R.id.item_praise).setOnClickListener(new View.OnClickListener() { 55 | @Override 56 | public void onClick(View v) { 57 | mItemLike.addFavor(); 58 | } 59 | }); 60 | // 刷新Item 61 | itemView.findViewById(R.id.item_notify).setOnClickListener(new View.OnClickListener() { 62 | @Override 63 | public void onClick(View v) { 64 | notifyItemChanged(getLayoutPosition()); 65 | } 66 | }); 67 | // InitLikeView 68 | this.initLikeView(); 69 | } 70 | 71 | /** 72 | * InitLikeView 73 | */ 74 | private void initLikeView() { 75 | // 添加资源文件 76 | this.mItemLike.addLikeImages( 77 | R.drawable.heart0, R.drawable.heart1, R.drawable.heart2, 78 | R.drawable.heart3, R.drawable.heart4, R.drawable.heart5, 79 | R.drawable.heart6, R.drawable.heart7, R.drawable.heart8); 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/heart0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/app/src/main/res/drawable-xhdpi/heart0.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/heart1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/app/src/main/res/drawable-xhdpi/heart1.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/heart2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/app/src/main/res/drawable-xhdpi/heart2.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/heart3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/app/src/main/res/drawable-xhdpi/heart3.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/heart4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/app/src/main/res/drawable-xhdpi/heart4.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/heart5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/app/src/main/res/drawable-xhdpi/heart5.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/heart6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/app/src/main/res/drawable-xhdpi/heart6.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/heart7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/app/src/main/res/drawable-xhdpi/heart7.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/heart8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/app/src/main/res/drawable-xhdpi/heart8.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 18 | 19 | 28 | 29 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 20 | 21 | 31 | 32 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_recycler.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_viewpager2.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_recycler.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 17 | 18 | 27 | 28 | 39 | 40 | 52 | 53 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_viewpager2.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 17 | 18 | 27 | 28 | 39 | 40 | 52 | 53 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/app/src/main/res/mipmap-xhdpi/logo.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/app/src/main/res/mipmap-xxhdpi/logo.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | KsgLikeView 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | // 引入配置文件 3 | apply from: "config.gradle" 4 | 5 | buildscript { 6 | repositories { 7 | google() 8 | jcenter() 9 | 10 | } 11 | dependencies { 12 | classpath 'com.android.tools.build:gradle:3.4.1' 13 | 14 | // NOTE: Do not place your application dependencies here; they belong 15 | // in the individual module build.gradle files 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | google() 22 | jcenter() 23 | } 24 | } 25 | 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } 29 | -------------------------------------------------------------------------------- /config.gradle: -------------------------------------------------------------------------------- 1 | ext { 2 | 3 | // Android开发版本配置 4 | android = [ 5 | compileSdkVersion: 29, 6 | buildToolsVersion: "30.0.2", 7 | applicationId : "com.ksg.likeview", 8 | minSdkVersion : 19, 9 | targetSdkVersion : 29, 10 | versionCode : 1, 11 | versionName : "1.0.0", 12 | ] 13 | 14 | // Androidx配置 15 | constraint = '2.0.4' 16 | recycler = '1.1.0' 17 | appcompat = '1.2.0' 18 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | 21 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Sep 17 14:21:57 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /images/like_list.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/images/like_list.gif -------------------------------------------------------------------------------- /images/like_main.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/images/like_main.jpg -------------------------------------------------------------------------------- /images/like_normal.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/images/like_normal.gif -------------------------------------------------------------------------------- /images/like_viewpager.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/images/like_viewpager.gif -------------------------------------------------------------------------------- /lib_likeview/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /lib_likeview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.android.compileSdkVersion 5 | buildToolsVersion rootProject.ext.android.buildToolsVersion 6 | 7 | defaultConfig { 8 | minSdkVersion rootProject.ext.android.minSdkVersion 9 | targetSdkVersion rootProject.ext.android.targetSdkVersion 10 | } 11 | 12 | buildTypes { 13 | release { 14 | minifyEnabled false 15 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 16 | } 17 | } 18 | } 19 | 20 | dependencies { 21 | // Androidx 22 | api 'androidx.appcompat:appcompat:1.2.0' 23 | api 'androidx.constraintlayout:constraintlayout:2.0.4' 24 | } 25 | -------------------------------------------------------------------------------- /lib_likeview/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /lib_likeview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /lib_likeview/src/main/java/com/kaisengao/likeview/like/AnimationLayout.java: -------------------------------------------------------------------------------- 1 | package com.kaisengao.likeview.like; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.animation.AnimatorSet; 6 | import android.animation.ValueAnimator; 7 | import android.content.Context; 8 | import android.graphics.BitmapFactory; 9 | import android.graphics.PointF; 10 | import android.util.AttributeSet; 11 | import android.view.View; 12 | import android.widget.FrameLayout; 13 | 14 | import com.kaisengao.likeview.like.evaluator.CurveEvaluatorRecord; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | import java.util.Random; 19 | 20 | import androidx.annotation.DrawableRes; 21 | import androidx.annotation.NonNull; 22 | import androidx.annotation.Nullable; 23 | 24 | /** 25 | * @ClassName: AnimationLayout 26 | * @Author: KaiSenGao 27 | * @CreateDate: 2020/12/24 10:58 28 | * @Description: 29 | */ 30 | public abstract class AnimationLayout extends FrameLayout implements IAnimationLayout { 31 | 32 | protected final Random mRandom = new Random(); 33 | 34 | protected int mViewWidth, mViewHeight; 35 | 36 | protected float mPicWidth, mPicHeight; 37 | 38 | protected List mAnimatorSets; 39 | 40 | protected CurveEvaluatorRecord mEvaluatorRecord; 41 | 42 | public AnimationLayout(@NonNull Context context) { 43 | this(context, null); 44 | } 45 | 46 | public AnimationLayout(@NonNull Context context, @Nullable AttributeSet attrs) { 47 | super(context, attrs); 48 | } 49 | 50 | @Override 51 | protected void onAttachedToWindow() { 52 | super.onAttachedToWindow(); 53 | // 初始化 54 | this.init(); 55 | } 56 | 57 | /** 58 | * 初始化 59 | */ 60 | protected void init() { 61 | // 动画集合 62 | if (mAnimatorSets == null) { 63 | this.mAnimatorSets = new ArrayList<>(); 64 | } 65 | // 贝塞尔曲线缓存类 66 | if (mEvaluatorRecord == null) { 67 | this.mEvaluatorRecord = new CurveEvaluatorRecord(); 68 | } 69 | } 70 | 71 | /** 72 | * 获取资源图片信息 73 | * 74 | * @param resId 资源Id 75 | */ 76 | public void getPictureInfo(@DrawableRes int resId) { 77 | // 获取图片 78 | BitmapFactory.Options options = new BitmapFactory.Options(); 79 | // 只读取图片,不加载到内存中 80 | options.inJustDecodeBounds = true; 81 | BitmapFactory.decodeResource(getContext().getResources(), resId, options); 82 | // 获取图片的宽高 83 | this.mPicWidth = options.outWidth; 84 | this.mPicHeight = options.outHeight; 85 | } 86 | 87 | @Override 88 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 89 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 90 | this.mViewWidth = getMeasuredWidth(); 91 | this.mViewHeight = getMeasuredHeight(); 92 | } 93 | 94 | @Override 95 | protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) { 96 | super.onSizeChanged(width, height, oldWidth, oldHeight); 97 | this.mViewWidth = getMeasuredWidth(); 98 | this.mViewHeight = getMeasuredHeight(); 99 | } 100 | 101 | /** 102 | * 贝塞尔曲线路径更新事件 103 | */ 104 | protected static class CurveUpdateLister implements ValueAnimator.AnimatorUpdateListener { 105 | 106 | private final View mChild; 107 | 108 | protected CurveUpdateLister(View child) { 109 | this.mChild = child; 110 | } 111 | 112 | @Override 113 | public void onAnimationUpdate(ValueAnimator animation) { 114 | PointF value = (PointF) animation.getAnimatedValue(); 115 | this.mChild.setX(value.x); 116 | this.mChild.setY(value.y); 117 | this.mChild.setAlpha(1 - animation.getAnimatedFraction()); 118 | } 119 | } 120 | 121 | /** 122 | * 动画结束监听器,用于释放无用的资源 123 | */ 124 | protected class AnimationEndListener extends AnimatorListenerAdapter { 125 | 126 | private View mChild; 127 | 128 | private final AnimatorSet mAnimatorSet; 129 | 130 | protected AnimationEndListener(View child, AnimatorSet animatorSet) { 131 | this.mChild = child; 132 | this.mAnimatorSet = animatorSet; 133 | // 缓存 134 | mAnimatorSets.add(mAnimatorSet); 135 | } 136 | 137 | @Override 138 | public void onAnimationEnd(Animator animation) { 139 | super.onAnimationEnd(animation); 140 | // 移除View 141 | removeView(mChild); 142 | // 移除缓存 143 | mAnimatorSets.remove(mAnimatorSet); 144 | // 释放View 145 | this.mChild = null; 146 | } 147 | } 148 | 149 | @Override 150 | protected void onDetachedFromWindow() { 151 | super.onDetachedFromWindow(); 152 | // 销毁资源 153 | this.destroy(); 154 | } 155 | 156 | /** 157 | * 销毁资源 158 | */ 159 | public void destroy() { 160 | // 移除所有View 161 | this.removeAllViews(); 162 | // 取消动画 释放资源 163 | if (mAnimatorSets != null) { 164 | // 取消动画 165 | for (AnimatorSet animatorSet : mAnimatorSets) { 166 | animatorSet.getListeners().clear(); 167 | animatorSet.cancel(); 168 | } 169 | this.mAnimatorSets.clear(); 170 | this.mAnimatorSets = null; 171 | } 172 | // 清空缓存路径 173 | if (mEvaluatorRecord != null) { 174 | this.mEvaluatorRecord.destroy(); 175 | this.mEvaluatorRecord = null; 176 | } 177 | } 178 | } -------------------------------------------------------------------------------- /lib_likeview/src/main/java/com/kaisengao/likeview/like/IAnimationLayout.java: -------------------------------------------------------------------------------- 1 | package com.kaisengao.likeview.like; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @ClassName: IAnimationLayout 7 | * @Author: KaiSenGao 8 | * @CreateDate: 2020/12/24 10:57 9 | * @Description: 10 | */ 11 | public interface IAnimationLayout { 12 | 13 | /** 14 | * 添加 资源文件 15 | * 16 | * @param resId resId 17 | */ 18 | void addLikeImage(int resId); 19 | 20 | /** 21 | * 添加 资源文件组 22 | * 23 | * @param resIds resIds 24 | */ 25 | void addLikeImages(Integer... resIds); 26 | 27 | /** 28 | * 添加 资源文件列表 29 | * 30 | * @param resIds resIds 31 | */ 32 | void addLikeImages(List resIds); 33 | 34 | /** 35 | * 添加 发送 36 | */ 37 | void addFavor(); 38 | } -------------------------------------------------------------------------------- /lib_likeview/src/main/java/com/kaisengao/likeview/like/KsgLikeView.java: -------------------------------------------------------------------------------- 1 | package com.kaisengao.likeview.like; 2 | 3 | import android.animation.AnimatorSet; 4 | import android.animation.ObjectAnimator; 5 | import android.animation.ValueAnimator; 6 | import android.content.Context; 7 | import android.content.res.TypedArray; 8 | import android.graphics.PointF; 9 | import android.util.AttributeSet; 10 | import android.view.Gravity; 11 | import android.view.View; 12 | import android.view.animation.LinearInterpolator; 13 | 14 | import com.kaisengao.likeview.R; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | 20 | import androidx.appcompat.widget.AppCompatImageView; 21 | 22 | /** 23 | * @ClassName: KsgLikeView 24 | * @Author: KaiSenGao 25 | * @CreateDate: 2019-09-17 14:23 26 | * @Description: 飘心View 27 | */ 28 | public class KsgLikeView extends AnimationLayout { 29 | 30 | private int mEnterDuration; 31 | 32 | private int mCurveDuration; 33 | 34 | private final List mLikeRes; 35 | 36 | public KsgLikeView(Context context) { 37 | this(context, null); 38 | } 39 | 40 | public KsgLikeView(Context context, AttributeSet attrs) { 41 | super(context, attrs); 42 | // Init TypedArray 43 | this.initTypedArray(attrs); 44 | // Create Resource List 45 | this.mLikeRes = new ArrayList<>(); 46 | } 47 | 48 | /** 49 | * Init TypedArray 50 | */ 51 | private void initTypedArray(AttributeSet attrs) { 52 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.KsgLikeView); 53 | // 进入动画时长 54 | this.mEnterDuration = typedArray.getInteger(R.styleable.KsgLikeView_ksg_enter_duration, 1500); 55 | // 路径动画时长 56 | this.mCurveDuration = typedArray.getInteger(R.styleable.KsgLikeView_ksg_curve_duration, 4500); 57 | // 回收 58 | typedArray.recycle(); 59 | } 60 | 61 | /** 62 | * 添加 资源文件 63 | * 64 | * @param resId resId 65 | */ 66 | @Override 67 | public void addLikeImage(int resId) { 68 | this.addLikeImages(resId); 69 | } 70 | 71 | /** 72 | * 添加 资源文件组 73 | * 74 | * @param resIds resIds 75 | */ 76 | @Override 77 | public void addLikeImages(Integer... resIds) { 78 | this.addLikeImages(Arrays.asList(resIds)); 79 | } 80 | 81 | /** 82 | * 添加 资源文件列表 83 | * 84 | * @param resIds resIds 85 | */ 86 | @Override 87 | public void addLikeImages(List resIds) { 88 | this.mLikeRes.addAll(resIds); 89 | } 90 | 91 | /** 92 | * 添加 发送 93 | */ 94 | @Override 95 | public void addFavor() { 96 | // 非空验证 97 | if (mLikeRes.isEmpty()) { 98 | throw new NullPointerException("Missing resource file!"); 99 | } 100 | // 随机获取一个资源 101 | int favorRes = Math.abs(mLikeRes.get(mRandom.nextInt(mLikeRes.size()))); 102 | // 生成 配置参数 103 | LayoutParams layoutParams = createLayoutParams(favorRes); 104 | // 创建一个资源View 105 | AppCompatImageView favorView = new AppCompatImageView(getContext()); 106 | favorView.setImageResource(favorRes); 107 | // 开始执行动画 108 | this.start(favorView, layoutParams); 109 | } 110 | 111 | /** 112 | * 生成 配置参数 113 | */ 114 | private LayoutParams createLayoutParams(int crystalLeaf) { 115 | // 获取图片信息 116 | this.getPictureInfo(crystalLeaf); 117 | // 初始化布局参数 118 | return new LayoutParams((int) mPicWidth, (int) mPicHeight, Gravity.BOTTOM | Gravity.CENTER); 119 | } 120 | 121 | /** 122 | * 开始执行动画 123 | * 124 | * @param child child 125 | * @param layoutParams layoutParams 126 | */ 127 | private void start(View child, LayoutParams layoutParams) { 128 | // 设置进入动画 129 | AnimatorSet enterAnimator = generateEnterAnimation(child); 130 | // 设置路径动画 131 | ValueAnimator curveAnimator = generateCurveAnimation(child); 132 | // 执行动画集合 133 | AnimatorSet animatorSet = new AnimatorSet(); 134 | animatorSet.playTogether(curveAnimator, enterAnimator); 135 | animatorSet.addListener(new AnimationEndListener(child, animatorSet)); 136 | animatorSet.start(); 137 | // add父布局 138 | super.addView(child, layoutParams); 139 | } 140 | 141 | /** 142 | * 进入动画 143 | * 144 | * @return 动画集合 145 | */ 146 | private AnimatorSet generateEnterAnimation(View child) { 147 | AnimatorSet enterAnimation = new AnimatorSet(); 148 | enterAnimation.playTogether( 149 | ObjectAnimator.ofFloat(child, ALPHA, 0.2f, 1f), 150 | ObjectAnimator.ofFloat(child, SCALE_X, 0.2f, 1f), 151 | ObjectAnimator.ofFloat(child, SCALE_Y, 0.2f, 1f)); 152 | // 加一些动画差值器 153 | enterAnimation.setInterpolator(new LinearInterpolator()); 154 | return enterAnimation.setDuration(mEnterDuration); 155 | } 156 | 157 | /** 158 | * 贝赛尔曲线动画 159 | * 160 | * @return 动画集合 161 | */ 162 | private ValueAnimator generateCurveAnimation(View child) { 163 | // 起点 坐标 164 | PointF pointStart = new PointF((mViewWidth - mPicWidth) / 2, mViewHeight - mPicHeight); 165 | // 终点 坐标 166 | PointF pointEnd = new PointF(((mViewWidth - mPicWidth) / 2) + ((mRandom.nextBoolean() ? 1 : -1) * mRandom.nextInt(100)), 0); 167 | // 属性动画 168 | PointF pointF1 = getTogglePoint(1); 169 | PointF pointF2 = getTogglePoint(2); 170 | ValueAnimator curveAnimator = ValueAnimator.ofObject(mEvaluatorRecord.getCurrentPath(pointF1, pointF2), pointStart, pointEnd); 171 | curveAnimator.addUpdateListener(new CurveUpdateLister(child)); 172 | curveAnimator.setInterpolator(new LinearInterpolator()); 173 | return curveAnimator.setDuration(mCurveDuration); 174 | } 175 | 176 | private PointF getTogglePoint(int scale) { 177 | PointF pointf = new PointF(); 178 | // 减去100 是为了控制 x轴活动范围 179 | pointf.x = mRandom.nextInt((mViewWidth - 100)); 180 | // 再Y轴上 为了确保第二个控制点 在第一个点之上,我把Y分成了上下两半 181 | pointf.y = (float) mRandom.nextInt((mViewHeight - 100)) / scale; 182 | return pointf; 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /lib_likeview/src/main/java/com/kaisengao/likeview/like/evaluator/CurveEvaluatorRecord.java: -------------------------------------------------------------------------------- 1 | package com.kaisengao.likeview.like.evaluator; 2 | 3 | import android.animation.TypeEvaluator; 4 | import android.graphics.PointF; 5 | import android.util.SparseArray; 6 | 7 | import java.util.Random; 8 | 9 | /** 10 | * @ClassName: CurveEvaluatorRecord 11 | * @Author: KaiSenGao 12 | * @CreateDate: 2020/12/24 10:58 13 | * @Description: 贝塞尔曲线缓存类 14 | */ 15 | public class CurveEvaluatorRecord { 16 | 17 | private static final int MAX_PATH_COUNTS = 100; 18 | 19 | private final Random mRandom = new Random(); 20 | 21 | private int mCurrentPathCounts; 22 | 23 | private SparseArray> mPathArray; 24 | 25 | public CurveEvaluatorRecord() { 26 | this.mPathArray = new SparseArray<>(); 27 | } 28 | 29 | /** 30 | * 生成曲线路线 31 | */ 32 | public TypeEvaluator getCurrentPath(PointF pointF1, PointF pointF2) { 33 | TypeEvaluator evaluator; 34 | // 记录已生成路径 35 | ++mCurrentPathCounts; 36 | // 如果已经生成的路径数目超过最大设定,就从路径缓存中随机取一个路径用于绘制,否则新生成一个 37 | if (mCurrentPathCounts > MAX_PATH_COUNTS) { 38 | // 读取缓存 39 | evaluator = mPathArray.get(Math.abs(mRandom.nextInt() % MAX_PATH_COUNTS) + 1); 40 | } else { 41 | // 创建路径 42 | evaluator = createPath(pointF1, pointF2); 43 | // 缓存 44 | this.mPathArray.put(mCurrentPathCounts, evaluator); 45 | } 46 | return evaluator; 47 | } 48 | 49 | /** 50 | * 生成 贝塞尔路径 51 | */ 52 | private TypeEvaluator createPath(PointF pointF1, PointF pointF2) { 53 | return new ThreeCurveEvaluator(pointF1, pointF2); 54 | } 55 | 56 | /** 57 | * destroy 58 | */ 59 | public void destroy() { 60 | if (mPathArray != null) { 61 | this.mPathArray.clear(); 62 | this.mPathArray = null; 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /lib_likeview/src/main/java/com/kaisengao/likeview/like/evaluator/ThreeCurveEvaluator.java: -------------------------------------------------------------------------------- 1 | package com.kaisengao.likeview.like.evaluator; 2 | 3 | import android.animation.TypeEvaluator; 4 | import android.graphics.PointF; 5 | 6 | /** 7 | * @ClassName: ThreeCurveEvaluator 8 | * @Author: KaiSenGao 9 | * @CreateDate: 2020/12/24 10:58 10 | * @Description: 三阶贝赛尔曲线 11 | */ 12 | public class ThreeCurveEvaluator implements TypeEvaluator { 13 | 14 | private final PointF mControlP1; 15 | private final PointF mControlP2; 16 | 17 | public ThreeCurveEvaluator(PointF pointF1, PointF pointF2) { 18 | this.mControlP1 = pointF1; 19 | this.mControlP2 = pointF2; 20 | } 21 | 22 | @Override 23 | public PointF evaluate(float fraction, PointF startValue, PointF endValue) { 24 | PointF pointCur = new PointF(); 25 | float leftTime = 1.0f - fraction; 26 | // 三阶贝赛尔曲线 27 | pointCur.x = (float) Math.pow(leftTime, 3) * startValue.x 28 | + 3 * (float) Math.pow(leftTime, 2) * fraction * mControlP1.x 29 | + 3 * leftTime * (float) Math.pow(fraction, 2) * mControlP2.x 30 | + (float) Math.pow(fraction, 3) * endValue.x; 31 | 32 | pointCur.y = (float) Math.pow(leftTime, 3) * startValue.y 33 | + 3 * (float) Math.pow(leftTime, 2) * fraction * mControlP1.y 34 | + 3 * leftTime * fraction * fraction * mControlP2.y 35 | + (float) Math.pow(fraction, 3) * endValue.y; 36 | return pointCur; 37 | } 38 | } -------------------------------------------------------------------------------- /lib_likeview/src/main/res/drawable-xhdpi/default_favor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaisengao/KsgLikeView/16338d8ce8555400a4e2da9a9fd2723894bd5c29/lib_likeview/src/main/res/drawable-xhdpi/default_favor.png -------------------------------------------------------------------------------- /lib_likeview/src/main/res/values/attr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /lib_likeview/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | lib_likeView 3 | 4 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':lib_likeview' 2 | --------------------------------------------------------------------------------