@@ -3,16 +3,12 @@ package com.omega_r.libs.views
33import android.annotation.SuppressLint
44import android.content.Context
55import android.content.res.Resources
6- import android.content.res.TypedArray
76import android.graphics.Typeface
8- import android.os.Build
97import android.util.AttributeSet
108import androidx.appcompat.widget.AppCompatTextView
119import androidx.appcompat.widget.TintTypedArray
12- import androidx.core.content.res.ResourcesCompat
1310import com.omega_r.libs.omegatypes.*
1411
15-
1612/* *
1713 * Created by Anton Knyazev on 18.05.2019.
1814 */
@@ -60,6 +56,7 @@ open class OmegaTextView @JvmOverloads constructor(
6056 }
6157
6258 private val startTextStyle = Style ()
59+ private val middleTextStyle = Style ()
6360 private val endTextStyle = Style ()
6461
6562 private var initData: Boolean = true
@@ -74,7 +71,11 @@ open class OmegaTextView @JvmOverloads constructor(
7471 }
7572
7673 @SuppressLint(" RestrictedApi" )
77- private fun initWithAttributes (context : Context , attrs : AttributeSet ? = null, defStyleAttr : Int = android.R .attr.textViewStyle) {
74+ private fun initWithAttributes (
75+ context : Context ,
76+ attrs : AttributeSet ? = null,
77+ defStyleAttr : Int = android.R .attr.textViewStyle
78+ ) {
7879 val a = TintTypedArray .obtainStyledAttributes(context, attrs, R .styleable.OmegaTextView , defStyleAttr, 0 )
7980
8081 for (i in 0 until a.indexCount) {
@@ -88,24 +89,36 @@ open class OmegaTextView @JvmOverloads constructor(
8889 R .styleable.OmegaTextView_startTextSize -> {
8990 startTextStyle.textSize = Size .from(a.getDimension(attr, 0f ), Size .Unit .PX )
9091 }
92+ R .styleable.OmegaTextView_middleTextSize -> {
93+ middleTextStyle.textSize = Size .from(a.getDimension(attr, 0f ), Size .Unit .PX )
94+ }
9195 R .styleable.OmegaTextView_endTextSize -> {
9296 endTextStyle.textSize = Size .from(a.getDimension(attr, 0f ), Size .Unit .PX )
9397 }
9498 R .styleable.OmegaTextView_startTextStyle -> {
9599 startTextStyle.style = a.getInt(attr, STYLE_NONE )
96100 }
101+ R .styleable.OmegaTextView_middleTextStyle -> {
102+ middleTextStyle.style = a.getInt(attr, STYLE_NONE )
103+ }
97104 R .styleable.OmegaTextView_endTextStyle -> {
98105 endTextStyle.style = a.getInt(attr, STYLE_NONE )
99106 }
100107 R .styleable.OmegaTextView_startTextColor -> {
101108 startTextStyle.textColor = a.getColor(attr, startTextStyle.textColor)
102109 }
110+ R .styleable.OmegaTextView_middleTextColor -> {
111+ middleTextStyle.textColor = a.getColor(attr, middleTextStyle.textColor)
112+ }
103113 R .styleable.OmegaTextView_endTextColor -> {
104114 endTextStyle.textColor = a.getColor(attr, endTextStyle.textColor)
105115 }
106116 R .styleable.OmegaTextView_startTextFontFamily -> {
107117 obtainFont(intoStyle = startTextStyle, typedArray = a, attr = attr)
108118 }
119+ R .styleable.OmegaTextView_middleTextFontFamily -> {
120+ obtainFont(intoStyle = middleTextStyle, typedArray = a, attr = attr)
121+ }
109122 R .styleable.OmegaTextView_endTextFontFamily -> {
110123 obtainFont(intoStyle = endTextStyle, typedArray = a, attr = attr)
111124 }
@@ -152,7 +165,11 @@ open class OmegaTextView @JvmOverloads constructor(
152165
153166 private fun updateAllText (force : Boolean = false) {
154167 if (initData || force) {
155- val allText = (startText + startTextStyle) + startSpaceText + text + endSpaceText + (endText + endTextStyle)
168+ val allText = (startText + startTextStyle) +
169+ startSpaceText +
170+ (text + middleTextStyle) +
171+ endSpaceText +
172+ (endText + endTextStyle)
156173 super .setText(allText?.getCharSequence(context), BufferType .NORMAL )
157174 }
158175 }
@@ -211,7 +228,7 @@ open class OmegaTextView @JvmOverloads constructor(
211228 }
212229
213230 if (textColor != 0 ) {
214- result + = TextStyle .color(textColor)
231+ result + = TextStyle .color(Color .fromInt( textColor) )
215232 }
216233
217234 fontTypeface?.let {
0 commit comments