forked from hush/SilentDragonAndroid
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
967 B
20 lines
967 B
package cash.z.ecc.android.ext
|
|
|
|
import android.text.Spanned
|
|
import android.text.style.ForegroundColorSpan
|
|
import androidx.annotation.ColorRes
|
|
import androidx.core.text.toSpannable
|
|
|
|
fun CharSequence.toColoredSpan(@ColorRes colorResId: Int, coloredPortion: String): CharSequence {
|
|
return toSpannable().apply {
|
|
val start = this@toColoredSpan.indexOf(coloredPortion)
|
|
setSpan(ForegroundColorSpan(colorResId.toAppColor()), start, start + coloredPortion.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
}
|
|
}
|
|
|
|
fun CharSequence.toSplitColorSpan(@ColorRes startColorResId: Int, @ColorRes endColorResId: Int, startColorLength: Int): CharSequence {
|
|
return toSpannable().apply {
|
|
setSpan(ForegroundColorSpan(startColorResId.toAppColor()), 0, startColorLength - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
setSpan(ForegroundColorSpan(endColorResId.toAppColor()), startColorLength, this@toSplitColorSpan.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
}
|
|
}
|
|
|