Skip to content

Commit

Permalink
add a DynamicShape
Browse files Browse the repository at this point in the history
  • Loading branch information
chief committed Feb 25, 2021
1 parent f00f55b commit a88c724
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.takusemba.spotlight.OnTargetListener
import com.takusemba.spotlight.Spotlight
import com.takusemba.spotlight.Target
import com.takusemba.spotlight.shape.Circle
import com.takusemba.spotlight.shape.DynamicShape

class ActivitySampleActivity : AppCompatActivity(R.layout.activity_activity_sample) {

Expand All @@ -27,9 +28,10 @@ class ActivitySampleActivity : AppCompatActivity(R.layout.activity_activity_samp
// first target
val firstRoot = FrameLayout(this)
val first = layoutInflater.inflate(R.layout.layout_target, firstRoot)
val view = findViewById<View>(R.id.one)
val firstTarget = Target.Builder()
.setAnchor(findViewById<View>(R.id.one))
.setShape(Circle(100f))
.setAnchor(view)
.setShape(DynamicShape(view))
.setOverlay(first)
.setOnTargetListener(object : OnTargetListener {
override fun onStarted() {
Expand Down
15 changes: 14 additions & 1 deletion spotlight/src/main/java/com/takusemba/spotlight/Target.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.view.View
import com.takusemba.spotlight.effet.Effect
import com.takusemba.spotlight.effet.EmptyEffect
import com.takusemba.spotlight.shape.Circle
import com.takusemba.spotlight.shape.DynamicShape
import com.takusemba.spotlight.shape.RoundedRectangle
import com.takusemba.spotlight.shape.Shape

/**
Expand Down Expand Up @@ -59,7 +61,18 @@ class Target(
* Sets [shape] of the spot of [Target].
*/
fun setShape(shape: Shape): Builder = apply {
this.shape = shape
if (shape is DynamicShape) {
shape.view.let {
val rect = RoundedRectangle(
height = it.measuredHeight.toFloat() + shape.padding.top,
width = it.measuredWidth.toFloat() + shape.padding.left,
radius = shape.padding.radius.toFloat()
)
this.shape = rect
}
} else {
this.shape = shape
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.takusemba.spotlight.shape

import android.animation.TimeInterpolator
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.PointF
import android.view.View

class DynamicShape(val view: View, val padding: Padding = Padding()) : Shape {
override val duration: Long
get() = TODO("Not yet implemented")
override val interpolator: TimeInterpolator
get() = TODO("Not yet implemented")

override fun draw(canvas: Canvas, point: PointF, value: Float, paint: Paint) {
TODO("Not yet implemented")
}

class Padding(
val left: Int = DEFAULT_PADDING, val top: Int = DEFAULT_PADDING,
val right: Int = DEFAULT_PADDING, val bottom: Int = DEFAULT_PADDING,
val radius: Int = DEFAULT_CORNER_RADIUS
) {
constructor(horizontal: Int, vertical: Int, radius: Int) : this(horizontal, vertical,
horizontal,
vertical, radius)

constructor(horizontal: Int, vertical: Int) : this(horizontal, vertical, horizontal,
vertical)
}

companion object {
val DEFAULT_PADDING = 10
val DEFAULT_CORNER_RADIUS = 0
}
}

0 comments on commit a88c724

Please sign in to comment.