Open In App

Getting Your TextViews Rendered Faster in Android 13

Last Updated : 26 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Android 13 significantly enhances TextView instances’ hyphenation performance. Hyphenation makes wrapped text easier to read and increases the adaptability of your UI. Starting with Android 13, hyphenation performance has been up to 200% optimized, allowing you to enable it in your TextView with essentially no impact on rendering speed. Use the fullFast or normalFast frequencies in setHyphenationFrequency to enable faster hyphenation().

APIs for Text Conversion

Japanese and Chinese speakers frequently employ phonetic letter input techniques, which slow down functions like auto-completion and searching. Apps can make use of the new text conversion API in Android 13 to help users locate what they’re looking for more quickly and easily. For instance, a Japanese user previously needed to follow these steps in order to search:

  • Enter their search term’s phonetic pronunciation in Hiragana (such as a place or an app name)
  • Receive their search results at last
  • To search again using Kanji characters, convert the Hiragana characters using the keyboard.

GeekTip: Japanese users can now write in Hiragana and instantly get live Kanji search results thanks to the new text conversion API, skipping steps 2 and 3.

By employing a line height that is customized for each language, Android 13 improves the display of non-Latin scripts (such as Tamil, Burmese, Telugu, and Tibetan). The improved character positioning and clipping are both benefits of the new line heights. By focusing on Android 13, your app can benefit from these enhancements. Test your apps after utilizing the new line spacing because it’s possible that it will modify how your user interface appears in languages other than Latin. The most recent updates, corrections, and modifications included in Unicode ICU 70, Unicode CLDR 40, and Unicode 14.0 are added in Android 13.

Here are a few noteworthy changes:

  1. When English (United Kingdom) enGB translation resources are not accessible, both English (Canada) enCA and English (Republic of the Philippines) enPH employ English (United States) en translation resources.
  2. For Spanish (es), Italian (it), Portuguese (PT), and Portuguese (es), many plural categories have been added. This is used for huge numbers and is similar to the French that was included in CLDR v38.

Although we generally take text rendering for granted, the process used to create rows of text is actually quite interesting. I’ll describe two ways to text rendering in this blog post and how Android caters to both. Let’s start by discussing the traditional strategy, the greedy algorithm.

Knuth-Plass Algorithm 

This method operates by minimizing demerits. There is something known as a “stretchability factor” for each set of letters and spaces. This is the range of feasible character spacing that would still make the word properly readable. The algorithm will compare each line that follows the first with the preceding one in an effort to gauge the range of possible combinations and select the one with the smallest difference. The procedure then keeps going till the paragraph is finished. Similar to kerning, tracking likewise uses fewer gaps between characters to produce output that is more aesthetically pleasing. As was said above, this is well-liked for cursive typefaces.

Example:

GEEKS FOR GEEKS

Using the Knuth-Plass approach the output would be like this:

         Line width: 10
GEEKS    Remaining space: 1
FOR      Remaining space: 9
GEEKS    Remaining space: 0

Using the greedy Approach this would have been the final output:

         Line width: 8
GEEKS    Remaining space: 0
FOR      Remaining space: 7
GEEKS    Remaining space: 1

In many ways, hyphenation is challenging. In order to be effective, a hyphenation algorithm fundamentally needs some kind of lexicon and decision heuristics. Consider the word impeachment as an example. The hyphenated form of the term is impeachment or impeachment. Of course, one may contend that any solution is valid. But it’s pretty clear that the latter is more aesthetically pleasing. However, there are still other hyphenation-related issues that deserve discussion.

  • It is wise to avoid hyphenating two lines that are close together.
  • There is more than enough room right after the second-to-last line of a paragraph to fill in the whole term without the need for a hyphen.
  • Of course, some of these guidelines can be disregarded by different hyphenation techniques.

Conclusion

Time and time again, including this most recent change to text rendering, demonstrates that all of these micro-optimizations can wait and be completed much later because their influence on a functioning product is… at least in this instance, virtually nonexistent.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads