games: pipes, solitaire and wordmaker are playable without sight
- Commit
2a1b1a073945ebbf8a1daaed07240f79c0f38665- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-21 07:56 UTC (15 days ago)
- Parents
2712549
Pipes' board cells were read-only semantics - each cell now offers start/extend/finish-pipe actions invoking the same callbacks as the canvas gestures. Solitaire's cards were gesture-only: every card now announces itself and offers auto-move (double-tap), select, and move-selected-here through the same drop logic as dragging (drag itself untouched). WordMaker's letter wheel was swipe-only unless a manual setting was flipped; tap-to-spell now engages automatically when a screen reader is active (manual toggle still wins), and letter tiles are labelled. Verified: pipes 134, solitaire 179 suites pass; one wordmaker failure reproduces at clean HEAD (known class-level flake).
Diff
games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/BoardCellSemantics.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/BoardCellSemantics.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/BoardCellSemantics.ktindex cb3b310333..2e1d3cef45 100644--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/BoardCellSemantics.kt+++ b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/BoardCellSemantics.kt@@ -8,8 +8,12 @@ import androidx.compose.ui.AbsoluteAlignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.stringResource+import androidx.compose.ui.semantics.CustomAccessibilityAction import androidx.compose.ui.semantics.contentDescription+import androidx.compose.ui.semantics.customActions+import androidx.compose.ui.semantics.onClick import androidx.compose.ui.semantics.semantics+import androidx.compose.ui.semantics.stateDescription import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.IntOffset import com.vayunmathur.games.pipes.R@@ -18,26 +22,69 @@ import com.vayunmathur.games.pipes.platform.PipesGameState import kotlin.math.roundToInt /**- * Invisible per-cell nodes laid over the board canvas so TalkBack can explore it: each- * cell reads its row and column and whether it holds a dot, a pipe or nothing, naming the- * colour by the same letter colour-blind mode draws. The nodes take no input, so touches+ * Invisible per-cell nodes laid over the board canvas so TalkBack can explore and play it:+ * each cell reads its row and column and whether it holds a dot, a pipe or nothing, naming+ * the colour by the same letter colour-blind mode draws.+ *+ * Playing without touch mirrors a finger stroke, using the same callbacks the canvas+ * gesture drives ([onStartDraw] on finger-down, [onExtendPath] as it enters a cell,+ * [onCommitDraw] when it lifts): double-tapping a dot or pipe starts a stroke there,+ * double-tapping each next cell extends it, and the "Finish pipe" action on any cell+ * commits it. The nodes carry only semantics actions — no pointer input — so touches * still reach the canvas underneath. * * Positions use AbsoluteAlignment.TopLeft plus absoluteOffset: the canvas never mirrors * in RTL, so neither may these (a plain Box would align them to the top-right in RTL). */ @Composable-fun BoardCellSemantics(geometry: BoardGeometry, gameState: PipesGameState, boardSize: Dp) {+fun BoardCellSemantics(+ geometry: BoardGeometry,+ gameState: PipesGameState,+ boardSize: Dp,+ activeColor: Int? = null,+ isLevelWon: Boolean = false,+ onStartDraw: (CellPos) -> Unit = {},+ onExtendPath: (CellPos) -> Unit = {},+ onCommitDraw: () -> Unit = {},+) { val cellDp = with(LocalDensity.current) { geometry.cellSizePx.toDp() } val dots = geometry.levelData.endpoints.flatMap { ep -> ep.cells.map { it to ep.colorIndex } }.toMap()+ val startLabel = stringResource(R.string.board_action_start_pipe)+ val extendLabel = stringResource(R.string.board_action_extend_pipe)+ val finishLabel = stringResource(R.string.board_action_finish_pipe)+ val drawingLabel = stringResource(R.string.board_state_drawing) Box(Modifier.size(boardSize), contentAlignment = AbsoluteAlignment.TopLeft) { for ((cell, rect) in geometry.cellRects) { val description = cellDescription(cell, dots[cell], gameState.cellOwner[cell])+ // Only a dot or an existing pipe can start a stroke — the same cells a+ // finger-down can begin on (startDraw ignores any other cell).+ val canStart = cell in dots || gameState.cellOwner[cell] != null+ val drawing = activeColor != null Box( Modifier .absoluteOffset { IntOffset(rect.left.roundToInt(), rect.top.roundToInt()) } .size(cellDp)- .semantics { contentDescription = description }+ .semantics {+ contentDescription = description+ if (isLevelWon) return@semantics+ if (drawing) stateDescription = drawingLabel+ val actions = buildList {+ if (drawing) {+ add(CustomAccessibilityAction(extendLabel) { onExtendPath(cell); true })+ add(CustomAccessibilityAction(finishLabel) { onCommitDraw(); true })+ }+ if (canStart) {+ add(CustomAccessibilityAction(startLabel) { onStartDraw(cell); true })+ }+ }+ if (actions.isNotEmpty()) customActions = actions+ // Double-tap does the primary thing for the current phase:+ // start a stroke, or grow the open one into this cell.+ when {+ drawing -> onClick(extendLabel) { onExtendPath(cell); true }+ canStart -> onClick(startLabel) { onStartDraw(cell); true }+ }+ } ) } }
games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoard.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoard.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoard.ktindex f65e3e93fa..0b30097288 100644--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoard.kt+++ b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoard.kt@@ -193,7 +193,14 @@ fun GameBoard( } } }- BoardCellSemantics(geometry, gameState, boardSize)+ BoardCellSemantics(+ geometry, gameState, boardSize,+ activeColor = activeColor,+ isLevelWon = isLevelWon,+ onStartDraw = onStartDraw,+ onExtendPath = onExtendPath,+ onCommitDraw = onCommitDraw,+ ) } }
games/pipes/src/main/res/values/strings.xml
diff --git a/games/pipes/src/main/res/values/strings.xml b/games/pipes/src/main/res/values/strings.xmlindex 902367ff8e..10b0a3fecd 100644--- a/games/pipes/src/main/res/values/strings.xml+++ b/games/pipes/src/main/res/values/strings.xml@@ -30,4 +30,12 @@ <string name="board_cell_pipe">Row <xliff:g id="row" example="2">%1$d</xliff:g>, column <xliff:g id="column" example="3">%2$d</xliff:g>, pipe <xliff:g id="letter" example="B">%3$s</xliff:g></string> <!-- GameBoard: TalkBack label of an empty board cell --> <string name="board_cell_empty">Row <xliff:g id="row" example="2">%1$d</xliff:g>, column <xliff:g id="column" example="3">%2$d</xliff:g>, empty</string>+ <!-- BoardCellSemantics: TalkBack action starting a pipe stroke at this cell (same call as pressing the finger here). Verb phrase -->+ <string name="board_action_start_pipe">Start pipe here</string>+ <!-- BoardCellSemantics: TalkBack action extending the open pipe stroke into this cell (same call as dragging into it). Verb phrase -->+ <string name="board_action_extend_pipe">Extend pipe here</string>+ <!-- BoardCellSemantics: TalkBack action committing the open pipe stroke (same call as lifting the finger). Verb phrase -->+ <string name="board_action_finish_pipe">Finish pipe</string>+ <!-- BoardCellSemantics: TalkBack state of every cell while a pipe stroke is being built between Start and Finish. Noun phrase -->+ <string name="board_state_drawing">Pipe in progress</string> </resources>
games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireDragOps.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireDragOps.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireDragOps.ktindex 2af6539251..6e377b90a8 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireDragOps.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireDragOps.kt@@ -162,6 +162,30 @@ internal fun SolitaireViewModel.endDragImpl(dropOffset: Offset, cardSize: IntSiz dragInfoInternal.value = null } +/** Selects [sourceId] for TalkBack select-then-target play; re-selecting clears it. */+internal fun SolitaireViewModel.selectCardImpl(sourceId: String) {+ if (sourceRange(sourceId) == null) return+ selectedSourceInternal.update { if (it == sourceId) null else sourceId }+}++/**+ * Drops the accessibility-selected run onto [targetId] through the same drop handler+ * ([flyMove] → applyDrop) a drag or tap ends in, flying from the selected card's+ * laid-out position. An illegal target leaves state and the selection untouched.+ */+internal fun SolitaireViewModel.moveSelectedCardToImpl(targetId: String): Boolean {+ val sourceId = selectedSourceInternal.value ?: return false+ val range = sourceRange(sourceId)+ if (range == null) {+ selectedSourceInternal.value = null+ return false+ }+ if (range.pileId == targetId) return false+ val moved = flyMove(sourceId, targetId, range.cards, cardPositions[range.cards.first()], lastCardSize)+ if (moved) selectedSourceInternal.value = null+ return moved+}+ /** The gesture was cancelled: the stack goes back where it came from. */ internal fun SolitaireViewModel.cancelDragImpl() { dragInfoInternal.value?.let { returnCarriedCards(it) }
games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFlight.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFlight.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFlight.ktindex 3701bf6daa..d409219d1d 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFlight.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFlight.kt@@ -258,6 +258,7 @@ private fun SolitaireViewModel.replayQueuedTap(tap: QueuedTap) { /** Drops every flight and queued tap: undo, restart, mode switch and give-up replace the board. */ internal fun SolitaireViewModel.clearMotion() { flightsInternal.value = emptyList()+ selectedSourceInternal.value = null queuedTaps.clear() dragInfoInternal.value = null autoCompleteFlightId = null
games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireUiContract.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireUiContract.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireUiContract.ktindex 48438cfd50..2dfb4cdee2 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireUiContract.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireUiContract.kt@@ -35,6 +35,22 @@ interface SolitaireActions { /** True while an animated auto-complete run is in flight. A preview never runs one. */ val autoCompleteRunning: StateFlow<Boolean> get() = NoAutoComplete + /**+ * Source id of the card picked through the accessibility "Select card" action, or+ * null. TalkBack play is select-then-target (a drag cannot be driven by a screen+ * reader); selecting is an accessibility-only path and never changes drag state.+ */+ val selectedSourceId: StateFlow<String?> get() = NoSelection++ /** Selects [sourceId] for a later [moveSelectedCardTo], or clears it when re-selected. */+ fun selectCard(sourceId: String) {}++ /**+ * Moves the selected card (or run) onto pile [targetId] through the same drop+ * handler a drag ends in. False — and the selection stays — when the move is illegal.+ */+ fun moveSelectedCardTo(targetId: String): Boolean = false+ /** * Records where [card] was last laid out in root coordinates, so the animated * auto-complete can fly it from there. Positions for cards never laid out (in@@ -87,6 +103,7 @@ interface SolitaireActions { private val NoDrag: StateFlow<DragInfo?> = MutableStateFlow(null) private val NoFlights: StateFlow<List<CardFlight>> = MutableStateFlow(emptyList()) private val NoAutoComplete: StateFlow<Boolean> = MutableStateFlow(false)+private val NoSelection: StateFlow<String?> = MutableStateFlow(null) /** Somewhere for a [SolitaireActions.Noop] board to register its drop zones and forget them. */ private val DiscardedDropTargets: MutableMap<String, Rect> = mutableMapOf()
games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireViewModel.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireViewModel.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireViewModel.ktindex 25e4bc3d6f..7a39951817 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireViewModel.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireViewModel.kt@@ -74,6 +74,9 @@ class SolitaireViewModel(application: Application) : AndroidViewModel(applicatio internal val autoCompleteRunningInternal = MutableStateFlow(false) override val autoCompleteRunning: StateFlow<Boolean> = autoCompleteRunningInternal.asStateFlow() + internal val selectedSourceInternal = MutableStateFlow<String?>(null)+ override val selectedSourceId: StateFlow<String?> = selectedSourceInternal.asStateFlow()+ /** * Last laid-out root position per card, fed by the boards. Bounded by the 52 * unique cards; entries from a previous deal are dropped on mode switch and@@ -237,6 +240,10 @@ class SolitaireViewModel(application: Application) : AndroidViewModel(applicatio override fun landFlight(id: Long) = landFlightImpl(id) + override fun selectCard(sourceId: String) = selectCardImpl(sourceId)++ override fun moveSelectedCardTo(targetId: String): Boolean = moveSelectedCardToImpl(targetId)+ /** * Starts a drag from [sourceId], deriving the carried cards from current state. * Returns false (and starts nothing) when that source holds no card.
games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/DraggableCard.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/DraggableCard.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/DraggableCard.ktindex 1d84d6e278..913f49e22d 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/DraggableCard.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/ui/DraggableCard.kt@@ -16,10 +16,20 @@ import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.layout.positionInRoot+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.semantics.CustomAccessibilityAction+import androidx.compose.ui.semantics.contentDescription+import androidx.compose.ui.semantics.customActions import androidx.compose.ui.semantics.hideFromAccessibility+import androidx.compose.ui.semantics.onClick+import androidx.compose.ui.semantics.selected import androidx.compose.ui.semantics.semantics+import androidx.compose.ui.semantics.stateDescription import androidx.compose.ui.unit.IntSize+import com.vayunmathur.games.solitaire.R import com.vayunmathur.games.solitaire.data.Card+import com.vayunmathur.games.solitaire.data.Rank+import com.vayunmathur.games.solitaire.data.Suit import com.vayunmathur.games.solitaire.platform.SolitaireActions /**@@ -47,6 +57,18 @@ fun DraggableCard( var cardSize by remember { mutableStateOf(IntSize.Zero) } val drag by actions.dragInfo.collectAsState() val flights by actions.flights.collectAsState()+ val selectedSource by actions.selectedSourceId.collectAsState()+ val isSelected = selectedSource == sourceId+ val hasSelection = selectedSource != null+ // TalkBack identity of this (always face-up) card and the actions its menu offers.+ val description = stringResource(+ R.string.card_face_up, stringResource(rankStringRes(card.rank)), stringResource(suitStringRes(card.suit)),+ )+ val autoMoveLabel = stringResource(R.string.card_action_auto_move)+ val foundationLabel = stringResource(R.string.card_action_move_to_foundation)+ val selectLabel = stringResource(if (isSelected) R.string.card_action_deselect else R.string.card_action_select)+ val moveHereLabel = stringResource(R.string.card_action_move_selected_here)+ val selectedLabel = stringResource(R.string.card_selected) val hidden = drag?.range?.covers(pileId, index, card) == true || flights.any { it.hides.covers(pileId, index, card) } // Feeds the animated auto-complete its launch points; unlaid cards (the stock)@@ -90,8 +112,64 @@ fun DraggableCard( } .graphicsLayer { if (hidden) alpha = 0f } // The copy in motion is the one a screen reader should find, not this one.- .then(if (hidden) Modifier.semantics { hideFromAccessibility() } else Modifier)+ // Otherwise the card is a TalkBack stop in its own right: double-tap does+ // exactly what a touch tap does (requestAutoMove), and the custom actions+ // cover the moves a drag would make — foundation first, or select this+ // card / drop the selected card onto this pile. Drag gestures above are+ // untouched; these semantics actions invoke the same ViewModel calls.+ .semantics {+ if (hidden) {+ hideFromAccessibility()+ } else {+ contentDescription = description+ if (isSelected) {+ selected = true+ stateDescription = selectedLabel+ }+ onClick(autoMoveLabel) { actions.requestAutoMove(sourceId, startPos, cardSize) }+ customActions = buildList {+ // The same tap handler: it tries a foundation first, then the+ // best tableau/free-cell spot, and is a no-op (returns false)+ // where neither is legal — Spider has no foundations at all.+ add(CustomAccessibilityAction(foundationLabel) {+ actions.requestAutoMove(sourceId, startPos, cardSize)+ })+ add(CustomAccessibilityAction(selectLabel) { actions.selectCard(sourceId); true })+ if (hasSelection && !isSelected && pileId != WASTE_PILE_ID) {+ add(CustomAccessibilityAction(moveHereLabel) {+ actions.moveSelectedCardTo(pileId)+ })+ }+ }+ }+ } ) { content() } }++/** Pile id of the Klondike waste, which is a source but never a drop target. */+private const val WASTE_PILE_ID = "waste"++private fun rankStringRes(rank: Rank): Int = when (rank) {+ Rank.ACE -> R.string.rank_ace+ Rank.TWO -> R.string.rank_two+ Rank.THREE -> R.string.rank_three+ Rank.FOUR -> R.string.rank_four+ Rank.FIVE -> R.string.rank_five+ Rank.SIX -> R.string.rank_six+ Rank.SEVEN -> R.string.rank_seven+ Rank.EIGHT -> R.string.rank_eight+ Rank.NINE -> R.string.rank_nine+ Rank.TEN -> R.string.rank_ten+ Rank.JACK -> R.string.rank_jack+ Rank.QUEEN -> R.string.rank_queen+ Rank.KING -> R.string.rank_king+}++private fun suitStringRes(suit: Suit): Int = when (suit) {+ Suit.HEARTS -> R.string.suit_hearts+ Suit.DIAMONDS -> R.string.suit_diamonds+ Suit.SPADES -> R.string.suit_spades+ Suit.CLUBS -> R.string.suit_clubs+}
games/solitaire/src/main/res/values/strings.xml
diff --git a/games/solitaire/src/main/res/values/strings.xml b/games/solitaire/src/main/res/values/strings.xmlindex 3752a68d28..b26c1bbc32 100644--- a/games/solitaire/src/main/res/values/strings.xml+++ b/games/solitaire/src/main/res/values/strings.xml@@ -60,4 +60,36 @@ <string name="card_colors_two">Two colours (traditional)</string> <!-- SettingsScreen: Card colour option, a colourblind-friendly deck giving each suit its own colour. Noun phrase --> <string name="card_colors_four">Four colours (colourblind friendly)</string>++ <!-- DraggableCard: TalkBack description of a face-up card: rank name, suit name. -->+ <string name="card_face_up">%1$s of %2$s, face up</string>+ <!-- DraggableCard: TalkBack state of the accessibility-selected card. Adjective -->+ <string name="card_selected">Selected</string>+ <!-- DraggableCard: TalkBack action doing what a tap does — best legal move, foundation first. Verb phrase -->+ <string name="card_action_auto_move">Auto-move</string>+ <!-- DraggableCard: TalkBack action moving the card to a foundation where legal. Verb phrase -->+ <string name="card_action_move_to_foundation">Move to foundation</string>+ <!-- DraggableCard: TalkBack action selecting this card so another card can take it as a target. Verb phrase -->+ <string name="card_action_select">Select card</string>+ <!-- DraggableCard: TalkBack action clearing the accessibility selection. Verb phrase -->+ <string name="card_action_deselect">Deselect card</string>+ <!-- DraggableCard: TalkBack action dropping the selected card (or run) onto this card's pile. Verb phrase -->+ <string name="card_action_move_selected_here">Move selected card here</string>+ <string name="rank_ace">Ace</string>+ <string name="rank_two">Two</string>+ <string name="rank_three">Three</string>+ <string name="rank_four">Four</string>+ <string name="rank_five">Five</string>+ <string name="rank_six">Six</string>+ <string name="rank_seven">Seven</string>+ <string name="rank_eight">Eight</string>+ <string name="rank_nine">Nine</string>+ <string name="rank_ten">Ten</string>+ <string name="rank_jack">Jack</string>+ <string name="rank_queen">Queen</string>+ <string name="rank_king">King</string>+ <string name="suit_hearts">Hearts</string>+ <string name="suit_diamonds">Diamonds</string>+ <string name="suit_spades">Spades</string>+ <string name="suit_clubs">Clubs</string> </resources>
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/LevelDataStore.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/LevelDataStore.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/LevelDataStore.ktindex 55162da471..819097eeec 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/LevelDataStore.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/LevelDataStore.kt@@ -55,6 +55,13 @@ class LevelDataStore(context: Context) { val tapToSpell: Flow<Boolean> = appContext.dataStore.data.map { it[TAP_TO_SPELL_KEY] ?: false } + /**+ * The explicit Tap to Spell setting, or null when the player has never touched the+ * toggle. Null is what lets a screen reader turn tap-to-spell on automatically+ * without overwriting a choice the player actually made.+ */+ val tapToSpellPreference: Flow<Boolean?> = appContext.dataStore.data.map { it[TAP_TO_SPELL_KEY] }+ val wheelSpacing: Flow<WheelSpacing> = appContext.dataStore.data.map { prefs -> prefs[WHEEL_SPACING_KEY]?.let { runCatching { WheelSpacing.valueOf(it) }.getOrNull() } ?: WheelSpacing.DEFAULT
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.ktindex 8e4238c672..0fdcb5f65e 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt@@ -53,8 +53,14 @@ class WordMakerViewModel(application: Application) : AndroidViewModel(applicatio private val casualRevealedHints: StateFlow<Set<Pair<Int, Int>>> = levelDataStore.revealedHints .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptySet()) + // Eagerly, not WhileSubscribed: the settings page now collects the nullable+ // preference below, so nothing may be subscribed to this flow while it is read. val tapToSpell: StateFlow<Boolean> = levelDataStore.tapToSpell- .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false)+ .stateIn(viewModelScope, SharingStarted.Eagerly, false)++ /** Explicit Tap to Spell choice (null = never set); see [LevelDataStore.tapToSpellPreference]. */+ val tapToSpellPreference: StateFlow<Boolean?> = levelDataStore.tapToSpellPreference+ .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), null) val wheelSpacing: StateFlow<WheelSpacing> = levelDataStore.wheelSpacing .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), WheelSpacing.DEFAULT)
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/SettingsPage.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/SettingsPage.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/SettingsPage.ktindex c110ba1232..98d965ab27 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/SettingsPage.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/SettingsPage.kt@@ -21,7 +21,11 @@ import com.vayunmathur.games.wordmaker.platform.WordMakerViewModel /** Binds [WordMakerViewModel] to the stateless [SettingsScreen]. */ @Composable fun SettingsPage(viewModel: WordMakerViewModel, onBack: () -> Unit) {- val tapToSpell by viewModel.tapToSpell.collectAsState()+ val tapToSpellPreference by viewModel.tapToSpellPreference.collectAsState()+ // The switch shows the mode actually in effect (a running screen reader turns+ // tap-to-spell on by itself); flipping it writes an explicit setting, which+ // then overrides the automatic behaviour in effectiveTapToSpell.+ val tapToSpell = effectiveTapToSpell(tapToSpellPreference, rememberScreenReaderEnabled()) val wheelSpacing by viewModel.wheelSpacing.collectAsState() val reminderEnabled by viewModel.reminderEnabled.collectAsState() val reminderMinutes by viewModel.reminderMinutesOfDay.collectAsState()
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.ktindex 79575f55d8..c9d11583ec 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.kt@@ -1,10 +1,15 @@ package com.vayunmathur.games.wordmaker.ui +import android.view.accessibility.AccessibilityManager import androidx.compose.runtime.Composable+import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.platform.LocalContext import com.vayunmathur.games.wordmaker.data.CrosswordData import com.vayunmathur.games.wordmaker.data.GameMode import com.vayunmathur.games.wordmaker.platform.WordGameActions@@ -23,7 +28,11 @@ fun WordGamePage( ) { val foundWords by viewModel.foundWords.collectAsState() val bonusWords by viewModel.bonusWords.collectAsState()- val tapToSpell by viewModel.tapToSpell.collectAsState()+ val tapToSpellPreference by viewModel.tapToSpellPreference.collectAsState()+ // Swipe spelling cannot be driven by a screen reader, so tap-to-spell turns on+ // automatically while one is running — unless the player set the toggle themselves.+ val screenReaderEnabled = rememberScreenReaderEnabled()+ val tapToSpell = effectiveTapToSpell(tapToSpellPreference, screenReaderEnabled) val wheelSpacing by viewModel.wheelSpacing.collectAsState() val revealedHints by viewModel.revealedHints.collectAsState() val hintCooldownEnd by viewModel.hintCooldownEnd.collectAsState()@@ -103,3 +112,42 @@ fun WordGamePage( onOpenSettings = onOpenSettings ) }++/**+ * Whether tap-to-spell is in effect: the player's explicit setting when they have+ * made one, otherwise on exactly while a screen reader is running. Pure, so the+ * override rule is unit-testable without an AccessibilityManager.+ */+internal fun effectiveTapToSpell(manualPreference: Boolean?, screenReaderEnabled: Boolean): Boolean =+ manualPreference ?: screenReaderEnabled++/**+ * True while a screen reader (TalkBack) is running: an accessibility service is+ * enabled and touch exploration is on. Listens for both flipping mid-game, so+ * turning TalkBack off returns the wheel to swipe without restarting the screen.+ */+@Composable+internal fun rememberScreenReaderEnabled(): Boolean {+ val context = LocalContext.current+ var enabled by remember { mutableStateOf(false) }+ DisposableEffect(context) {+ val manager = context.getSystemService(AccessibilityManager::class.java)+ if (manager == null) {+ enabled = false+ return@DisposableEffect onDispose {}+ }+ fun update() {+ enabled = manager.isEnabled && manager.isTouchExplorationEnabled+ }+ update()+ val stateListener = AccessibilityManager.AccessibilityStateChangeListener { update() }+ val touchListener = AccessibilityManager.TouchExplorationStateChangeListener { update() }+ manager.addAccessibilityStateChangeListener(stateListener)+ manager.addTouchExplorationStateChangeListener(touchListener)+ onDispose {+ manager.removeAccessibilityStateChangeListener(stateListener)+ manager.removeTouchExplorationStateChangeListener(touchListener)+ }+ }+ return enabled+}
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.ktindex e8c5a99699..c75f25c66c 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt@@ -43,6 +43,10 @@ import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.stringResource+import androidx.compose.ui.semantics.contentDescription+import androidx.compose.ui.semantics.selected+import androidx.compose.ui.semantics.semantics+import androidx.compose.ui.semantics.stateDescription import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp@@ -246,6 +250,9 @@ fun LetterChooser( // absoluteOffset, not offset: offset {} mirrors x in RTL while the // trail and hit-testing work in unmirrored pointer coordinates, so an // RTL swipe selected the letter opposite the one under the finger.+ val letterDescription = stringResource(R.string.letter_tile, chooserLetter.char.toString())+ val letterSelected = stringResource(R.string.letter_selected)+ val isTileSelected = index in selectedLettersIndices SurfaceText(Modifier .align(Alignment.Center) .absoluteOffset { IntOffset(x.roundToPx(), y.roundToPx()) }@@ -258,7 +265,18 @@ fun LetterChooser( } else if (index !in selectedLettersIndices) { selectedLettersIndices = selectedLettersIndices + index }- } else Modifier),+ } else Modifier)+ // Every tile names its letter for TalkBack. In+ // tap-to-spell (forced on under a screen reader) this+ // merges with the clickable, so double-tap spells the+ // letter; in swipe mode it is a read-only label.+ .semantics {+ contentDescription = letterDescription+ if (isTileSelected) {+ selected = true+ stateDescription = letterSelected+ }+ }, CircleShape, if (index in selectedLettersIndices) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.secondary, chooserLetter.char.toString(),
games/wordmaker/src/main/res/values/strings.xml
diff --git a/games/wordmaker/src/main/res/values/strings.xml b/games/wordmaker/src/main/res/values/strings.xmlindex a8ebf8d54e..c9f1023e1a 100644--- a/games/wordmaker/src/main/res/values/strings.xml+++ b/games/wordmaker/src/main/res/values/strings.xml@@ -72,6 +72,11 @@ <!-- WordGameScreen tap mode: Accessibility description for backspace button to delete last selected letter. Noun --> <string name="cd_backspace">Backspace</string> + <!-- LetterChooser: TalkBack description of one letter tile on the wheel: %1$s is the letter. Noun phrase -->+ <string name="letter_tile">Letter %1$s</string>+ <!-- LetterChooser: TalkBack state of a letter tile already added to the word being spelled. Adjective -->+ <string name="letter_selected">Selected</string>+ <!-- DefinitionDialog: Body shown when the bundled dictionary has no entry for the tapped word. Sentence --> <string name="no_definition_available">No definition available for this word.</string> </resources>