keyboard: offer every vulgar fraction on the number row (#555)
- Commit
ba5ad5a87a23034dc05166bc9eb5db31ed85430e- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-12 17:34 UTC (23 days ago)
- Parents
21e77ea
Request (GitHub #555, item 7): add more fractions to the long-press alternates. Only ½⅓¼⅛⅔¾⅜⅝⅞ were offered. Changes (Layouts.DIGIT_ALTERNATES): the other nine precomposed fractions, ⅕⅖⅗⅘⅙⅚⅐⅑⅒, are added. That makes every vulgar fraction in Unicode except ↉ (0/3). Each fraction sits under its numerator, ordered by denominator, as the existing ones were: 1 ¹½⅓¼⅕⅙⅛ 2 ²⅔⅖ 3 ³¾⅗⅜ 4 ⁴⅘ 5 ⁵⅚⅝ 7 ⁷⅞⅐ 9 ⁹⅑ 0 ⁰∅ⁿ⅒ Constraint: the alternates popup is a single row. Each entry gets 44 dp, shrinking to share the screen width when the row would overflow, and the key's own character comes first. KeyboardLayoutTest caps every list at 7 alternates (8 entries, about 352 dp) so entries stay a usable size on a small phone. Filing all ten unit fractions under 1 would have meant 11 entries, about 33 dp each on a 360 dp screen. So the 1 key keeps the six commonest (½⅓¼⅕⅙⅛, 7 alternates with ¹), and the three rarest go on their denominator's key instead: ⅐ on 7, ⅑ on 9, ⅒ on 0. No list exceeds the cap and the popup width is unchanged for every key. A two-row popup (item 2) would lift the limit but is out of scope here. User-visible effect: long-press the number-row keys for the new fractions. The 4 and 9 keys now print a corner hint (⅘, ⅑) like 2, 3, 5 and 7 already did. The 1 key's hint is still ½. Verification: - KeyboardLayoutTest: new test checks that all 18 fractions are offered exactly once across DIGIT_ALTERNATES and that the 1 key still starts with ¹½⅓¼. The existing 7-alternate cap and number-row key tests cover the rest. - :keyboard compileDevKotlin, testDevUnitTest, lint and detekt in the build container.
Diff
keyboard/src/main/java/com/vayunmathur/keyboard/util/Layouts.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/util/Layouts.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/util/Layouts.ktindex 11f54c8ed1..21c776ecde 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/util/Layouts.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/util/Layouts.kt@@ -82,10 +82,18 @@ object Layouts { '&' to "§", '#' to "№", ) - /** Long-press alternates for the digits: superscripts and the common fractions. */+ /**+ * Long-press alternates for the digits: superscripts and every precomposed vulgar+ * fraction Unicode has (#555), each filed under its numerator in denominator order.+ *+ * The exception is the 1 key, which would need ten fractions and blow the seven-entry+ * cap the popup can show on a small phone (see KeyboardLayoutTest): it keeps the six+ * commonest, and the rarest three sit on their denominator's key instead — ⅐ on 7, ⅑ on+ * 9, ⅒ on 0 — where the digit already on the key is the hint.+ */ val DIGIT_ALTERNATES: Map<Char, String> = mapOf(- '1' to "¹½⅓¼⅛", '2' to "²⅔", '3' to "³¾⅜", '4' to "⁴", '5' to "⁵⅝",- '6' to "⁶", '7' to "⁷⅞", '8' to "⁸", '9' to "⁹", '0' to "⁰∅ⁿ",+ '1' to "¹½⅓¼⅕⅙⅛", '2' to "²⅔⅖", '3' to "³¾⅗⅜", '4' to "⁴⅘", '5' to "⁵⅚⅝",+ '6' to "⁶", '7' to "⁷⅞⅐", '8' to "⁸", '9' to "⁹⅑", '0' to "⁰∅ⁿ⅒", ) /** The alternates for a symbol-page or number-row key, or "" if it has none. */
keyboard/src/test/java/com/vayunmathur/keyboard/util/KeyboardLayoutTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/util/KeyboardLayoutTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/util/KeyboardLayoutTest.ktindex 17454b0d70..9e02b086d9 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/util/KeyboardLayoutTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/util/KeyboardLayoutTest.kt@@ -88,6 +88,17 @@ class KeyboardLayoutTest { } } + /** #555: every precomposed fraction is on the number row exactly once. */+ @Test+ fun `digit alternates offer every vulgar fraction once`() {+ val fractions = "½⅓⅔¼¾⅕⅖⅗⅘⅙⅚⅐⅛⅜⅝⅞⅑⅒"+ val offered = Layouts.DIGIT_ALTERNATES.values.joinToString("").filter { it in fractions }+ assertEquals(fractions.toSet(), offered.toSet())+ assertEquals(fractions.length, offered.length, "a fraction is offered on two keys")+ // The commonest stay first on the 1 key, so its corner hint is unchanged.+ assertTrue(Layouts.DIGIT_ALTERNATES.getValue('1').startsWith("¹½⅓¼"))+ }+ /** * The corner preview exists to show the user something they could not guess, so an * accented form of the key's own letter is not worth printing — those keep the dot.