Last active
January 21, 2021 18:15
-
-
Save akexorcist/56ea9c160dcc47ec5a41d0e1a2b073d6 to your computer and use it in GitHub Desktop.
Build Coupon UI - Setup paint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CouponLayout : FrameLayout { | |
private var borderWidth = /* ... */ | |
private var backgroundPathColor = /* ... */ | |
private var backgroundPathColorStateList: ColorStateList? = /* ... */ | |
private var borderPathColor = /* ... */ | |
private var borderPathColorStateList: ColorStateList? = /* ... */ | |
/* ... */ | |
private val borderPaint = Paint().apply { isAntiAlias = true } | |
private val backgroundPaint = Paint().apply { isAntiAlias = true } | |
/* ... */ | |
private fun setupPaint() { | |
borderPaint.color = getAvailableColor(borderPathColor, borderPathColorStateList) | |
borderPaint.strokeWidth = borderWidth | |
borderPaint.style = Paint.Style.STROKE | |
backgroundPaint.color = getAvailableColor(backgroundPathColor, backgroundPathColorStateList) | |
backgroundPaint.style = Paint.Style.FILL | |
} | |
@ColorInt | |
private fun getAvailableColor(@ColorInt color: Int, colorStateList: ColorStateList?): Int = if (colorStateList != null) { | |
val defaultColor = colorStateList.getColorForState(intArrayOf(), 0) | |
colorStateList.getColorForState(drawableState, defaultColor) | |
} else { | |
color | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment