@@ -30,10 +30,12 @@ import android.util.AttributeSet
30
30
import android.util.Property
31
31
import android.view.animation.OvershootInterpolator
32
32
import androidx.annotation.IntRange
33
+ import androidx.core.graphics.ColorUtils
33
34
import androidx.core.os.bundleOf
34
35
import androidx.core.view.ViewCompat
35
36
import com.google.android.material.floatingactionbutton.FloatingActionButton
36
37
import com.google.android.material.stateful.ExtendableSavedState
38
+ import kotlin.math.max
37
39
38
40
private val STATE_KEY = CounterFab ::class .java.name + " .STATE"
39
41
private const val COUNT_STATE = " COUNT"
@@ -78,11 +80,7 @@ class CounterFab @JvmOverloads constructor(
78
80
private val textPadding = TEXT_PADDING_DP * resources.displayMetrics.density
79
81
80
82
private val circlePaint = Paint (Paint .ANTI_ALIAS_FLAG ).apply {
81
- style = Paint .Style .FILL
82
- }
83
- private val maskPaint = Paint (Paint .ANTI_ALIAS_FLAG ).apply {
84
- style = Paint .Style .FILL
85
- color = MASK_COLOR
83
+ style = Style .FILL
86
84
}
87
85
private val textPaint = Paint (Paint .ANTI_ALIAS_FLAG ).apply {
88
86
style = Style .FILL_AND_STROKE
@@ -158,7 +156,9 @@ class CounterFab @JvmOverloads constructor(
158
156
circlePaint.color
159
157
}
160
158
}
161
- }
159
+ }.applyColorMask()
160
+
161
+ private fun Int.applyColorMask () = ColorUtils .compositeColors(MASK_COLOR , this )
162
162
163
163
/* *
164
164
* Increase the current count value by 1
@@ -199,7 +199,7 @@ class CounterFab @JvmOverloads constructor(
199
199
}
200
200
201
201
private fun calculateCircleBounds () {
202
- val circleRadius = Math . max(textBounds.width(), textBounds.height()) / 2f + textPadding
202
+ val circleRadius = max(textBounds.width(), textBounds.height()) / 2f + textPadding
203
203
val circleEnd = (circleRadius * 2 ).toInt()
204
204
if (isSizeMini) {
205
205
val circleStart = (circleRadius / 2 ).toInt()
@@ -245,8 +245,6 @@ class CounterFab @JvmOverloads constructor(
245
245
val radius = circleBounds.width() / 2f * animationFactor
246
246
// Solid circle
247
247
canvas.drawCircle(cx, cy, radius, circlePaint)
248
- // Mask circle
249
- canvas.drawCircle(cx, cy, radius, maskPaint)
250
248
// Count text
251
249
textPaint.textSize = textSize * animationFactor
252
250
canvas.drawText(countText, cx, cy + textBounds.height() / 2f , textPaint)
0 commit comments