@@ -22,13 +22,15 @@ class TextDrawable private constructor(builder: Builder) : ShapeDrawable(builder
2222 private val fontSize: Int
2323 private val radius: Float
2424 private val borderThickness: Int
25+ private val fullSizeFont: Boolean
2526
2627 init {
2728 // shape properties
2829 shape = builder.shape
2930 height = builder.height
3031 width = builder.width
3132 radius = builder.radius
33+ fullSizeFont = builder.fullSizeFont
3234
3335 // text and color
3436 text = if (builder.toUpperCase) builder.text!! .toUpperCase() else builder.text
@@ -80,7 +82,11 @@ class TextDrawable private constructor(builder: Builder) : ShapeDrawable(builder
8082 // draw text
8183 val width = if (this .width < 0 ) r.width() else this .width
8284 val height = if (this .height < 0 ) r.height() else this .height
83- val fontSize = if (this .fontSize < 0 ) Math .min(width, height) / 2 else this .fontSize
85+ val fontSize = if (fullSizeFont) {
86+ if (this .fontSize < 0 ) Math .min(width, height) else this .fontSize
87+ } else {
88+ if (this .fontSize < 0 ) Math .min(width, height) / 2 else this .fontSize
89+ }
8490 textPaint.textSize = fontSize.toFloat()
8591 canvas.drawText(text, (width / 2 ).toFloat(), height / 2 - (textPaint.descent() + textPaint.ascent()) / 2 , textPaint)
8692
@@ -119,7 +125,7 @@ class TextDrawable private constructor(builder: Builder) : ShapeDrawable(builder
119125 return height
120126 }
121127
122- class Builder () : IConfigBuilder, IShapeBuilder, IBuilder {
128+ class Builder : IConfigBuilder , IShapeBuilder , IBuilder {
123129
124130 var text: String? = null
125131 var color: Int = 0
@@ -133,6 +139,7 @@ class TextDrawable private constructor(builder: Builder) : ShapeDrawable(builder
133139 var isBold: Boolean = false
134140 var toUpperCase: Boolean = false
135141 var radius: Float = 0 .toFloat()
142+ var fullSizeFont: Boolean = false
136143
137144 init {
138145 text = " "
@@ -233,6 +240,11 @@ class TextDrawable private constructor(builder: Builder) : ShapeDrawable(builder
233240 this .text = text
234241 return TextDrawable (this )
235242 }
243+
244+ override fun fullSizeFont (): IConfigBuilder {
245+ this .fullSizeFont = true
246+ return this
247+ }
236248 }
237249
238250 interface IConfigBuilder {
@@ -244,6 +256,7 @@ class TextDrawable private constructor(builder: Builder) : ShapeDrawable(builder
244256 fun fontSize (size : Int ): IConfigBuilder
245257 fun bold (): IConfigBuilder
246258 fun toUpperCase (): IConfigBuilder
259+ fun fullSizeFont (): IConfigBuilder
247260 fun endConfig (): IShapeBuilder
248261 }
249262
0 commit comments