Provide an assistive technology application with information about text changes

You can provide accessibility information about the custom UI components 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 the basic accessibility information about a custom UI component. AccessibleText provides the information about the text in a custom UI component that displays text.
  2. Create a class that extends the Field class and implements AccessibleContext and AccessibleText.
    public class AccessibleTextClass extends Field 
      implements AccessibleContext, AccessibleText 
    {
    }
    
  3. 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; 
    
  4. 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;
    }   
    
  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 user cannot select text.
    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 user cannot select text.
    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 user cannot select text.
    public int getCaretPosition() 
    {
      return _cursor;
    }
    
  8. 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);
      }
    }
    
  9. Implement AccessibleText.getLineCount() to provide access to the number of lines of text.
    public int getLineCount()
    {
      return _lines.size();
    }
    
  10. Implement AccessibleText.getCharCount() to provide access to the number of characters in the text.
    public int getCharCount()
    {
      return _text.length();
    }
    

Was this information helpful? Send us your comments.