Skip to content

Commit

Permalink
[#144] Add the new setDotsStrokeWidth method for SpringDotsIndicator …
Browse files Browse the repository at this point in the history
…and WormDotsIndicator
  • Loading branch information
tommybuonomo committed Apr 30, 2022
1 parent da21118 commit 8f542aa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
app:dotsColor="@color/md_white_1000"
app:dotsStrokeWidth="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spring_dots_indicator" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,24 @@ class SpringDotsIndicator @JvmOverloads constructor(
/**
* Set the stroke indicator dots color.
*
* @param color the color fo the stroke indicator dots.
* @param color the color for the stroke indicator dots.
*/
fun setStrokeDotsIndicatorColor(color: Int) {
dotsStrokeColor = color
for (v in dots) {
setUpDotBackground(true, v)
}
}

/**
* Set the dots stroke width.
*
* @param width the stroke width color for the indicator dots.
*/
fun setDotsStrokeWidth(width: Float) {
dotsStrokeWidth = width
for (v in dots) {
setUpDotBackground(true, v)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WormDotsIndicator @JvmOverloads constructor(
private var dotIndicatorLayout: View? = null

// Attributes
private var dotsStrokeWidth: Int = 0
private var dotsStrokeWidth: Float = 0f
private var dotIndicatorColor: Int = 0
private var dotsStrokeColor: Int = 0

Expand All @@ -45,7 +45,7 @@ class WormDotsIndicator @JvmOverloads constructor(
strokeDotsLinearLayout.orientation = HORIZONTAL
addView(strokeDotsLinearLayout)

dotsStrokeWidth = dpToPx(2) // 2dp
dotsStrokeWidth = dpToPxF(2f) // 2dp
dotIndicatorColor = context.getThemePrimaryColor()
dotsStrokeColor = dotIndicatorColor

Expand All @@ -61,8 +61,8 @@ class WormDotsIndicator @JvmOverloads constructor(
// Spring dots attributes
dotsStrokeWidth = a.getDimension(
R.styleable.WormDotsIndicator_dotsStrokeWidth,
dotsStrokeWidth.toFloat()
).toInt()
dotsStrokeWidth
)

a.recycle()
}
Expand Down Expand Up @@ -149,11 +149,11 @@ class WormDotsIndicator @JvmOverloads constructor(
private fun setUpDotBackground(stroke: Boolean, dotImageView: View) {
val dotBackground = dotImageView.background as GradientDrawable
if (stroke) {
dotBackground.setStroke(dotsStrokeWidth, dotsStrokeColor)
dotBackground.setStroke(dotsStrokeWidth.toInt(), dotsStrokeColor)
} else {
dotBackground.setColor(dotIndicatorColor)
}
dotBackground.cornerRadius = dotsCornerRadius.toFloat()
dotBackground.cornerRadius = dotsCornerRadius
}

override fun refreshDotColor(index: Int) {
Expand Down Expand Up @@ -237,4 +237,16 @@ class WormDotsIndicator @JvmOverloads constructor(
setUpDotBackground(true, v)
}
}

/**
* Set the dots stroke width.
*
* @param width the stroke width color for the indicator dots.
*/
fun setDotsStrokeWidth(width: Float) {
dotsStrokeWidth = width
for (v in dots) {
setUpDotBackground(true, v)
}
}
}

0 comments on commit 8f542aa

Please sign in to comment.