The Android system provides information to accessibility services about the user interface interaction through
AccessibilityEvent
objects. Prior to Android 4.0, the information available in an
accessibility event, while providing a significant amount of detail
about a user interface control selected by the user, offered limited
contextual information. In many cases, this missing context information
might be critical to understanding the meaning of the selected control.
An
example of an interface where context is critical is a calendar or day
planner. If the user selects a 4:00 PM time slot in a Monday to Friday
day list and the accessibility service announces “4 PM”, but does not
announce the weekday name, the day of the month, or the month name, the
resulting feedback is confusing. In this case, the context of a user
interface control is critical to a user who wants to schedule a meeting.
Android
4.0 significantly extends the amount of information that an
accessibility service can obtain about an user interface interaction by
composing accessibility events based on the view hierarchy. A view
hierarchy is the set of user interface components that contain the
component (its parents) and the user interface elements that may be
contained by that component (its children). In this way, the Android
system can provide much richer detail about accessibility events,
allowing accessibility services to provide more useful feedback to
users.
An accessibility service gets information about an user interface event through an
AccessibilityEvent passed by the system to the service’s onAccessibilityEvent()
callback method. This object provides details about the event,
including the type of object being acted upon, its descriptive text and
other details. Starting in Android 4.0 (and supported in previous
releases through the AccessibilityEventCompat object in the Support Library), you can obtain additional information about the event using these calls:AccessibilityEvent.getRecordCount()andgetRecord(int)- These methods allow you to retrieve the set ofAccessibilityRecordobjects which contributed to theAccessibilityEventpassed to you by the system. This level of detail provides more context for the event that triggered your accessibility service.AccessibilityEvent.getSource()- This method returns anAccessibilityNodeInfoobject. This object allows you to request view layout hierarchy (parents and children) of the component that originated the accessibility event. This feature allows an accessibility service to investigate the full context of an event, including the content and state of any enclosing views or child views.Important: The ability to investigate the view hierarchy from anAccessibilityEventpotentially exposes private user information to your accessibility service. For this reason, your service must request this level of access through the accessibility service configuration XML file, by including thecanRetrieveWindowContentattribute and setting it totrue. If you do not include this setting in your service configuration xml file, calls togetSource()fail.Note: In Android 4.1 (API Level 16) and higher, thegetSource()method, as well asAccessibilityNodeInfo.getChild()andgetParent(), return only view objects that are considered important for accessibility (views that draw content or respond to user actions). If your service requires all views, it can request them by setting theflagsmember of the service'sAccessibilityServiceInfoinstance toFLAG_INCLUDE_NOT_IMPORTANT_VIEWS.
No comments:
Post a Comment