Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. class ArcProgressBar : View {
  2. private val trackPaint = Paint(Paint.ANTI_ALIAS_FLAG)
  3. private val progressPaint = Paint(Paint.ANTI_ALIAS_FLAG)
  4. private val rect = RectF()
  5. var trackColor = Color.BLACK
  6. set(value) {
  7. field = value
  8. trackPaint.color = value
  9. invalidate()
  10. }
  11. var progressColor = Color.RED
  12. set(value) {
  13. field = value
  14. progressPaint.color = value
  15. invalidate()
  16. }
  17. var progress: Int = 0
  18. set(value) {
  19. field = value
  20. invalidate()
  21. Timber.e("$value")
  22. }
  23.  
  24. constructor(context: Context?) : super(context)
  25. constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
  26. constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
  27.  
  28. init {
  29. trackPaint.style = Paint.Style.STROKE
  30. progressPaint.style = Paint.Style.STROKE
  31. trackPaint.strokeWidth = 4f
  32. progressPaint.strokeWidth = 4f
  33. }
  34.  
  35. override fun onDraw(canvas: Canvas?) {
  36. super.onDraw(canvas)
  37. canvas?.let {
  38. val progressEndAngle = progress * 1.8f
  39.  
  40. rect.set(left.toFloat(), top.toFloat(), right.toFloat(), bottom.toFloat())
  41. //track
  42. it.drawArc(rect, 90f, 180f, false, trackPaint)
  43.  
  44. //progress
  45. // it.drawArc(rect, 0f, progressEndAngle, false, progressPaint)
  46.  
  47. //start ic_dot
  48. it.drawCircle(right - 4f, bottom - 4f, 8f, if (progress == 0) trackPaint else progressPaint)
  49.  
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement