Skip to content

Commit 23af31d

Browse files
authored
Merge pull request #4 from JDevZone/dev
Dev
2 parents fdb7215 + 143116f commit 23af31d

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

app/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
android:layout_margin="30dp"
1313
app:fpl_backgroundColor="@color/colorRedTrans"
1414
app:fpl_progressColor="@color/colorGreenTrans"
15-
app:fpl_isRounded="false"
15+
app:fpl_isRounded="true"
1616
app:fpl_progress="0"
17+
app:fpl_roundedCornerRadius="50"
1718
app:fpl_progressDuration="3000"
1819
app:fpl_progressDirection="left_to_right"
1920
app:fpl_shouldRestart="false"

fillprogresslayout/src/main/java/com/devzone/fillprogresslayout/FillProgressLayout.kt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ class FillProgressLayout : LinearLayout {
119119

120120
private fun initPaint() {
121121
backgroundPaint.apply {
122-
this.style = Paint.Style.FILL
123-
this.color = mBackgroundColor
122+
style = Paint.Style.FILL
123+
color = mBackgroundColor
124124
}
125125
progressPaint.apply {
126-
this.style = Paint.Style.FILL
127-
this.color = mProgressColor
126+
style = Paint.Style.FILL
127+
color = mProgressColor
128128
}
129129

130130
}
@@ -166,27 +166,30 @@ class FillProgressLayout : LinearLayout {
166166
}
167167

168168
private fun drawNormalProgress(canvas: Canvas?) {
169-
canvas?.let {
170-
it.drawRect(backRectF, backgroundPaint)
171-
it.drawRect(progressRectF, progressPaint)
169+
canvas?.apply {
170+
drawRect(backRectF, backgroundPaint)
171+
drawRect(progressRectF, progressPaint)
172172
}
173173
}
174174

175175
private fun drawRoundedProgress(canvas: Canvas?) {
176-
canvas?.let {
177-
it.drawRoundRect(backRectF, mCornerRadius, mCornerRadius, backgroundPaint)
178-
it.drawRoundRect(progressRectF, mCornerRadius, mCornerRadius, progressPaint)
176+
canvas?.apply {
177+
save()
178+
drawRoundRect(backRectF, mCornerRadius, mCornerRadius, backgroundPaint)
179+
clipPath(clipPath)
180+
drawRect(progressRectF, progressPaint)
181+
restore()
179182
}
180183
}
181184

182-
override fun dispatchDraw(canvas: Canvas?) {
183-
if (isRounded)
184-
canvas?.clipPath(clipPath)
185-
super.dispatchDraw(canvas)
186-
}
187185

188186
private fun isValidRes(res: Int) = res != View.NO_ID
189187

188+
override fun onDetachedFromWindow() {
189+
clearAnimation()
190+
super.onDetachedFromWindow()
191+
}
192+
190193
//---------------------public setters--------------------------------------------------------------------//
191194

192195
fun setProgress(p: Int) {

0 commit comments

Comments
 (0)