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

The following examples show how to use androidx.core.view.accessibility.AccessibilityNodeInfoCompat#ACTION_CLICK . 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: KeyboardAccessibilityNodeProvider.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
/**
 * Performs the specified accessibility action for the given key.
 *
 * @param key The on which to perform the action.
 * @param action The action to perform.
 * @return The result of performing the action, or false if the action is not supported.
 */
boolean performActionForKey(final Key key, final int action) {
    switch (action) {
    case AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS:
        mAccessibilityFocusedView = getVirtualViewIdOf(key);
        sendAccessibilityEventForKey(
                key, AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
        return true;
    case AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
        mAccessibilityFocusedView = UNDEFINED;
        sendAccessibilityEventForKey(
                key, AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
        return true;
    case AccessibilityNodeInfoCompat.ACTION_CLICK:
        sendAccessibilityEventForKey(key, AccessibilityEvent.TYPE_VIEW_CLICKED);
        mDelegate.performClickOn(key);
        return true;
    case AccessibilityNodeInfoCompat.ACTION_LONG_CLICK:
        sendAccessibilityEventForKey(key, AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
        mDelegate.performLongClickOn(key);
        return true;
    default:
        return false;
    }
}
 
Example 2
Source File: Chip.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean onPerformActionForVirtualView(
    int virtualViewId, int action, Bundle arguments) {
  if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) {
    if (virtualViewId == CHIP_BODY_VIRTUAL_ID) {
      return performClick();
    } else if (virtualViewId == CLOSE_ICON_VIRTUAL_ID) {
      return performCloseIconClick();
    }
  }
  return false;
}
 
Example 3
Source File: ActionVariables.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getBoolean(int variableId) {
  switch (variableId) {
    case ACTION_IS_CUSTOM_ACTION:
      return AccessibilityNodeInfoUtils.isCustomAction(mAction);
    case ACTION_IS_CLICK:
      return mAction.getId() == AccessibilityNodeInfoCompat.ACTION_CLICK;
    case ACTION_IS_LONG_CLICK:
      return mAction.getId() == AccessibilityNodeInfoCompat.ACTION_LONG_CLICK;
    default:
      return mParentVariables.getBoolean(variableId);
  }
}
 
Example 4
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 5
Source File: RadialMenuView.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean performActionForItem(RadialMenuItem item, int action) {
  switch (action) {
    case AccessibilityNodeInfoCompat.ACTION_CLICK:
      item.onClickPerformed();
      return true;
  }

  return false;
}
 
Example 6
Source File: TimePickerClockDelegate.java    From DateTimePicker with Apache License 2.0 4 votes vote down vote up
public ClickActionDelegate(Context context, int resId) {
    mClickAction = new AccessibilityNodeInfoCompat.AccessibilityActionCompat(AccessibilityNodeInfoCompat.ACTION_CLICK, context.getString(resId));
    /*mClickAction = new AccessibilityAction(
            AccessibilityNodeInfo.ACTION_CLICK, context.getString(resId));*/
}
 
Example 7
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 8
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 9
Source File: ActionBuildingUtils.java    From talkback with Apache License 2.0 4 votes vote down vote up
/**
 * Get the {@link SwitchAccessActionBase}s that the given {@link SwitchAccessNodeCompat} can
 * perform.
 *
 * <p>Note: methods #hasMultipleActions and #isActionSupportedByNode should be updated if the
 * logic of this one changes.
 *
 * @param service The {@link AccessibilityService} used to check whether auto-select is enabled
 * @param nodeCompat The {@link SwitchAccessNodeCompat} to get actions for
 * @param actionTimeline The {@link SwitchAccessActionTimeline} used for the given {@code
 *     nodeCompat) if it does not already have one. The timeline is used to check if the {@code
 *     nodeCompat} has undo or redo actions
 * @return A list of {@link SwitchAccessActionBase}s that the given {@link SwitchAccessNodeCompat}
 *     can perform
 */
public static List<SwitchAccessActionBase> getActionsForNode(
    AccessibilityService service,
    SwitchAccessNodeCompat nodeCompat,
    SwitchAccessActionTimeline actionTimeline) {
  // Get the latest text in this node. If the user types something without using the switches, the
  // node doesn't get updated automatically.
  nodeCompat.refresh();
  List<SwitchAccessActionBase> actions = new ArrayList<>();
  List<AccessibilityActionCompat> originalActions = nodeCompat.getActionList();
  boolean autoselectEnabled = SwitchAccessPreferenceUtils.isAutoselectEnabled(service);
  for (AccessibilityActionCompat action : originalActions) {
    if (autoselectEnabled && (action.getId() == AccessibilityNodeInfoCompat.ACTION_CLICK)) {
      actions.clear();
      actions.add(new SwitchAccessAction(nodeCompat, action));
      return actions;
    }
    if (isActionSupportedBySwitchAccess(action)) {
      if (isMovementAction(action.getId())) {
        actions.addAll(getSwitchAccessMovementActionsForNode(nodeCompat, action));
      } else if (action.getId() == AccessibilityNodeInfoCompat.ACTION_SET_SELECTION) {
        actions.addAll(getSwitchAccessActionsForSetSelectionAction(nodeCompat, action));
      } else {
        actions.add(new SwitchAccessAction(nodeCompat, action));
      }
    }
  }

  // Get a copy of nodeCompat so that if it is recycled before the corresponding timeline is
  // removed, the timeline doesn't act on a recycled node.
  SwitchAccessNodeCompat node = nodeCompat.obtainCopy();
  SwitchAccessActionTimeline switchAccessActionTimeline =
      (SwitchAccessActionTimeline)
          UndoRedoManager.getInstance(RecycleBehavior.DO_RECYCLE_NODES)
              .getTimelineForNodeCompat(node, actionTimeline);
  if (switchAccessActionTimeline == null) {
    node.recycle();
  } else if (node.isEditable()) {
    if (switchAccessActionTimeline.canPerformUndo()) {
      actions.add(new SwitchAccessAction(node, TextEditingUtils.ACTION_UNDO));
    }
    if (switchAccessActionTimeline.canPerformRedo()) {
      actions.add(new SwitchAccessAction(node, TextEditingUtils.ACTION_REDO));
    }
  }

  return actions;
}