๐ Number Line Game Mode (Developer Docs)
The Number Line Game is an interactive mode in zMantra where learners move along a number line to reach a target position.
It supports spatial number sense development, incremental navigation, and accessibility via TalkBack.
๐ Location
com.zendalona.zmantra.presentation.features.game.numberline.NumberLineFragment
com.zendalona.zmantra.presentation.features.game.numberline.NumberLineViewModel
com.zendalona.zmantra.presentation.features.game.numberline.customView.NumberLineView
๐ Core Responsibilities
- NumberLineFragment
- Hosts UI for the number line task.
- Presents questions (e.g., "Move to 3").
- Manages navigation via left/right buttons.
- Observes state from
NumberLineViewModel
. - Triggers accessibility announcements.
-
Validates when the learner reaches the correct answer.
-
NumberLineViewModel
- Holds number line state (
start
,end
,currentPosition
). - Provides methods to move left/right and shift the visible range when boundaries are reached.
-
Encapsulates logic for updating LiveData to drive the UI.
-
NumberLineView (CustomView)
- Draws the line, numbers, and mascot emoji.
- Updates dynamically as learner moves.
- Sends custom accessibility descriptions of the line and position.
- Handles TalkBack focus events with announcements.
โ๏ธ Fragment Fields
Variable | Type | Purpose |
---|---|---|
questions |
List<GameQuestion> |
Sequence of tasks ("Move to X" , answer=X ). |
currentIndex |
Int |
Index of current question. |
answer |
Int |
Target position for current question. |
questionDesc |
String |
Human-readable description. |
questionStartTime |
Long |
Timestamp for timing responses. |
isFirstQuestion |
Boolean |
Ensures focus is set on first question only. |
currentPosLabel |
String |
String resource for "Current position". |
answerCheckRunnable |
Runnable? |
Delayed check of correctness after movement. |
๐ Flow
1. Setup
onCreate()
โ initializeNumberLineViewModel
and set speech rate.onCreateView()
โ bind UI, attach click listeners, set up LiveData observers.
2. Load Questions
onQuestionsLoaded()
โ fallback default if none provided ("Move to 3"
).- Calls
askNextQuestion()
.
3. Ask Question
- Updates
questionDesc
+answer
. - Displays in
numberLineQuestion
. - Posts accessibility announcement:
"Move to 3". - On first question, auto-focuses question text.
4. Move on Number Line
- Left/Right buttons โ
viewModel.moveLeft()
/viewModel.moveRight()
. - If end of range reached โ range shifts (e.g., -5..5 โ 6..16).
- Observers redraw
NumberLineView
and updatecurrentPositionTv
.
5. Check Answer
- After each move,
answerCheckRunnable
is delayed (2s). - If current position == target โ
getGrade()
andshowResultDialog()
. - Otherwise, learner continues adjusting until correct.
6. Next Question
- After correct answer,
askNextQuestion()
loads the next one. - Ends game when all questions are complete.
๐จ NumberLineView (CustomView)
- Draws:
- Horizontal line across screen.
- Tick marks/numbers (
start โ end
). - Mascot emoji ๐จโ๐ฆฝ above the current position.
- Accessibility:
- Announces current position when updated.
- Custom
AccessibilityDelegateCompat
โ announces position when view gains focus. - Overrides
onInitializeAccessibilityNodeInfo()
with custom description:
"Number line from -5 to 5, current position is 0".
๐ก ViewModel Responsibilities
- State management with LiveData:
lineStart
,lineEnd
,currentPosition
.- Movement:
- Right:
current++
or shift range right. - Left:
current--
or shift range left. - Shifting:
- Maintains window size of 10 numbers.
- Shifts in chunks (
-5..5 โ 6..16
). - Logs for debugging (
Log.d
).
๐ง Accessibility Features
- Question: spoken via TTS.
- Number line: announces "Current position is X" on updates.
- Focus events: auto-announce when question or number line receives TalkBack focus.
- Custom content descriptions for TalkBack context.
๐งช Testing Notes
- UI
- Verify line, numbers, and mascot render correctly at all ranges.
- Ensure shifting left/right updates range smoothly.
- Accessibility
- TalkBack announces questions and positions.
- Focus on
numberLineView
announces correct content. - Position updates trigger announcements.
- Game Flow
- Correct position โ result dialog โ next question.
- Incorrect position โ stays until corrected.
- Performance
- Verify handler callbacks cancel properly in
onPause()
. - No memory leaks from binding (
binding=null
inonDestroyView()
).