Java Code Examples for androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat#getId()
The following examples show how to use
androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat#getId() .
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: ActionBuildingUtils.java From talkback with Apache License 2.0 | 6 votes |
/** * Returns whether the given {@link AccessibilityActionCompat} is supported by the given {@link * SwitchAccessNodeCompat}. If the action is a movement action, return {@code true} if the given * node is editable and has nonempty text. If the action is a selection action, return {@code * true} if the given node is an EditText and has nonempty text. Otherwise, all other supported * actions are possible. * * <p>Note: methods #hasMultipleActions and #getActionsForNode should be updated if the logic of * this one changes. * * @param action The action to check * @param nodeCompat The node for which we will check whether it is possible to perform the * provided action * @return {@code true} if the given {@link AccessibilityActionCompat} is supported by the given * {@link SwitchAccessNodeCompat} */ public static boolean isActionSupportedByNode( AccessibilityActionCompat action, SwitchAccessNodeCompat nodeCompat) { if (isActionSupportedBySwitchAccess(action)) { boolean isMovementOption = isMovementAction(action.getId()); boolean isSelection = (action.getId() == AccessibilityNodeInfoCompat.ACTION_SET_SELECTION); if (!isMovementOption && !isSelection) { return true; } boolean textIsEmpty = TextUtils.isEmpty(nodeCompat.getText()); boolean canMoveInNode = isMovementOption && nodeCompat.isEditable() && !textIsEmpty; if (canMoveInNode) { return true; } boolean isSelectingNonEmptyEditTextNode = isSelection && (Role.getRole(nodeCompat) == Role.ROLE_EDIT_TEXT) && !textIsEmpty; if (isSelectingNonEmptyEditTextNode) { return true; } } return false; }
Example 2
Source File: AccessibilityUtils.java From material-components-android with Apache License 2.0 | 5 votes |
/** Used to check onInitializeAccessibilityNodeInfo */ public static boolean hasAction( AccessibilityNodeInfoCompat info, AccessibilityActionCompat action) { List<AccessibilityActionCompat> actions = info.getActionList(); for (int i = 0; i < actions.size(); i++) { if (actions.get(i).getId() == action.getId()) { return true; } } return false; }
Example 3
Source File: AccessibilityNodeInfoUtils.java From talkback with Apache License 2.0 | 5 votes |
/** * Returns {@code true} if the node supports the specified action. This method supports actions * introduced in API level 21 and later. However, it does not support bitmasks. */ public static boolean supportsAction(AccessibilityNodeInfoCompat node, int action) { // New actions in >= API 21 won't appear in getActions() but in getActionList(). // On Lollipop+ devices, pre-API 21 actions will also appear in getActionList(). List<AccessibilityActionCompat> actions = node.getActionList(); int size = actions.size(); for (int i = 0; i < size; ++i) { AccessibilityActionCompat actionCompat = actions.get(i); if (actionCompat.getId() == action) { return true; } } return false; }
Example 4
Source File: ActionBuildingUtils.java From talkback with Apache License 2.0 | 5 votes |
private static boolean isActionSupportedBySwitchAccess(AccessibilityActionCompat action) { // White-listed framework actions if (action.getId() <= SYSTEM_ACTION_MAX) { return FRAMEWORK_ACTIONS.contains(action.getId()); } // Support custom actions with proper labels. return !TextUtils.isEmpty(action.getLabel()); }
Example 5
Source File: AccessibilityNodeInfoUtils.java From talkback with Apache License 2.0 | 4 votes |
public static boolean isCustomAction(AccessibilityActionCompat action) { return action.getId() > SYSTEM_ACTION_MAX; }
Example 6
Source File: ActionBuildingUtils.java From talkback with Apache License 2.0 | 4 votes |
/** * 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; }
Example 7
Source File: OptionScanHighlighter.java From talkback with Apache License 2.0 | 4 votes |
@Override public void run() { int[] layoutCoordinates = new int[2]; for (TreeScanLeafNode node : nodes) { Rect rect = node.getRectForNodeHighlight(); if (rect == null) { continue; } int halfStrokeWidth = (int) highlightPaint.getStrokeWidth() / 2; GradientDrawable mainHighlightDrawable = getHighlightDrawable(halfStrokeWidth, rect); @KeyFor("MAIN_TO_OUTER_HIGHLIGHT_COLOR_MAP") int mainPaintColor = highlightPaint.getColor(); mainHighlightDrawable.setStroke(halfStrokeWidth, mainPaintColor); GradientDrawable outerHighlightDrawable = null; if (MAIN_TO_OUTER_HIGHLIGHT_COLOR_MAP.containsKey(mainPaintColor)) { outerHighlightDrawable = getHighlightDrawable(halfStrokeWidth, rect); outerHighlightDrawable.setStroke( halfStrokeWidth / 2, MAIN_TO_OUTER_HIGHLIGHT_COLOR_MAP.get(mainPaintColor)); } // Determine which scroll arrows we should show. boolean shouldShowUpArrow = false; boolean shouldShowDownArrow = false; boolean shouldShowRightArrow = false; boolean shouldShowLeftArrow = false; boolean supportsScrollForward = false; boolean supportsScrollBackward = false; if (FeatureFlags.scrollArrows() && (VERSION.SDK_INT >= VERSION_CODES.N) && node.isScrollable()) { for (AccessibilityActionCompat action : node.getActionList()) { if (action.getId() == AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) { supportsScrollBackward = true; } else if (action.getId() == AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) { supportsScrollForward = true; } else if (VERSION.SDK_INT >= VERSION_CODES.N_MR1) { if (action.getId() == AccessibilityActionCompat.ACTION_SCROLL_UP.getId()) { shouldShowUpArrow = true; } else if (action.getId() == AccessibilityActionCompat.ACTION_SCROLL_DOWN.getId()) { shouldShowDownArrow = true; } else if (action.getId() == AccessibilityActionCompat.ACTION_SCROLL_RIGHT.getId()) { shouldShowRightArrow = true; } else if (action.getId() == AccessibilityActionCompat.ACTION_SCROLL_LEFT.getId()) { shouldShowLeftArrow = true; } } } // If only the less granular version of a scroll action is supported, show the possible // scroll directions for that scroll action. if (supportsScrollForward && !shouldShowDownArrow && !shouldShowRightArrow) { shouldShowDownArrow = true; shouldShowRightArrow = true; } if (supportsScrollBackward && !shouldShowUpArrow && !shouldShowLeftArrow) { shouldShowUpArrow = true; shouldShowLeftArrow = true; } } ImageView imageView = new ImageView(overlayController.getContext()); imageView.setBackground( getFinalHighlightDrawable( shouldShowUpArrow, shouldShowDownArrow, shouldShowRightArrow, shouldShowLeftArrow, mainHighlightDrawable, outerHighlightDrawable)); // Align image with node we're highlighting final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(rect.width(), rect.height()); layoutParams.leftMargin = rect.left - layoutCoordinates[0]; layoutParams.topMargin = rect.top - layoutCoordinates[1]; imageView.setLayoutParams(layoutParams); overlayController.addViewAndShow(imageView); } }
Example 8
Source File: RuleCustomAction.java From talkback with Apache License 2.0 | 4 votes |
/** * Populates a menu with the context menu items for a node, searching up its ancestor hierarchy if * the current node has no custom actions. * * @param service The parent service. * @param menuItemBuilder builder to create menu items * @param node The node to process * @param includeAncestors sets to {@code false} not to search its ancestor */ private void populateMenuItemsForNode( TalkBackService service, ContextMenuItemBuilder menuItemBuilder, AccessibilityNodeInfoCompat node, List<ContextMenuItem> menu, boolean includeAncestors) { if (node == null) { return; } for (AccessibilityActionCompat action : node.getActionList()) { CharSequence label = ""; int id = action.getId(); // On Android O, sometime TalkBack get fails on performing actions (mostly on notification // shelf). And deferring the action make the but unreproducible. See for details. boolean deferToWindowsSrable = false; if (AccessibilityNodeInfoUtils.isCustomAction(action)) { label = action.getLabel(); } else if (id == AccessibilityNodeInfoCompat.ACTION_DISMISS) { label = service.getString(R.string.title_action_dismiss); deferToWindowsSrable = true; } else if (id == AccessibilityNodeInfoCompat.ACTION_EXPAND) { label = service.getString(R.string.title_action_expand); deferToWindowsSrable = true; } else if (id == AccessibilityNodeInfoCompat.ACTION_COLLAPSE) { label = service.getString(R.string.title_action_collapse); deferToWindowsSrable = true; } if (TextUtils.isEmpty(label)) { continue; } ContextMenuItem item = menuItemBuilder.createMenuItem(service, Menu.NONE, id, Menu.NONE, label); item.setOnMenuItemClickListener( new CustomMenuItem(id, AccessibilityNodeInfoCompat.obtain(node))); if ((Build.VERSION.SDK_INT == VERSION_CODES.O || Build.VERSION.SDK_INT == VERSION_CODES.O_MR1) && deferToWindowsSrable) { item.setDeferredType(DeferredType.WINDOWS_STABLE); } item.setCheckable(false); menu.add(item); } if (!includeAncestors) { return; } if (menu.isEmpty()) { populateMenuItemsForNode( service, menuItemBuilder, node.getParent(), menu, /* includeAncestors= */ true); } }
Example 9
Source File: SwitchAccessAction.java From talkback with Apache License 2.0 | 2 votes |
/** * @param nodeCompat The {@link SwitchAccessNodeCompat} to perform this action on * @param actionCompat The {@link AccessibilityActionCompat} whose id and label to use to identify * this action * @param args Additional arguments to use when performing this action */ public SwitchAccessAction( SwitchAccessNodeCompat nodeCompat, AccessibilityActionCompat actionCompat, Bundle args) { this(nodeCompat, actionCompat.getId(), actionCompat.getLabel(), args); }
Example 10
Source File: SwitchAccessActionGroup.java From talkback with Apache License 2.0 | 2 votes |
/** * @param actionCompat The {@link AccessibilityActionCompat} whose id and label identify this * action group */ public SwitchAccessActionGroup(AccessibilityActionCompat actionCompat) { this(actionCompat.getId(), actionCompat.getLabel()); }