File tree Expand file tree Collapse file tree
java/com/devzone/fpl_sample
fillprogresslayout/src/main/java/com/devzone/fillprogresslayout Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ package com.devzone.fpl_sample
22
33import android.os.Bundle
44import android.view.View
5+ import android.widget.Button
56import androidx.appcompat.app.AppCompatActivity
6- import androidx.appcompat.widget.AppCompatButton
77import kotlinx.android.synthetic.main.activity_main.*
88
99class MainActivity : AppCompatActivity () {
@@ -17,12 +17,13 @@ class MainActivity : AppCompatActivity() {
1717 }
1818
1919 fun toggleFill (view : View ) {
20- val button: AppCompatButton = view as AppCompatButton
20+ val button: Button = view as Button
2121 button.isEnabled = false
2222
2323 isFilled = ! isFilled
2424 fillL.setProgress(if (isFilled) 100 else 0 )
25- fillL.setDoOnProgressEnd { v ->
25+ fillB.setProgress(if (isFilled) 100 else 0 )
26+ fillB.setDoOnProgressEnd { v ->
2627 button.isEnabled = true ;button.text = if (isFilled) " Unfill" else " Fill"
2728 }
2829
Original file line number Diff line number Diff line change 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"
16+ app : fpl_roundedCornerRadius =" 100"
1617 app : fpl_progress =" 0"
1718 app : fpl_progressDuration =" 2000"
1819 app : fpl_progressDirection =" left_to_right"
4445 <com .devzone.fillprogresslayout.FillProgressLayout
4546 android : layout_alignBottom =" @+id/tv"
4647 android : layout_alignParentTop =" true"
48+ app : fpl_roundedCornerRadius =" 100"
49+ app : fpl_isRounded =" true"
4750 android : id =" @+id/fillB"
4851 android : layout_width =" match_parent"
4952 android : layout_height =" wrap_content" />
5760 android : layout_height =" wrap_content" />
5861 </RelativeLayout >
5962
60- <androidx .appcompat.widget.AppCompatButton
63+ <Button
6164 android : layout_width =" wrap_content"
6265 android : layout_height =" wrap_content"
6366 android : layout_gravity =" center_horizontal"
Original file line number Diff line number Diff line change @@ -190,6 +190,12 @@ class FillProgressLayout : LinearLayout {
190190 super .onDetachedFromWindow()
191191 }
192192
193+ override fun dispatchDraw (canvas : Canvas ? ) { // child clipping done here
194+ if (isRounded)
195+ canvas?.clipPath(clipPath)
196+ super .dispatchDraw(canvas)
197+ }
198+
193199// ---------------------public setters--------------------------------------------------------------------//
194200
195201 fun setProgress (p : Int ) {
@@ -210,12 +216,14 @@ class FillProgressLayout : LinearLayout {
210216 fun setProgressBackgroundColor (@ColorRes resId : Int ) {
211217 if (isValidRes(resId)) {
212218 mBackgroundColor = ContextCompat .getColor(context, resId)
219+ initPaint()
213220 }
214221 }
215222
216223 fun setProgressColor (@ColorRes resId : Int ) {
217224 if (isValidRes(resId)) {
218225 mProgressColor = ContextCompat .getColor(context, resId)
226+ initPaint()
219227 }
220228 }
221229
You can’t perform that action at this time.
0 commit comments