โ๏ธ Drawing Game Mode (Developer Docs)
The DrawingFragment implements the Drawing Game Mode in zMantra.
This mode challenges learners to draw specific shapes (e.g., circle, square, triangle) on a custom canvas.
It is designed to be hands-on and exploratory, allowing learners to practice geometric understanding through free drawing.
๐ Location
com.zendalona.zmantra.presentation.features.game.drawing.DrawingFragment
๐ Core Responsibilities
- Render Custom Drawing Canvas
- Uses
DrawingView
(a customView
) for capturing freehand drawing. -
Clears and resets canvas when needed.
-
Load & Present Questions
- Reads questions from
GameQuestion
list. - Each question provides a shape name (
expression
). -
Generates accessible instructions (e.g., "Draw a Circle").
-
User Interaction
- Reset button โ clears canvas.
-
Submit button โ moves to next question.
-
Accessibility Support
- Announces task instructions using TalkBack.
- Announces canvas reset action.
-
Announces movement to next question.
-
Game Flow
- Sequentially cycles through
GameQuestion
s. - Ends session with completion announcement โ auto-navigates back after delay.
โ๏ธ Key Fields
Variable | Type | Purpose |
---|---|---|
_binding / binding |
FragmentGameDrawingBinding |
View binding for layout. |
drawingView |
DrawingView? |
Custom canvas for drawing shapes. |
isFirstQuestion |
Boolean |
Ensures first question text gets TalkBack focus. |
currentQuestion |
GameQuestion? |
Holds currently active question. |
currentIndex |
Int |
Tracks which question index is being shown. |
questions |
List<GameQuestion> |
All questions for this mode. |
๐ Lifecycle
- onCreateView()
-
Inflates layout and inserts
DrawingView
into container. -
onViewCreated()
-
Sets listeners for Reset & Submit buttons.
-
onQuestionsLoaded()
- Loads all available questions.
- If empty โ disables buttons & shows "No questions available".
-
Otherwise โ starts with
loadQuestionAt(0)
. -
loadQuestionAt(index: Int, questions: List
) - Prepares instruction (e.g., "Draw a Square").
- Updates UI and accessibility announcements.
- Clears canvas.
- Resets
attemptCount
. -
If no more questions โ announces "Task completed" and exits fragment.
-
checkAnswer()
- Currently a placeholder.
- Shows "Moving to next question" message.
- Advances to the next question.
-
In the future โ can be extended for automatic drawing recognition.
-
onResume()/onPause()
- Forwards lifecycle to
DrawingView
for any resource handling.
๐จ Drawing Logic
DrawingView
handles all drawing gestures (not included here, but assumed to provide:clearCanvas()
,onResume()
,onPause()
).- User input is not validated against shapes yet โ currently free drawing only.
๐ง Accessibility
- Announces drawing tasks (e.g., "Please draw a triangle").
- Announces canvas reset (e.g., "Canvas cleared").
- Announces navigation to next question.
- Ensures focus is given to first question text for TalkBack.
๐งช Testing Notes
- Verify Reset button clears canvas properly.
- Confirm Submit button moves to next question.
- Validate completion behavior:
- At end of questions โ "Task completed" announcement.
- Navigates back after 3 seconds.
- Test TalkBack focus on first question.
- Check canvas usability across devices and screen densities.