Skip to content

Commit ef561ea

Browse files
authored
Merge pull request #9 from ashishsumann/feature/thickness_and_padding
Feature Request - circle thickness and padding
2 parents 78f2352 + 9ab1333 commit ef561ea

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,13 @@ thats it and how you can use the RadialProgressView in your project.
9393
|Set MaxProgressValues|----|rpb.setMaxProgressValues(int,int,int)|----|
9494
|Set Only OuterProgress|app:hasOneProgressView="true/false"|rpb.setOneProgressView(true/false)|false|
9595
|Set Only Outer and CenterProgress|app:hasTwoProgressView="true/false"|rpb.setTwoProgressView(true/false)|false|
96+
|Set Circle Thickness***|app:circleThickness="float"|rpb.setCircleThickness(float)|1f|
97+
|Set Circle Padding|app:circlePadding="float"|rpb.setCirclePadding(float)|10f|
9698

9799
> **angle = 0/90/180/270
98100
101+
> ***circleThickness between 0f to 1f
102+
99103
You can also get value related to the RadialProgressView,
100104

101105

radialprogressbar/src/main/java/com/mindorks/RadialProgressBar.kt

+50-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import kotlin.collections.ArrayList
2020
* @author Himanshu Singh
2121
*/
2222

23-
class RadialProgressBar : View {
23+
@Suppress("MemberVisibilityCanBePrivate", "unused")
24+
open class RadialProgressBar : View {
2425
constructor(context: Context) : this(context, null)
2526
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
2627
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
@@ -52,6 +53,8 @@ class RadialProgressBar : View {
5253
private var backgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG)
5354
private var hasOneProgressView = false
5455
private var hasTwoProgressView = false
56+
private var mCircleThickness = 1f
57+
private var mCirclePadding = 10f
5558

5659
/**
5760
* Data of the Outer View
@@ -146,6 +149,8 @@ class RadialProgressBar : View {
146149
a.getColor(R.styleable.RadialProgressBar_outerEmptyProgressColor, mEmptyProgressColorOuterView)
147150
mEmptyProgressColorInnerView =
148151
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)
149154
a.recycle()
150155
hasElevation(mElevation)
151156
hasOneProgressView(hasOneProgressView)
@@ -171,6 +176,8 @@ class RadialProgressBar : View {
171176
setStartAngleCenterView(mStartAngleCenterView)
172177
setStartAngleInnerView(mStartAngleInnerView)
173178
setStartAngleOuterView(mStartAngleOuterView)
179+
setCircleThickness(mCircleThickness)
180+
setCirclePadding(mCirclePadding)
174181

175182
}
176183

@@ -180,9 +187,9 @@ class RadialProgressBar : View {
180187
private fun drawInnerProgressView(canvas: Canvas?) {
181188
val diameter = Math.min(mViewWidth, mViewHeight)
182189
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)
186193
val oval = RectF(paddingView + addVal, paddingView + addVal, diameter - subVal, diameter - subVal)
187194
mPaintInnerView.strokeWidth = stroke
188195
mPaintInnerView.isAntiAlias = true
@@ -228,9 +235,9 @@ class RadialProgressBar : View {
228235
private fun drawCenterProgressView(canvas: Canvas?) {
229236
val diameter = Math.min(mViewWidth, mViewHeight)
230237
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)
234241
val oval = RectF(paddingView + addVal, paddingView + addVal, diameter - subVal, diameter - subVal)
235242
mPaintCenterView.strokeWidth = stroke
236243
mPaintCenterView.isAntiAlias = true
@@ -276,7 +283,7 @@ class RadialProgressBar : View {
276283
private fun drawOuterProgressView(canvas: Canvas?) {
277284
val diameter = Math.min(mViewWidth, mViewHeight)
278285
val paddingView = (diameter / 16.0).toFloat()
279-
val stroke = (diameter / 8).toFloat()
286+
val stroke = (diameter / 8).toFloat() * mCircleThickness
280287
val oval = RectF(paddingView, paddingView, diameter - paddingView, diameter - paddingView)
281288
mPaintOuterView.strokeWidth = stroke
282289

@@ -451,6 +458,20 @@ class RadialProgressBar : View {
451458
}
452459
}
453460

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+
454475
/**
455476
Set the Start Angle for Center Progress View
456477
*/
@@ -720,4 +741,25 @@ class RadialProgressBar : View {
720741
invalidate()
721742
}
722743

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+
723765
}

radialprogressbar/src/main/res/values/attrs.xml

+2
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@
3030
<attr name="hasEmptyProgressBar" format="boolean"/>
3131
<attr name="hasOneProgressView" format="boolean"/>
3232
<attr name="hasTwoProgressView" format="boolean"/>
33+
<attr name="circleThickness" format="float"/>
34+
<attr name="circlePadding" format="float"/>
3335
</declare-styleable>
3436
</resources>

0 commit comments

Comments
 (0)