Skip to content

Commit cf9fae1

Browse files
committed
Add gif.
Add color res methods.
1 parent 5562b4c commit cf9fae1

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

app/src/main/java/com/iammert/tileprogressviewsample/MainActivity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package com.iammert.tileprogressviewsample
22

33
import androidx.appcompat.app.AppCompatActivity
44
import android.os.Bundle
5+
import android.os.Handler
6+
import android.os.Looper
57
import com.iammert.tileprogressview.TiledProgressView
68

79
class MainActivity : AppCompatActivity() {
810
override fun onCreate(savedInstanceState: Bundle?) {
911
super.onCreate(savedInstanceState)
1012
setContentView(R.layout.activity_main)
1113

12-
findViewById<TiledProgressView>(R.id.tileProgressView).setProgress(0.6f)
14+
findViewById<TiledProgressView>(R.id.tileProgressView).setProgress(6f)
1315
}
1416
}

art/animatedart.gif

676 KB
Loading

tileprogressview/src/main/java/com/iammert/tileprogressview/TiledProgressView.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.util.AttributeSet
77
import android.view.View
88
import android.view.animation.LinearInterpolator
99
import androidx.annotation.ColorInt
10+
import androidx.annotation.ColorRes
1011
import androidx.annotation.FloatRange
1112
import androidx.core.animation.addListener
1213
import androidx.core.content.ContextCompat
@@ -94,7 +95,7 @@ class TiledProgressView @JvmOverloads constructor(
9495
)
9596
}
9697

97-
fun setProgress(@FloatRange(from = 0.0, to = 1.0) progressValue: Float) {
98+
fun setProgress(@FloatRange(from = 0.0, to = 100.0) progressValue: Float) {
9899
progressAnimator.setFloatValues(currentProgressValue, progressValue)
99100
progressAnimator.start()
100101
currentProgressValue = progressValue
@@ -105,6 +106,21 @@ class TiledProgressView @JvmOverloads constructor(
105106
invalidate()
106107
}
107108

109+
fun setLoadingColorRes(@ColorRes progressColorRes: Int) {
110+
foregroundProgressPaint.color = ContextCompat.getColor(context, progressColorRes)
111+
invalidate()
112+
}
113+
114+
fun setColor(@ColorInt color: Int) {
115+
backgroundProgressPaint.color = color
116+
invalidate()
117+
}
118+
119+
fun setColorRes(@ColorRes colorRes: Int) {
120+
backgroundProgressPaint.color = ContextCompat.getColor(context, colorRes)
121+
invalidate()
122+
}
123+
108124
private fun initializeProgressRectFs() {
109125
if (viewRect.isEmpty) return
110126
backgroundProgressRect.set(viewRect)
@@ -179,7 +195,7 @@ class TiledProgressView @JvmOverloads constructor(
179195
val min = foregroundProgressRectMin.width()
180196
val max = foregroundProgressRectMax.width()
181197
val maxProgress = max - min
182-
val currentProgress = maxProgress * animatedValue
198+
val currentProgress = maxProgress * animatedValue / 100f
183199
foregroundProgressRectCurrent.right =
184200
foregroundProgressRectCurrent.left +
185201
(foregroundProgressRadius * 2f) +

0 commit comments

Comments
 (0)