For a fitness app, I'm looking to display a message on a smartwatch emulator which can be read by the TalkBack facility and (when spoken) is understandable by the user when TalkBack highlights the TextView. The + sign has several different meanings, e.g. plus, add, positive, increase, etc. In this case I want the word 'plus' to be spoken by TalkBack. Is this something that Java can provide? This also needs to be something understandable by different languages when strings are localised.
Expected result
Text on display: Number of steps: 4↑ (2↑ + 2↑)
Talkback should say: "4 up (2 up + 2 up)"
Current code
val imageGetter = Html.ImageGetter { name ->
val resId = if (name == "arrow") { R.drawable.ic_arrow_up }
else { throw IllegalArgumentException("what the heck is $arrow") }
ResourcesCompat.getDrawable(resources, resId, requireActivity().theme)?.apply {
setBounds(0, 0, intrinsicWidth, intrinsicHeight)
}
}
val txtNumberOfSteps = getString(R.string.number_of_steps)
val txt4 = String.format("%d", 4)
val txt2 = String.format("%d", 2)
val htmlTxtSteps = "$txtNumberOfSteps $txt4 <img src=\"arrow\"/> ($txt2 <img src=\"arrow\"/> + $txt2" <img src=\"arrow\"/>)"
val txtStepsClimbed = Html.fromHtml(htmlTxtSteps, Html.FROM_HTML_MODE_COMPACT, imageGetter, null)
myTv.setText = txtStepsClimbed
strings.xml
<string name="number_of_steps">Number of steps: </string>