Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature/marker shape oval #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added a new attribute called markerShape where you can set a oval sha…
…pe for the markers
marcus-vinicius-freitas committed Sep 7, 2021
commit e0991c38e071235a366c0e425cd5f5e10cf8020a
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -19,7 +19,8 @@
app:markers="6,18,30,42,54"
app:markersLabels="test1,test2,test3,test4,test5"
app:markerColor="@color/colorPrimaryDark"
app:markerWidth="2dp"
app:markerShape="oval"
app:markerRadius="6dp"
app:progressColor="@color/colorAccent"
app:textMargin="10dp"
app:textSize="14sp"
Original file line number Diff line number Diff line change
@@ -20,13 +20,17 @@ class StepProgressView @JvmOverloads constructor(
private var totalProgress: Int by OnValidateProp(184)

//list should be sorted in increasing order as per markers progress
var markers: MutableList<Int> by OnLayoutProp(mutableListOf())
private var markers: MutableList<Int> by OnLayoutProp(mutableListOf())

var markersLabels: MutableList<String> by OnLayoutProp(mutableListOf())
private var markersLabels: MutableList<String> by OnLayoutProp(mutableListOf())

var currentProgress: Int by OnValidateProp(0)

var markerWidth: Float by OnValidateProp(3F.pxValue())
private var markerWidth: Float by OnValidateProp(3F.pxValue())

var markerRadius: Float by OnValidateProp(2F.pxValue())

var markerShape: Int by OnValidateProp(0)

var rectRadius: Float by OnValidateProp(5F.pxValue())

@@ -110,6 +114,8 @@ class StepProgressView @JvmOverloads constructor(
progressBarWidth)
textMargin = a.getDimension(R.styleable.StepProgressView_textMargin, textMargin)
markerWidth = a.getDimension(R.styleable.StepProgressView_markerWidth, markerWidth)
markerRadius = a.getDimension(R.styleable.StepProgressView_markerRadius, markerRadius)
markerShape = a.getInt(R.styleable.StepProgressView_markerShape, markerShape)
textSizeMarkers = a.getDimension(R.styleable.StepProgressView_textSize, textSizeMarkers)

progressBackgroundColor = a.getColor(R.styleable.StepProgressView_progressBackgroundColor,
@@ -201,7 +207,6 @@ class StepProgressView @JvmOverloads constructor(
extraWidthRightText = 0F

markersLabels.run {

if (size == 0)
return 0F

@@ -289,8 +294,15 @@ class StepProgressView @JvmOverloads constructor(
val left: Float = (i / totalProgress.toFloat()) * (rBar.right - rBar.left) +
extraWidthLeftText

canvas.drawRect(left - markerWidth / 2, rBar.top, left + markerWidth / 2
, rBar.bottom, paintMarkers)
when(markerShape) {
0 -> {
canvas.drawRect(left - markerWidth / 2, rBar.top, left + markerWidth / 2
, rBar.bottom, paintMarkers)
}
1 -> {
canvas.drawCircle(left - markerWidth / 2, rBar.top + progressBarHeight / 2, markerRadius, paintMarkers)
}
}
}
}

7 changes: 6 additions & 1 deletion step-progress/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
<attr name="progressBarHeight" format="dimension" />
<attr name="progressBarWidth" format="dimension" />
<attr name="textMargin" format="dimension" />
<attr name="markerWidth" format="dimension" />
<attr name="textSize" format="dimension" />
<attr name="totalProgress" format="integer" />
<attr name="currentProgress" format="integer" />
@@ -18,6 +17,12 @@

<attr name="markers" format="string" />
<attr name="markersLabels" format="string" />
<attr name="markerWidth" format="dimension" />
<attr name="markerRadius" format="dimension" />
<attr name="markerShape">
<enum name="rect" value="0"/>
<enum name="oval" value="1"/>
</attr>
</declare-styleable>

</resources>