@@ -30,10 +30,12 @@ import android.util.AttributeSet
3030import android.util.Property
3131import android.view.animation.OvershootInterpolator
3232import androidx.annotation.IntRange
33+ import androidx.core.graphics.ColorUtils
3334import androidx.core.os.bundleOf
3435import androidx.core.view.ViewCompat
3536import com.google.android.material.floatingactionbutton.FloatingActionButton
3637import com.google.android.material.stateful.ExtendableSavedState
38+ import kotlin.math.max
3739
3840private val STATE_KEY = CounterFab ::class .java.name + " .STATE"
3941private const val COUNT_STATE = " COUNT"
@@ -78,11 +80,7 @@ class CounterFab @JvmOverloads constructor(
7880 private val textPadding = TEXT_PADDING_DP * resources.displayMetrics.density
7981
8082 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
8684 }
8785 private val textPaint = Paint (Paint .ANTI_ALIAS_FLAG ).apply {
8886 style = Style .FILL_AND_STROKE
@@ -158,7 +156,9 @@ class CounterFab @JvmOverloads constructor(
158156 circlePaint.color
159157 }
160158 }
161- }
159+ }.applyColorMask()
160+
161+ private fun Int.applyColorMask () = ColorUtils .compositeColors(MASK_COLOR , this )
162162
163163 /* *
164164 * Increase the current count value by 1
@@ -199,7 +199,7 @@ class CounterFab @JvmOverloads constructor(
199199 }
200200
201201 private fun calculateCircleBounds () {
202- val circleRadius = Math . max(textBounds.width(), textBounds.height()) / 2f + textPadding
202+ val circleRadius = max(textBounds.width(), textBounds.height()) / 2f + textPadding
203203 val circleEnd = (circleRadius * 2 ).toInt()
204204 if (isSizeMini) {
205205 val circleStart = (circleRadius / 2 ).toInt()
@@ -245,8 +245,6 @@ class CounterFab @JvmOverloads constructor(
245245 val radius = circleBounds.width() / 2f * animationFactor
246246 // Solid circle
247247 canvas.drawCircle(cx, cy, radius, circlePaint)
248- // Mask circle
249- canvas.drawCircle(cx, cy, radius, maskPaint)
250248 // Count text
251249 textPaint.textSize = textSize * animationFactor
252250 canvas.drawText(countText, cx, cy + textBounds.height() / 2f , textPaint)
0 commit comments