Help Center
Local Navigation
- Understanding accessibility
- Best practice: Designing accessible applications
-
Developing accessible BlackBerry device applications by using the Accessibility API
- Accessibility API concepts
- Introduction to the Accessibility API
- The AccessibilityDemo sample application
- Notifying an assistive technology application when the UI changes
- UI changes that trigger a notification to an assistive technology application
- UI component states and properties
- Provide an assistive technology application with information about a UI change
- Provide an assistive technology application with information about text changes
- Provide an assistive technology application with access to information from a table
- Provide an assistive technology application with access to numeric values
- Enable an assistive technology application to receive notification of UI events
- Test an accessible BlackBerry device application
- Related resources
- Provide feedback
- Document revision history
- Legal notice
BlackBerry Manuals & Help
>
Developer Documentation
>
Java Development Guides and API Reference
>
Development Guide
Accessibility - BlackBerry Java SDK - 6.0
Provide an assistive technology application with information about text changes
You can provide accessibility information about the custom UI components that display text.
- Import the required interfaces.
import net.rim.device.api.ui.accessibility.AccessibleContext; import net.rim.device.api.ui.accessibility.AccessibleText;
AccessibleContext provides the basic accessibility information about a custom UI component. AccessibleText provides the information about the text in a custom UI component that displays text. - Create a class that extends the Field class and implements AccessibleContext
and AccessibleText.
public class AccessibleTextClass extends Field implements AccessibleContext, AccessibleText { } - Create the variables to store the information about the custom UI component's state and contents.
private int _state; private int _cursor, _anchor; private String _text; private Vector _lines; private Vector _words;
- Implement AccessibleText.getAtIndex(int part, int index) to provide access to the text at a given position.
public String getAtIndex(int part, int index) { switch(part) { case AccessibleText.CHAR: return String.valueOf(_text.charAt(index)); case AccessibleText.LINE: return (String) _lines.elementAt(index); case AccessibleText.WORD: return (String) _words.elementAt(index); } return null; } - Implement AccessibleText.getSelectionStart() to provide access to the position of the first character of text that a BlackBerry®
device user
selects.
Return 0 if the user cannot select text.
public int getSelectionStart() { return _anchor; } - Implement AccessibleText.getSelectionEnd() to provide access to the position of the last character of text that a BlackBerry
device user
selects. Return 0 if the user cannot select text.
public int getSelectionEnd() { return _cursor; } - Implement AccessibleText.getCaretPosition() to provide access to the position of the cursor within the text. Return 0 if the user cannot select text.
public int getCaretPosition() { return _cursor; } - Implement AccessibleText.getSelectionText() to provide access to the selected part of the text.
public String getSelectionText() { int start = getSelectionStart(); int end = getSelectionEnd(); if (start<end) { return _text.getText(start,end); } else { return _text.getText(end,start); } } - Implement AccessibleText.getLineCount() to provide access to the number of lines of text.
public int getLineCount() { return _lines.size(); } - Implement AccessibleText.getCharCount() to provide access to the number of characters in the text.
public int getCharCount() { return _text.length(); }