Skip to content

Commit 0b514e9

Browse files
authored
Merge pull request #6 from JDevZone/dev
Dev
2 parents aa45ad7 + 8486dbf commit 0b514e9

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

app/src/main/java/com/devzone/fpl_sample/MainActivity.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package com.devzone.fpl_sample
22

33
import android.os.Bundle
44
import android.view.View
5+
import android.widget.Button
56
import androidx.appcompat.app.AppCompatActivity
6-
import androidx.appcompat.widget.AppCompatButton
77
import kotlinx.android.synthetic.main.activity_main.*
88

99
class 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

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
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"
@@ -44,6 +45,8 @@
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"/>
@@ -57,7 +60,7 @@
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"

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)