@@ -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