Skip to content

Commit 143116f

Browse files
committed
rounded progress clip optimised again
1 parent 4627dcc commit 143116f

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class FillProgressLayout : LinearLayout {
5656
private val clipPath = Path()
5757
private var progressRectF = RectF()
5858
private var backRectF = RectF()
59-
private var clipProgressPath = Path()
6059

6160

6261
constructor(context: Context) : super(context) {
@@ -120,12 +119,12 @@ class FillProgressLayout : LinearLayout {
120119

121120
private fun initPaint() {
122121
backgroundPaint.apply {
123-
this.style = Paint.Style.FILL
124-
this.color = mBackgroundColor
122+
style = Paint.Style.FILL
123+
color = mBackgroundColor
125124
}
126125
progressPaint.apply {
127-
this.style = Paint.Style.FILL
128-
this.color = mProgressColor
126+
style = Paint.Style.FILL
127+
color = mProgressColor
129128
}
130129

131130
}
@@ -139,7 +138,6 @@ class FillProgressLayout : LinearLayout {
139138
if (isRounded) {
140139
clipPath.addRoundRect(backRectF, mCornerRadius, mCornerRadius, Path.Direction.CW)
141140
clipPath.close()
142-
clipProgressPath.set(clipPath)
143141
}
144142

145143
}
@@ -178,17 +176,12 @@ class FillProgressLayout : LinearLayout {
178176
canvas?.apply {
179177
save()
180178
drawRoundRect(backRectF, mCornerRadius, mCornerRadius, backgroundPaint)
181-
clipPath(clipProgressPath)
179+
clipPath(clipPath)
182180
drawRect(progressRectF, progressPaint)
183181
restore()
184182
}
185183
}
186184

187-
override fun dispatchDraw(canvas: Canvas?) {
188-
if (isRounded)
189-
canvas?.clipPath(clipPath)
190-
super.dispatchDraw(canvas)
191-
}
192185

193186
private fun isValidRes(res: Int) = res != View.NO_ID
194187

0 commit comments

Comments
 (0)