calculator: solid Enter icon, digits stay digits under 2nd
- Commit
f394f82c4d84ffaa3fe35881ee0dc291eb334c89- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-06 03:33 UTC (9 hours ago)
- Parents
fafe8ce
Two keypad fixes from the owner. The Enter key was a text ⏎ glyph. It is now the solid (filled) return icon: Key gains an isEnterKey spec flag and both the portrait and landscape key buttons render IconReturn() for it, which the library manifest already defines as AutoMirrored.Filled.KeyboardReturn (library/ui/icons.tsv, the S and F IconReturn rows), so no new manifest line was needed and no generated source was touched. The on-device tests now find the key by its Return content description instead of the ⏎ text. The shipped variable change also relabelled the digit keys to letters a-k under 2nd. Undo that: digit keys have no second label or second press any more, so 2nd shifts only the function/operator keys it traditionally shifts and the numpad emits digits in both layers. Variable names are entered only via the var dropup, which is unchanged. calculator/AGENTS.md now describes the current variable set, the dropup-only entry and the filled Enter icon. Tests assert the key spec (empty label, isEnterKey, digit keys with no second layer), that the filled Return icon is shown and submits, and that with 2nd latched the 7 key is still displayed and emits 7. Verified: :calculator:testDevUnitTest (238 tests), :calculator:lint and :calculator:lintVitalRelease green (lintVitalRelease is SKIPPED by the build, as on the base). No devices were used, so the androidTest updates are compile-level only.
Diff
calculator/AGENTS.md
diff --git a/calculator/AGENTS.md b/calculator/AGENTS.mdindex 1a1e4f222a..e5f6cbc58d 100644--- a/calculator/AGENTS.md+++ b/calculator/AGENTS.md@@ -14,7 +14,7 @@ _Install: ./install calculator (dev by default)._ **Purpose:** Modern Material You calculator — scientific/basic modes, function graphing with analysis, and a multi-category unit converter with live currency rates. **Key features:** - Scientific + basic keypad with multi-line expression history: lines stack above the input, tapping a line reuses its result, long-pressing loads its expression for in-place editing (submitting re-runs that line and every line after it in order), and assigned variables show above the input and survive AC-- Variables instead of an M register: the `var` key opens a dropup listing every assignable single letter (`a`–`z` except reserved `e`; the picker is not limited by the keypad's 2nd-layer letters, which still type `a`–`k` directly) with current values; selecting one inserts just its name. Single letters that also spell the graph free variable (`x`/`t`) or units (`c`/`g`/`h`/`k`/`m`/`s`) are assignable in the calculator tab: once assigned, the variable wins in variable position (assignment target, picker insertion, later references), while graph/widget/intent expressions keep the original meaning. Typing/picking a name, then the literal `=` key, a value and Enter assigns (`a=5`); a name alone plus Enter reads its value; any other line plus Enter evaluates as a plain expression. Only a leading `<name>=<expr>` line assigns on Enter, and genuinely reserved names (`e`, multi-letter `ans`/`pi`/`tau`/`phi`/`theta`, functions, multi-letter unit tokens) can never be assigned. The literal `=` key is a regular key in the top section and never submits; the accent Enter key (`⏎`, bottom-right) submits+- Variables instead of an M register: the `var` key opens a dropup listing every assignable single letter with current values; selecting one inserts just its name (variable names are entered only this way — the 2nd layer shifts function/operator keys only and digit keys always emit digits). Assignable letters are `a`–`z` except the prohibited set in `Expression.prohibitedSingleLetterVariableNames`, derived from the engine's reserved meanings: `e` (Euler), `x`/`t` (graph free variable) and every single-letter unit token/alias in `UnitRegistry.parseTokens` (`a`/`b`/`c`/`f`/`g`/`h`/`j`/`k`/`l`/`m`/`n`/`s`/`v`/`w`); today that leaves `d`/`i`/`o`/`p`/`q`/`r`/`u`/`y`/`z`. A prohibited letter keeps its original meaning everywhere and can never be assigned: it is absent from the dropup and a `<letter>=…` line is rejected like other invalid assignments; a pre-existing assignment to a now-prohibited letter is ignored (its line still evaluates, the variable is dropped) on the next re-evaluation. Picking a name, then the literal `=` key, a value and Enter assigns (`d=5`); a name alone plus Enter reads its value; any other line plus Enter evaluates as a plain expression. Only a leading `<name>=<expr>` line assigns on Enter, and reserved names (`e`, multi-letter `ans`/`pi`/`tau`/`phi`/`theta`, functions, multi-letter unit tokens) can never be assigned. The literal `=` key is a regular key in the top section and never submits; the accent Enter key (filled return icon, bottom-right) submits - Graph page: plots functions with root / intercept / min-max / intersection detection - Unit converter across many categories incl. live currency rates (`CurrencyApi` over `:library:network`) - Home-screen widgets for both calculator and unit converter (`:library:widgets` Glance)
calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorEvaluateTest.kt
diff --git a/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorEvaluateTest.kt b/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorEvaluateTest.ktindex 80ef544adc..1cc25123fc 100644--- a/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorEvaluateTest.kt+++ b/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorEvaluateTest.kt@@ -47,7 +47,7 @@ class CalculatorEvaluateTest { // Main content is actually visible: the keypad equals key plus a tab label. assertNotNull( "calculator keypad never appeared; the app may have crashed on launch",- device.wait(Until.findObject(By.text(EQUALS_KEY)), CONTENT_TIMEOUT_MS),+ device.wait(Until.findObject(By.desc(EQUALS_KEY)), CONTENT_TIMEOUT_MS), ) assertNotNull( "calculator tabs never appeared",@@ -57,7 +57,11 @@ class CalculatorEvaluateTest { // Standard precedence: 2 + 3 x 4 evaluates to 14. The keypad // labels multiply as the proper sign (U+00D7), not ASCII x. for (key in arrayOf("2", "+", "3", "×", "4", EQUALS_KEY)) {- val button = device.wait(Until.findObject(By.text(key)), SHORT_TIMEOUT_MS)+ val button =+ device.wait(+ Until.findObject(if (key == EQUALS_KEY) By.desc(key) else By.text(key)),+ SHORT_TIMEOUT_MS,+ ) assertNotNull("keypad key $key never appeared", button) button!!.click() }@@ -97,7 +101,7 @@ class CalculatorEvaluateTest { private const val GATE_TIMEOUT_MS = 5_000L private const val SHORT_TIMEOUT_MS = 5_000L private const val BOTTOM_TAB_LABEL = "Calculator"- private const val EQUALS_KEY = "⏎"+ private const val EQUALS_KEY = "Return" private const val EXPECTED_RESULT = "14" private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"
calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorGraphTest.kt
diff --git a/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorGraphTest.kt b/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorGraphTest.ktindex e49a9219d1..4b6eee7341 100644--- a/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorGraphTest.kt+++ b/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorGraphTest.kt@@ -37,7 +37,7 @@ class CalculatorGraphTest { ) assertNotNull( "calculator keypad never appeared; the app may have crashed on launch",- device.wait(Until.findObject(By.text(EQUALS_KEY)), CONTENT_TIMEOUT_MS),+ device.wait(Until.findObject(By.desc(EQUALS_KEY)), CONTENT_TIMEOUT_MS), ) val graphTab = device.wait(Until.findObject(By.text(GRAPH_TAB)), CONTENT_TIMEOUT_MS) assertNotNull("Graph tab never appeared", graphTab)@@ -78,7 +78,7 @@ class CalculatorGraphTest { private companion object { private const val CONTENT_TIMEOUT_MS = 15_000L private const val GATE_TIMEOUT_MS = 5_000L- private const val EQUALS_KEY = "⏎"+ private const val EQUALS_KEY = "Return" private const val GRAPH_TAB = "Graph" private const val ADD_FUNCTION = "Add function" private const val FUNCTION_PLACEHOLDER = "f(x)"
calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorUnitsTest.kt
diff --git a/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorUnitsTest.kt b/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorUnitsTest.ktindex 42d6acce70..2bb4b8fed9 100644--- a/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorUnitsTest.kt+++ b/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/CalculatorUnitsTest.kt@@ -37,7 +37,7 @@ class CalculatorUnitsTest { ) assertNotNull( "calculator keypad never appeared; the app may have crashed on launch",- device.wait(Until.findObject(By.text(EQUALS_KEY)), CONTENT_TIMEOUT_MS),+ device.wait(Until.findObject(By.desc(EQUALS_KEY)), CONTENT_TIMEOUT_MS), ) val unitsTab = device.wait(Until.findObject(By.text(UNITS_TAB)), CONTENT_TIMEOUT_MS) assertNotNull("Units tab never appeared", unitsTab)@@ -96,7 +96,7 @@ class CalculatorUnitsTest { private const val CONTENT_TIMEOUT_MS = 15_000L private const val GATE_TIMEOUT_MS = 5_000L private const val SHORT_TIMEOUT_MS = 5_000L- private const val EQUALS_KEY = "⏎"+ private const val EQUALS_KEY = "Return" private const val UNITS_TAB = "Units" // Candidate categories observed on device; the converter opens on
calculator/src/androidTest/java/com/vayunmathur/calculator/ui/FullE2eTest.kt
diff --git a/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/FullE2eTest.kt b/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/FullE2eTest.ktindex edad747f16..2dae47b21b 100644--- a/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/FullE2eTest.kt+++ b/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/FullE2eTest.kt@@ -53,7 +53,7 @@ class FullE2eTest { // Main content is actually visible: the keypad equals key plus a tab label. assertNotNull( "calculator keypad never appeared; the app may have crashed on launch",- device.wait(Until.findObject(By.text(EQUALS_KEY)), CONTENT_TIMEOUT_MS),+ device.wait(Until.findObject(By.desc(EQUALS_KEY)), CONTENT_TIMEOUT_MS), ) assertNotNull( "calculator tabs never appeared",@@ -100,7 +100,7 @@ class FullE2eTest { private const val GATE_TIMEOUT_MS = 5_000L private const val SHORT_TIMEOUT_MS = 5_000L private const val BOTTOM_TAB_LABEL = "Calculator"- private const val EQUALS_KEY = "⏎"+ private const val EQUALS_KEY = "Return" private const val PERMISSION_GATE_TITLE = "Grant Required Permissions" /**
calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorKeypad.kt
diff --git a/calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorKeypad.kt b/calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorKeypad.ktindex ea08d12e50..2f006b8635 100644--- a/calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorKeypad.kt+++ b/calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorKeypad.kt@@ -36,6 +36,7 @@ import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.ButtonDefaults import com.vayunmathur.library.ui.FilterChip import com.vayunmathur.library.ui.HorizontalDivider+import com.vayunmathur.library.ui.IconReturn import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.rememberHaptics@@ -57,6 +58,8 @@ internal class Key( val secondPress: ((CalculatorActions) -> Unit)? = null, /** True only for the `var` key: it opens the variable dropup instead of pressing. */ val isVariablePicker: Boolean = false,+ /** True only for the Enter key: it renders the filled return icon, not a text label. */+ val isEnterKey: Boolean = false, val onPress: (CalculatorActions) -> Unit, ) @@ -104,18 +107,20 @@ internal fun RowScope.KeyButton( colors = colors, contentPadding = PaddingValues(0.dp), ) {- Text(label, fontSize = if (label.length >= 4) 13.sp else 18.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)+ if (key.isEnterKey) {+ IconReturn()+ } else {+ Text(label, fontSize = if (label.length >= 4) 13.sp else 18.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)+ } } } /** Builds the 8-row keypad for the given angle mode. */ internal fun buildCalculatorRows(angleMode: AngleMode): List<List<Key>> { fun ins(text: String): (CalculatorActions) -> Unit = { it.append(text) }- // The digits' 2nd layer spells variable names (a-k, skipping e = Euler's- // constant), so a line like `a=5` can be typed with the existing 2nd- // modifier — no new mode. The literal `=` in the top section only builds- // such a line; the accent Enter key (bottom-right, where `=` used to- // sit) is the one that submits it.+ // Variable names come only from the `var` dropup; 2nd shifts function/+ // operator keys only, digit keys always stay digits. The literal `=`+ // builds an assignment; the Enter key (bottom-right) submits it. return listOf( listOf( Key("2nd", KeyEmphasis.Toggle) {},@@ -144,32 +149,32 @@ internal fun buildCalculatorRows(angleMode: AngleMode): List<List<Key>> { Key(if (angleMode == AngleMode.DEGREES) "DEG" else "RAD", KeyEmphasis.Function) { it.toggleAngleMode() }, ), listOf(- Key("7", second = "a", secondPress = ins("a")) { it.append("7") },- Key("8", second = "b", secondPress = ins("b")) { it.append("8") },- Key("9", second = "c", secondPress = ins("c")) { it.append("9") },+ Key("7") { it.append("7") },+ Key("8") { it.append("8") },+ Key("9") { it.append("9") }, Key("÷", KeyEmphasis.Operator) { it.append("/") }, Key("⌫", KeyEmphasis.Operator) { it.backspace() }, ), listOf(- Key("4", second = "d", secondPress = ins("d")) { it.append("4") },- Key("5", second = "f", secondPress = ins("f")) { it.append("5") },- Key("6", second = "g", secondPress = ins("g")) { it.append("6") },+ Key("4") { it.append("4") },+ Key("5") { it.append("5") },+ Key("6") { it.append("6") }, Key("×", KeyEmphasis.Operator) { it.append("*") }, Key("%", KeyEmphasis.Operator) { it.append("%") }, ), listOf(- Key("1", second = "h", secondPress = ins("h")) { it.append("1") },- Key("2", second = "i", secondPress = ins("i")) { it.append("2") },- Key("3", second = "j", secondPress = ins("j")) { it.append("3") },+ Key("1") { it.append("1") },+ Key("2") { it.append("2") },+ Key("3") { it.append("3") }, Key("−", KeyEmphasis.Operator) { it.append("-") }, Key("nCr", KeyEmphasis.Function, second = "nPr", onPress = ins("nCr("), secondPress = ins("nPr(")), ), listOf( Key("ans", KeyEmphasis.Function) { it.append("ans") },- Key("0", second = "k", secondPress = ins("k")) { it.append("0") },+ Key("0") { it.append("0") }, Key(".") { it.append(".") }, Key("+", KeyEmphasis.Operator) { it.append("+") },- Key("⏎", KeyEmphasis.Primary) { it.evaluate() },+ Key("", KeyEmphasis.Primary, isEnterKey = true) { it.evaluate() }, ), ) }
calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorLandscape.kt
diff --git a/calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorLandscape.kt b/calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorLandscape.ktindex de087797d1..0f6a2c5b34 100644--- a/calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorLandscape.kt+++ b/calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorLandscape.kt@@ -21,6 +21,7 @@ import com.vayunmathur.calculator.platform.CalculatorActions import com.vayunmathur.calculator.platform.CalculatorUiState import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.ButtonDefaults+import com.vayunmathur.library.ui.IconReturn import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.rememberHaptics@@ -165,6 +166,10 @@ private fun RowScope.LandscapeKeyButton( colors = colors, contentPadding = PaddingValues(0.dp), ) {- Text(label, fontSize = if (label.length >= 4) 13.sp else 18.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)+ if (key.isEnterKey) {+ IconReturn()+ } else {+ Text(label, fontSize = if (label.length >= 4) 13.sp else 18.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)+ } } }
calculator/src/test/java/com/vayunmathur/calculator/ui/CalculatorScreensComposeTest.kt
diff --git a/calculator/src/test/java/com/vayunmathur/calculator/ui/CalculatorScreensComposeTest.kt b/calculator/src/test/java/com/vayunmathur/calculator/ui/CalculatorScreensComposeTest.ktindex d07c1f10ad..163d4ca447 100644--- a/calculator/src/test/java/com/vayunmathur/calculator/ui/CalculatorScreensComposeTest.kt+++ b/calculator/src/test/java/com/vayunmathur/calculator/ui/CalculatorScreensComposeTest.kt@@ -4,6 +4,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onAllNodesWithText+import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextReplacement@@ -45,7 +46,11 @@ class CalculatorScreensComposeTest { assertEquals("=", rad[3][1].label) assertEquals("RAD", rad[3][2].label) assertEquals("DEG", buildCalculatorRows(AngleMode.DEGREES)[3][2].label)- assertEquals("⏎", rad[7][4].label)+ assertEquals("", rad[7][4].label)+ assertTrue(rad[7][4].isEnterKey)+ // Digit keys have no 2nd-layer letters: digits stay digits in both layers.+ val digitKeys = rad.flatten().filter { it.label in listOf("0", "1", "2", "3", "4", "5", "6", "7", "8", "9") }+ assertTrue(digitKeys.all { it.second == null && it.secondPress == null }, digitKeys.map { it.label }.toString()) // The M register keys are gone. val labels = rad.flatten().map { it.label } assertTrue(labels.none { it in listOf("MC", "MR", "M+", "M-") }, labels.toString())@@ -122,7 +127,31 @@ class CalculatorScreensComposeTest { rule.onNodeWithText("7").assertIsDisplayed() rule.onNodeWithText("7").performClick() assertEquals(listOf("7"), actions.appended)- rule.onNodeWithText("⏎").performClick()+ rule.onNodeWithContentDescription("Return").performClick()+ assertEquals(1, actions.evaluated)+ }++ @Test fun calculatorScreenSecondKeyKeepsDigitsAsDigits() {+ val actions = RecordingActions()+ rule.setContent {+ CalculatorScreen(state = CalculatorUiState(), actions = actions)+ }+ rule.onNodeWithText("2nd").performClick()+ // Function keys shift, digit keys do not relabel to letters.+ rule.onNodeWithText("7").assertIsDisplayed()+ rule.onNodeWithText("7").performClick()+ assertEquals(listOf("7"), actions.appended)+ }++ @Test fun enterKeyUsesFilledReturnIcon() {+ val actions = RecordingActions()+ rule.setContent {+ CalculatorScreen(state = CalculatorUiState(), actions = actions)+ }+ // The filled IconReturn wrapper (AutoMirrored.Filled.KeyboardReturn+ // in icons.tsv) carries the "Return" content description.+ rule.onNodeWithContentDescription("Return").assertIsDisplayed()+ rule.onNodeWithContentDescription("Return").performClick() assertEquals(1, actions.evaluated) } @@ -145,14 +174,14 @@ class CalculatorScreensComposeTest { CalculatorUiState( input = "10", preview = "10",- variables = mapOf("a" to "5"),+ variables = mapOf("d" to "5"), history = listOf(HistoryEntry("2+3", "5")), ), actions = actions, ) } rule.onAllNodesWithText("10")[0].assertIsDisplayed()- rule.onNodeWithText("a = 5").assertIsDisplayed()+ rule.onNodeWithText("d = 5").assertIsDisplayed() } @Test fun variableDropupNameTapInsertsJustTheName() {@@ -165,7 +194,7 @@ class CalculatorScreensComposeTest { } rule.setContent { CalculatorScreen(- state = CalculatorUiState(variables = mapOf("a" to "5")),+ state = CalculatorUiState(variables = mapOf("d" to "5")), actions = actions, ) }@@ -173,10 +202,10 @@ class CalculatorScreensComposeTest { // Assigned variables show their current value in the dropup (a // second `a = 5` node beside the one in the display); the rest // show the bare name.- assertTrue(rule.onAllNodesWithText("a = 5").fetchSemanticsNodes().isNotEmpty())- rule.onNodeWithText("b").assertIsDisplayed()- rule.onNodeWithText("b").performClick()- assertEquals("b", inserted)+ assertTrue(rule.onAllNodesWithText("d = 5").fetchSemanticsNodes().isNotEmpty())+ rule.onNodeWithText("p").assertIsDisplayed()+ rule.onNodeWithText("p").performClick()+ assertEquals("p", inserted) } @Test fun calculatorScreenUnitPickerSeededOpen() {