Help Center

Local Navigation

Provide an assistive technology application with information about text changes

  1. Import the net.rim.device.api.ui.accessibility.AccessibleText interface.
  2. Create a class the implements the AccessibleText interface, to provide information about a character, line, or word that is located before a certain point in the text.
    public class AccessibleTextClass implements AccessibleText {
    }
    
  3. Implement AccessibleText.getBeforeIndex(int part, int index), to provide access to a character, line, or word that is located before a point in the text .
    public String getBeforeIndex(int part, int index){
            switch (part){
    case AccessibleText.CHAR:
                    return _text.substring(0, index);
                case AccessibleText.WORD:
                    int wordStart = findWordStart(_text, index);
                    return _text.substring(0, wordStart);
                case AccessibleText.LINE:
                default :{
                    int lineStart = findLineStart(_text, index);
                    return _text.substring(0, lineStart);
                }
            }
            return null;
        }
    
  4. Implement AccessibleText.getAtIndex(int part, int index), to provide access to the text at the position of the cursor.
    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;
        }
    
  5. Implement AccessibleText.getSelectionStart(), to provide access to the position of the first character of text that a BlackBerry® device user selects.
    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.
    public int getSelectionEnd() {
            return _cursor;
        }
    
  7. Implement AccessibleText.getCaretPosition(), to provide access to the position of the cursor within the text of a custom UI component.
    public int getCaretPosition() {
            return _cursor;
        }
    
  8. Implement AccessibleText.getSelectionText(), to provide access to the selected portion of the text within a custom UI component.
    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 a custom UI component.
    public int getLineCount()
        {
            String[] lines = splitLines(_text);
            return lines.length;
        }
    
  10. Implement AccessibleText.getCharCount(), to provide access to the number of characters in the text within a custom UI component.
    public int getCharCount()
        {
            return _text.length();
        }
    }
    

Index


Was this information helpful? Send us your comments.