├── .gitignore
├── .idea
└── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── LICENSE
├── README.md
├── RELEASENOTES.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── takusemba
│ │ └── spotlightsample
│ │ ├── ActivitySampleActivity.kt
│ │ ├── ChooserActivity.kt
│ │ ├── FragmentSampleActivity.kt
│ │ └── FragmentSampleFragment.kt
│ └── res
│ ├── drawable-xxhdpi
│ └── ic_arrow.png
│ ├── layout
│ ├── activity_activity_sample.xml
│ ├── activity_chooser.xml
│ ├── activity_fragment_sample.xml
│ ├── fragment_fragment_sample.xml
│ └── layout_target.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
├── arts
├── customTarget.gif
├── logo_yello.png
└── simpleTarget.gif
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── publish.gradle
├── settings.gradle
└── spotlight
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
└── main
├── AndroidManifest.xml
├── java
└── com
│ └── takusemba
│ └── spotlight
│ ├── OnSpotlightListener.kt
│ ├── OnTargetListener.kt
│ ├── Spotlight.kt
│ ├── SpotlightView.kt
│ ├── Target.kt
│ ├── effet
│ ├── Effect.kt
│ ├── EmptyEffect.kt
│ ├── FlickerEffect.kt
│ └── RippleEffect.kt
│ └── shape
│ ├── Circle.kt
│ ├── RoundedRectangle.kt
│ └── Shape.kt
└── res
└── values
└── strings.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/*
5 | !/.idea/codeStyles/
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
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 | xmlns:android
234 |
235 | .*
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 | xmlns:.*
245 |
246 | .*
247 |
248 |
249 | BY_NAME
250 |
251 |
252 |
253 |
254 |
255 |
256 | .*:id
257 |
258 | http://schemas.android.com/apk/res/android
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 | .*:name
268 |
269 | http://schemas.android.com/apk/res/android
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 | name
279 |
280 | ^$
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 | style
290 |
291 | ^$
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 | .*
301 |
302 | ^$
303 |
304 |
305 | BY_NAME
306 |
307 |
308 |
309 |
310 |
311 |
312 | .*:orientation
313 |
314 | http://schemas.android.com/apk/res/android
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 | .*:layout_width
324 |
325 | http://schemas.android.com/apk/res/android
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 | .*:layout_height
335 |
336 | http://schemas.android.com/apk/res/android
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 | .*:layout_weight
346 |
347 | http://schemas.android.com/apk/res/android
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 | .*:layout_.*
357 |
358 | http://schemas.android.com/apk/res/android
359 |
360 |
361 | BY_NAME
362 |
363 |
364 |
365 |
366 |
367 |
368 | .*:width
369 |
370 | http://schemas.android.com/apk/res/android
371 |
372 |
373 | BY_NAME
374 |
375 |
376 |
377 |
378 |
379 |
380 | .*:height
381 |
382 | http://schemas.android.com/apk/res/android
383 |
384 |
385 | BY_NAME
386 |
387 |
388 |
389 |
390 |
391 |
392 | .*
393 |
394 | http://schemas.android.com/apk/res/android
395 |
396 |
397 | BY_NAME
398 |
399 |
400 |
401 |
402 |
403 |
404 | .*
405 |
406 | .*
407 |
408 |
409 | BY_NAME
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 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Spotlight
2 |
3 |
4 |
5 | 
6 | 
7 | 
8 | 
9 |
10 | ## Gradle
11 |
12 | ```groovy
13 | dependencies {
14 | implementation 'com.github.takusemba:spotlight:x.x.x'
15 | }
16 | ```
17 |
18 |
19 | ## Usage
20 |
21 | ```kt
22 | val spotlight = Spotlight.Builder(this)
23 | .setTargets(firstTarget, secondTarget, thirdTarget ...)
24 | .setBackgroundColor(R.color.spotlightBackground)
25 | .setDuration(1000L)
26 | .setAnimation(DecelerateInterpolator(2f))
27 | .setContainer(viewGroup)
28 | .setOnSpotlightListener(object : OnSpotlightListener {
29 | override fun onStarted() {
30 | Toast.makeText(this@MainActivity, "spotlight is started", Toast.LENGTH_SHORT).show()
31 | }
32 | override fun onEnded() {
33 | Toast.makeText(this@MainActivity, "spotlight is ended", Toast.LENGTH_SHORT).show()
34 | }
35 | })
36 | .build()
37 | ```
38 |
39 | If you want to show Spotlight immediately, you have to wait until views are laid out.
40 |
41 | ```kt
42 | // with core-ktx method.
43 | view.doOnPreDraw { Spotlight.Builder(this)...start() }
44 | ```
45 |
46 |
47 |
48 |
49 |
50 |
51 | ## Target
52 | Create a Target to add Spotlight.
53 |
54 | Target is a spot to be casted by Spotlight. You can add multiple targets to Spotlight.
55 |
56 | ```kt
57 | val target = Target.Builder()
58 | .setAnchor(100f, 100f)
59 | .setShape(Circle(100f))
60 | .setEffect(RippleEffect(100f, 200f, argb(30, 124, 255, 90)))
61 | .setOverlay(layout)
62 | .setOnTargetListener(object : OnTargetListener {
63 | override fun onStarted() {
64 | makeText(this@MainActivity, "first target is started", LENGTH_SHORT).show()
65 | }
66 | override fun onEnded() {
67 | makeText(this@MainActivity, "first target is ended", LENGTH_SHORT).show()
68 | }
69 | })
70 | .build()
71 | ```
72 |
73 |
74 |
75 |
76 |
77 | ## Start/Finish Spotlight
78 |
79 | ```kt
80 | val spotlight = Spotlight.Builder(this)...start()
81 |
82 | spotlight.finish()
83 | ```
84 |
85 | ## Next/Previous/Show Target
86 |
87 | ```kt
88 | val spotlight = Spotlight.Builder(this)...start()
89 |
90 | spotlight.next()
91 |
92 | spotlight.previous()
93 |
94 | spotlight.show(2)
95 | ```
96 |
97 | ## Custom Shape
98 | `Shape` defines how your target will look like.
99 | [Circle](https://github.com/TakuSemba/Spotlight/blob/master/spotlight/src/main/java/com/takusemba/spotlight/shape/Circle.kt) and [RoundedRectangle](https://github.com/TakuSemba/Spotlight/blob/master/spotlight/src/main/java/com/takusemba/spotlight/shape/RoundedRectangle.kt) shapes are already implemented, but if you want your custom shape, it's arhivable by implementing `Shape` interface.
100 |
101 |
102 | ```kt
103 | class CustomShape(
104 | override val duration: Long,
105 | override val interpolator: TimeInterpolator
106 | ) : Shape {
107 |
108 | override fun draw(canvas: Canvas, point: PointF, value: Float, paint: Paint) {
109 | // draw your shape here.
110 | }
111 | }
112 | ```
113 |
114 | ## Custom Effect
115 | `Effect` allows you to decorates your target.
116 | [RippleEffect](https://github.com/TakuSemba/Spotlight/blob/master/spotlight/src/main/java/com/takusemba/spotlight/effet/RippleEffect.kt) and [FlickerEffect](https://github.com/TakuSemba/Spotlight/blob/master/spotlight/src/main/java/com/takusemba/spotlight/effet/FlickerEffect.kt) shapes are already implemented, but if you want your custom effect, it's arhivable by implementing `Effect` interface.
117 |
118 |
119 | ```kt
120 | class CustomEffect(
121 | override val duration: Long,
122 | override val interpolator: TimeInterpolator,
123 | override val repeatMode: Int
124 | ) : Effect {
125 |
126 | override fun draw(canvas: Canvas, point: PointF, value: Float, paint: Paint) {
127 | // draw your effect here.
128 | }
129 | }
130 | ```
131 |
132 | ## Sample
133 | Clone this repo and check out the [app](https://github.com/TakuSemba/Spotlight/tree/master/app) module.
134 |
135 | ## Author
136 |
137 | * **Taku Semba**
138 | * **Github** - (https://github.com/takusemba)
139 | * **Twitter** - (https://twitter.com/takusemba)
140 | * **Facebook** - (https://www.facebook.com/takusemba)
141 |
142 | ## Licence
143 | ```
144 | Copyright 2017 Taku Semba.
145 |
146 | Licensed under the Apache License, Version 2.0 (the "License");
147 | you may not use this file except in compliance with the License.
148 | You may obtain a copy of the License at
149 |
150 | http://www.apache.org/licenses/LICENSE-2.0
151 |
152 | Unless required by applicable law or agreed to in writing, software
153 | distributed under the License is distributed on an "AS IS" BASIS,
154 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
155 | See the License for the specific language governing permissions and
156 | limitations under the License.
157 | ```
158 |
--------------------------------------------------------------------------------
/RELEASENOTES.md:
--------------------------------------------------------------------------------
1 | Release notes
2 | ==========
3 |
4 | Version 2.0.5 **(1021-3-19)**
5 | ----------------------------
6 | - Fix onStarted is called twice. ([#120](https://github.com/TakuSemba/Spotlight/issues/120))
7 |
8 | Version 2.0.4 **(1021-2-27)**
9 | ----------------------------
10 | - Update Kotlin to 1.4.31.
11 |
12 | Version 2.0.3 **(1020-10-26)**
13 | ----------------------------
14 | - Accept ColorInt as background color. ([#108](https://github.com/TakuSemba/Spotlight/pull/108))
15 |
16 | Version 2.0.2 **(1020-9-4)**
17 | ----------------------------
18 | - Update dependencies.
19 | - Provide overloaded constructors for `Shape` and `Effect` implementations. ([#87](https://github.com/TakuSemba/Spotlight/issues/87))
20 | - Throw an Exception when you add an empty target to Spotlight. ([#84](https://github.com/TakuSemba/Spotlight/issues/84))
21 | - Fix anchor is a bit off when using custom container.
22 | - Fix issue where SpotlightView is leaked via an animation listener. ([#93](https://github.com/TakuSemba/Spotlight/issues/93))
23 | - Fix behavior of RippleEffect.
24 | - Start Effect after Target is drawn.
25 |
26 | Version 2.0.1 **(1019-11-11)**
27 | ----------------------------
28 | - Fix internal logic.
29 |
30 | Version 2.0.0 **(1019-11-11)**
31 | ----------------------------
32 | - Require kotlin 1.3.50.
33 | - Remove SimpleTarget.
34 | - Remove `isClosedOnTouchedOutside` attribute.
35 | - Add `Spotlight.next()`, `Spotlight.previous()`, `Spotlight.show()` functionality.
36 | - **next**: show the next target after closing the current target if exists.
37 | - **previous**: show the previous target after closing the current target if exists.
38 | - **show**: show the target at specified index. (e.g. show(1)).
39 | - Add `setContainer` to set a custom container to hold a SpotlightView. The default is DecoderView.
40 | - Add Effect feature. `RippleEffect` and `FlickerEffect` are provided by default.
41 | ```kt
42 | val target = Target.Builder()
43 | .setAnchor(100f, 100f)
44 | .setShape(Circle(150f))
45 | .setEffect(FlickerEffect(200f, rgb(124, 255, 90)))
46 | .build()
47 | ```
48 |
49 | Thank you for the feature requests from @OliverCulleyDeLange, @hamz4k.
50 |
51 | Version 1.8.0 **(2019-1-5)**
52 | ----------------------------
53 | - Add Rounded rectangle shape.
54 |
55 | Version 1.5.0 **(2018-5-13)**
56 | ----------------------------
57 | - Add custom shapes functionality.
58 | - Add skip feature.
59 |
60 | Version 1.3.0 **(2018-2-8)**
61 | ----------------------------
62 | - Add click handling listener.
63 |
64 | Version 1.2.0 **(2018-1-27)**
65 | ----------------------------
66 | - Add Overlay color attribute.
67 |
68 | Version 1.0.0 **(2017-7-2)**
69 | ----------------------------
70 | - Initial Release.
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion configs.compileSdkVersion
6 | defaultConfig {
7 | minSdkVersion configs.minSdkVersion
8 | targetSdkVersion configs.targetSdkVersion
9 | }
10 | }
11 |
12 | dependencies {
13 | implementation deps.kotlin.stdlib
14 | implementation deps.androidx.appcompat
15 | implementation deps.androidx.constraintLayout
16 | implementation project(':spotlight')
17 | debugImplementation deps.leakcanary
18 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/takusemba/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
27 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/takusemba/spotlightsample/ActivitySampleActivity.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlightsample
2 |
3 | import android.os.Bundle
4 | import android.view.View
5 | import android.view.animation.DecelerateInterpolator
6 | import android.widget.FrameLayout
7 | import android.widget.Toast
8 | import android.widget.Toast.LENGTH_SHORT
9 | import android.widget.Toast.makeText
10 | import androidx.appcompat.app.AppCompatActivity
11 | import com.takusemba.spotlight.OnSpotlightListener
12 | import com.takusemba.spotlight.OnTargetListener
13 | import com.takusemba.spotlight.Spotlight
14 | import com.takusemba.spotlight.Target
15 | import com.takusemba.spotlight.shape.Circle
16 |
17 | class ActivitySampleActivity : AppCompatActivity(R.layout.activity_activity_sample) {
18 |
19 | private var currentToast: Toast? = null
20 |
21 | override fun onCreate(savedInstanceState: Bundle?) {
22 | super.onCreate(savedInstanceState)
23 |
24 | findViewById(R.id.start).setOnClickListener { startButton ->
25 | val targets = ArrayList()
26 |
27 | // first target
28 | val firstRoot = FrameLayout(this)
29 | val first = layoutInflater.inflate(R.layout.layout_target, firstRoot)
30 | val firstTarget = Target.Builder()
31 | .setAnchor(findViewById(R.id.one))
32 | .setShape(Circle(100f))
33 | .setOverlay(first)
34 | .setOnTargetListener(object : OnTargetListener {
35 | override fun onStarted() {
36 | currentToast?.cancel()
37 | currentToast = makeText(
38 | this@ActivitySampleActivity,
39 | "first target is started",
40 | LENGTH_SHORT
41 | )
42 | currentToast?.show()
43 | }
44 |
45 | override fun onEnded() {
46 | currentToast?.cancel()
47 | currentToast = makeText(
48 | this@ActivitySampleActivity,
49 | "first target is ended",
50 | LENGTH_SHORT
51 | )
52 | currentToast?.show()
53 | }
54 | })
55 | .build()
56 |
57 | targets.add(firstTarget)
58 |
59 | // second target
60 | val secondRoot = FrameLayout(this)
61 | val second = layoutInflater.inflate(R.layout.layout_target, secondRoot)
62 | val secondTarget = Target.Builder()
63 | .setAnchor(findViewById(R.id.two))
64 | .setShape(Circle(150f))
65 | .setOverlay(second)
66 | .setOnTargetListener(object : OnTargetListener {
67 | override fun onStarted() {
68 | currentToast?.cancel()
69 | currentToast = makeText(
70 | this@ActivitySampleActivity,
71 | "second target is started",
72 | LENGTH_SHORT
73 | )
74 | currentToast?.show()
75 | }
76 |
77 | override fun onEnded() {
78 | currentToast?.cancel()
79 | currentToast = makeText(
80 | this@ActivitySampleActivity,
81 | "second target is ended",
82 | LENGTH_SHORT
83 | )
84 | currentToast?.show()
85 | }
86 | })
87 | .build()
88 |
89 | targets.add(secondTarget)
90 |
91 | // third target
92 | val thirdRoot = FrameLayout(this)
93 | val third = layoutInflater.inflate(R.layout.layout_target, thirdRoot)
94 | val thirdTarget = Target.Builder()
95 | .setAnchor(findViewById(R.id.three))
96 | .setShape(Circle(200f))
97 | .setOverlay(third)
98 | .setOnTargetListener(object : OnTargetListener {
99 | override fun onStarted() {
100 | currentToast?.cancel()
101 | currentToast = makeText(
102 | this@ActivitySampleActivity,
103 | "third target is started",
104 | LENGTH_SHORT
105 | )
106 | currentToast?.show()
107 | }
108 |
109 | override fun onEnded() {
110 | currentToast?.cancel()
111 | currentToast = makeText(
112 | this@ActivitySampleActivity,
113 | "third target is ended",
114 | LENGTH_SHORT
115 | )
116 | currentToast?.show()
117 | }
118 | })
119 | .build()
120 |
121 | targets.add(thirdTarget)
122 |
123 | // create spotlight
124 | val spotlight = Spotlight.Builder(this@ActivitySampleActivity)
125 | .setTargets(targets)
126 | .setBackgroundColorRes(R.color.spotlightBackground)
127 | .setDuration(1000L)
128 | .setAnimation(DecelerateInterpolator(2f))
129 | .setOnSpotlightListener(object : OnSpotlightListener {
130 | override fun onStarted() {
131 | currentToast?.cancel()
132 | currentToast = makeText(
133 | this@ActivitySampleActivity,
134 | "spotlight is started",
135 | LENGTH_SHORT
136 | )
137 | currentToast?.show()
138 | startButton.isEnabled = false
139 | }
140 |
141 | override fun onEnded() {
142 | currentToast?.cancel()
143 | currentToast = makeText(
144 | this@ActivitySampleActivity,
145 | "spotlight is ended",
146 | LENGTH_SHORT
147 | )
148 | currentToast?.show()
149 | startButton.isEnabled = true
150 | }
151 | })
152 | .build()
153 |
154 | spotlight.start()
155 |
156 | val nextTarget = View.OnClickListener { spotlight.next() }
157 |
158 | val closeSpotlight = View.OnClickListener { spotlight.finish() }
159 |
160 | first.findViewById(R.id.close_target).setOnClickListener(nextTarget)
161 | second.findViewById(R.id.close_target).setOnClickListener(nextTarget)
162 | third.findViewById(R.id.close_target).setOnClickListener(nextTarget)
163 |
164 | first.findViewById(R.id.close_spotlight).setOnClickListener(closeSpotlight)
165 | second.findViewById(R.id.close_spotlight).setOnClickListener(closeSpotlight)
166 | third.findViewById(R.id.close_spotlight).setOnClickListener(closeSpotlight)
167 | }
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/app/src/main/java/com/takusemba/spotlightsample/ChooserActivity.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlightsample
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import android.widget.ArrayAdapter
6 | import android.widget.ListView
7 | import androidx.appcompat.app.AppCompatActivity
8 |
9 | class ChooserActivity : AppCompatActivity(R.layout.activity_chooser) {
10 |
11 | private val samples: Array = arrayOf(
12 | SAMPLE_SPOTLIGHT_ON_ACTIVITY,
13 | SAMPLE_SPOTLIGHT_ON_FRAGMENT
14 | )
15 |
16 | override fun onCreate(savedInstanceState: Bundle?) {
17 | super.onCreate(savedInstanceState)
18 | val listView = findViewById(R.id.sample_list)
19 | val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, samples)
20 | listView.adapter = adapter
21 | listView.setOnItemClickListener { _, _, position, _ ->
22 | when (samples[position]) {
23 | SAMPLE_SPOTLIGHT_ON_ACTIVITY -> {
24 | val intent = Intent(this, ActivitySampleActivity::class.java)
25 | startActivity(intent)
26 | }
27 | SAMPLE_SPOTLIGHT_ON_FRAGMENT -> {
28 | val intent = Intent(this, FragmentSampleActivity::class.java)
29 | startActivity(intent)
30 | }
31 | }
32 | }
33 | }
34 |
35 | companion object {
36 | private const val SAMPLE_SPOTLIGHT_ON_ACTIVITY = "Spotlight on Activity"
37 | private const val SAMPLE_SPOTLIGHT_ON_FRAGMENT = "Spotlight on Fragment"
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/takusemba/spotlightsample/FragmentSampleActivity.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlightsample
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 |
5 | class FragmentSampleActivity : AppCompatActivity(R.layout.activity_fragment_sample)
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/takusemba/spotlightsample/FragmentSampleFragment.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlightsample
2 |
3 | import android.os.Bundle
4 | import android.view.View
5 | import android.view.animation.DecelerateInterpolator
6 | import android.widget.FrameLayout
7 | import android.widget.Toast
8 | import androidx.fragment.app.Fragment
9 | import com.takusemba.spotlight.OnSpotlightListener
10 | import com.takusemba.spotlight.OnTargetListener
11 | import com.takusemba.spotlight.Spotlight
12 | import com.takusemba.spotlight.Target
13 | import com.takusemba.spotlight.shape.Circle
14 |
15 | class FragmentSampleFragment : Fragment(R.layout.fragment_fragment_sample) {
16 |
17 | private var currentToast: Toast? = null
18 |
19 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
20 | super.onViewCreated(view, savedInstanceState)
21 | view.findViewById(R.id.start).setOnClickListener { startButton ->
22 | val targets = ArrayList()
23 |
24 | // first target
25 | val firstRoot = FrameLayout(requireContext())
26 | val first = layoutInflater.inflate(R.layout.layout_target, firstRoot)
27 | val firstTarget = Target.Builder()
28 | .setAnchor(view.findViewById(R.id.one))
29 | .setShape(Circle(100f))
30 | .setOverlay(first)
31 | .setOnTargetListener(object : OnTargetListener {
32 | override fun onStarted() {
33 | currentToast?.cancel()
34 | currentToast = Toast.makeText(
35 | requireContext(),
36 | "first target is started",
37 | Toast.LENGTH_SHORT
38 | )
39 | currentToast?.show()
40 | }
41 |
42 | override fun onEnded() {
43 | currentToast?.cancel()
44 | currentToast = Toast.makeText(
45 | requireContext(),
46 | "first target is ended",
47 | Toast.LENGTH_SHORT
48 | )
49 | currentToast?.show()
50 | }
51 | })
52 | .build()
53 |
54 | targets.add(firstTarget)
55 |
56 | // second target
57 | val secondRoot = FrameLayout(requireActivity())
58 | val second = layoutInflater.inflate(R.layout.layout_target, secondRoot)
59 | val secondTarget = Target.Builder()
60 | .setAnchor(view.findViewById(R.id.two))
61 | .setShape(Circle(150f))
62 | .setOverlay(second)
63 | .setOnTargetListener(object : OnTargetListener {
64 | override fun onStarted() {
65 | currentToast?.cancel()
66 | currentToast = Toast.makeText(
67 | requireContext(),
68 | "second target is started",
69 | Toast.LENGTH_SHORT
70 | )
71 | currentToast?.show()
72 | }
73 |
74 | override fun onEnded() {
75 | currentToast?.cancel()
76 | currentToast = Toast.makeText(
77 | requireContext(),
78 | "second target is ended",
79 | Toast.LENGTH_SHORT
80 | )
81 | currentToast?.show()
82 | }
83 | })
84 | .build()
85 |
86 | targets.add(secondTarget)
87 |
88 | // third target
89 | val thirdRoot = FrameLayout(requireContext())
90 | val third = layoutInflater.inflate(R.layout.layout_target, thirdRoot)
91 | val thirdTarget = Target.Builder()
92 | .setAnchor(view.findViewById(R.id.three))
93 | .setShape(Circle(200f))
94 | .setOverlay(third)
95 | .setOnTargetListener(object : OnTargetListener {
96 | override fun onStarted() {
97 | currentToast?.cancel()
98 | currentToast = Toast.makeText(
99 | requireContext(),
100 | "third target is started",
101 | Toast.LENGTH_SHORT
102 | )
103 | currentToast?.show()
104 | }
105 |
106 | override fun onEnded() {
107 | currentToast?.cancel()
108 | currentToast = Toast.makeText(
109 | requireContext(),
110 | "third target is ended",
111 | Toast.LENGTH_SHORT
112 | )
113 | currentToast?.show()
114 | }
115 | })
116 | .build()
117 |
118 | targets.add(thirdTarget)
119 |
120 | // create spotlight
121 | val spotlight = Spotlight.Builder(requireActivity())
122 | .setTargets(targets)
123 | .setBackgroundColorRes(R.color.spotlightBackground)
124 | .setDuration(1000L)
125 | .setAnimation(DecelerateInterpolator(2f))
126 | .setOnSpotlightListener(object : OnSpotlightListener {
127 | override fun onStarted() {
128 | currentToast?.cancel()
129 | currentToast = Toast.makeText(
130 | requireContext(),
131 | "spotlight is started",
132 | Toast.LENGTH_SHORT
133 | )
134 | currentToast?.show()
135 | startButton.isEnabled = false
136 | }
137 |
138 | override fun onEnded() {
139 | currentToast?.cancel()
140 | currentToast = Toast.makeText(
141 | requireContext(),
142 | "spotlight is ended",
143 | Toast.LENGTH_SHORT
144 | )
145 | currentToast?.show()
146 | startButton.isEnabled = true
147 | }
148 | })
149 | .build()
150 |
151 | spotlight.start()
152 |
153 | val nextTarget = View.OnClickListener { spotlight.next() }
154 |
155 | val closeSpotlight = View.OnClickListener { spotlight.finish() }
156 |
157 | first.findViewById(R.id.close_target).setOnClickListener(nextTarget)
158 | second.findViewById(R.id.close_target).setOnClickListener(nextTarget)
159 | third.findViewById(R.id.close_target).setOnClickListener(nextTarget)
160 |
161 | first.findViewById(R.id.close_spotlight).setOnClickListener(closeSpotlight)
162 | second.findViewById(R.id.close_spotlight).setOnClickListener(closeSpotlight)
163 | third.findViewById(R.id.close_spotlight).setOnClickListener(closeSpotlight)
164 | }
165 | }
166 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/app/src/main/res/drawable-xxhdpi/ic_arrow.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_activity_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
22 |
23 |
38 |
39 |
53 |
54 |
55 |
69 |
70 |
74 |
83 |
84 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_chooser.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fragment_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_fragment_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
22 |
23 |
38 |
39 |
53 |
54 |
55 |
69 |
70 |
74 |
83 |
84 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_target.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
23 |
24 |
37 |
38 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/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 | #BF000000
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SpotlightApp
3 |
4 | 1
5 | 2
6 | 3
7 | Start Spotlight
8 | Close Spotlight
9 | Next Target
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/arts/customTarget.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/arts/customTarget.gif
--------------------------------------------------------------------------------
/arts/logo_yello.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/arts/logo_yello.png
--------------------------------------------------------------------------------
/arts/simpleTarget.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/arts/simpleTarget.gif
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.configs = [
3 | version: "2.0.5",
4 | groupId: "com.github.takusemba",
5 | artifactId: "spotlight",
6 | description: "Android Library that lights items for tutorials or walk-throughs etc...",
7 | siteUrl: "https://github.com/TakuSemba/Spotlight",
8 | gitUrl: "https://github.com/TakuSemba/Spotlight.git",
9 | developerId: "takusemba",
10 | developerName: "TakuSemba",
11 | developerEmail: "takusemba.ele@gmail.com",
12 | licenseName: "The Apache Software License, Version 2.0",
13 | licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0.txt",
14 |
15 | compileSdkVersion: 30,
16 | minSdkVersion: 14,
17 | targetSdkVersion: 30,
18 | ]
19 | ext.versions = [
20 | kotlin: '1.4.31',
21 | ]
22 | ext.deps = [
23 | androidPlugin: "com.android.tools.build:gradle:4.1.2",
24 | kotlin: [
25 | plugin: "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}",
26 | stdlib: "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}",
27 | ],
28 | androidx: [
29 | appcompat: "androidx.appcompat:appcompat:1.2.0",
30 | constraintLayout: "androidx.constraintlayout:constraintlayout:2.0.1",
31 | ],
32 | leakcanary: 'com.squareup.leakcanary:leakcanary-android:2.4'
33 | ]
34 | repositories {
35 | google()
36 | jcenter()
37 | }
38 | dependencies {
39 | classpath deps.androidPlugin
40 | classpath deps.kotlin.plugin
41 | }
42 | }
43 |
44 | allprojects {
45 | repositories {
46 | google()
47 | jcenter()
48 | }
49 | }
50 |
51 | task clean(type: Delete) {
52 | delete rootProject.buildDir
53 | }
54 |
--------------------------------------------------------------------------------
/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 | android.useAndroidX=true
13 | android.enableJetifier=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TakuSemba/Spotlight/d19e4ddc8dc0b2ced3b55d2a34dd68af96692d2d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/publish.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven-publish'
2 | apply plugin: 'signing'
3 |
4 | ext["sonatypeUsername"] = ''
5 | ext["sonatypePassword"] = ''
6 |
7 | // https://getstream.io/blog/publishing-libraries-to-mavencentral-2021/
8 | File secretPropsFile = project.rootProject.file('local.properties')
9 | if (secretPropsFile.exists()) {
10 | Properties p = new Properties()
11 | new FileInputStream(secretPropsFile).withCloseable { is ->
12 | p.load(is)
13 | }
14 | p.each { name, value ->
15 | ext[name] = value
16 | }
17 | } else {
18 | ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
19 | ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
20 | ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
21 | ext["sonatypeUsername"] = System.getenv('SONATYPE_USERNAME')
22 | ext["sonatypePassword"] = System.getenv('SONATYPE_PASSWORD')
23 | }
24 |
25 | // https://gist.github.com/wasabeef/2f2ae8d97b429e7d967128125dc47854
26 | version configs.version
27 | group configs.groupId
28 |
29 | task sourcesJar(type: Jar) {
30 | archiveClassifier.set("sources")
31 | from android.sourceSets.getByName("main").java.srcDirs
32 | }
33 |
34 | task javadoc(type: Javadoc) {
35 | options.addStringOption('Xdoclint:none', '-quiet')
36 | source = android.sourceSets.getByName("main").java.srcDirs
37 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
38 | excludes = ['**/*.kt']
39 | }
40 |
41 | task javadocJar(type: Jar, dependsOn: javadoc) {
42 | archiveClassifier.set("javadoc")
43 | from javadoc.destinationDir
44 | }
45 |
46 | afterEvaluate {
47 | publishing {
48 | publications {
49 | release(MavenPublication) {
50 | artifactId = configs.artifactId
51 | from components.release
52 | artifact javadocJar
53 | artifact sourcesJar
54 | pom {
55 | name = configs.artifactId
56 | description = configs.description
57 | url = configs.siteUrl
58 | licenses {
59 | license {
60 | name = configs.licenseName
61 | url = configs.licenseUrl
62 | }
63 | }
64 | developers {
65 | developer {
66 | id = configs.developerId
67 | name = configs.developerName
68 | email = configs.developerEmail
69 | }
70 | }
71 | scm {
72 | connection = configs.gitUrl
73 | developerConnection = configs.gitUrl
74 | url = configs.siteUrl
75 | }
76 | }
77 | }
78 | }
79 | repositories {
80 | maven {
81 | def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
82 | def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
83 | url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
84 | credentials {
85 | username = "${sonatypeUsername}"
86 | password = "${sonatypePassword}"
87 | }
88 | }
89 | }
90 | }
91 | }
92 |
93 | signing {
94 | sign publishing.publications
95 | }
96 |
97 | javadoc {
98 | if (JavaVersion.current().isJava9Compatible()) {
99 | options.addBooleanOption('html5', true)
100 | }
101 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':spotlight'
2 |
--------------------------------------------------------------------------------
/spotlight/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/spotlight/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion configs.compileSdkVersion
6 | defaultConfig {
7 | minSdkVersion configs.minSdkVersion
8 | targetSdkVersion configs.targetSdkVersion
9 | }
10 | }
11 |
12 | dependencies {
13 | implementation deps.kotlin.stdlib
14 | implementation deps.androidx.appcompat
15 | }
16 |
17 | apply from: "../publish.gradle"
--------------------------------------------------------------------------------
/spotlight/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/takusemba/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/spotlight/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/spotlight/src/main/java/com/takusemba/spotlight/OnSpotlightListener.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlight
2 |
3 | /**
4 | * Listener to notify the state of Spotlight.
5 | */
6 | interface OnSpotlightListener {
7 |
8 | /**
9 | * Called when Spotlight is started
10 | */
11 | fun onStarted()
12 |
13 | /**
14 | * Called when Spotlight is ended
15 | */
16 | fun onEnded()
17 | }
18 |
--------------------------------------------------------------------------------
/spotlight/src/main/java/com/takusemba/spotlight/OnTargetListener.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlight
2 |
3 | /**
4 | * Listener to notify the state of Target.
5 | */
6 | interface OnTargetListener {
7 |
8 | /**
9 | * Called when Target is started
10 | */
11 | fun onStarted()
12 |
13 | /**
14 | * Called when Target is started
15 | */
16 | fun onEnded()
17 | }
18 |
--------------------------------------------------------------------------------
/spotlight/src/main/java/com/takusemba/spotlight/Spotlight.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlight
2 |
3 | import android.animation.Animator
4 | import android.animation.AnimatorListenerAdapter
5 | import android.animation.TimeInterpolator
6 | import android.app.Activity
7 | import android.view.ViewGroup
8 | import android.view.ViewGroup.LayoutParams.MATCH_PARENT
9 | import android.view.animation.DecelerateInterpolator
10 | import androidx.annotation.ColorInt
11 | import androidx.annotation.ColorRes
12 | import androidx.core.content.ContextCompat
13 | import java.util.concurrent.TimeUnit
14 |
15 | /**
16 | * Holds all of the [Target]s and [SpotlightView] to show/hide [Target], [SpotlightView] properly.
17 | * [SpotlightView] can be controlled with [start]/[finish].
18 | * All of the [Target]s can be controlled with [next]/[previous]/[show].
19 | *
20 | * Once you finish the current [Spotlight] with [finish], you can not start the [Spotlight] again
21 | * unless you create a new [Spotlight] to start again.
22 | */
23 | class Spotlight private constructor(
24 | private val spotlight: SpotlightView,
25 | private val targets: Array,
26 | private val duration: Long,
27 | private val interpolator: TimeInterpolator,
28 | private val container: ViewGroup,
29 | private val spotlightListener: OnSpotlightListener?
30 | ) {
31 |
32 | private var currentIndex = NO_POSITION
33 |
34 | init {
35 | container.addView(spotlight, MATCH_PARENT, MATCH_PARENT)
36 | }
37 |
38 | /**
39 | * Starts [SpotlightView] and show the first [Target].
40 | */
41 | fun start() {
42 | startSpotlight()
43 | }
44 |
45 | /**
46 | * Closes the current [Target] if exists, and shows a [Target] at the specified [index].
47 | * If target is not found at the [index], it will throw an exception.
48 | */
49 | fun show(index: Int) {
50 | showTarget(index)
51 | }
52 |
53 | /**
54 | * Closes the current [Target] if exists, and shows the next [Target].
55 | * If the next [Target] is not found, Spotlight will finish.
56 | */
57 | fun next() {
58 | showTarget(currentIndex + 1)
59 | }
60 |
61 | /**
62 | * Closes the current [Target] if exists, and shows the previous [Target].
63 | * If the previous target is not found, it will throw an exception.
64 | */
65 | fun previous() {
66 | showTarget(currentIndex - 1)
67 | }
68 |
69 | /**
70 | * Closes Spotlight and [SpotlightView] will remove all children and be removed from the [container].
71 | */
72 | fun finish() {
73 | finishSpotlight()
74 | }
75 |
76 | /**
77 | * Starts Spotlight.
78 | */
79 | private fun startSpotlight() {
80 | spotlight.startSpotlight(duration, interpolator, object : AnimatorListenerAdapter() {
81 | override fun onAnimationStart(animation: Animator) {
82 | spotlightListener?.onStarted()
83 | }
84 |
85 | override fun onAnimationEnd(animation: Animator) {
86 | showTarget(0)
87 | }
88 | })
89 | }
90 |
91 | /**
92 | * Closes the current [Target] if exists, and show the [Target] at [index].
93 | */
94 | private fun showTarget(index: Int) {
95 | if (currentIndex == NO_POSITION) {
96 | val target = targets[index]
97 | currentIndex = index
98 | spotlight.startTarget(target)
99 | target.listener?.onStarted()
100 | } else {
101 | spotlight.finishTarget(object : AnimatorListenerAdapter() {
102 | override fun onAnimationEnd(animation: Animator) {
103 | val previousIndex = currentIndex
104 | val previousTarget = targets[previousIndex]
105 | previousTarget.listener?.onEnded()
106 | if (index < targets.size) {
107 | val target = targets[index]
108 | currentIndex = index
109 | spotlight.startTarget(target)
110 | target.listener?.onStarted()
111 | } else {
112 | finishSpotlight()
113 | }
114 | }
115 | })
116 | }
117 | }
118 |
119 | /**
120 | * Closes Spotlight.
121 | */
122 | private fun finishSpotlight() {
123 | spotlight.finishSpotlight(duration, interpolator, object : AnimatorListenerAdapter() {
124 | override fun onAnimationEnd(animation: Animator) {
125 | spotlight.cleanup()
126 | container.removeView(spotlight)
127 | spotlightListener?.onEnded()
128 | }
129 | })
130 | }
131 |
132 | companion object {
133 |
134 | private const val NO_POSITION = -1
135 | }
136 |
137 | /**
138 | * Builder to build [Spotlight].
139 | * All parameters should be set in this [Builder].
140 | */
141 | class Builder(private val activity: Activity) {
142 |
143 | private var targets: Array? = null
144 | private var duration: Long = DEFAULT_DURATION
145 | private var interpolator: TimeInterpolator = DEFAULT_ANIMATION
146 | @ColorInt private var backgroundColor: Int = DEFAULT_OVERLAY_COLOR
147 | private var container: ViewGroup? = null
148 | private var listener: OnSpotlightListener? = null
149 |
150 | /**
151 | * Sets [Target]s to show on [Spotlight].
152 | */
153 | fun setTargets(vararg targets: Target): Builder = apply {
154 | require(targets.isNotEmpty()) { "targets should not be empty. " }
155 | this.targets = arrayOf(*targets)
156 | }
157 |
158 | /**
159 | * Sets [Target]s to show on [Spotlight].
160 | */
161 | fun setTargets(targets: List): Builder = apply {
162 | require(targets.isNotEmpty()) { "targets should not be empty. " }
163 | this.targets = targets.toTypedArray()
164 | }
165 |
166 | /**
167 | * Sets [duration] to start/finish [Spotlight].
168 | */
169 | fun setDuration(duration: Long): Builder = apply {
170 | this.duration = duration
171 | }
172 |
173 | /**
174 | * Sets [backgroundColor] resource on [Spotlight].
175 | */
176 | fun setBackgroundColorRes(@ColorRes backgroundColorRes: Int): Builder = apply {
177 | this.backgroundColor = ContextCompat.getColor(activity, backgroundColorRes)
178 | }
179 |
180 | /**
181 | * Sets [backgroundColor] on [Spotlight].
182 | */
183 | fun setBackgroundColor(@ColorInt backgroundColor: Int): Builder = apply {
184 | this.backgroundColor = backgroundColor
185 | }
186 |
187 | /**
188 | * Sets [interpolator] to start/finish [Spotlight].
189 | */
190 | fun setAnimation(interpolator: TimeInterpolator): Builder = apply {
191 | this.interpolator = interpolator
192 | }
193 |
194 | /**
195 | * Sets [container] to hold [SpotlightView]. DecoderView will be used if not specified.
196 | */
197 | fun setContainer(container: ViewGroup) = apply {
198 | this.container = container
199 | }
200 |
201 | /**
202 | * Sets [OnSpotlightListener] to notify the state of [Spotlight].
203 | */
204 | fun setOnSpotlightListener(listener: OnSpotlightListener): Builder = apply {
205 | this.listener = listener
206 | }
207 |
208 | fun build(): Spotlight {
209 |
210 | val spotlight = SpotlightView(activity, null, 0, backgroundColor)
211 | val targets = requireNotNull(targets) { "targets should not be null. " }
212 | val container = container ?: activity.window.decorView as ViewGroup
213 |
214 | return Spotlight(
215 | spotlight = spotlight,
216 | targets = targets,
217 | duration = duration,
218 | interpolator = interpolator,
219 | container = container,
220 | spotlightListener = listener
221 | )
222 | }
223 |
224 | companion object {
225 |
226 | private val DEFAULT_DURATION = TimeUnit.SECONDS.toMillis(1)
227 |
228 | private val DEFAULT_ANIMATION = DecelerateInterpolator(2f)
229 |
230 | @ColorInt private val DEFAULT_OVERLAY_COLOR: Int = 0x6000000
231 | }
232 | }
233 | }
234 |
--------------------------------------------------------------------------------
/spotlight/src/main/java/com/takusemba/spotlight/SpotlightView.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlight
2 |
3 | import android.animation.Animator
4 | import android.animation.AnimatorListenerAdapter
5 | import android.animation.ObjectAnimator
6 | import android.animation.TimeInterpolator
7 | import android.animation.ValueAnimator
8 | import android.animation.ValueAnimator.AnimatorUpdateListener
9 | import android.animation.ValueAnimator.INFINITE
10 | import android.animation.ValueAnimator.ofFloat
11 | import android.content.Context
12 | import android.graphics.Canvas
13 | import android.graphics.Paint
14 | import android.graphics.PointF
15 | import android.graphics.PorterDuff
16 | import android.graphics.PorterDuffXfermode
17 | import android.util.AttributeSet
18 | import android.view.View
19 | import android.view.ViewGroup.LayoutParams.MATCH_PARENT
20 | import android.widget.FrameLayout
21 | import androidx.annotation.ColorInt
22 |
23 | /**
24 | * [SpotlightView] starts/finishes [Spotlight], and starts/finishes a current [Target].
25 | */
26 | internal class SpotlightView @JvmOverloads constructor(
27 | context: Context,
28 | attrs: AttributeSet? = null,
29 | defStyleAttr: Int = 0,
30 | @ColorInt backgroundColor: Int,
31 | ) : FrameLayout(context, attrs, defStyleAttr) {
32 |
33 | private val backgroundPaint by lazy {
34 | Paint().apply { color = backgroundColor }
35 | }
36 |
37 | private val shapePaint by lazy {
38 | Paint().apply { xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR) }
39 | }
40 |
41 | private val effectPaint by lazy { Paint() }
42 |
43 | private val invalidator = AnimatorUpdateListener { invalidate() }
44 |
45 | private var shapeAnimator: ValueAnimator? = null
46 | private var effectAnimator: ValueAnimator? = null
47 | private var target: Target? = null
48 |
49 | init {
50 | setWillNotDraw(false)
51 | setLayerType(View.LAYER_TYPE_HARDWARE, null)
52 | }
53 |
54 | override fun onDraw(canvas: Canvas) {
55 | super.onDraw(canvas)
56 | canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), backgroundPaint)
57 | val currentTarget = target
58 | val currentShapeAnimator = shapeAnimator
59 | val currentEffectAnimator = effectAnimator
60 | if (currentTarget != null && currentEffectAnimator != null && currentShapeAnimator != null && !currentShapeAnimator.isRunning) {
61 | currentTarget.effect.draw(
62 | canvas = canvas,
63 | point = currentTarget.anchor,
64 | value = currentEffectAnimator.animatedValue as Float,
65 | paint = effectPaint
66 | )
67 | }
68 | if (currentTarget != null && currentShapeAnimator != null) {
69 | currentTarget.shape.draw(
70 | canvas = canvas,
71 | point = currentTarget.anchor,
72 | value = currentShapeAnimator.animatedValue as Float,
73 | paint = shapePaint
74 | )
75 | }
76 | }
77 |
78 | /**
79 | * Starts [Spotlight].
80 | */
81 | fun startSpotlight(
82 | duration: Long,
83 | interpolator: TimeInterpolator,
84 | listener: Animator.AnimatorListener
85 | ) {
86 | val objectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f).apply {
87 | setDuration(duration)
88 | setInterpolator(interpolator)
89 | addListener(listener)
90 | }
91 | objectAnimator.start()
92 | }
93 |
94 | /**
95 | * Finishes [Spotlight].
96 | */
97 | fun finishSpotlight(
98 | duration: Long,
99 | interpolator: TimeInterpolator,
100 | listener: Animator.AnimatorListener
101 | ) {
102 | val objectAnimator = ObjectAnimator.ofFloat(this, "alpha", 1f, 0f).apply {
103 | setDuration(duration)
104 | setInterpolator(interpolator)
105 | addListener(listener)
106 | }
107 | objectAnimator.start()
108 | }
109 |
110 | /**
111 | * Starts the provided [Target].
112 | */
113 | fun startTarget(target: Target) {
114 | removeAllViews()
115 | addView(target.overlay, MATCH_PARENT, MATCH_PARENT)
116 | this.target = target.apply {
117 | // adjust anchor in case where custom container is set.
118 | val location = IntArray(2)
119 | getLocationInWindow(location)
120 | val offset = PointF(location[0].toFloat(), location[1].toFloat())
121 | anchor.offset(-offset.x, -offset.y)
122 | }
123 | this.shapeAnimator?.removeAllListeners()
124 | this.shapeAnimator?.removeAllUpdateListeners()
125 | this.shapeAnimator?.cancel()
126 | this.shapeAnimator = ofFloat(0f, 1f).apply {
127 | duration = target.shape.duration
128 | interpolator = target.shape.interpolator
129 | addUpdateListener(invalidator)
130 | addListener(object : AnimatorListenerAdapter() {
131 | override fun onAnimationEnd(animation: Animator) {
132 | removeAllListeners()
133 | removeAllUpdateListeners()
134 | }
135 |
136 | override fun onAnimationCancel(animation: Animator) {
137 | removeAllListeners()
138 | removeAllUpdateListeners()
139 | }
140 | })
141 | }
142 | this.effectAnimator?.removeAllListeners()
143 | this.effectAnimator?.removeAllUpdateListeners()
144 | this.effectAnimator?.cancel()
145 | this.effectAnimator = ofFloat(0f, 1f).apply {
146 | startDelay = target.shape.duration
147 | duration = target.effect.duration
148 | interpolator = target.effect.interpolator
149 | repeatMode = target.effect.repeatMode
150 | repeatCount = INFINITE
151 | addUpdateListener(invalidator)
152 | addListener(object : AnimatorListenerAdapter() {
153 | override fun onAnimationEnd(animation: Animator) {
154 | removeAllListeners()
155 | removeAllUpdateListeners()
156 | }
157 |
158 | override fun onAnimationCancel(animation: Animator) {
159 | removeAllListeners()
160 | removeAllUpdateListeners()
161 | }
162 | })
163 | }
164 | shapeAnimator?.start()
165 | effectAnimator?.start()
166 | }
167 |
168 | /**
169 | * Finishes the current [Target].
170 | */
171 | fun finishTarget(listener: Animator.AnimatorListener) {
172 | val currentTarget = target ?: return
173 | val currentAnimatedValue = shapeAnimator?.animatedValue ?: return
174 | shapeAnimator?.removeAllListeners()
175 | shapeAnimator?.removeAllUpdateListeners()
176 | shapeAnimator?.cancel()
177 | shapeAnimator = ofFloat(currentAnimatedValue as Float, 0f).apply {
178 | duration = currentTarget.shape.duration
179 | interpolator = currentTarget.shape.interpolator
180 | addUpdateListener(invalidator)
181 | addListener(listener)
182 | addListener(object : AnimatorListenerAdapter() {
183 | override fun onAnimationEnd(animation: Animator) {
184 | removeAllListeners()
185 | removeAllUpdateListeners()
186 | }
187 |
188 | override fun onAnimationCancel(animation: Animator) {
189 | removeAllListeners()
190 | removeAllUpdateListeners()
191 | }
192 | })
193 | }
194 | effectAnimator?.removeAllListeners()
195 | effectAnimator?.removeAllUpdateListeners()
196 | effectAnimator?.cancel()
197 | effectAnimator = null
198 | shapeAnimator?.start()
199 | }
200 |
201 | fun cleanup() {
202 | effectAnimator?.removeAllListeners()
203 | effectAnimator?.removeAllUpdateListeners()
204 | effectAnimator?.cancel()
205 | effectAnimator = null
206 | shapeAnimator?.removeAllListeners()
207 | shapeAnimator?.removeAllUpdateListeners()
208 | shapeAnimator?.cancel()
209 | shapeAnimator = null
210 | removeAllViews()
211 | }
212 | }
213 |
--------------------------------------------------------------------------------
/spotlight/src/main/java/com/takusemba/spotlight/Target.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlight
2 |
3 | import android.graphics.PointF
4 | import android.view.View
5 | import com.takusemba.spotlight.effet.Effect
6 | import com.takusemba.spotlight.effet.EmptyEffect
7 | import com.takusemba.spotlight.shape.Circle
8 | import com.takusemba.spotlight.shape.Shape
9 |
10 | /**
11 | * Target represents the spot that Spotlight will cast.
12 | */
13 | class Target(
14 | val anchor: PointF,
15 | val shape: Shape,
16 | val effect: Effect,
17 | val overlay: View?,
18 | val listener: OnTargetListener?
19 | ) {
20 |
21 | /**
22 | * [Builder] to build a [Target].
23 | * All parameters should be set in this [Builder].
24 | */
25 | class Builder {
26 |
27 | private var anchor: PointF = DEFAULT_ANCHOR
28 | private var shape: Shape = DEFAULT_SHAPE
29 | private var effect: Effect = DEFAULT_EFFECT
30 | private var overlay: View? = null
31 | private var listener: OnTargetListener? = null
32 |
33 | /**
34 | * Sets a pointer to start a [Target].
35 | */
36 | fun setAnchor(view: View): Builder = apply {
37 | val location = IntArray(2)
38 | view.getLocationInWindow(location)
39 | val x = location[0] + view.width / 2f
40 | val y = location[1] + view.height / 2f
41 | setAnchor(x, y)
42 | }
43 |
44 | /**
45 | * Sets an anchor point to start [Target].
46 | */
47 | fun setAnchor(x: Float, y: Float): Builder = apply {
48 | setAnchor(PointF(x, y))
49 | }
50 |
51 | /**
52 | * Sets an anchor point to start [Target].
53 | */
54 | fun setAnchor(anchor: PointF): Builder = apply {
55 | this.anchor = anchor
56 | }
57 |
58 | /**
59 | * Sets [shape] of the spot of [Target].
60 | */
61 | fun setShape(shape: Shape): Builder = apply {
62 | this.shape = shape
63 | }
64 |
65 | /**
66 | * Sets [effect] of the spot of [Target].
67 | */
68 | fun setEffect(effect: Effect): Builder = apply {
69 | this.effect = effect
70 | }
71 |
72 | /**
73 | * Sets [overlay] to be laid out to describe [Target].
74 | */
75 | fun setOverlay(overlay: View): Builder = apply {
76 | this.overlay = overlay
77 | }
78 |
79 | /**
80 | * Sets [OnTargetListener] to notify the state of [Target].
81 | */
82 | fun setOnTargetListener(listener: OnTargetListener): Builder = apply {
83 | this.listener = listener
84 | }
85 |
86 | fun build() = Target(
87 | anchor = anchor,
88 | shape = shape,
89 | effect = effect,
90 | overlay = overlay,
91 | listener = listener
92 | )
93 |
94 | companion object {
95 |
96 | private val DEFAULT_ANCHOR = PointF(0f, 0f)
97 |
98 | private val DEFAULT_SHAPE = Circle(100f)
99 |
100 | private val DEFAULT_EFFECT = EmptyEffect()
101 | }
102 | }
103 | }
--------------------------------------------------------------------------------
/spotlight/src/main/java/com/takusemba/spotlight/effet/Effect.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlight.effet
2 |
3 | import android.animation.TimeInterpolator
4 | import android.graphics.Canvas
5 | import android.graphics.Paint
6 | import android.graphics.PointF
7 |
8 | /**
9 | * Additional effect drawing in loop to Shape.
10 | */
11 | interface Effect {
12 |
13 | /**
14 | * [duration] to draw Effect.
15 | */
16 | val duration: Long
17 |
18 | /**
19 | * [interpolator] to draw Effect.
20 | */
21 | val interpolator: TimeInterpolator
22 |
23 | /**
24 | * [repeatMode] to draw Effect.
25 | */
26 | val repeatMode: Int
27 |
28 | /**
29 | * Draw the Effect.
30 | *
31 | * @param value the animated value from 0 to 1 and this value is looped until Target finishes.
32 | */
33 | fun draw(canvas: Canvas, point: PointF, value: Float, paint: Paint)
34 | }
--------------------------------------------------------------------------------
/spotlight/src/main/java/com/takusemba/spotlight/effet/EmptyEffect.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlight.effet
2 |
3 | import android.animation.ObjectAnimator
4 | import android.animation.TimeInterpolator
5 | import android.graphics.Canvas
6 | import android.graphics.Paint
7 | import android.graphics.PointF
8 | import android.view.animation.LinearInterpolator
9 | import java.util.concurrent.TimeUnit
10 |
11 | /**
12 | * [Effect] that does not do anything.
13 | */
14 | class EmptyEffect @JvmOverloads constructor(
15 | override val duration: Long = DEFAULT_DURATION,
16 | override val interpolator: TimeInterpolator = DEFAULT_INTERPOLATOR,
17 | override val repeatMode: Int = DEFAULT_REPEAT_MODE
18 | ) : Effect {
19 |
20 | override fun draw(canvas: Canvas, point: PointF, value: Float, paint: Paint) = Unit
21 |
22 | companion object {
23 |
24 | val DEFAULT_DURATION = TimeUnit.MILLISECONDS.toMillis(0)
25 |
26 | val DEFAULT_INTERPOLATOR = LinearInterpolator()
27 |
28 | const val DEFAULT_REPEAT_MODE = ObjectAnimator.REVERSE
29 | }
30 | }
--------------------------------------------------------------------------------
/spotlight/src/main/java/com/takusemba/spotlight/effet/FlickerEffect.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlight.effet
2 |
3 | import android.animation.ObjectAnimator
4 | import android.animation.TimeInterpolator
5 | import android.graphics.Canvas
6 | import android.graphics.Paint
7 | import android.graphics.PointF
8 | import android.view.animation.LinearInterpolator
9 | import androidx.annotation.ColorInt
10 | import java.util.concurrent.TimeUnit
11 |
12 | /**
13 | * Draws an flicker effects.
14 | */
15 | class FlickerEffect @JvmOverloads constructor(
16 | private val radius: Float,
17 | @ColorInt private val color: Int,
18 | override val duration: Long = DEFAULT_DURATION,
19 | override val interpolator: TimeInterpolator = DEFAULT_INTERPOLATOR,
20 | override val repeatMode: Int = DEFAULT_REPEAT_MODE
21 | ) : Effect {
22 |
23 | override fun draw(canvas: Canvas, point: PointF, value: Float, paint: Paint) {
24 | paint.color = color
25 | paint.alpha = (value * 255).toInt()
26 | canvas.drawCircle(point.x, point.y, radius, paint)
27 | }
28 |
29 | companion object {
30 |
31 | val DEFAULT_DURATION = TimeUnit.MILLISECONDS.toMillis(1000)
32 |
33 | val DEFAULT_INTERPOLATOR = LinearInterpolator()
34 |
35 | const val DEFAULT_REPEAT_MODE = ObjectAnimator.REVERSE
36 | }
37 | }
--------------------------------------------------------------------------------
/spotlight/src/main/java/com/takusemba/spotlight/effet/RippleEffect.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlight.effet
2 |
3 | import android.animation.ObjectAnimator
4 | import android.animation.TimeInterpolator
5 | import android.graphics.Canvas
6 | import android.graphics.Paint
7 | import android.graphics.PointF
8 | import android.view.animation.DecelerateInterpolator
9 | import androidx.annotation.ColorInt
10 | import java.util.concurrent.TimeUnit
11 |
12 | /**
13 | * Draws an ripple effects.
14 | */
15 | class RippleEffect @JvmOverloads constructor(
16 | private val offset: Float,
17 | private val radius: Float,
18 | @ColorInt private val color: Int,
19 | override val duration: Long = DEFAULT_DURATION,
20 | override val interpolator: TimeInterpolator = DEFAULT_INTERPOLATOR,
21 | override val repeatMode: Int = DEFAULT_REPEAT_MODE
22 | ) : Effect {
23 |
24 | init {
25 | require(offset < radius) { "holeRadius should be bigger than rippleRadius." }
26 | }
27 |
28 | override fun draw(canvas: Canvas, point: PointF, value: Float, paint: Paint) {
29 | val radius = offset + ((radius - offset) * value)
30 | val alpha = (255 - value * 255).toInt()
31 | paint.color = color
32 | paint.alpha = alpha
33 | canvas.drawCircle(point.x, point.y, radius, paint)
34 | }
35 |
36 | companion object {
37 |
38 | val DEFAULT_DURATION = TimeUnit.MILLISECONDS.toMillis(1000)
39 |
40 | val DEFAULT_INTERPOLATOR = DecelerateInterpolator(1f)
41 |
42 | const val DEFAULT_REPEAT_MODE = ObjectAnimator.REVERSE
43 | }
44 | }
--------------------------------------------------------------------------------
/spotlight/src/main/java/com/takusemba/spotlight/shape/Circle.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlight.shape
2 |
3 | import android.animation.TimeInterpolator
4 | import android.graphics.Canvas
5 | import android.graphics.Paint
6 | import android.graphics.PointF
7 | import android.view.animation.DecelerateInterpolator
8 | import java.util.concurrent.TimeUnit
9 |
10 | /**
11 | * [Shape] of Circle with customizable radius.
12 | */
13 | class Circle @JvmOverloads constructor(
14 | private val radius: Float,
15 | override val duration: Long = DEFAULT_DURATION,
16 | override val interpolator: TimeInterpolator = DEFAULT_INTERPOLATOR
17 | ) : Shape {
18 |
19 | override fun draw(canvas: Canvas, point: PointF, value: Float, paint: Paint) {
20 | canvas.drawCircle(point.x, point.y, value * radius, paint)
21 | }
22 |
23 | companion object {
24 |
25 | val DEFAULT_DURATION = TimeUnit.MILLISECONDS.toMillis(500)
26 |
27 | val DEFAULT_INTERPOLATOR = DecelerateInterpolator(2f)
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/spotlight/src/main/java/com/takusemba/spotlight/shape/RoundedRectangle.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlight.shape
2 |
3 | import android.animation.TimeInterpolator
4 | import android.graphics.Canvas
5 | import android.graphics.Paint
6 | import android.graphics.PointF
7 | import android.graphics.RectF
8 | import android.view.animation.DecelerateInterpolator
9 | import java.util.concurrent.TimeUnit
10 |
11 | /**
12 | * [Shape] of RoundedRectangle with customizable height, width, and radius.
13 | */
14 | class RoundedRectangle @JvmOverloads constructor(
15 | private val height: Float,
16 | private val width: Float,
17 | private val radius: Float,
18 | override val duration: Long = DEFAULT_DURATION,
19 | override val interpolator: TimeInterpolator = DEFAULT_INTERPOLATOR
20 | ) : Shape {
21 |
22 | override fun draw(canvas: Canvas, point: PointF, value: Float, paint: Paint) {
23 | val halfWidth = width / 2 * value
24 | val halfHeight = height / 2 * value
25 | val left = point.x - halfWidth
26 | val top = point.y - halfHeight
27 | val right = point.x + halfWidth
28 | val bottom = point.y + halfHeight
29 | val rect = RectF(left, top, right, bottom)
30 | canvas.drawRoundRect(rect, radius, radius, paint)
31 | }
32 |
33 | companion object {
34 |
35 | val DEFAULT_DURATION = TimeUnit.MILLISECONDS.toMillis(500)
36 |
37 | val DEFAULT_INTERPOLATOR = DecelerateInterpolator(2f)
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/spotlight/src/main/java/com/takusemba/spotlight/shape/Shape.kt:
--------------------------------------------------------------------------------
1 | package com.takusemba.spotlight.shape
2 |
3 | import android.animation.TimeInterpolator
4 | import android.graphics.Canvas
5 | import android.graphics.Paint
6 | import android.graphics.PointF
7 | import com.takusemba.spotlight.Target
8 |
9 | /**
10 | * Shape of a [Target] that would be drawn by Spotlight View.
11 | * For any shape of target, this Shape class need to be implemented.
12 | */
13 | interface Shape {
14 |
15 | /**
16 | * [duration] to draw Shape.
17 | */
18 | val duration: Long
19 |
20 | /**
21 | * [interpolator] to draw Shape.
22 | */
23 | val interpolator: TimeInterpolator
24 |
25 | /**
26 | * Draws the Shape.
27 | *
28 | * @param value the animated value from 0 to 1.
29 | */
30 | fun draw(canvas: Canvas, point: PointF, value: Float, paint: Paint)
31 | }
32 |
--------------------------------------------------------------------------------
/spotlight/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Spotlight
3 |
4 |
--------------------------------------------------------------------------------