Java Code Examples for androidx.core.view.accessibility.AccessibilityNodeInfoCompat#ACTION_NEXT_AT_MOVEMENT_GRANULARITY

The following examples show how to use androidx.core.view.accessibility.AccessibilityNodeInfoCompat#ACTION_NEXT_AT_MOVEMENT_GRANULARITY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupedMenuItemWithTextAction.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Override
public int getIconResource() {
  int actionId = action.getId();
  switch (actionId) {
    case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
    case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
      return R.drawable.ic_text;
    case TextEditingUtils.ACTION_DELETE_TEXT:
      return R.drawable.ic_delete_text;
    case AccessibilityNodeInfoCompat.ACTION_SET_SELECTION:
      return R.drawable.ic_highlight_text;
    default:
      // We don't know what the action is. Don't show an icon.
      return 0;
  }
}
 
Example 2
Source File: GroupedMenuItemWithTextAction.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Override
public String getText() {
  CharSequence label = action.getLabel();
  if (label != null) {
    return label.toString();
  }

  int actionId = action.getId();
  switch (actionId) {
    case TextEditingUtils.ACTION_DELETE_TEXT:
      return service.getString(R.string.action_group_name_delete);
    case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
      return service.getString(R.string.switch_access_move_prev);
    case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
      return service.getString(R.string.switch_access_move_next);
    case AccessibilityNodeInfoCompat.ACTION_SET_SELECTION:
      return service.getString(R.string.action_group_name_highlight);
    default:
      // This should never happen.
      return "";
  }
}
 
Example 3
Source File: GroupedMenuItemWithTextAction.java    From talkback with Apache License 2.0 6 votes vote down vote up
private static SwitchAccessMenuItemEnum.MenuItem getMenuItemEnumFromAction(
    SwitchAccessActionGroup action) {
  switch (action.getId()) {
    case TextEditingUtils.ACTION_DELETE_TEXT:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_DELETE;
    case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_MOVE_TO_PREVIOUS;
    case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_MOVE_TO_NEXT;
    case AccessibilityNodeInfoCompat.ACTION_SET_SELECTION:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_HIGHLIGHT_TEXT;
    default:
      // This should never happen.
      LogUtils.e(TAG, "Action is not supported by the GroupMenuItem");
      return SwitchAccessMenuItemEnum.MenuItem.ITEM_UNSPECIFIED;
  }
}
 
Example 4
Source File: ProcessorPhoneticLetters.java    From talkback with Apache License 2.0 6 votes vote down vote up
/** Handle an event that indicates a text is being traversed at character granularity. */
private void processTraversalEvent(AccessibilityEvent event, EventId eventId) {
  final CharSequence text = AccessibilityEventUtils.getEventTextOrDescription(event);
  if (TextUtils.isEmpty(text)) {
    return;
  }

  String letter;
  if ((event.getAction() == AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY
          || event.getAction()
              == AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY)
      && event.getFromIndex() >= 0
      && event.getFromIndex() < text.length()) {
    letter = String.valueOf(text.charAt(event.getFromIndex()));
  } else {
    return;
  }
  speakPhoneticLetterForTraversedText(
      TextUtils.equals(event.getPackageName(), PackageManagerUtils.TALBACK_PACKAGE),
      letter,
      eventId);
}
 
Example 5
Source File: SwitchAccessAction.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
// LINT.IfChange(generateInverseAction)
public TimelineAction generateInverseAction() {
  Bundle args = new Bundle();
  switch (getId()) {
    case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
    case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
    case AccessibilityNodeInfoCompat.ACTION_SET_SELECTION:
      // If previousSelectionStart == -1 or previousSelectionEnd == -1, performing this action
      // does nothing.
      args.putInt(
          AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, previousSelectionStart);
      args.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, previousSelectionEnd);
      return new SwitchAccessAction(
          nodeCompat, AccessibilityActionCompat.ACTION_SET_SELECTION, args);
    case AccessibilityNodeInfoCompat.ACTION_CUT:
    case AccessibilityNodeInfoCompat.ACTION_PASTE:
    case TextEditingUtils.ACTION_DELETE_TEXT:
      args.putInt(
          AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, previousSelectionStart);
      args.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, previousSelectionEnd);
      args.putCharSequence(
          AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, previousTextContent);
      return new SwitchAccessAction(nodeCompat, AccessibilityActionCompat.ACTION_SET_TEXT, args);
    default:
      // Action is not undoable.
      return null;
  }
}
 
Example 6
Source File: NodeActionMenuItem.java    From talkback with Apache License 2.0 5 votes vote down vote up
private static SwitchAccessMenuItemEnum.MenuItem getMenuItemForAction(SwitchAccessAction action) {
  switch (action.getId()) {
    case AccessibilityNodeInfoCompat.ACTION_CLICK:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_CLICK;
    case AccessibilityNodeInfoCompat.ACTION_LONG_CLICK:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_LONG_CLICK;
    case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_SCROLL_FORWARD;
    case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_SCROLL_BACKWARD;
    case AccessibilityNodeInfoCompat.ACTION_DISMISS:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_DISMISS;
    case AccessibilityNodeInfoCompat.ACTION_COLLAPSE:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_COLLAPSE;
    case AccessibilityNodeInfoCompat.ACTION_EXPAND:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_EXPAND;
    case AccessibilityNodeInfoCompat.ACTION_SET_SELECTION:
      return getMenuItemForSetSelectionAction(action);
    case AccessibilityNodeInfoCompat.ACTION_CUT:
      return getMenuItemForCutAction(action);
    case AccessibilityNodeInfoCompat.ACTION_COPY:
      return getMenuItemForCopyAction(action);
    case AccessibilityNodeInfoCompat.ACTION_PASTE:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_PASTE;
    case TextEditingUtils.ACTION_DELETE_TEXT:
      return getMenuItemForDeleteTextAction(action);
    case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
      return getMenuItemForNextAtMovementGranularityAction(action);
    case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
      return getMenuItemForPreviousAtMovementGranularityAction(action);
    case TextEditingUtils.ACTION_UNDO:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_UNDO;
    case TextEditingUtils.ACTION_REDO:
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_REDO;
    default:
      // Other actions such as "App info", "Add to home screen" etc.
      return SwitchAccessMenuItemEnum.MenuItem.ACTION_MENU_CUSTOM_ACTION;
  }
}
 
Example 7
Source File: DirectionNavigationActor.java    From talkback with Apache License 2.0 5 votes vote down vote up
/** Converts linear navigation direction to the granularity navigation action. */
private static int logicalDirectionToNavigationAction(
    @TraversalStrategy.SearchDirection int logicalDirection) {
  if (logicalDirection == TraversalStrategy.SEARCH_FOCUS_FORWARD) {
    return AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY;
  } else if (logicalDirection == TraversalStrategy.SEARCH_FOCUS_BACKWARD) {
    return AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY;
  } else {
    throw new IllegalStateException("Unknown logical direction");
  }
}
 
Example 8
Source File: AccessibilityNodeInfoUtils.java    From talkback with Apache License 2.0 4 votes vote down vote up
public static String actionToString(int action) {
  switch (action) {
    case AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS:
      return "ACTION_ACCESSIBILITY_FOCUS";
    case AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
      return "ACTION_CLEAR_ACCESSIBILITY_FOCUS";
    case AccessibilityNodeInfoCompat.ACTION_CLEAR_FOCUS:
      return "ACTION_CLEAR_FOCUS";
    case AccessibilityNodeInfoCompat.ACTION_CLEAR_SELECTION:
      return "ACTION_CLEAR_SELECTION";
    case AccessibilityNodeInfoCompat.ACTION_CLICK:
      return "ACTION_CLICK";
    case AccessibilityNodeInfoCompat.ACTION_COLLAPSE:
      return "ACTION_COLLAPSE";
    case AccessibilityNodeInfoCompat.ACTION_COPY:
      return "ACTION_COPY";
    case AccessibilityNodeInfoCompat.ACTION_CUT:
      return "ACTION_CUT";
    case AccessibilityNodeInfoCompat.ACTION_DISMISS:
      return "ACTION_DISMISS";
    case AccessibilityNodeInfoCompat.ACTION_EXPAND:
      return "ACTION_EXPAND";
    case AccessibilityNodeInfoCompat.ACTION_FOCUS:
      return "ACTION_FOCUS";
    case AccessibilityNodeInfoCompat.ACTION_LONG_CLICK:
      return "ACTION_LONG_CLICK";
    case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
      return "ACTION_NEXT_AT_MOVEMENT_GRANULARITY";
    case AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT:
      return "ACTION_NEXT_HTML_ELEMENT";
    case AccessibilityNodeInfoCompat.ACTION_PASTE:
      return "ACTION_PASTE";
    case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
      return "ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY";
    case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_HTML_ELEMENT:
      return "ACTION_PREVIOUS_HTML_ELEMENT";
    case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD:
      return "ACTION_SCROLL_BACKWARD";
    case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD:
      return "ACTION_SCROLL_FORWARD";
    case AccessibilityNodeInfoCompat.ACTION_SELECT:
      return "ACTION_SELECT";
    case AccessibilityNodeInfoCompat.ACTION_SET_SELECTION:
      return "ACTION_SET_SELECTION";
    case AccessibilityNodeInfoCompat.ACTION_SET_TEXT:
      return "ACTION_SET_TEXT";
    default:
      return "(unhandled)";
  }
}
 
Example 9
Source File: NodeActionMenuItem.java    From talkback with Apache License 2.0 4 votes vote down vote up
/** Returns an icon resource id associated with the current action. */
@Override
public int getIconResource() {
  int actionId = action.getId();
  switch (actionId) {
    case AccessibilityNodeInfoCompat.ACTION_CLICK:
      return R.drawable.ic_select;
    case AccessibilityNodeInfoCompat.ACTION_LONG_CLICK:
      return R.drawable.ic_long_press;
    case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD:
      return R.drawable.ic_scroll_down;
    case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD:
      return R.drawable.ic_scroll_up;
    case AccessibilityNodeInfoCompat.ACTION_DISMISS:
      return R.drawable.ic_dismiss;
    case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
    case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
      return R.drawable.ic_text;
    case AccessibilityNodeInfoCompat.ACTION_COLLAPSE:
      return R.drawable.ic_collapse;
    case AccessibilityNodeInfoCompat.ACTION_EXPAND:
      return R.drawable.ic_expand;
    case AccessibilityNodeInfoCompat.ACTION_SET_SELECTION:
      return R.drawable.ic_highlight_text;
    case AccessibilityNodeInfoCompat.ACTION_CUT:
      return R.drawable.ic_cut;
    case AccessibilityNodeInfoCompat.ACTION_COPY:
      return R.drawable.ic_copy;
    case AccessibilityNodeInfoCompat.ACTION_PASTE:
      return R.drawable.ic_paste;
    case TextEditingUtils.ACTION_DELETE_TEXT:
      return R.drawable.ic_delete_text;
    case TextEditingUtils.ACTION_UNDO:
      return R.drawable.ic_undo;
    case TextEditingUtils.ACTION_REDO:
      return R.drawable.ic_redo;
    default:
      // We don't know what the action is. Don't show an icon.
      return 0;
  }
}
 
Example 10
Source File: ActionBuildingUtils.java    From talkback with Apache License 2.0 4 votes vote down vote up
/** Return if the given action id represents a movement action. */
private static boolean isMovementAction(int actionId) {
  return (actionId == AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY)
      || (actionId == AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
}
 
Example 11
Source File: CursorGranularityManager.java    From talkback with Apache License 2.0 4 votes vote down vote up
/**
 * Attempt to navigate within the currently locked node at the current granularity. You should
 * call either {@link #setGranularityAt} or {@link #adjustGranularityAt} before calling this
 * method.
 *
 * @return The result of navigation, which is always {@link #NOT_SUPPORTED} if there is no locked
 *     node or if the requested granularity is {@link CursorGranularity#DEFAULT}.
 */
public int navigate(int action, EventId eventId) {
  LogUtils.d(TAG, "Navigate with action: " + AccessibilityNodeInfoUtils.actionToString(action));
  if (lockedNode == null) {
    return NOT_SUPPORTED;
  }

  final CursorGranularity requestedGranularity = currentGranularity;
  if ((requestedGranularity == null) || (requestedGranularity == CursorGranularity.DEFAULT)) {
    return NOT_SUPPORTED;
  }

  // Handle web granularity separately.
  if (requestedGranularity.isWebGranularity()) {
    LogUtils.d(TAG, "Granularity navigation handled by web view");
    return navigateWeb(action, requestedGranularity, eventId);
  }

  final Bundle arguments = new Bundle();
  final int count = navigableNodes.size();
  final int increment;
  boolean forward = false;

  switch (action) {
    case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
      increment = 1;
      forward = true;
      if (currentNodeIndex < 0) {
        currentNodeIndex++;
      }
      break;
    case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
      increment = -1;
      if (currentNodeIndex >= count) {
        currentNodeIndex--;
      }
      break;
    default:
      return NOT_SUPPORTED;
  }

  while ((currentNodeIndex >= 0) && (currentNodeIndex < count)) {
    if (isSelectionModeActive()) {
      arguments.putBoolean(
          AccessibilityNodeInfoCompat.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN, true);
    }

    arguments.putInt(
        AccessibilityNodeInfoCompat.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
        requestedGranularity.value);

    final AccessibilityNodeInfoCompat currentNode = navigableNodes.get(currentNodeIndex);

    if (GranularityTraversal.shouldHandleGranularityTraversalInTalkback(currentNode, service)) {
      if (granularityTraversal.traverseAtGranularity(
          currentNode, requestedGranularity.value, forward, eventId)) {
        return SUCCESS;
      }
    } else if (PerformActionUtils.performAction(currentNode, action, arguments, eventId)) {
      LogUtils.d(TAG, "Granularity traversal handled by framework");
      return SUCCESS;
    }

    LogUtils.v(
        TAG, "Failed to move with granularity %s, trying next node", requestedGranularity.name());

    // If movement failed, advance to the next node and try again.
    currentNodeIndex += increment;
  }

  return HIT_EDGE;
}
 
Example 12
Source File: CursorGranularityManager.java    From talkback with Apache License 2.0 4 votes vote down vote up
/**
 * Attempts to navigate web content at the specified granularity.
 *
 * @param action The accessibility action to perform, one of:
 *     <ul>
 *       <li>{@link AccessibilityNodeInfoCompat#ACTION_NEXT_AT_MOVEMENT_GRANULARITY}
 *       <li>{@link AccessibilityNodeInfoCompat#ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY}
 *     </ul>
 *
 * @param granularity The granularity at which to navigate.
 * @return The result of navigation, which is always {@link #NOT_SUPPORTED} if there is no locked
 *     node or if the requested granularity is {@link CursorGranularity#DEFAULT}.
 */
private int navigateWeb(int action, CursorGranularity granularity, EventId eventId) {
  final int movementType;
  final String htmlElementType;

  switch (action) {
    case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
      movementType = WebInterfaceUtils.DIRECTION_FORWARD;
      break;
    case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
      movementType = WebInterfaceUtils.DIRECTION_BACKWARD;
      break;
    default:
      return NOT_SUPPORTED;
  }

  switch (granularity) {
    case WEB_HEADING:
      htmlElementType = WebInterfaceUtils.HTML_ELEMENT_MOVE_BY_HEADING;
      break;
    case WEB_LINK:
      htmlElementType = WebInterfaceUtils.HTML_ELEMENT_MOVE_BY_LINK;
      break;
    case WEB_LIST:
      htmlElementType = WebInterfaceUtils.HTML_ELEMENT_MOVE_BY_LIST;
      break;
    case WEB_CONTROL:
      htmlElementType = WebInterfaceUtils.HTML_ELEMENT_MOVE_BY_CONTROL;
      break;
    case WEB_LANDMARK:
      htmlElementType = WebInterfaceUtils.HTML_ELEMENT_MOVE_BY_LANDMARK;
      break;
    default:
      return NOT_SUPPORTED;
  }

  if (!WebInterfaceUtils.performNavigationToHtmlElementAction(
      lockedNode, movementType, htmlElementType, eventId)) {
    return HIT_EDGE;
  }

  return SUCCESS;
}
 
Example 13
Source File: WebInterfaceUtils.java    From talkback with Apache License 2.0 3 votes vote down vote up
/**
 * Sends an instruction to ChromeVox to move within a page at a specified granularity in a given
 * direction.
 *
 * <p>WARNING: Calling this method with a source node of {@link android.webkit.WebView} has the
 * side effect of closing the IME if currently displayed.
 *
 * @param node The node containing web content with ChromeVox to which the message should be sent
 * @param direction {@link #DIRECTION_FORWARD} or {@link #DIRECTION_BACKWARD}
 * @param granularity The granularity with which to move or a special case argument.
 * @return {@code true} if the action was performed, {@code false} otherwise.
 */
public static boolean performNavigationAtGranularityAction(
    AccessibilityNodeInfoCompat node, int direction, int granularity, EventId eventId) {
  final int action =
      (direction == DIRECTION_FORWARD)
          ? AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY
          : AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY;
  final Bundle args = new Bundle();
  args.putInt(AccessibilityNodeInfoCompat.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT, granularity);
  return PerformActionUtils.performAction(node, action, args, eventId);
}