Skip to content

Commit

Permalink
Merge pull request #9 from ashishsumann/feature/thickness_and_padding
Browse files Browse the repository at this point in the history
Feature Request - circle thickness and padding
  • Loading branch information
hi-manshu authored Jun 19, 2020
2 parents 78f2352 + 9ab1333 commit ef561ea
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ thats it and how you can use the RadialProgressView in your project.
|Set MaxProgressValues|----|rpb.setMaxProgressValues(int,int,int)|----|
|Set Only OuterProgress|app:hasOneProgressView="true/false"|rpb.setOneProgressView(true/false)|false|
|Set Only Outer and CenterProgress|app:hasTwoProgressView="true/false"|rpb.setTwoProgressView(true/false)|false|
|Set Circle Thickness***|app:circleThickness="float"|rpb.setCircleThickness(float)|1f|
|Set Circle Padding|app:circlePadding="float"|rpb.setCirclePadding(float)|10f|

> **angle = 0/90/180/270
> ***circleThickness between 0f to 1f
You can also get value related to the RadialProgressView,


Expand Down
58 changes: 50 additions & 8 deletions radialprogressbar/src/main/java/com/mindorks/RadialProgressBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import kotlin.collections.ArrayList
* @author Himanshu Singh
*/

class RadialProgressBar : View {
@Suppress("MemberVisibilityCanBePrivate", "unused")
open class RadialProgressBar : View {
constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
Expand Down Expand Up @@ -52,6 +53,8 @@ class RadialProgressBar : View {
private var backgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG)
private var hasOneProgressView = false
private var hasTwoProgressView = false
private var mCircleThickness = 1f
private var mCirclePadding = 10f

/**
* Data of the Outer View
Expand Down Expand Up @@ -146,6 +149,8 @@ class RadialProgressBar : View {
a.getColor(R.styleable.RadialProgressBar_outerEmptyProgressColor, mEmptyProgressColorOuterView)
mEmptyProgressColorInnerView =
a.getColor(R.styleable.RadialProgressBar_innerEmptyProgressColor, mEmptyProgressColorInnerView)
mCircleThickness = a.getFloat(R.styleable.RadialProgressBar_circleThickness, mCircleThickness)
mCirclePadding = a.getFloat(R.styleable.RadialProgressBar_circlePadding, mCirclePadding)
a.recycle()
hasElevation(mElevation)
hasOneProgressView(hasOneProgressView)
Expand All @@ -171,6 +176,8 @@ class RadialProgressBar : View {
setStartAngleCenterView(mStartAngleCenterView)
setStartAngleInnerView(mStartAngleInnerView)
setStartAngleOuterView(mStartAngleOuterView)
setCircleThickness(mCircleThickness)
setCirclePadding(mCirclePadding)

}

Expand All @@ -180,9 +187,9 @@ class RadialProgressBar : View {
private fun drawInnerProgressView(canvas: Canvas?) {
val diameter = Math.min(mViewWidth, mViewHeight)
val paddingView = (diameter / 16.0).toFloat()
val stroke = (diameter / 8).toFloat()
val addVal = (stroke * 2) + 20f
val subVal = ((stroke * 2) + paddingView + 20f)
val stroke = (diameter / 8).toFloat() * mCircleThickness
val addVal = (stroke * 2) + 2 * mCirclePadding
val subVal = ((stroke * 2) + paddingView + 2 * mCirclePadding)
val oval = RectF(paddingView + addVal, paddingView + addVal, diameter - subVal, diameter - subVal)
mPaintInnerView.strokeWidth = stroke
mPaintInnerView.isAntiAlias = true
Expand Down Expand Up @@ -228,9 +235,9 @@ class RadialProgressBar : View {
private fun drawCenterProgressView(canvas: Canvas?) {
val diameter = Math.min(mViewWidth, mViewHeight)
val paddingView = (diameter / 16.0).toFloat()
val stroke = (diameter / 8).toFloat()
val addVal = stroke + 10f
val subVal = (stroke + paddingView + 10f)
val stroke = (diameter / 8).toFloat() * mCircleThickness
val addVal = stroke + mCirclePadding
val subVal = (stroke + paddingView + mCirclePadding)
val oval = RectF(paddingView + addVal, paddingView + addVal, diameter - subVal, diameter - subVal)
mPaintCenterView.strokeWidth = stroke
mPaintCenterView.isAntiAlias = true
Expand Down Expand Up @@ -276,7 +283,7 @@ class RadialProgressBar : View {
private fun drawOuterProgressView(canvas: Canvas?) {
val diameter = Math.min(mViewWidth, mViewHeight)
val paddingView = (diameter / 16.0).toFloat()
val stroke = (diameter / 8).toFloat()
val stroke = (diameter / 8).toFloat() * mCircleThickness
val oval = RectF(paddingView, paddingView, diameter - paddingView, diameter - paddingView)
mPaintOuterView.strokeWidth = stroke

Expand Down Expand Up @@ -451,6 +458,20 @@ class RadialProgressBar : View {
}
}

/**
@return thickness for the progress views
*/
fun getCircleThickness(): Float {
return mCircleThickness
}

/**
@return padding between the progress views
*/
fun getCirclePadding(): Float {
return mCirclePadding
}

/**
Set the Start Angle for Center Progress View
*/
Expand Down Expand Up @@ -720,4 +741,25 @@ class RadialProgressBar : View {
invalidate()
}

/**
set the thickness for the progress views
value should be between 0f to 1f
*/
fun setCircleThickness(value: Float) {
mCircleThickness = when {
value < 0f -> 0f
value > 1f -> 1f
else -> value
}
invalidate()
}

/**
set the padding between the progress views
*/
fun setCirclePadding(value: Float) {
mCirclePadding = value
invalidate()
}

}
2 changes: 2 additions & 0 deletions radialprogressbar/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@
<attr name="hasEmptyProgressBar" format="boolean"/>
<attr name="hasOneProgressView" format="boolean"/>
<attr name="hasTwoProgressView" format="boolean"/>
<attr name="circleThickness" format="float"/>
<attr name="circlePadding" format="float"/>
</declare-styleable>
</resources>

0 comments on commit ef561ea

Please sign in to comment.