├── .gitignore
├── .idea
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── dbnavigator.xml
├── encodings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── LICENSE
├── README.md
├── WIKIPAGE.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── zcy
│ │ └── pudding
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── zcy
│ │ │ └── pudding
│ │ │ └── demo
│ │ │ ├── JavaActivity.java
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.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
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── zcy
│ └── pudding
│ └── ExampleUnitTest.kt
├── build.gradle
├── demogif
├── first3.gif
├── startActivity.gif
└── withDialog.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── pudding
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── zcy
│ │ └── pudding
│ │ └── ExampleInstrumentedTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── zcy
│ │ └── pudding
│ │ ├── Choco.kt
│ │ ├── Pudding.kt
│ │ └── SwipeDismissTouchListener.kt
│ └── res
│ ├── anim
│ └── alerter_pulse.xml
│ ├── drawable
│ ├── alerter_ic_notifications.xml
│ └── ic_event_available_black_24dp.xml
│ ├── layout
│ └── layout_choco.xml
│ └── values
│ ├── color.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── style.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # IntelliJ
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/assetWizardSettings.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 | .idea/caches
44 |
45 | # Keystore files
46 | # Uncomment the following line if you do not want to check your keystore files in.
47 | #*.jks
48 |
49 | # External native build folder generated in Android Studio 2.2 and later
50 | .externalNativeBuild
51 |
52 | # Google Services (e.g. APIs or Firebase)
53 | google-services.json
54 |
55 | # Freeline
56 | freeline.py
57 | freeline/
58 | freeline_project_description.json
59 |
60 | # fastlane
61 | fastlane/report.xml
62 | fastlane/Preview.html
63 | fastlane/screenshots
64 | fastlane/test_output
65 | fastlane/readme.md
--------------------------------------------------------------------------------
/.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 | xmlns:android
41 |
42 | ^$
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | xmlns:.*
52 |
53 | ^$
54 |
55 |
56 | BY_NAME
57 |
58 |
59 |
60 |
61 |
62 |
63 | .*:id
64 |
65 | http://schemas.android.com/apk/res/android
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | .*:name
75 |
76 | http://schemas.android.com/apk/res/android
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | name
86 |
87 | ^$
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 | style
97 |
98 | ^$
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 | .*
108 |
109 | ^$
110 |
111 |
112 | BY_NAME
113 |
114 |
115 |
116 |
117 |
118 |
119 | .*
120 |
121 | http://schemas.android.com/apk/res/android
122 |
123 |
124 | ANDROID_ATTRIBUTE_ORDER
125 |
126 |
127 |
128 |
129 |
130 |
131 | .*
132 |
133 | .*
134 |
135 |
136 | BY_NAME
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/.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 |
455 |
456 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.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 |
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 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 zhaocy
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Pudding
2 | [](https://jitpack.io/#o0o0oo00/Pudding)
3 |
4 |
5 | 代替Toast/SnackBar新方式,使用WindowManager 无需申请权限
6 |
7 | ### WIKI
8 |
9 | [中文说明](https://github.com/o0o0oo00/Pudding/blob/master/WIKIPAGE.md)
10 |
11 | ### Usage
12 |
13 | ```groovy
14 | allprojects {
15 | repositories {
16 | ...
17 | maven { url 'https://jitpack.io' }
18 | ```
19 |
20 | ```groovy
21 | implementation 'com.github.o0o0oo00:Pudding:1.2.1'
22 | ```
23 |
24 |
25 |
26 | GIF可能要等会就顺畅了,一开始可能会比较迟钝 (●゚ω゚●)
27 |
28 | 常见的可配置的几种形式
29 |
30 | Common configurable Pudding
31 |
32 |
33 |
34 | ```kotlin
35 | Pudding.create(this) {
36 | setTitle("This is Title")
37 | setText("this is text")
38 | }.show()
39 | ```
40 |
41 | ```kotlin
42 | Pudding.create(this) {
43 | setChocoBackgroundColor(resources.getColor(R.color.colorAccent))
44 | setTitleTypeface(Typeface.DEFAULT_BOLD)
45 | }.show()
46 | ```
47 |
48 | ```kotlin
49 | Pudding.create(this) {
50 | setTitle("Choco Title")
51 | setText("this is text")
52 | setIcon(R.drawable.ic_event_available_black_24dp)
53 | }.show()
54 | ```
55 |
56 | ```kotlin
57 | Pudding.create(this) {
58 | setTitle("Choco Title")
59 | setText("This is Text , it's very short and I don't like short \n This is Text , it's very short and I don't like short")
60 | onShow {
61 | Toast.makeText(this@MainActivity, "onShowListener", Toast.LENGTH_SHORT).show()
62 | }
63 | onDismiss {
64 | Toast.makeText(this@MainActivity, "onDismissListener", Toast.LENGTH_SHORT).show()
65 | }
66 | }.show()
67 | ```
68 |
69 |
70 | 配合[FancyDialog](https://github.com/o0o0oo00/FancyDialog)可实现**Pudding**显示在**Dialog**的阴影之上
71 |
72 | With [FancyDialog](https://github.com/o0o0oo00/FancyDialog), Pudding can be displayed above the shadow of Dialog.
73 |
74 |
75 |
76 |
77 |
78 | 每个Activity拥有各自的Pudding,互相之间不影响
79 |
80 | Each Activity has its own Pudding, which does not affect each other.
81 |
82 |
83 |
84 |
85 |
86 | **Imitate [Alerter](https://github.com/Tapadoo/Alerter) and ☆⌒(*^-゜)v THX!! a lot**
87 |
88 | ### what's different
89 |
90 | Use activity decorView we can show a view on top of Activity。but when dialog is showing , its black background will cover the view , that is not cool. so i create this repository to solve this problem , and I hope it's useful to you
91 |
92 | ### Something new
93 |
94 | * Use DSL style to config `Choco`
95 | * Show Queue
96 | * Cover Dialog/PopWindow
97 | * Don't need to request permission
98 |
99 |
100 | #### TODO
101 |
102 | 1. 两种addView方式
103 | - [x] activity decorView
104 | - [x] windowManager
105 | - [x] 动画显示
106 | - [x] 生命周期控制
107 | - [x] 有权限/无权限情况 (考虑到这个需求不是很大,而且每个项目的权限适配都不一致,而且国产手机权限这一块参差不齐,所以决定不做这一块了,对功能也没影响)
108 | - [x] 各个版本的适配
109 |
110 | 2. 内部显示队列(考虑可以使用kotlin通道来实现)
111 | - [x] 上一条未消失时,后来一条等待
112 | - [x] 直接顶掉上一条,上一条渐变消失
113 |
114 | 3. 左右/上下滑动消失动画
115 |
116 | - [x] 上下消失
117 | - [x] 左右滑动消失
118 |
119 | 4. Pudding cover dialog
120 |
121 | - [x] 配合[FancyDialog](https://github.com/o0o0oo00/FancyDialog)实现
122 |
123 |
124 |
125 | #### 可能会有的疑问:
126 |
127 | - [x] **Pudding**使用的是WindowManager 难道不需要申请权限吗?
128 |
129 | - [x] **Pudding**使用`WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL`的层级低于系统级层级`TYPE_SYSTEM_ALERT`也就是在2000之下,是不需要申请权限的。
130 |
131 | - [x] 不同的Activity对应的WindowManager是否相同
132 |
133 | - [x] 不同的window,不同的WindowManager,相同的WindowManagerGlobal(最终实现view的添加、删除、更新)
134 |
135 | - [x] 不同的WindowManager为什么可以移除对方的View
136 |
137 | - [x] 因为所有的Activity共同只有一个WindowManagerGlobal(其内部持有所有添加的View的集合引用)
138 |
139 | - [X] 如何去维护一个Pudding队列
140 |
141 | - [x] 用一个`Map`
142 | - [X] 什么时间 去clear这个map (●゚ω゚●)挠头?
143 | when activity destory clean the key which is activity toString()
144 |
--------------------------------------------------------------------------------
/WIKIPAGE.md:
--------------------------------------------------------------------------------
1 | # Window & WindowManager
2 |
3 | ## 手写一个Alert弹窗控件
4 |
5 | #### Window的添加与删除
6 |
7 | 每一个Window都对应着一个View和一个ViewRootImpl。Window和View通过ViewRootImpl来建立联系(ViewRootImpl是Window的实际展现形式,它是视图层级结构的最顶部。)
8 |
9 | 通过WindowManager的addView来实现在屏幕上添加一个View,但它只是一个接口,真正的实现是WindowManagerImpl
10 |
11 | WindowManagerImpl这种工作模式是典型的桥接模式,将所有的操作全部委托给WindowManagerGlobal这个**单例类**来实现,而其内部则是通过ViewRootImpl来更新界面并完成Window的添加过程。
12 |
13 | ##### 添加过程
14 |
15 | WindowManagerGlobal.java/addView
16 |
17 | ```kotlin
18 | root = new ViewRootImpl(view.getContext(), display);
19 | mViews.add(view);
20 | mRoots.add(root);
21 | root.setView(view, wparams, panelParentView);
22 | ```
23 |
24 | 这里的这个root,是新创建出的`ViewRootImpl(view.getContext(), display);`前面说了,它其实是Window的实际展现形式,暂且理解为window本身,这样我们将view添加到window本身上了。
25 |
26 | 真正的调用顺序:**windowManager -> WindowManagerImpl -> WindowManagerGlobal -> ViewRootImpl**
27 |
28 | ##### 删除过程
29 |
30 | WindowManagerGlobal.java
31 |
32 | ```kotlin
33 | removeView(View view, boolean immediate)
34 | ```
35 |
36 | 它有一个**immediate**参数表示是否是立即移除,其中**removeView**是异步方法**removeViewImmediate**为同步方法。方法内部拿到了view的index之后去`ArrayList mRoots`中寻找对应的**Index**。然后调用`removeViewLocked(index, immediate);`此时将View添加到了`ArraySet mDyingViews`中去,并没有立即执行删除,而是发送一个消息
37 |
38 | ```
39 | boolean die(boolean immediate) {
40 | ...
41 | if (immediate && !mIsInTraversal) {
42 | doDie();
43 | return false;
44 | }
45 | mHandler.sendEmptyMessage(MSG_DIE);
46 | }
47 | ```
48 |
49 | 如果是同步删除,会直接移除,并刷新**mRoots**等属性列表
50 |
51 | 此时我们就会收到`onDetachedFromWindow()`这个方法的调用。
52 |
53 | ```kotlin
54 | void doDie() {
55 | ...
56 | if (mAdded) {
57 | dispatchDetachedFromWindow();
58 | }
59 |
60 | WindowManagerGlobal.getInstance().doRemoveView(this);
61 | }
62 | ```
63 |
64 |
65 |
66 | #### Window与Activity
67 |
68 | Activity的启动过程很复杂,最终会由**ActivityThread**中的`performLaunchActivity()`来完成整个启动过程,在这个方法内部会通过类加载器创建Activity的实例对象,并调用其`attach`方法为其关联运行过程中所依赖的一系列上下文环境变量
69 |
70 | 在**Activity**`attach()`中,新建一个`Window`实例作为自己的成员变量,它的类型为`PhoneWindow`,这是抽象类`Window`的一个子类。然后设置`mWindow`的`WindowManager`。
71 |
72 | ##### Activity的布局是如何加载到Window上的
73 |
74 | Activity中的window就是phoneWindow,而Activity中的setContentView就是调用的phoneWindow的setContentView。
75 |
76 | ````kotlin
77 | public void setContentView(@LayoutRes int layoutResID) {
78 | getWindow().setContentView(layoutResID);
79 | initWindowDecorActionBar();
80 | }
81 | ````
82 |
83 | PhoneWindow.java/setContentView
84 |
85 | ```
86 | if (mContentParent == null) {
87 | installDecor();
88 | } else if (!hasFeature(FEATURE_CONTENT_TRANSITIONS)) {
89 | mContentParent.removeAllViews();
90 | }
91 | ```
92 |
93 | PhoneWindow中 包含一个DecorView,
94 |
95 | 如果为null就新建一个,通过`installDecor()`,内部调用`generateDecor(-1);`创建mDecor。
96 |
97 | 如果mDecor不为null那么直接关联上phoneWindow`mDecor.setWindow(this);`
98 |
99 |
100 |
101 | 拿到了mDecor后去生成布局`mContentParent = generateLayout(mDecor);`
102 |
103 | 在`generateLayout`中,将Activity的布局addView到decorView上`mDecor.onResourcesLoaded(mLayoutInflater, layoutResource);`
104 |
105 | `onResourcesLoaded`内部实现最终的`addView(root, 0, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));`
106 |
107 |
108 |
109 | ##### DecorView添加到WindowManager上
110 |
111 | 在ActivityThread的handleResumeActivity方法中,首先会调用Activity的onResume方法,接着会调用Activity的`makeVisible()`
112 |
113 | 只有在Activity的`makeVisible()`被调用的时候,DecorView才会被addview进Windowmanager
114 |
115 | ```java
116 | void makeVisible() {
117 | if (!mWindowAdded) {
118 | ViewManager wm = getWindowManager();
119 | wm.addView(mDecor, getWindow().getAttributes());
120 | mWindowAdded = true;
121 | }
122 | mDecor.setVisibility(View.VISIBLE);
123 | }
124 |
125 | ```
126 |
127 |
128 |
129 | ##### 不同的Activity对应的WindowManager是否相同
130 |
131 | - **不同**的`WindowManager`对象,**相同**的`WindowManagerGlobal`
132 | - `WindowManager` 只是一个`interface`,它真正的对象是`WindowManagerImpl`,而`WindowManagerImpl`中的addView,removeView等方法,又是直接调用了`WindowManagerGlobal`的相应方法。
133 | - `WindowManagerImpl`中依赖的`WindowManagerGlobal`也是单例模式创建的,所以app范围内,`WindowManagerGlobal`实例也只有一个
134 |
135 |
136 |
137 | #### Window 层级关系
138 |
139 | Dialog的弹窗需要Context,而这个Context必须是Activity,其内的Window包含一个token。如果没有这个Token就会报错。
140 |
141 | ```
142 | “Caused by: android.view.WindowManager$BadToken-Exception: Unable to add window --token null is not for an application”
143 | ```
144 |
145 | 而系统级的Window就不需要token。因此我们可以
146 |
147 | ```kotlin
148 | dialog.getWindow().setType(LayoutParams.TYPE_SYSTEM_OVERLAY)
149 | ```
150 |
151 | 来实现一个系统级别的Dialog。But运行时权限如果不给的话,就不会显示出来,显然这是不被接受的。
152 |
153 | 我们知道View在window上的显示是有层级顺序的,层级高的覆盖在层级低的View之上。
154 | Activity的层级为 `TYPE_APPLICATION`
155 |
156 | PopupWindow的层级为`TYPE_APPLICATION_PANEL`
157 |
158 | Dialog的层级为`TYPE_SYSTEM_OVERLAY`
159 |
160 | 而我们只需要添加一个层级为`TYPE_APPLICATION_SUB_PANEL`的View到Window上面即可
161 |
162 | ##### 为什么不把View的层级设置的高一点呢?
163 |
164 | ```kotlin
165 | android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@308ebe3 -- permission denied for window type 2000
166 | ```
167 |
168 | 我们在这里验证了View的层级为2000以下的时候是不需要申请权限的
169 |
170 | 那么我们要实现这个WindowManager添加的View显示在Dialog之上,就只剩剩下一个东西了,就是降低**Dialog**的背景等级 或者 改为使用**PopUpWindow**来代替**Dialog**。
171 |
172 | 我采用的是,改Dialog的背景阴影为Activity的透明度
173 |
174 | #### Window Leak
175 |
176 | 这里的处理方式是将传入的Activity绑定lifecycle,然后在onDestroy的时候,将**Pudding**`dismiss`掉
177 |
178 | **Pudding**类继承`LifecycleObserver`
179 |
180 | ```kotlin
181 | class Pudding : LifecycleObserver
182 | ```
183 |
184 | 绑定生命周期,并且Activity的每个生命周期都可以通知到**Pudding**
185 |
186 | ```kotlin
187 | activity.lifecycle.addObserver(this)
188 | ```
189 |
190 | 监听状态
191 |
192 | ```
193 | // window manager must associate activity's lifecycle
194 | @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
195 | fun onDestroy(owner: LifecycleOwner) {
196 | choco.hide(windowManager ?: return, true)
197 | owner.lifecycle.removeObserver(this) // 移除监听事件
198 | }
199 | ```
200 |
201 | [代码详情](https://github.com/o0o0oo00/Pudding)
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 28
9 | defaultConfig {
10 | applicationId "com.zcy.pudding"
11 | minSdkVersion 21
12 | targetSdkVersion 28
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation project(':pudding')
27 | implementation 'com.github.o0o0oo00:FancyDialog:1.0.0'
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
30 | implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'
31 | implementation 'androidx.core:core-ktx:1.1.0-alpha05'
32 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
36 | }
37 |
--------------------------------------------------------------------------------
/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/androidTest/java/com/zcy/pudding/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.zcy.pudding
2 |
3 | import androidx.test.InstrumentationRegistry
4 | import androidx.test.runner.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("com.zcy.pudding", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcy/pudding/demo/JavaActivity.java:
--------------------------------------------------------------------------------
1 | package com.zcy.pudding.demo;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import androidx.annotation.Nullable;
7 | import androidx.appcompat.app.AppCompatActivity;
8 | import com.zcy.pudding.Choco;
9 | import com.zcy.pudding.Pudding;
10 | import kotlin.Unit;
11 | import kotlin.jvm.functions.Function1;
12 |
13 | /**
14 | * @author: zhaochunyu
15 | * @description: ${DESP}
16 | * @date: 2019-07-01
17 | */
18 | public class JavaActivity extends AppCompatActivity {
19 |
20 | @Override
21 | protected void onCreate(@Nullable Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 | }
25 |
26 | public void click1(View view){
27 | Pudding.create(this, new Function1() {
28 | @Override
29 | public Unit invoke(Choco choco) {
30 | choco.setText("Java Call");
31 | return null;
32 | }
33 | }).show();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcy/pudding/demo/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.zcy.pudding.demo
2 |
3 | import android.content.Intent
4 | import android.graphics.Typeface
5 | import android.os.Bundle
6 | import android.text.Editable
7 | import android.text.TextWatcher
8 | import android.view.View
9 | import android.widget.Toast
10 | import androidx.appcompat.app.AlertDialog
11 | import androidx.appcompat.app.AppCompatActivity
12 | import com.zcy.fancydialog.askDialog
13 | import com.zcy.pudding.Pudding
14 | import kotlinx.android.synthetic.main.activity_main.*
15 |
16 | class MainActivity : AppCompatActivity() {
17 |
18 | override fun onCreate(savedInstanceState: Bundle?) {
19 | super.onCreate(savedInstanceState)
20 | setContentView(R.layout.activity_main)
21 |
22 | editText.addTextChangedListener(object : TextWatcher {
23 | override fun afterTextChanged(s: Editable?) {
24 | Pudding.create(this@MainActivity) {
25 | setTitle("This is Title")
26 | }.show()
27 | }
28 |
29 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
30 | }
31 |
32 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
33 | }
34 |
35 | })
36 | }
37 |
38 | // 默认形式
39 | fun click1(view: View) {
40 | Pudding.create(this) {
41 | setTitle("This is Title")
42 | setText("this is text")
43 | }
44 | .show()
45 | }
46 |
47 | // 设置背景颜色、字体
48 | fun click2(view: View) {
49 | Pudding.create(this) {
50 | setChocoBackgroundColor(resources.getColor(R.color.colorAccent))
51 | setTitleTypeface(Typeface.DEFAULT_BOLD)
52 | }.show()
53 | }
54 |
55 | // 更改icon
56 | fun click3(view: View) {
57 | Pudding.create(this) {
58 | setTitle("Choco Title")
59 | setText("this is text")
60 | setIcon(R.drawable.ic_event_available_black_24dp)
61 | }.show()
62 | }
63 |
64 | // 长说明 文字形式
65 | fun click4(view: View) {
66 | Pudding.create(this) {
67 | setText(R.string.verbose_text_text)
68 | setIcon(R.drawable.ic_event_available_black_24dp)
69 | }.show()
70 | }
71 |
72 | // 永久显示
73 | fun click5(view: View) {
74 | Pudding.create(this) {
75 | setTitle("Choco Title")
76 | enableInfiniteDuration = true
77 | }.show()
78 | }
79 |
80 | // loading 形式
81 | fun click6(view: View) {
82 | Pudding.create(this) {
83 | setTitle("Choco Title")
84 | setEnableProgress(true)
85 | }.show()
86 | }
87 |
88 | // loading 形式
89 | fun click8(view: View) {
90 | Pudding.create(this) {
91 | setTitle("Choco Title")
92 | setText("This is Text , it's very short and I don't like short \n This is Text , it's very short and I don't like short")
93 | enableInfiniteDuration = true
94 | enableSwipeToDismiss()
95 | }.show()
96 | }
97 |
98 | // loading 形式
99 | fun click9(view: View) {
100 | Pudding.create(this) {
101 | setTitle("Choco Title")
102 | setText("This is Text , it's very short and I don't like short \n This is Text , it's very short and I don't like short")
103 | onShow {
104 | Toast.makeText(this@MainActivity, "onShowListener", Toast.LENGTH_SHORT).show()
105 | }
106 | onDismiss {
107 | Toast.makeText(this@MainActivity, "onDismissListener", Toast.LENGTH_SHORT).show()
108 | }
109 | }.show()
110 | }
111 |
112 | // loading 形式
113 | fun click7(view: View) {
114 | Pudding.create(this) {
115 | setTitle("Choco Title")
116 | setText("This is Text , it's very short and I don't like short \n This is Text , it's very short and I don't like short")
117 | setChocoBackgroundColor(resources.getColor(R.color.color_FFCC00))
118 | enableInfiniteDuration = true
119 | addButton("OK", R.style.PuddingButton, View.OnClickListener {
120 | hide()
121 | Toast.makeText(this@MainActivity, "click ok", Toast.LENGTH_SHORT).show()
122 | })
123 | addButton("NO", R.style.PuddingButton, View.OnClickListener {
124 | Toast.makeText(this@MainActivity, "click no", Toast.LENGTH_SHORT).show()
125 | })
126 |
127 | }.show()
128 | }
129 |
130 | fun showAlertDialog(view: View) {
131 | AlertDialog.Builder(this)
132 | .setTitle("AlertDialog")
133 | .setMessage("normal AlertDialog will cover Pudding")
134 | .create().show()
135 | }
136 |
137 | fun showFancyDialog(view: View) {
138 | askDialog(supportFragmentManager) {
139 | mTitle = "FancyDialog"
140 | mMessage = "Use DSL it's so Awesome"
141 | onlySure = true
142 | lowerBackground = true
143 | }
144 | }
145 |
146 | // 启动一个Activity ,验证是否存在lack window exception
147 | fun startAnActivity(view: View) {
148 | startActivity(Intent(this, MainActivity::class.java))
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
23 |
24 |
31 |
32 |
39 |
40 |
47 |
48 |
55 |
56 |
63 |
64 |
71 |
72 |
79 |
80 |
87 |
88 |
92 |
93 |
101 |
102 |
110 |
111 |
112 |
113 |
120 |
121 |
125 |
126 |
127 |
128 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 | #FFCC00
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Pudding
3 | Default Pudding
4 | Color Background Pudding
5 | Custom Icon Pudding
6 | Verbose Text
7 | Infinity Pudding
8 | Start An Activity
9 | Normal Dialog
10 | Fancy Dialog
11 | Loading Pudding
12 | Swipe Dismiss
13 | Show/Dismiss Listener
14 | This is a verbose text . And has a lot of words . You can see this text is so long . 男人最怕的就是短啊。 所以长一点最好了,我喜欢,^_^
15 | With Button
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zcy/pudding/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.zcy.pudding
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.3.21'
5 | repositories {
6 | google()
7 | jcenter()
8 |
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.3.2'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | maven { url 'https://jitpack.io' }
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/demogif/first3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/demogif/first3.gif
--------------------------------------------------------------------------------
/demogif/startActivity.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/demogif/startActivity.gif
--------------------------------------------------------------------------------
/demogif/withDialog.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/demogif/withDialog.gif
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
19 | # AndroidX package structure to make it clearer which packages are bundled with the
20 | # Android operating system, and which are packaged with your app's APK
21 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
22 | android.useAndroidX=true
23 | # Automatically convert third-party libraries to use AndroidX
24 | android.enableJetifier=true
25 |
26 | # Kotlin code style for this project: "official" or "obsolete":
27 | kotlin.code.style=official
28 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/o0o0oo00/Pudding/b6ae287ac25db7a027ab90a631ffc6fd5d741987/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Mar 18 19:51:36 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-4.10.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 |
--------------------------------------------------------------------------------
/pudding/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/pudding/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android-extensions'
3 | apply plugin: 'kotlin-android'
4 |
5 | android {
6 | compileSdkVersion 28
7 |
8 |
9 |
10 | defaultConfig {
11 | minSdkVersion 19
12 | targetSdkVersion 28
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 |
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 |
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 |
32 | implementation 'com.android.support:appcompat-v7:28.0.0'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
35 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
36 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
37 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
38 | }
39 | repositories {
40 | mavenCentral()
41 | }
42 |
--------------------------------------------------------------------------------
/pudding/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 |
--------------------------------------------------------------------------------
/pudding/src/androidTest/java/com/zcy/pudding/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zcy.pudding;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zcy.warning.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/pudding/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/pudding/src/main/java/com/zcy/pudding/Choco.kt:
--------------------------------------------------------------------------------
1 | package com.zcy.pudding
2 |
3 | import android.animation.ObjectAnimator
4 | import android.content.Context
5 | import android.graphics.*
6 | import android.graphics.drawable.Drawable
7 | import android.os.Build
8 | import android.os.Handler
9 | import android.text.TextUtils
10 | import android.util.AttributeSet
11 | import android.util.Log
12 | import android.view.HapticFeedbackConstants
13 | import android.view.View
14 | import android.view.WindowManager
15 | import android.view.animation.AnimationUtils
16 | import android.view.animation.AnticipateOvershootInterpolator
17 | import android.view.animation.OvershootInterpolator
18 | import android.widget.Button
19 | import android.widget.FrameLayout
20 | import androidx.annotation.*
21 | import androidx.appcompat.content.res.AppCompatResources
22 | import androidx.appcompat.view.ContextThemeWrapper
23 | import androidx.core.content.ContextCompat
24 | import kotlinx.android.synthetic.main.layout_choco.view.*
25 |
26 | /**
27 | * @author: https://github.com/o0o0oo00
28 | * @description: custom Choco view
29 | *
30 | * @date: 2019/3/15
31 | */
32 | class Choco @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
33 | FrameLayout(context, attrs, defStyleAttr) {
34 |
35 | private lateinit var animEnter: ObjectAnimator
36 | private val animEnterInterceptor = OvershootInterpolator()
37 | private var enableIconPulse = true
38 |
39 | var enableInfiniteDuration = false
40 | private var enableProgress = false
41 | private var enabledVibration = false
42 | private var buttons = ArrayList