Skip to content

Commit

Permalink
- repaired stateable colors
Browse files Browse the repository at this point in the history
  • Loading branch information
zTrap committed Apr 13, 2019
1 parent 6988e90 commit f057320
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions library-core/src/main/java/com/mikepenz/iconics/IconicsDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ import com.mikepenz.iconics.utils.toIconicsSizeRes

/** A custom [Drawable] which can display icons from icon fonts. */
open class IconicsDrawable(protected val context: Context) : Drawable() {
protected val iconBrush =
IconicsBrush(TextPaint(Paint.ANTI_ALIAS_FLAG)).apply {
colorsList =
ColorStateList.valueOf(Color.BLACK)
}
protected val iconBrush = IconicsBrush(TextPaint(Paint.ANTI_ALIAS_FLAG))
protected val backgroundContourBrush = IconicsBrush(Paint(Paint.ANTI_ALIAS_FLAG))
protected val backgroundBrush = IconicsBrush(Paint(Paint.ANTI_ALIAS_FLAG))
protected val contourBrush = IconicsBrush(Paint(Paint.ANTI_ALIAS_FLAG))
Expand Down Expand Up @@ -99,10 +95,13 @@ open class IconicsDrawable(protected val context: Context) : Drawable() {
private var iconColorFilter: ColorFilter? = null

init {
iconBrush.paint.apply {
style = Paint.Style.FILL
textAlign = Paint.Align.CENTER
isUnderlineText = false
iconBrush.also {
it.colorsList = ColorStateList.valueOf(Color.BLACK)
it.paint.apply {
style = Paint.Style.FILL
textAlign = Paint.Align.CENTER
isUnderlineText = false
}
}

contourBrush.paint.style = Paint.Style.STROKE
Expand Down Expand Up @@ -815,6 +814,7 @@ open class IconicsDrawable(protected val context: Context) : Drawable() {
*/
fun clearShadow(): IconicsDrawable {
iconBrush.paint.clearShadowLayer()

invalidateSelf()
return this
}
Expand Down Expand Up @@ -916,6 +916,8 @@ open class IconicsDrawable(protected val context: Context) : Drawable() {
*/
fun colorFilter(cf: ColorFilter?): IconicsDrawable {
colorFilter = cf

invalidateSelf()
return this
}

Expand Down Expand Up @@ -1077,7 +1079,7 @@ open class IconicsDrawable(protected val context: Context) : Drawable() {
}

override fun getOpacity(): Int {
if (tintFilter != null || iconBrush.paint.colorFilter != null) {
if (tintFilter != null || iconColorFilter != null) {
return PixelFormat.TRANSLUCENT
}
when (alpha) {
Expand All @@ -1089,10 +1091,10 @@ open class IconicsDrawable(protected val context: Context) : Drawable() {

// in some cases (e.g. on API 16) stateSet might be null
override fun onStateChange(stateSet: IntArray?): Boolean {
var isNeedsRedraw = (iconBrush.applyState(stateSet)
|| contourBrush.applyState(stateSet)
|| backgroundBrush.applyState(stateSet)
|| backgroundContourBrush.applyState(stateSet))
var isNeedsRedraw = iconBrush.applyState(stateSet)
isNeedsRedraw = contourBrush.applyState(stateSet) || isNeedsRedraw
isNeedsRedraw = backgroundBrush.applyState(stateSet) || isNeedsRedraw
isNeedsRedraw = backgroundContourBrush.applyState(stateSet) || isNeedsRedraw

if (tint != null) {
updateTintFilter()
Expand Down

0 comments on commit f057320

Please sign in to comment.