Provide an assistive technology application with information about a UI change

  1. Import the required interface.
    import net.rim.device.api.ui.accessibility.AccessibleContext;
    
    AccessibleContext provides the basic accessibility information about a custom UI component.
  2. Create a class that extends the Field class and implements AccessibleContext.
    public class MyCustomComponent extends Field 
      implements AccessibleContext
    {
    }
    
  3. Create the variables to store the accessibility information for a custom UI component, such as state information.
    private int _state = AccessibleState.UNSET;
    private String _accessibleName;
    private String _title;
    
  4. Create the methods that add and remove the states for a custom UI component.
    protected void addAccessibleStates(int states) 
    {
      _state = _state & ~AccessibleState.UNSET;
      _state = _state | states;
    }
    
    protected void removeAccessibleStates(int states) 
    {
      _state = _state & ~states;
    }
    
    public void setAccessibleName(String accessibleName) 
    {
      _accessibleName = accessibleName;
    }
    
  5. Implement the get() methods of AccessibleContext to provide access to the tabular, textual, or numerical information for a custom UI component. Return null if the method does not apply to a custom UI component. For example, if the component does not provide textual information, return null in getAccessibleText().
    public AccessibleTable getAccessibleTable() 
    {
      return null;
    }
    
    public AccessibleText getAccessibleText() 
    {
      return null;
    }
    
    public AccessibleValue getAccessibleValue() 
    {
      return null;
    }
    
  6. Create a method that returns an instance of the class that implements AccessibleContext to provide accessibility information about a change to a custom UI component.
    public AccessibleContext getAccessibleContext() 
    {
      return this;
    }
    
  7. Implement AccessibleContext.getAccessibleRole() to provide information about the type of custom UI component.
    public int getAccessibleRole() 
    {
      return AccessibleRole.PANEL;
    }
    
  8. Implement AccessibleContext.getAccessibleChildCount() to provide information about the number of accessible child components that a custom UI component contains. It is up to you as the developer of a custom UI component to decide whether or not the component contains accessible children. For example, you can decide whether a child element is an accessible child component based on whether the child element can gain focus and whether the user can interact with the child element directly.
    public int getAccessibleChildCount() 
    {
      return _icons.size();
    }
    
  9. Implement AccessibleContext.getAccessibleChildAt(int) to provide information about an accessible child component that a custom UI component contains.
    public AccessibleContext getAccessibleChildAt(int arg0) 
    {
      return (Icon) _icons.elementAt( index );
    }
    
  10. Implement AccessibleContext.getAccessibleName() to provide the name of a custom UI component that changes.
    public String getAccessibleName() 
    {
      return _accessibleName;
    }
    
  11. Create a method that invokes AccessibleEventDispatcher.dispatchAccessibleEvent(stateChange, oldState, newState, this) to send a notification when the state of a custom UI component changes. Pass the following arguments to the method:
    • the event
    • the old state of the custom UI component
    • the new state of the custom UI component
    • an instance of the custom UI component
    protected void onFocus(int direction)
    {
      super.onFocus(direction);
           
      int oldState = _state;
      _state = _state | AccessibleState.FOCUSED;
         
      if(isVisible())
      {
        AccessibleEventDispatcher.dispatchAccessibleEvent( 
          AccessibleContext.ACCESSIBLE_STATE_CHANGED, 
          new Integer(oldState), 
          new Integer(_state), 
          this);
      }
    }
    

Was this information helpful? Send us your comments.