Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ArcProgressBar : View {
- private val trackPaint = Paint(Paint.ANTI_ALIAS_FLAG)
- private val progressPaint = Paint(Paint.ANTI_ALIAS_FLAG)
- private val rect = RectF()
- var trackColor = Color.BLACK
- set(value) {
- field = value
- trackPaint.color = value
- invalidate()
- }
- var progressColor = Color.RED
- set(value) {
- field = value
- progressPaint.color = value
- invalidate()
- }
- var progress: Int = 0
- set(value) {
- field = value
- invalidate()
- Timber.e("$value")
- }
- constructor(context: Context?) : super(context)
- constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
- constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
- init {
- trackPaint.style = Paint.Style.STROKE
- progressPaint.style = Paint.Style.STROKE
- trackPaint.strokeWidth = 4f
- progressPaint.strokeWidth = 4f
- }
- override fun onDraw(canvas: Canvas?) {
- super.onDraw(canvas)
- canvas?.let {
- val progressEndAngle = progress * 1.8f
- rect.set(left.toFloat(), top.toFloat(), right.toFloat(), bottom.toFloat())
- //track
- it.drawArc(rect, 90f, 180f, false, trackPaint)
- //progress
- // it.drawArc(rect, 0f, progressEndAngle, false, progressPaint)
- //start ic_dot
- it.drawCircle(right - 4f, bottom - 4f, 8f, if (progress == 0) trackPaint else progressPaint)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement