### Start Spotlight After View Layout Source: https://github.com/takusemba/spotlight/blob/master/README.md This Kotlin snippet shows how to ensure the Spotlight is started only after the target views have been measured and laid out. It uses the `doOnPreDraw` extension function from core-ktx for this purpose. ```kotlin // with core-ktx method. view.doOnPreDraw { Spotlight.Builder(this)...start() } ``` -------------------------------- ### Initialize and Build Spotlight Instance Source: https://github.com/takusemba/spotlight/blob/master/README.md This Kotlin code demonstrates how to create an instance of the Spotlight manager. It involves setting up targets, background color, animation, container, and a listener for spotlight events. The spotlight will only start after the views are laid out. ```kotlin val spotlight = Spotlight.Builder(this) .setTargets(firstTarget, secondTarget, thirdTarget ...) .setBackgroundColor(R.color.spotlightBackground) .setDuration(1000L) .setAnimation(DecelerateInterpolator(2f)) .setContainer(viewGroup) .setOnSpotlightListener(object : OnSpotlightListener { override fun onStarted() { Toast.makeText(this@MainActivity, "spotlight is started", Toast.LENGTH_SHORT).show() } override fun onEnded() { Toast.makeText(this@MainActivity, "spotlight is ended", Toast.LENGTH_SHORT).show() } }) .build() ``` -------------------------------- ### Control Spotlight Start, Finish, and Progression Source: https://github.com/takusemba/spotlight/blob/master/README.md These Kotlin snippets illustrate how to control the Spotlight sequence. You can start the spotlight, explicitly finish it, move to the next or previous target, or show a specific target by its index. ```kotlin val spotlight = Spotlight.Builder(this)...start() spotlight.finish() ``` ```kotlin val spotlight = Spotlight.Builder(this)...start() spotlight.next() spotlight.previous() spotlight.show(2) ``` -------------------------------- ### Create a Custom Target for Spotlight Source: https://github.com/takusemba/spotlight/blob/master/README.md This Kotlin code defines a Target object, which is a specific point of interest to be highlighted by Spotlight. You can customize its anchor position, shape, visual effect, and an overlay view. It also includes listeners for target start and end events. ```kotlin val target = Target.Builder() .setAnchor(100f, 100f) .setShape(Circle(100f)) .setEffect(RippleEffect(100f, 200f, argb(30, 124, 255, 90))) .setOverlay(layout) .setOnTargetListener(object : OnTargetListener { override fun onStarted() { makeText(this@MainActivity, "first target is started", LENGTH_SHORT).show() } override fun onEnded() { makeText(this@MainActivity, "first target is ended", LENGTH_SHORT).show() } }) .build() ``` -------------------------------- ### Add Spotlight Dependency to Gradle Source: https://github.com/takusemba/spotlight/blob/master/README.md This code snippet shows how to add the Spotlight library as a dependency to your Android project using Gradle. Ensure you replace 'x.x.x' with the latest version of the library. ```groovy dependencies { implementation 'com.github.takusemba:spotlight:x.x.x' } ``` -------------------------------- ### Implement a Custom Spotlight Effect Source: https://github.com/takusemba/spotlight/blob/master/README.md This Kotlin code shows how to create a custom visual effect for Spotlight targets by implementing the `Effect` interface. Similar to custom shapes, you must provide duration, interpolator, repeat mode, and implement the `draw` method for the effect's rendering logic. ```kotlin class CustomEffect( override val duration: Long, override val interpolator: TimeInterpolator, override val repeatMode: Int ) : Effect { override fun draw(canvas: Canvas, point: PointF, value: Float, paint: Paint) { // draw your effect here. } } ``` -------------------------------- ### Add FlickerEffect with Custom Shape in Spotlight (Kotlin) Source: https://github.com/takusemba/spotlight/blob/master/RELEASENOTES.md Demonstrates how to create a Target with a custom shape and apply the FlickerEffect. This requires building a Target using the Target.Builder, specifying the anchor point, shape, and effect. The code assumes the availability of Shape and Effect classes within the Spotlight library. ```kotlin val target = Target.Builder() .setAnchor(100f, 100f) .setShape(Circle(150f)) .setEffect(FlickerEffect(200f, rgb(124, 255, 90))) .build() ``` -------------------------------- ### Implement a Custom Spotlight Shape Source: https://github.com/takusemba/spotlight/blob/master/README.md This Kotlin code defines a custom shape for Spotlight targets by implementing the `Shape` interface. You need to provide the duration, interpolator, and implement the `draw` method to define how the shape is rendered on the canvas. ```kotlin class CustomShape( override val duration: Long, override val interpolator: TimeInterpolator ) : Shape { override fun draw(canvas: Canvas, point: PointF, value: Float, paint: Paint) { // draw your shape here. } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.