@@ -20,6 +20,7 @@ package com.mikepenz.iconics
2020
2121import android.content.Context
2222import android.content.res.ColorStateList
23+ import android.content.res.Resources
2324import android.graphics.Bitmap
2425import android.graphics.Canvas
2526import android.graphics.Color
@@ -35,6 +36,7 @@ import android.graphics.Typeface
3536import android.graphics.drawable.Drawable
3637import android.os.Build
3738import android.text.TextPaint
39+ import android.util.AttributeSet
3840import android.util.Log
3941import androidx.annotation.ColorInt
4042import androidx.annotation.ColorRes
@@ -43,9 +45,11 @@ import androidx.annotation.Dimension
4345import androidx.annotation.Dimension.DP
4446import androidx.annotation.Dimension.PX
4547import androidx.annotation.IntRange
48+ import androidx.core.content.res.TypedArrayUtils.obtainAttributes
4649import androidx.core.graphics.drawable.DrawableCompat
4750import androidx.core.view.ViewCompat
4851import com.mikepenz.iconics.animation.IconicsAnimatedDrawable
52+ import com.mikepenz.iconics.core.R
4953import com.mikepenz.iconics.typeface.IIcon
5054import com.mikepenz.iconics.typeface.ITypeface
5155import com.mikepenz.iconics.utils.clearedIconName
@@ -55,6 +59,7 @@ import com.mikepenz.iconics.utils.toIconicsColorRes
5559import com.mikepenz.iconics.utils.toIconicsSizeDp
5660import com.mikepenz.iconics.utils.toIconicsSizePx
5761import com.mikepenz.iconics.utils.toIconicsSizeRes
62+ import org.xmlpull.v1.XmlPullParser
5863
5964/* * A custom [Drawable] which can display icons from icon fonts. */
6065open class IconicsDrawable (protected val context : Context ? = null ) : Drawable() {
@@ -432,7 +437,17 @@ open class IconicsDrawable(protected val context: Context? = null) : Drawable()
432437 * @return The current IconicsDrawable for chaining.
433438 */
434439 fun color (colors : IconicsColor ): IconicsDrawable {
435- iconBrush.colorsList = colors.extractList(context!! )
440+ color(colors.extractList(context!! ))
441+ return this
442+ }
443+
444+ /* *
445+ * Set the color of the drawable.
446+ *
447+ * @return The current IconicsDrawable for chaining.
448+ */
449+ fun color (colors : ColorStateList ? ): IconicsDrawable {
450+ iconBrush.colorsList = colors
436451 if (iconBrush.applyState(state)) {
437452 invalidateSelf()
438453 }
@@ -539,7 +554,17 @@ open class IconicsDrawable(protected val context: Context? = null) : Drawable()
539554 * @return The current IconicsDrawable for chaining.
540555 */
541556 fun size (size : IconicsSize ): IconicsDrawable {
542- sizeY = size.extract(context!! )
557+ size(size.extract(context!! ))
558+ return this
559+ }
560+
561+ /* *
562+ * Set the size by X and Y axis of the drawable.
563+ *
564+ * @return The current IconicsDrawable for chaining.
565+ */
566+ fun size (size : Int ): IconicsDrawable {
567+ sizeY = size
543568 sizeX = sizeY
544569 setBounds(0 , 0 , sizeX, sizeY)
545570
@@ -1251,6 +1276,21 @@ open class IconicsDrawable(protected val context: Context? = null) : Drawable()
12511276 private fun needMirroring (): Boolean {
12521277 return isAutoMirroredCompat && DrawableCompat .getLayoutDirection(this ) == ViewCompat .LAYOUT_DIRECTION_RTL
12531278 }
1279+
1280+ override fun inflate (r : Resources , parser : XmlPullParser , attrs : AttributeSet , theme : Resources .Theme ? ) {
1281+ super .inflate(r, parser, attrs, theme)
1282+ val a = obtainAttributes(r, theme, attrs, R .styleable.Iconics );
1283+ val ico_icon = a.getString(R .styleable.Iconics_ico_icon )
1284+ val ico_color = a.getColorStateList(R .styleable.Iconics_ico_color )
1285+ val ico_size = a.getDimensionPixelSize(R .styleable.Iconics_ico_size , Int .MIN_VALUE )
1286+ ico_icon?.also { icon(it) }
1287+ ico_color?.also { color(ico_color) }
1288+ if (ico_size != Int .MIN_VALUE ) {
1289+ size(ico_size)
1290+ }
1291+ a.recycle();
1292+
1293+ }
12541294}
12551295
12561296// VARIOUS convenient extension functions for quick common setters
0 commit comments