An Android library for highlight guide
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.ForgetSky:LightGuide:1.0.1'
}
val lightguide = LightGuide.Builder(this)
.setTargets(firstTarget, secondTarget, thirdTarget ...)
.setBackgroundColor(R.color.lightguideBackground)
.setDuration(1000L)
.setAnimation(DecelerateInterpolator(2f))
.setContainer(viewGroup)
.setOnLightGuideListener(object : OnLightGuideListener {
override fun onStarted() {
Toast.makeText(this@MainActivity, "lightguide is started", Toast.LENGTH_SHORT).show()
}
override fun onEnded() {
Toast.makeText(this@MainActivity, "lightguide is ended", Toast.LENGTH_SHORT).show()
}
override fun onClick() {
Toast.makeText(this@MainActivity, "lightguide is click", Toast.LENGTH_SHORT).show()
}
})
.build()
If you want to show LightGuide immediately, you have to wait until views are laid out.
// with core-ktx method.
view.doOnPreDraw { LightGuide.Builder(this)...start() }
Create a Target to add LightGuide.
Target is a highLight to be casted by LightGuide. You can add multiple targets to LightGuide.
val target = Target.Builder()
.setAnchor(100f, 100f)
.setShape(Circle(100f))
.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()
}
override fun onClick() {
makeText(this@MainActivity, "first target is onClick", LENGTH_SHORT).show()
}
})
.build()
The display position of the overlay view can be adjusted automatically according to the highlighted area,
val lightguide = LightGuide.Builder(this)...start()
lightguide.finish()
val lightguide = LightGuide.Builder(this)...start()
lightguide.next()
lightguide.previous()
lightguide.show(2)
Shape
defines how your target will look like.
Circle and RoundedRectangle shapes are already implemented, but if you want your custom shape, it's arhivable by implementing Shape
interface.
override val margin: Float = 20f,
override val duration: Long = DEFAULT_DURATION,
override val interpolator: TimeInterpolator = DEFAULT_INTERPOLATOR
) : Shape {
override fun draw(canvas: Canvas, value: Float, paint: Paint) {
// draw your shape here.
}
}
Clone this repo and check out the app module.
Copyright 2017 Taku Semba.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.