Help Center

Local Navigation

Provide an assistive technology application with information about text changes

You can provide accessibility information about the custom UI controls that display text.

  1. Import the required interfaces.
    import net.rim.device.api.ui.accessibility.AccessibleContext;
    import net.rim.device.api.ui.accessibility.AccessibleText;
    
    AccessibleContext provides basic accessibility information about a custom UI control. AccessibleText provides information about the text in a custom UI control that displays text.
  2. Create a class that extends Field and implements the AccessibleContext and AccessibleText interfaces.
    public class AccessibleTextClass extends Field 
      implements AccessibleContext, AccessibleText 
    {
    }
    
  3. Create variables to store the custom UI control's accessibility state and the contents.
    private int _state;
    private int _cursor, _anchor;
    private String _text;
    private Vector _lines; 
    private Vector _words; 
    
  4. Implement AccessibleText.getAtIndex(int part, int index), to provide access to the text at a given position in the custom UI control.
    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;
    }   
    
  5. 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 device user cannot select text in the custom UI control.
    public int getSelectionStart() 
    {
      return _anchor;
    }
    
  6. 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 device user cannot select text in the custom UI control.
    public int getSelectionEnd() 
    {
      return _cursor;
    }
    
  7. Implement AccessibleText.getCaretPosition(), to provide access to the position of the cursor within the text. Return 0 if the device user cannot select text in the custom UI control.
    public int getCaretPosition() 
    {
      return _cursor;
    }
    
  8. Implement AccessibleText.getSelectionText(), to provide access to the selected part of the text within the custom UI control.
    public String getSelectionText() 
    {
      int start = getSelectionStart();
      int end = getSelectionEnd();
      if (start<end) {
        return _text.getText(start,end);
      } else {
        return _text.getText(end,start);
      }
    }
    
  9. Implement AccessibleText.getLineCount(), to provide access to the number of lines of text within the custom UI control.
    public int getLineCount()
    {
      return _lines.size();
    }
    
  10. Implement AccessibleText.getCharCount(), to provide access to the number of characters in the text within the custom UI control.
    public int getCharCount()
    {
      return _text.length();
    }
    

Index


Was this information helpful? Send us your comments.