@@ -20,7 +20,8 @@ import kotlin.collections.ArrayList
20
20
* @author Himanshu Singh
21
21
*/
22
22
23
- class RadialProgressBar : View {
23
+ @Suppress(" MemberVisibilityCanBePrivate" , " unused" )
24
+ open class RadialProgressBar : View {
24
25
constructor (context: Context ) : this (context, null )
25
26
constructor (context: Context , attrs: AttributeSet ? ) : this (context, attrs, 0 )
26
27
constructor (context: Context , attrs: AttributeSet ? , defStyleAttr: Int ) : super (context, attrs, defStyleAttr) {
@@ -52,6 +53,8 @@ class RadialProgressBar : View {
52
53
private var backgroundPaint = Paint (Paint .ANTI_ALIAS_FLAG )
53
54
private var hasOneProgressView = false
54
55
private var hasTwoProgressView = false
56
+ private var mCircleThickness = 1f
57
+ private var mCirclePadding = 10f
55
58
56
59
/* *
57
60
* Data of the Outer View
@@ -146,6 +149,8 @@ class RadialProgressBar : View {
146
149
a.getColor(R .styleable.RadialProgressBar_outerEmptyProgressColor , mEmptyProgressColorOuterView)
147
150
mEmptyProgressColorInnerView =
148
151
a.getColor(R .styleable.RadialProgressBar_innerEmptyProgressColor , mEmptyProgressColorInnerView)
152
+ mCircleThickness = a.getFloat(R .styleable.RadialProgressBar_circleThickness , mCircleThickness)
153
+ mCirclePadding = a.getFloat(R .styleable.RadialProgressBar_circlePadding , mCirclePadding)
149
154
a.recycle()
150
155
hasElevation(mElevation)
151
156
hasOneProgressView(hasOneProgressView)
@@ -171,6 +176,8 @@ class RadialProgressBar : View {
171
176
setStartAngleCenterView(mStartAngleCenterView)
172
177
setStartAngleInnerView(mStartAngleInnerView)
173
178
setStartAngleOuterView(mStartAngleOuterView)
179
+ setCircleThickness(mCircleThickness)
180
+ setCirclePadding(mCirclePadding)
174
181
175
182
}
176
183
@@ -180,9 +187,9 @@ class RadialProgressBar : View {
180
187
private fun drawInnerProgressView (canvas : Canvas ? ) {
181
188
val diameter = Math .min(mViewWidth, mViewHeight)
182
189
val paddingView = (diameter / 16.0 ).toFloat()
183
- val stroke = (diameter / 8 ).toFloat()
184
- val addVal = (stroke * 2 ) + 20f
185
- val subVal = ((stroke * 2 ) + paddingView + 20f )
190
+ val stroke = (diameter / 8 ).toFloat() * mCircleThickness
191
+ val addVal = (stroke * 2 ) + 2 * mCirclePadding
192
+ val subVal = ((stroke * 2 ) + paddingView + 2 * mCirclePadding )
186
193
val oval = RectF (paddingView + addVal, paddingView + addVal, diameter - subVal, diameter - subVal)
187
194
mPaintInnerView.strokeWidth = stroke
188
195
mPaintInnerView.isAntiAlias = true
@@ -228,9 +235,9 @@ class RadialProgressBar : View {
228
235
private fun drawCenterProgressView (canvas : Canvas ? ) {
229
236
val diameter = Math .min(mViewWidth, mViewHeight)
230
237
val paddingView = (diameter / 16.0 ).toFloat()
231
- val stroke = (diameter / 8 ).toFloat()
232
- val addVal = stroke + 10f
233
- val subVal = (stroke + paddingView + 10f )
238
+ val stroke = (diameter / 8 ).toFloat() * mCircleThickness
239
+ val addVal = stroke + mCirclePadding
240
+ val subVal = (stroke + paddingView + mCirclePadding )
234
241
val oval = RectF (paddingView + addVal, paddingView + addVal, diameter - subVal, diameter - subVal)
235
242
mPaintCenterView.strokeWidth = stroke
236
243
mPaintCenterView.isAntiAlias = true
@@ -276,7 +283,7 @@ class RadialProgressBar : View {
276
283
private fun drawOuterProgressView (canvas : Canvas ? ) {
277
284
val diameter = Math .min(mViewWidth, mViewHeight)
278
285
val paddingView = (diameter / 16.0 ).toFloat()
279
- val stroke = (diameter / 8 ).toFloat()
286
+ val stroke = (diameter / 8 ).toFloat() * mCircleThickness
280
287
val oval = RectF (paddingView, paddingView, diameter - paddingView, diameter - paddingView)
281
288
mPaintOuterView.strokeWidth = stroke
282
289
@@ -451,6 +458,20 @@ class RadialProgressBar : View {
451
458
}
452
459
}
453
460
461
+ /* *
462
+ @return thickness for the progress views
463
+ */
464
+ fun getCircleThickness (): Float {
465
+ return mCircleThickness
466
+ }
467
+
468
+ /* *
469
+ @return padding between the progress views
470
+ */
471
+ fun getCirclePadding (): Float {
472
+ return mCirclePadding
473
+ }
474
+
454
475
/* *
455
476
Set the Start Angle for Center Progress View
456
477
*/
@@ -720,4 +741,25 @@ class RadialProgressBar : View {
720
741
invalidate()
721
742
}
722
743
744
+ /* *
745
+ set the thickness for the progress views
746
+ value should be between 0f to 1f
747
+ */
748
+ fun setCircleThickness (value : Float ) {
749
+ mCircleThickness = when {
750
+ value < 0f -> 0f
751
+ value > 1f -> 1f
752
+ else -> value
753
+ }
754
+ invalidate()
755
+ }
756
+
757
+ /* *
758
+ set the padding between the progress views
759
+ */
760
+ fun setCirclePadding (value : Float ) {
761
+ mCirclePadding = value
762
+ invalidate()
763
+ }
764
+
723
765
}
0 commit comments