Skip to content

Instantly share code, notes, and snippets.

@svinouze
Last active November 10, 2020 09:48
Show Gist options
  • Save svinouze/d8f627d2141e79f9669abd0ebe148a5d to your computer and use it in GitHub Desktop.
Save svinouze/d8f627d2141e79f9669abd0ebe148a5d to your computer and use it in GitHub Desktop.
class SegmentedProgressBar @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
@get:ColorInt
var segmentColor: Int = Color.WHITE
var segmentAlpha: Float = 1f
private val segmentPath: Path = Path()
private val segmentPaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)
override fun onDraw(canvas: Canvas) {
val w = width.toFloat()
val h = height.toFloat()
segmentPath.run {
moveTo(0f, 0f)
lineTo(w, 0f)
lineTo(w, h)
lineTo(0f, h)
close()
}
segmentPaint.color = segmentColor
segmentPaint.alpha = alpha.toAlphaPaint()
canvas.drawPath(segmentPath, segmentPaint)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment