๐ก Hint System
The Hint System provides users with contextual assistance for each game mode โ helpful especially for new or visually impaired users.
๐ฏ Purpose
- Allow users to access hints when theyโre stuck.
- Offer accessibility-aware guidance (via TalkBack or custom service).
- Load hints dynamically based on the current game mode and language.
๐งฉ How It Works
1. ๐ Hint Button in Toolbar
The top-right "hint" icon is controlled by the current fragment. Each screen decides whether the icon is shown using:
interface HintIconVisibilityController {
fun shouldShowHintIcon(): Boolean
}
````
### 2. ๐ฌ Triggering the Hint
When the hint icon is tapped:
```kotlin
interface Hintable {
fun showHint()
}
- If the fragment implements
Hintable
, it displays the hint. - If not,
MainActivity
loads a fallbackHintFragment
using a default text file.
๐ Hint Content Source
โ Excel-Based Hint Lookup
Hints are stored in localized Excel files located at:
assets/hint/{language}.xlsx
๐ง Code: ExcelHintReader
public static String getHintFromExcel(Context context, String language, String mode)
- Reads
mode
andhint
columns from the Excel file. - Matches the current mode to return the correct hint.
โ Fallback Example
If no hint is found for the mode, or the Excel file fails to load, the fallback path is:
"en/hint/default.txt"
๐งช Example Hint File (en.xlsx
)
Mode | Hint Text |
---|---|
tap | Tap the correct answer to continue. |
shake | Shake the device when the answer is X. |
numberline | Drag the marker to the correct value. |
These Excel files are stored in the
assets/hint/
folder. They are easy to localize.
๐ Related Classes
File | Purpose |
---|---|
MainActivity.kt |
Loads the toolbar, handles hint menu logic. |
Hintable , HintIconVisibilityController |
Interfaces for fragment-based hint control. |
HintFragment.kt |
Fallback fragment to show default hint file. |
ExcelHintReader.java |
Reads localized hint from Excel based on mode. |
โฟ Accessibility Considerations
- Hint content is spoken aloud using TTS when shown.
- Compatible with TalkBack and custom accessibility service.
- Ensures users with visual impairments receive the same guidance.
๐งโ๐ป Developer Tips
- Add a new hint? Update the corresponding
.xlsx
file inassets/hint/
. - For a new game mode, ensure the mode string matches the one passed to
getHintFromExcel(...)
. - To hide the hint icon for a fragment, return
false
fromshouldShowHintIcon()
.
๐ Sample Code Snippets
Show Hint from Fragment
```kotlin override fun showHint() { val hintText = ExcelHintReader.getHintFromExcel(requireContext(), "en", "tap") DialogUtils.showInlineResult(requireActivity(), "Hint", hintText, R.drawable.hint) }