├── .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 | 12 | 18 | 25 | 435 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | alt text 4 | 5 | ![Build Status](https://app.bitrise.io/app/bcf0d555e7b41eb2/status.svg?token=2wvl_JilEbg6HB3B1tfKpA&branch=master) 6 | ![Download](https://api.bintray.com/packages/takusemba/maven/spotlight/images/download.svg) 7 | ![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg) 8 | ![API](https://img.shields.io/badge/API-14%2B-brightgreen.svg?style=flat) 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 |