For API >= 33 use font weight 700 for bold

This commit is contained in:
PhilKes 2025-05-10 17:49:19 +02:00
parent 118285545a
commit 86b74762c5
3 changed files with 12 additions and 3 deletions

View file

@ -122,7 +122,7 @@ fun String.applySpans(representations: List<SpanRepresentation>): Editable {
-> ->
try { try {
if (bold) { if (bold) {
editable.setSpan(StyleSpan(Typeface.BOLD), start, end) editable.setSpan(createBoldSpan(), start, end)
} }
if (italic) { if (italic) {
editable.setSpan(StyleSpan(Typeface.ITALIC), start, end) editable.setSpan(StyleSpan(Typeface.ITALIC), start, end)
@ -144,6 +144,13 @@ fun String.applySpans(representations: List<SpanRepresentation>): Editable {
return editable return editable
} }
fun createBoldSpan() =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
StyleSpan(Typeface.BOLD, 700)
} else {
StyleSpan(Typeface.BOLD)
}
/** /**
* Adjusts or removes spans based on the selection range. * Adjusts or removes spans based on the selection range.
* *

View file

@ -40,6 +40,7 @@ import com.philkes.notallyx.presentation.activity.note.PickNoteActivity.Companio
import com.philkes.notallyx.presentation.activity.note.PickNoteActivity.Companion.EXTRA_PICKED_NOTE_TYPE import com.philkes.notallyx.presentation.activity.note.PickNoteActivity.Companion.EXTRA_PICKED_NOTE_TYPE
import com.philkes.notallyx.presentation.add import com.philkes.notallyx.presentation.add
import com.philkes.notallyx.presentation.addIconButton import com.philkes.notallyx.presentation.addIconButton
import com.philkes.notallyx.presentation.createBoldSpan
import com.philkes.notallyx.presentation.dp import com.philkes.notallyx.presentation.dp
import com.philkes.notallyx.presentation.hideKeyboard import com.philkes.notallyx.presentation.hideKeyboard
import com.philkes.notallyx.presentation.setControlsContrastColorForAllViews import com.philkes.notallyx.presentation.setControlsContrastColorForAllViews
@ -212,7 +213,7 @@ class EditNoteActivity : EditActivity(Type.NOTE), AddNoteActions {
0, 0,
showAsAction = MenuItem.SHOW_AS_ACTION_NEVER, showAsAction = MenuItem.SHOW_AS_ACTION_NEVER,
) { ) {
binding.EnterBody.applySpan(StyleSpan(Typeface.BOLD)) binding.EnterBody.applySpan(createBoldSpan())
mode?.finish() mode?.finish()
} }
add( add(

View file

@ -8,6 +8,7 @@ import android.text.style.TypefaceSpan
import android.text.style.URLSpan import android.text.style.URLSpan
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import com.philkes.notallyx.R import com.philkes.notallyx.R
import com.philkes.notallyx.presentation.createBoldSpan
import com.philkes.notallyx.presentation.view.misc.StylableEditTextWithHistory import com.philkes.notallyx.presentation.view.misc.StylableEditTextWithHistory
class TextFormattingAdapter( class TextFormattingAdapter(
@ -35,7 +36,7 @@ class TextFormattingAdapter(
private val bold: Toggle = private val bold: Toggle =
Toggle(R.string.bold, R.drawable.format_bold, false) { Toggle(R.string.bold, R.drawable.format_bold, false) {
if (!it.checked) { if (!it.checked) {
editText.applySpan(StyleSpan(Typeface.BOLD)) editText.applySpan(createBoldSpan())
} else { } else {
editText.clearFormatting(type = StylableEditTextWithHistory.TextStyleType.BOLD) editText.clearFormatting(type = StylableEditTextWithHistory.TextStyleType.BOLD)
} }