diff --git a/lightspanner/src/main/java/zerobranch/lightspanner/Spans.kt b/lightspanner/src/main/java/zerobranch/lightspanner/Spans.kt index 7b12e6c..2f3547d 100644 --- a/lightspanner/src/main/java/zerobranch/lightspanner/Spans.kt +++ b/lightspanner/src/main/java/zerobranch/lightspanner/Spans.kt @@ -29,11 +29,12 @@ object Spans { textView: TextView, clickListener: (() -> Unit), touchListener: ((Boolean, TextPaint) -> Unit)? = null, - @ColorInt highlightColor: Int = Color.TRANSPARENT + @ColorInt highlightColor: Int = Color.TRANSPARENT, + isUnderlineText: Boolean = true ): ClickableSpan { textView.movementMethod = LinkMovementMethod.getInstance() textView.highlightColor = highlightColor - return SimpleClickableSpan(textView, clickListener, touchListener) + return SimpleClickableSpan(textView, clickListener, touchListener, isUnderlineText) } fun url(url: String, textView: TextView? = null): URLSpan { @@ -163,6 +164,11 @@ object Spans { dimensionType: DimensionType = DimensionType.PX ) = AbsoluteSizeSpan(dimensionType.toPx(size), false) + fun textSize( + context: Context, + @DimenRes dimenResId: Int + ) = AbsoluteSizeSpan(context.resources.getDimensionPixelSize(dimenResId), false) + fun relativeSize(@FloatRange(from = 0.0) proportion: Float) = RelativeSizeSpan(proportion) fun foregroundColor(@ColorInt colorInt: Int) = ForegroundColorSpan(colorInt) @@ -172,6 +178,13 @@ object Spans { @ColorRes colorResId: Int ) = ForegroundColorSpan(ContextCompat.getColor(context, colorResId)) + fun textColor(@ColorInt colorInt: Int) = foregroundColor(colorInt) + + fun textColor( + context: Context, + @ColorRes colorResId: Int + ) = foregroundColor(context, colorResId) + fun backgroundColor(@ColorInt colorInt: Int) = BackgroundColorSpan(colorInt) fun backgroundColor( diff --git a/lightspanner/src/main/java/zerobranch/lightspanner/custom/SimpleClickableSpan.kt b/lightspanner/src/main/java/zerobranch/lightspanner/custom/SimpleClickableSpan.kt index a6bb100..7292734 100644 --- a/lightspanner/src/main/java/zerobranch/lightspanner/custom/SimpleClickableSpan.kt +++ b/lightspanner/src/main/java/zerobranch/lightspanner/custom/SimpleClickableSpan.kt @@ -8,7 +8,8 @@ import android.widget.TextView class SimpleClickableSpan( private val textView: TextView, private val clickListener: (() -> Unit), - private val touchListener: ((Boolean, TextPaint) -> Unit)? + private val touchListener: ((Boolean, TextPaint) -> Unit)?, + private val isUnderlineText: Boolean ) : ClickableSpan() { override fun onClick(textView: View) { clickListener.invoke() @@ -16,6 +17,7 @@ class SimpleClickableSpan( override fun updateDrawState(textPaint: TextPaint) { super.updateDrawState(textPaint) + textPaint.isUnderlineText = isUnderlineText touchListener?.invoke(textView.isPressed, textPaint) textView.invalidate() }