Integrating with assistive technology software
On a BlackBerry® device with BlackBerry® Device Software version 4.6.1 or later, a BlackBerry device application that uses the UI component classes can provide information to an assistive technology application when a UI component changes. One example of an assistive technology application is a screen reader. The UI component classes include the ObjectChoiceField, RadioButtonField, and RichTextField classes in the net.rim.device.api.ui.component package.
If a BlackBerry device application uses the UI component classes and does not extend the classes, you do not need to alter the application to integrate with an assistive technology application. For example, if a BlackBerry device application uses the net.rim.device.api.ui.component.TextField class and does not extend the class, an assistive technology application can access information when the TextField object changes.
If a BlackBerry device application extends any of the UI component classes, and thus uses custom UI components, you must use the net.rim.device.api.ui.accessibility package to provide an assistive technology application with access to information about a custom UI component that changes. For example, a BlackBerry device application that uses a myTextField class that extends TextField must use the net.rim.device.api.ui.accessibility package to provide access to data when text in the myTextField object changes.
You must first determine whether the BlackBerry device supports the Accessibility APIs. Create an instance of the net.rim.device.api.ui.accessibility.AccessibilityManager class and invoke AccessibilityManager.isAccessibilitySupported(). If the method returns true, the BlackBerry device application can make data available to an assistive technology application.
To specify the type of information the application can provide to an assistive technology application, you must implement the AccessibleContext interface. The AccessibleContext interface enables a BlackBerry device application to provide information such as the name of the custom UI component, the parent component of the custom UI component, and the number of child components of a custom UI component. For example, invoking the method that implements the AccessibleContext.getAccessibleChildCount() method should return 4 if a Screen for a BlackBerry device application contains four myTextField objects.
You must implement the AccessibleContext interface to provide an assistive technology application with access to the textual, tabular, or numerical data from a custom UI component that changes. You must also implement the AccessibleText, AccessibleTable, and AccessibleValue interfaces.
After you implement the interfaces, you can invoke the methods that implement the AccessibleContext.getAccessibleText(), AccessibleContext.getAccessibleTable(), and AccessibleContext.getAccessibleValue() methods to return an object that provides access to the textual, tabular, and numerical data. For example, a BlackBerry device application that extends TextField can use an implementation of the AccessibleText.getAtIndex() and AccessibleText.getCaretPosition() methods to retrieve the String at a specific location in text and the position of the cursor in text.
To send notifications to an assistive technology application when a custom UI component changes, you must implement the net.rim.device.api.ui.accessibility.AccessibleEventListener interface. Various events can cause a BlackBerry device application to send notifications, including a change to the text in a field, a change in the location of the cursor in the text in a field, and a change to a field that a UI component contains. A notification about a change can contain different kinds of information, including the name of the custom UI component that changes, the type of change, the value of the data before the change, and the value of the data after the change.
Code sample: Making information about text changes available to an assistive technology application
class makeAccessibleText implements AccessibleText {
...
public String getAtIndex(int part, int index){
switch (part){
case AccessibleText.CHAR:
return _text.charAt(index);
case AccessibleText.WORD:
String[] words = splitWords(_text);
return words[index];
case AccessibleText.LINE:
String[] lines = splitLines(_text);
return lines[index];
}
return null;
}
}
class makeAccessible implements AccessibleContext {
...
makeAccessibleText makeAccessibleTextObj = new makeAccessibleText();
public AccessibleText getAccessibleText(){
return makeAccessibleTextObj;
}
...
}