├── .github
└── workflows
│ └── release.yml
├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── dbnavigator.xml
├── encodings.xml
├── gradle.xml
├── markdown-navigator-enh.xml
├── markdown-navigator.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── me
│ │ └── xuexuan
│ │ └── rain
│ │ └── MainActivity.java
│ └── res
│ ├── drawable
│ └── ic_launcher_background.xml
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_round.png
│ ├── star.png
│ └── sun.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gif
└── rain_sun.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── me
│ │ └── xuexuan
│ │ ├── ItemEmoje.kt
│ │ └── RainViewGroup.kt
│ └── res
│ └── drawable-xxhdpi
│ └── star.png
└── settings.gradle
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: RELEASE_CI
2 |
3 | on:
4 | push:
5 | # Sequence of patterns matched against refs/tags
6 | tags:
7 | - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
8 | jobs:
9 |
10 | build:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v1
14 | - name: set up JDK 1.8
15 | uses: actions/setup-java@v1
16 | with:
17 | java-version: 1.8
18 | # 打包apk
19 | - name: Build with Gradle
20 | run: chmod +x gradlew &&./gradlew assembleRelease
21 |
22 |
23 | # 上传apk 到action,在右上角查看
24 | # - name: Upload APK
25 | # uses: actions/upload-artifact@v1
26 | # with:
27 | # name: app
28 | # path: app/build/outputs/apk/release/emoji-rain.apk
29 |
30 | # apk 签名
31 | - name: Sign Apk
32 | id: sign
33 | uses: r0adkll/sign-android-release@v1
34 | with:
35 | releaseDirectory: app/build/outputs/apk/release/
36 | signingKeyBase64: ${{ secrets.SIGNING_KEY }}
37 | alias: ${{ secrets.ALIAS }}
38 | keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
39 | keyPassword: ${{ secrets.KEY_PASSWORD }}
40 |
41 | - name: Create Release
42 | id: create_release
43 | uses: actions/create-release@v1.0.0
44 | env:
45 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46 | with:
47 | tag_name: ${{ github.ref }}
48 | release_name: Release ${{ github.ref }}
49 | draft: false
50 | prerelease: false
51 |
52 | - name: Upload Release Asset
53 | id: upload-release-asset
54 | uses: actions/upload-release-asset@v1.0.1
55 | env:
56 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57 | with:
58 | upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
59 | asset_path: ${{ steps.sign.outputs.signedReleaseFile }}
60 | asset_name: emoji-rain.apk
61 | asset_content_type: application/zip
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | xmlns:android
68 |
69 | ^$
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 | xmlns:.*
79 |
80 | ^$
81 |
82 |
83 | BY_NAME
84 |
85 |
86 |
87 |
88 |
89 |
90 | .*:id
91 |
92 | http://schemas.android.com/apk/res/android
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | .*:name
102 |
103 | http://schemas.android.com/apk/res/android
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 | name
113 |
114 | ^$
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 | style
124 |
125 | ^$
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 | .*
135 |
136 | ^$
137 |
138 |
139 | BY_NAME
140 |
141 |
142 |
143 |
144 |
145 |
146 | .*
147 |
148 | http://schemas.android.com/apk/res/android
149 |
150 |
151 | ANDROID_ATTRIBUTE_ORDER
152 |
153 |
154 |
155 |
156 |
157 |
158 | .*
159 |
160 | .*
161 |
162 |
163 | BY_NAME
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/dbnavigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator-enh.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | Android
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | [](https://github.com/JantHsueh/EmojiRain/workflows/RELEASE_CI/badge.svg)
4 | [ ](https://bintray.com/jantxue/maven/Emoji-Rain/_latestVersion)
5 | [](https://www.apache.org/licenses/LICENSE-2.0)
6 |
7 | # 表情雨 ViewGroup
8 |
9 | 微信聊天中的表情雨效果一样。内部使用了资源缓存复用机制,在无限循环中,不会出现占用内存增长的问题,所以不会GC(除非),更流畅
10 |
11 | 先来看下效果,太阳雨。(gif有点卡顿,因为录制屏幕时的帧率不够,在项目中是很流畅的)
12 |
13 |
14 |
15 | # 使用教程
16 |
17 |
18 | 在项目的build.gradle 添加引用
19 |
20 | ```
21 | implementation 'me.xuexuan:emoji-rain:1.0.0'
22 | //为了减少版本冲突问题,库中没有引用constraintlayout,所以在自己的项目添加引用
23 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
24 | ```
25 |
26 |
27 |
28 | 例如:在布局文件中使用
29 |
30 | ```xml
31 |
35 |
36 |
37 |
38 | ```
39 | 它是一个viewGroup,继承ConstraintLayout。所以可以把它当做ConstraintLayout来使用
40 |
41 |
42 |
43 | ## 使用
44 |
45 | 获取到RainViewGroup的对象实例(例如:在java代码中,通过findViewById 获取)
46 |
47 | 调用start(),开启表情雨
48 | ```java
49 | rainViewGroup = findViewById(R.id.testView);
50 | rainViewGroup.start();
51 | ```
52 | 调用stop(),关闭表情雨
53 | ```java
54 | rainViewGroup.stop();
55 | ```
56 |
57 |
58 |
59 | ## 高级使用
60 |
61 | 项目提供了一些函数来实现自定义的效果
62 |
63 | ### 设置表情雨资源
64 |
65 | `setImgResId(mImgResId: Int)`
66 |
67 | ### 设置表情缩放比例
68 |
69 | `setScale(scaleRandom: Int, scaleOffset: Int)` 默认值是 `setScale(30, 70)`
70 |
71 |
72 | 在代码的实现`var i = (mRandom.nextInt(xxxRandom) + xxxOffset).toFloat() / 100f`
73 |
74 | 例如:`setScale(30, 70)` 那么i的取值范围就是[0.7,1)
75 |
76 |
77 | ### 设置屏幕最多显示的表情数量
78 | 屏幕最多的表情数量,以下简称单屏数量,可以理解为,表情雨的密度
79 |
80 | `setAmount(num: Int = mAmount)` 默认值是 20
81 |
82 |
83 | ### 设置表情雨次数
84 | 这里的次数,是指上面设置的表情数量的次数。在保持密度不变的情况下,设置下落数量。
85 |
86 |
87 |
88 | `setTimes(times: Int = INFINITE)` 默认值是 1
89 |
90 |
91 | 例如:
92 | - A:单屏数量(密度) = 50,次数 = 3,总共数量150。
93 | - B:单屏数量(密度) = 50,次数 = 1,总共数量50。
94 | - c:单屏数量(密度) = 150,次数 = 1,总共数量150。
95 |
96 |
97 |
98 | | | 表情密度 | 表情数量 | 下落时间
99 | | ------------ | ------------ |------------ |------------ |
100 | | A B | 相同 | A = 3\*B | A = 3\*B
101 | | A C | C = 3\*A | 相同 | A = 3\*B
102 | | B C | C = 3\*B | C = 3\*B| 相同
103 |
104 |
105 |
106 | ### 设置x,y轴偏移方向
107 |
108 | 设置x/y轴的偏移,每一次onDraw(),在上一次位置的基础上,在x/y轴上增加的偏移量。
109 |
110 | ```java
111 | setX(xRandom: Int, xOffset: Int)
112 | setY(yRandom: Int, yOffset: Int)
113 | ```
114 |
115 | 默认值是`setX(6,-3)` `setY(5,10)`
116 |
117 |
118 | 在代码中的实现`var i = mRandom.nextInt(xxxRandom) + xxxOffset`
119 |
120 | 例如:`setX(6,-3)`, i的取值范围就是 [-3,3)
121 |
122 |
123 | ### 设置初始的横坐标位置
124 |
125 | 设置表情初始位置,x值的范围,也就在屏幕宽度指定的范围内落下。避免表情x = 0(x = 屏幕宽度)时,xOffset为负值(正值),落下很小的距离,表情就划出屏幕的问题。
126 |
127 | `setWidth(widthRandom: Int, widthOffset: Int)` 默认值是`setWidth(200,100)`
128 |
129 | 在代码中的实现`var i = mRandom.nextInt(getWidth() - xxxRandom) + xxxOffset`,
130 | 例如:屏幕宽度是1080,`setWidth(200,100)`, i的取值范围就是 [980,100)
131 |
132 | # LICENSE
133 | ````
134 | Copyright 2020 XueXuan
135 |
136 | Licensed under the Apache License, Version 2.0 (the "License");
137 | you may not use this file except in compliance with the License.
138 | You may obtain a copy of the License at
139 |
140 | http://www.apache.org/licenses/LICENSE-2.0
141 |
142 | Unless required by applicable law or agreed to in writing, software
143 | distributed under the License is distributed on an "AS IS" BASIS,
144 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
145 | See the License for the specific language governing permissions and
146 | limitations under the License.
147 | ````
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | android {
5 | compileSdkVersion 28
6 | defaultConfig {
7 | applicationId "me.xuexuan.rain"
8 | minSdkVersion 19
9 | targetSdkVersion 28
10 |
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 |
22 | android.applicationVariants.all { variant ->
23 | variant.outputs.all {
24 | if (variant.buildType.name == 'release') {
25 | outputFileName = "emoji-rain.apk"
26 | }
27 | }
28 | }
29 | }
30 |
31 | dependencies {
32 | implementation fileTree(dir: 'libs', include: ['*.jar'])
33 | implementation "androidx.appcompat:appcompat:1.1.0"
34 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
35 | // implementation 'me.xuexuan:emoji-rain:1.0.0'
36 | api project(':library')
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/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 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/me/xuexuan/rain/MainActivity.java:
--------------------------------------------------------------------------------
1 | package me.xuexuan.rain;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.widget.Button;
6 |
7 | import androidx.appcompat.app.AppCompatActivity;
8 |
9 | import me.xuexuan.RainViewGroup;
10 |
11 | public class MainActivity extends AppCompatActivity {
12 |
13 | private RainViewGroup rainView;
14 | private Button btnStar;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 | rainView = findViewById(R.id.testView);
21 | btnStar = findViewById(R.id.btn_sun);
22 |
23 |
24 | //屏幕中最多显示item的数量
25 | rainView.setAmount(50);
26 | //设置下落的次数。在保持密度不变的情况下,设置下落数量。例如:数量 = 50,下落次数 = 3,总共数量150。
27 | // rainView.setTimes(2);
28 | //设置无效循环
29 | rainView.setTimes(RainViewGroup.INFINITE);
30 | rainView.start();
31 |
32 | btnStar.setOnClickListener(new View.OnClickListener() {
33 | @Override
34 | public void onClick(View v) {
35 | rainView.stop();
36 | rainView.setImgResId(R.mipmap.sun);
37 | rainView.start();
38 | }
39 | });
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/app/src/main/res/mipmap-xxhdpi/star.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/sun.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/app/src/main/res/mipmap-xxhdpi/sun.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Rain
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 | buildscript {
4 | ext.kotlin_version = '1.3.50'
5 |
6 |
7 | repositories {
8 | google()
9 | jcenter()
10 | }
11 | dependencies {
12 | classpath 'com.android.tools.build:gradle:3.5.3'
13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31"
14 | // classpath 'com.novoda:bintray-release:0.9.2'
15 |
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | google()
22 | jcenter()
23 | // maven{ url 'https://dl.bintray.com/jantxue/maven'}
24 | }
25 | }
26 |
27 | task clean(type: Delete) {
28 | delete rootProject.buildDir
29 | }
30 |
31 |
32 | ext {
33 | compileSdkVersion = 28
34 | minSdkVersion = 14
35 | targetSdkVersion = compileSdkVersion
36 |
37 | appCompatVersion = "1.1.0"
38 |
39 | // userOrg = "jantxue"
40 | // groupId = "me.xuexuan"
41 | // publishVersion = "1.0.0"
42 | // desc = "Imitation WeChat chat list emoji rain"
43 | // website = "https://github.com/JantHsueh/EmojiRain"
44 | // licences = ['Apache-2.0']
45 |
46 | }
--------------------------------------------------------------------------------
/gif/rain_sun.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/gif/rain_sun.gif
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 |
13 | # When configured, Gradle will run in incubating parallel mode.
14 | # This option should only be used with decoupled projects. More details, visit
15 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
16 | # org.gradle.parallel=true
17 | kotlin.code.style=official
18 | android.enableJetifier=true
19 | org.gradle.jvmargs=-Xmx1536M -Dkotlin.daemon.jvm.options\="-Xmx1536M"
20 | android.useAndroidX=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Sep 08 10:24:34 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | //apply plugin: 'com.novoda.bintray-release'
5 |
6 | android {
7 | compileSdkVersion 28
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 28
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | consumerProguardFiles 'consumer-rules.pro'
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | compileOnly 'androidx.constraintlayout:constraintlayout:1.1.3'
28 | }
29 |
30 | //publish {
31 | // artifactId = 'emoji-rain'
32 | // userOrg = rootProject.userOrg
33 | // groupId = rootProject.groupId
34 | // uploadName = 'Emoji-Rain'
35 | // publishVersion = rootProject.publishVersion
36 | // desc = rootProject.desc
37 | // website = rootProject.website
38 | // licences = rootProject.licences
39 | //}
--------------------------------------------------------------------------------
/library/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 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/library/src/main/java/me/xuexuan/ItemEmoje.kt:
--------------------------------------------------------------------------------
1 | package me.xuexuan
2 |
3 | import android.graphics.Bitmap
4 |
5 | class ItemEmoje {
6 | //坐标
7 | var x: Int = 0
8 | var y: Int = 0
9 | // 横向偏移
10 | var offsetX: Int = 0
11 | //纵向偏移
12 | var offsetY: Int = 0
13 | //缩放
14 | var scale: Float = 0.toFloat()
15 | //图片资源
16 | var bitmap: Bitmap? = null
17 | }
18 |
--------------------------------------------------------------------------------
/library/src/main/java/me/xuexuan/RainViewGroup.kt:
--------------------------------------------------------------------------------
1 | package me.xuexuan
2 |
3 | import android.content.Context
4 | import android.graphics.BitmapFactory
5 | import android.graphics.Canvas
6 | import android.graphics.Matrix
7 | import android.graphics.Paint
8 | import android.util.AttributeSet
9 | import androidx.constraintlayout.widget.ConstraintLayout
10 | import java.util.*
11 | import kotlin.collections.ArrayList
12 |
13 | /**
14 | * @author xuexuan https://github.com/JantHsueh
15 | * @date 2020年1月7日16:21:29
16 | */
17 |
18 | class RainViewGroup : ConstraintLayout {
19 |
20 | constructor(context: Context) : super(context) {}
21 |
22 | constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
23 |
24 | constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
25 | context,
26 | attrs,
27 | defStyleAttr
28 | ) {
29 | }
30 |
31 |
32 | private var mPaint: Paint? = null
33 | //图片处理
34 | private var mMatrix: Matrix? = null
35 | private var mRandom: Random? = null
36 | //判断是否运行的,默认没有
37 | private var mIsRun: Boolean = false
38 | //循环次数,如果是-1 无限循环
39 | private var mTimes = 1
40 | private var mAlways = false
41 | //屏幕上最多显示多少个
42 | private var mAmount = 20
43 | //表情包集合
44 | private var mBitmapList: MutableList = ArrayList()
45 |
46 | private var mBitmapRecycleList: MutableList = ArrayList()
47 | //表情图片
48 | private var mImgResId = R.drawable.star
49 |
50 |
51 | init {
52 | init()
53 | }
54 |
55 | private fun init() {
56 | mPaint = Paint()
57 | mPaint!!.isAntiAlias = true
58 | mPaint!!.isFilterBitmap = true
59 | mPaint!!.isDither = true
60 | mMatrix = Matrix()
61 | mRandom = Random()
62 |
63 | }
64 |
65 | override fun dispatchDraw(canvas: Canvas) {
66 | super.dispatchDraw(canvas)
67 | if (mIsRun) {
68 | //用于判断表情下落结束,结束即不再进行重绘
69 | var isInScreen = false
70 | run {
71 | var i = 0
72 | while (i < mBitmapList.size) {
73 | mMatrix!!.reset()
74 | //缩放
75 | mMatrix!!.setScale(mBitmapList[i].scale, mBitmapList[i].scale)
76 | //下落过程坐标
77 | mBitmapList[i].x = mBitmapList[i].x + mBitmapList[i].offsetX
78 | mBitmapList[i].y = mBitmapList[i].y + mBitmapList[i].offsetY
79 |
80 | //位移
81 | mMatrix!!.postTranslate(
82 | mBitmapList[i].x.toFloat(),
83 | mBitmapList[i].y.toFloat()
84 | )
85 |
86 | canvas.drawBitmap(mBitmapList[i].bitmap, mMatrix!!, mPaint)
87 | if (mBitmapList[i].y <= height && mBitmapList[i].x <= width) {//当表情仍在视图内,则继续重绘
88 | isInScreen = true
89 | } else {
90 | recycle(mBitmapList[i])
91 | i--
92 | }
93 | i++
94 | }
95 | }
96 |
97 | mIsRun = isInScreen
98 | if (mAlways && mBitmapList.size < ((mAmount* 4)/ 5)) {
99 | for (i in 0..(mAmount / 5)) {
100 | addItemToBitmapList()
101 | }
102 | mIsRun = true
103 | }
104 |
105 | postInvalidate()
106 | } else {
107 | release()
108 | }
109 | }
110 |
111 | /**
112 | * 释放资源
113 | */
114 | private fun release() {
115 | if (mBitmapList.size > 0) {
116 | for (itemEmoje in mBitmapList) {
117 | if (itemEmoje.bitmap?.isRecycled == false) {
118 | itemEmoje.bitmap?.recycle()
119 | }
120 | }
121 | mBitmapList.clear()
122 | }
123 |
124 | if (mBitmapRecycleList.size > 0) {
125 | for (itemEmoje in mBitmapRecycleList) {
126 | if (itemEmoje.bitmap?.isRecycled == false) {
127 | itemEmoje.bitmap?.recycle()
128 | }
129 | }
130 | mBitmapRecycleList.clear()
131 | }
132 |
133 | }
134 |
135 |
136 | /**
137 | * 回收资源
138 | */
139 | private fun recycle(item: ItemEmoje) {
140 |
141 | if (mBitmapList.size > 0) {
142 | mBitmapList.remove(item)
143 | }
144 |
145 | if (mBitmapRecycleList.size > 50) {
146 |
147 | if (mBitmapRecycleList[0].bitmap?.isRecycled == false) {
148 | mBitmapRecycleList[0].bitmap?.recycle()
149 | }
150 | mBitmapRecycleList.removeAt(0)
151 | }
152 | mBitmapRecycleList.add(item)
153 |
154 | }
155 |
156 |
157 | companion object {
158 | const val INFINITE = -1
159 | }
160 |
161 | /**
162 | * 设置表情雨资源id
163 | */
164 | fun setImgResId(mImgResId: Int) {
165 | this.mImgResId = mImgResId
166 | }
167 |
168 | /**
169 | * 设置表情的缩放比例
170 | */
171 | fun setScale(scaleRandom: Int, scaleOffset: Int) {
172 | mScaleRandom = scaleRandom
173 | mScaleOffset = scaleOffset
174 | }
175 |
176 | /**
177 | * 设置x轴的偏移,每一次绘制表情在x轴上的偏移量
178 | */
179 | fun setX(xRandom: Int, xOffset: Int) {
180 | mXRandom = xRandom
181 | mXOffset = xOffset
182 | }
183 |
184 | /**
185 | * 设置y轴的偏移,每一次绘制表情在y轴上的偏移量
186 | */
187 | fun setY(yRandom: Int, yOffset: Int) {
188 | mYRandom = yRandom
189 | mYOffset = yOffset
190 | }
191 |
192 |
193 | /**
194 | * 设置表情落下时的,初始x值的范围,也就在指定屏幕宽度的范围内落下。
195 | * 避免表情的随机的x = 0(x = 屏幕宽度)时,xOffset为负值(正值),落下很小的距离,表情就划出屏幕的问题
196 | */
197 | fun setWidth(widthRandom: Int, widthOffset: Int) {
198 | mWidthRandom = widthRandom
199 | mWidthOffset = widthOffset
200 | }
201 |
202 | fun setTimes(times: Int = INFINITE) {
203 | if (times == INFINITE) {
204 | mAlways = true
205 | this.mTimes = 1
206 | } else {
207 | mAlways = false
208 | this.mTimes = times
209 | }
210 | }
211 |
212 |
213 | fun setAmount(num: Int = mAmount) {
214 | mAmount = num
215 | }
216 |
217 |
218 | fun start() {
219 | this.mIsRun = true
220 | initData(mTimes * mAmount)
221 | invalidate()
222 | }
223 |
224 | fun stop() {
225 | this.mIsRun = false
226 | this.mAlways = false
227 | }
228 |
229 | private fun initData(num: Int = mAmount) {
230 | release()
231 | for (i in 0 until num) {
232 | addItemToBitmapList()
233 | }
234 | }
235 |
236 | private fun addItemToBitmapList() {
237 |
238 | val itemEmoje: ItemEmoje
239 | if (mBitmapRecycleList.size > 0) {
240 | itemEmoje = createItem(mBitmapRecycleList[0])
241 | mBitmapRecycleList.removeAt(0)
242 | } else {
243 | itemEmoje = createItem()
244 | }
245 | mBitmapList.add(itemEmoje)
246 | }
247 |
248 |
249 | private var mWidthRandom = 200
250 | private var mWidthOffset = 100
251 |
252 | private var mXRandom = 6
253 | private var mXOffset = -3
254 |
255 | private var mYRandom = 5
256 | private var mYOffset = 10
257 |
258 | private var mScaleRandom = 30
259 | private var mScaleOffset = 70
260 |
261 | private fun createItem(item: ItemEmoje? = null): ItemEmoje {
262 | var itemEmoje = item
263 |
264 | if (itemEmoje == null) {
265 | itemEmoje = ItemEmoje()
266 | itemEmoje.bitmap = BitmapFactory.decodeResource(resources, mImgResId)
267 | }
268 |
269 | var width = width
270 | var height = height
271 |
272 | if (width == 0 || height == 0) {
273 | val dm = resources.displayMetrics
274 | width = dm.widthPixels
275 | height = dm.heightPixels
276 | }
277 |
278 | //起始横坐标在[100,getWidth()-100) 之间
279 | itemEmoje.x = mRandom!!.nextInt(width - mWidthRandom) + mWidthOffset
280 | //起始纵坐标在(-getHeight(),0] 之间,即一开始位于屏幕上方以外
281 | itemEmoje.y = -mRandom!!.nextInt(mTimes * height)
282 |
283 | //横向偏移[-3,3) ,即左右摇摆区间
284 | itemEmoje.offsetX = mRandom!!.nextInt(mXRandom) + mXOffset
285 | //纵向偏移(11,16] ,即下拉速度
286 | itemEmoje.offsetY = mRandom!!.nextInt(mYRandom) + mYOffset
287 | //缩放比例[0.7,1) 之间
288 | itemEmoje.scale = (mRandom!!.nextInt(mScaleRandom) + mScaleOffset).toFloat() / 100f
289 |
290 | return itemEmoje
291 | }
292 | }
293 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JantHsueh/EmojiRain/9b9b70e1e984119baf0a12c8ce207620a55f125d/library/src/main/res/drawable-xxhdpi/star.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------