Skip to content

Accessibility Dialogs

๐Ÿง  What Is the Accessibility Dialog and Custom Accessibility Service?

๐Ÿ“ 1. Purpose

In the app ZMantra, the goal is to assist users with visual impairments or those who rely on screen readers (like TalkBack). To support this, the app:

  • Uses a custom accessibility service (MathsManthraAccessibilityService) to monitor user focus and interactions.
  • Prompts users with an Accessibility Dialog if they havenโ€™t enabled required accessibility settings.

๐Ÿ” 2. Accessibility Dialog: What It Is and Why Itโ€™s Shown

โœ… What It Does

This dialog appears when either:

  • TalkBack is ON but
  • Your custom service (MathsManthraAccessibilityService) is NOT enabled

It informs the user that they need to enable the custom service and redirects them to the Accessibility Settings screen.

โš™๏ธ How It Works (Code Path)

  • Triggered inside MainActivity:
if (!isServiceEnabled || !isTalkBackEnabled) {
    Handler(Looper.getMainLooper()).postDelayed({
        AccessibilityHelper.enforceAccessibilityRequirement(this)
    }, 500)
}
  • Then calls:
AccessibilityHelper.enforceAccessibilityRequirement(context)

Which checks:

if (!isServiceEnabled && isTalkBackOn) {
    showAccessibilityDialog(context)
}
  • And finally shows this dialog:
AlertDialog.Builder(context)
    .setTitle("Enable Accessibility")
    .setMessage("Please enable MathsManthra Accessibility Service in settings.")
    .setPositiveButton("Enable") {
        context.startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS))
    }

โ™ฟ 3. Custom Accessibility Service: MathsManthraAccessibilityService

๐Ÿ”Ž What It Does

This service listens for specific accessibility events like:

  • TYPE_VIEW_ACCESSIBILITY_FOCUSED: when a user focuses on a view via screen reader
  • TYPE_WINDOW_STATE_CHANGED: when the app's window changes

It logs these events and updates internal app state, like:

if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
    service.updateWindowState();
}

This lets your app respond only when your app is in focus (checked via package name) and adapt the UI or hints as needed.

โš™๏ธ How Itโ€™s Registered

This is declared in your AndroidManifest.xml (not shown here but assumed), and needs to be manually enabled by the user in Settings > Accessibility.

Once enabled, it stays active in the background while your app is open.


๐Ÿ” 4. AccessibilityHelper: Glue Between UI & Service

This class handles:

  • Checking if your service is enabled
  • Opening settings
  • Disabling/enabling touch passthrough regions (for advanced UI focus)
  • Holding a reference to the running service instance

๐Ÿงช Developer Summary

Feature Purpose Location in Code
Accessibility Dialog Prompts users to enable the custom service AccessibilityHelper.showAccessibilityDialog()
Custom Accessibility Service Monitors screen reader focus and interaction events MathsManthraAccessibilityService.kt/java
System TalkBack Detection Ensures TalkBack is enabled AccessibilityUtils.isSystemExploreByTouchEnabled()
Service Enable Check Confirms your service is active AccessibilityHelper.isMathsManthraAccessibilityServiceEnabled()