Java Code Examples for androidx.core.view.accessibility.AccessibilityNodeInfoCompat#getClassName()

The following examples show how to use androidx.core.view.accessibility.AccessibilityNodeInfoCompat#getClassName() . 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: AccessibilityNodeInfoUtils.java    From talkback with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the generating class of an
 * {@link AccessibilityNodeInfoCompat} matches a given {@link Class} by
 * type.
 *
 * @param node A sealed {@link AccessibilityNodeInfoCompat} dispatched by
 *            the accessibility framework.
 * @param referenceClass A {@link Class} to match by type or inherited type.
 * @return {@code true} if the {@link AccessibilityNodeInfoCompat} object
 *         matches the {@link Class} by type or inherited type,
 *         {@code false} otherwise.
 */
public static boolean nodeMatchesClassByType(
        Context context, AccessibilityNodeInfoCompat node, Class<?> referenceClass) {
    if ((node == null) || (referenceClass == null)) {
        return false;
    }

    // Attempt to take a shortcut.
    final CharSequence nodeClassName = node.getClassName();
    if (TextUtils.equals(nodeClassName, referenceClass.getName())) {
        return true;
    }

    final ClassLoadingManager loader = ClassLoadingManager.getInstance();
    final CharSequence appPackage = node.getPackageName();
    return loader.checkInstanceOf(context, nodeClassName, appPackage, referenceClass);
}
 
Example 2
Source File: AccessibilityNodeInfoUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
private static boolean nodeMatchesAnyClassName(
    @Nullable AccessibilityNodeInfoCompat node, CharSequence... classNames) {
  if (node == null || node.getClassName() == null || classNames == null) {
    return false;
  }

  for (CharSequence name : classNames) {
    if (TextUtils.equals(node.getClassName(), name)) {
      return true;
    }
  }

  return false;
}
 
Example 3
Source File: NodeDescription.java    From talkback with Apache License 2.0 5 votes vote down vote up
static NodeDescription obtain(AccessibilityNodeInfoCompat node) {
  CollectionItemInfoCompat itemInfo = node.getCollectionItemInfo();
  return new NodeDescription(
      node.getClassName(),
      node.getViewIdResourceName(),
      itemInfo == null ? INDEX_TYPE_RAW : INDEX_TYPE_COLLECTION,
      itemInfo == null ? UNDEFINED_INDEX : itemInfo.getRowIndex(),
      itemInfo == null ? UNDEFINED_INDEX : itemInfo.getColumnIndex(),
      getRawIndexInParent(node),
      node.hashCode());
}
 
Example 4
Source File: NodeActionMenuItem.java    From talkback with Apache License 2.0 4 votes vote down vote up
/**
 * @param service AccessibilityService used to retrieve strings from resources and to execute
 *     actions
 * @param nodeCompat Node on which the provided {@link SwitchAccessAction} is to be performed
 * @param action Action to be performed on the provided {@link AccessibilityNodeInfoCompat}
 */
public NodeActionMenuItem(
    AccessibilityService service,
    final AccessibilityNodeInfoCompat nodeCompat,
    final SwitchAccessAction action,
    final ActionTimeline actionTimeline,
    @Nullable final SelectMenuItemListener selectMenuItemListener) {

  onClickListener =
      new MenuItemOnClickListener() {
        @Override
        public void onClick() {
          action.execute(service);

          // Add action to the timeline if it's undoable.
          if (action.isUndoable()) {
            ActionTimeline timeline =
                UndoRedoManager.getInstance(RecycleBehavior.DO_RECYCLE_NODES)
                    .getTimelineForNodeCompat(nodeCompat, actionTimeline);
            if (timeline != null) {
              timeline.newActionPerformed(action);
            }
          }

          CharSequence nodeClassName = nodeCompat.getClassName();
          if ((selectMenuItemListener != null)
              && (nodeClassName != null)
              && !MenuButton.class.getName().contentEquals(nodeClassName)) {
            // Do not call SelectMenuItemListener if the associated AccessibilityNodeInfoCompat
            // corresponds to a Switch Access menu item. This method will be called whenever a
            // SwitchAccessAction is performed. When a menu item, for example "Scroll Forward" is
            // selected, two SwitchAccessActions will be performed. The first action is
            // ACTION_MENU_CLICK, which corresponds to clicking the "Scroll Forward" menu item.
            // The second action is ACTION_MENU_SCROLL_FORWARD, which corresponds to scrolling the
            // item that triggers the Switch Access menu. We should only log the second action, as
            // this is the action that is triggered by clicking the menu item.
            selectMenuItemListener.onMenuItemSelected(getMenuItemForAction(action));
          }
        }
      };
  this.service = service;
  this.action = action;
}