Skip to content

Commit

Permalink
change text visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
viveksaini75 committed Jun 27, 2022
1 parent 6057893 commit 443771e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 3 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@


<com.library.verticalseekbar.VerticalSeekbar
android:layout_width="40dp"
android:layout_width="50dp"
android:layout_height="250dp"
app:vs_cornerRadius="10dp"
app:vs_max="100"
app:vs_max="100"
app:vs_progress="10"
app:vs_textSize="16dp"
app:vs_textColor="#07D1F4"

android:layout_centerInParent="true"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class VerticalSeekbar : View {
iconWidth = a.getDimension(R.styleable.VerticalSeekbar_vs_iconSize, iconWidth)
textSize = a.getDimension(R.styleable.VerticalSeekbar_vs_textSize, textSize)
textColor = a.getColor(R.styleable.VerticalSeekbar_vs_textColor, textColor)
textVisibility = a.getBoolean(R.styleable.VerticalSeekbar_vs_textVisibility, textVisibility)
thread {
if (iconHiResId != -1)
iconHigh = getBitmapFromVectorDrawable(context, iconHiResId)
Expand Down Expand Up @@ -116,7 +117,7 @@ class VerticalSeekbar : View {
}
private val path = Path()
private val textRect: Rect = Rect()
private var textSize = dpToPx(30).toFloat()
private var textSize = dpToPx(20).toFloat()
set(value) {
field = value
invalidate()
Expand All @@ -129,6 +130,11 @@ class VerticalSeekbar : View {
private val textPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
isAntiAlias = true
}
private var textVisibility = false
set(value) {
field= value
invalidate()
}


override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
Expand Down Expand Up @@ -172,7 +178,6 @@ class VerticalSeekbar : View {

val x: Float = (left + (right - left - textRect.width()) / 2).toFloat()
val y: Float = top + (bottom - top) / 2 - (fm.descent + fm.ascent) / 2
canvas.drawText(progress.toString(), x, y, textPaint)


if (iconLow != null && iconMedium != null && iconHigh != null) {
Expand All @@ -187,6 +192,10 @@ class VerticalSeekbar : View {
canvas.drawBitmap(iconHigh!!, null, iconRect, null)
}
}
} else {
if (textVisibility) {
canvas.drawText(progress.toString(), x, y, textPaint)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions verticalseekbar/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
<attr name="vs_iconSize" format="dimension" />
<attr name="vs_textSize" format="dimension" />
<attr name="vs_textColor" format="color" />
<attr name="vs_textVisibility" format="boolean" />
</declare-styleable>
</resources>

0 comments on commit 443771e

Please sign in to comment.