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

The following examples show how to use androidx.core.view.accessibility.AccessibilityNodeInfoCompat#wrap() . 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: NumberPicker.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
private AccessibilityNodeInfo createAccessibiltyNodeInfoForInputText(
        int left, int top, int right, int bottom) {
    AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.wrap(mInputText.createAccessibilityNodeInfo());
    info.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
    if (mAccessibilityFocusedView != VIRTUAL_VIEW_ID_INPUT) {
        info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
    }
    if (mAccessibilityFocusedView == VIRTUAL_VIEW_ID_INPUT) {
        info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    }
    Rect boundsInParent = mTempRect;
    boundsInParent.set(left, top, right, bottom);
    info.setVisibleToUser(isVisibleToUser(boundsInParent));
    info.setBoundsInParent(boundsInParent);
    Rect boundsInScreen = boundsInParent;
    int[] locationOnScreen = mTempArray;
    getLocationOnScreen(locationOnScreen);
    boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
    info.setBoundsInScreen(boundsInScreen);
    return info.unwrap();
}
 
Example 2
Source File: BottomNavigationItemView.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info) {
  super.onInitializeAccessibilityNodeInfo(info);
  if (badgeDrawable != null && badgeDrawable.isVisible()) {
    CharSequence customContentDescription = itemData.getTitle();
    if (!TextUtils.isEmpty(itemData.getContentDescription())) {
      customContentDescription = itemData.getContentDescription();
    }
    info.setContentDescription(
        customContentDescription + ", " + badgeDrawable.getContentDescription());
  }
  AccessibilityNodeInfoCompat infoCompat = AccessibilityNodeInfoCompat.wrap(info);
  infoCompat.setCollectionItemInfo(
      CollectionItemInfoCompat.obtain(
          /* rowIndex= */ 0,
          /* rowSpan= */ 1,
          /* columnIndex= */ getItemPosition(),
          /* columnSpan= */ 1,
          /* heading= */ false,
          /* selected= */ isSelected()));
  if (isSelected()) {
    infoCompat.setClickable(false);
    infoCompat.removeAction(AccessibilityActionCompat.ACTION_CLICK);
  }
  infoCompat.setRoleDescription(getResources().getString(R.string.item_view_role_description));
}
 
Example 3
Source File: TabLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info) {
  super.onInitializeAccessibilityNodeInfo(info);
  if (badgeDrawable != null && badgeDrawable.isVisible()) {
    CharSequence customContentDescription = getContentDescription();
    info.setContentDescription(
        customContentDescription + ", " + badgeDrawable.getContentDescription());
  }
  AccessibilityNodeInfoCompat infoCompat = AccessibilityNodeInfoCompat.wrap(info);
  infoCompat.setCollectionItemInfo(
      CollectionItemInfoCompat.obtain(
          /* rowIndex= */ 0,
          /* rowSpan= */ 1,
          /* columnIndex= */ tab.getPosition(),
          /* columnSpan= */ 1,
          /* heading= */ false,
          /* selected= */ isSelected()));
  if (isSelected()) {
    infoCompat.setClickable(false);
    infoCompat.removeAction(AccessibilityActionCompat.ACTION_CLICK);
  }
  infoCompat.setRoleDescription("Tab");
}
 
Example 4
Source File: BottomNavigationMenuView.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info) {
  super.onInitializeAccessibilityNodeInfo(info);
  AccessibilityNodeInfoCompat infoCompat = AccessibilityNodeInfoCompat.wrap(info);
  infoCompat.setCollectionInfo(
      CollectionInfoCompat.obtain(
          /* rowCount= */ 1,
          /* columnCount= */ menu.getVisibleItems().size(),
          /* hierarchical= */ false,
          /* selectionMode = */ CollectionInfoCompat.SELECTION_MODE_SINGLE));
}
 
Example 5
Source File: MaterialButtonToggleGroup.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info) {
  super.onInitializeAccessibilityNodeInfo(info);
  AccessibilityNodeInfoCompat infoCompat = AccessibilityNodeInfoCompat.wrap(info);
  infoCompat.setCollectionInfo(
      CollectionInfoCompat.obtain(
          /* rowCount= */ 1,
          /* columnCount= */ getVisibleButtonCount(),
          /* hierarchical= */ false,
          /* selectionMode = */ isSingleSelection()
              ? CollectionInfoCompat.SELECTION_MODE_SINGLE
              : CollectionInfoCompat.SELECTION_MODE_MULTIPLE));
}
 
Example 6
Source File: TabLayout.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info) {
  super.onInitializeAccessibilityNodeInfo(info);
  AccessibilityNodeInfoCompat infoCompat = AccessibilityNodeInfoCompat.wrap(info);
  infoCompat.setCollectionInfo(
      CollectionInfoCompat.obtain(
          /* rowCount= */ 1,
          /* columnCount= */ getTabCount(),
          /* hierarchical= */ false,
          /* selectionMode = */ CollectionInfoCompat.SELECTION_MODE_SINGLE));
}
 
Example 7
Source File: ChipGroup.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info) {
  super.onInitializeAccessibilityNodeInfo(info);
  AccessibilityNodeInfoCompat infoCompat = AccessibilityNodeInfoCompat.wrap(info);
  // -1 for an unknown number of columns in a reflowing layout
  int columnCount = isSingleLine() ? getChipCount() : -1;
  infoCompat.setCollectionInfo(
      CollectionInfoCompat.obtain(
          /* rowCount= */ getRowCount(),
          /* columnCount= */ columnCount,
          /* hierarchical= */ false,
          /* selectionMode = */ isSingleSelection()
              ? CollectionInfoCompat.SELECTION_MODE_SINGLE
              : CollectionInfoCompat.SELECTION_MODE_MULTIPLE));
}
 
Example 8
Source File: Chip.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info) {
  super.onInitializeAccessibilityNodeInfo(info);
  if (isCheckable() || isClickable()) {
    info.setClassName(
        isCheckable()
            ? COMPOUND_BUTTON_ACCESSIBILITY_CLASS_NAME
            : BUTTON_ACCESSIBILITY_CLASS_NAME);
  } else {
    info.setClassName(GENERIC_VIEW_ACCESSIBILITY_CLASS_NAME);
  }
  info.setCheckable(isCheckable());
  info.setClickable(isClickable());

  if (getParent() instanceof ChipGroup) {
    ChipGroup chipGroup = ((ChipGroup) getParent());
    AccessibilityNodeInfoCompat infoCompat = AccessibilityNodeInfoCompat.wrap(info);
    // -1 for unknown column indices in a reflowing layout
    int columnIndex = chipGroup.isSingleLine() ? chipGroup.getIndexOfChip(this) : -1;
    infoCompat.setCollectionItemInfo(
        CollectionItemInfoCompat.obtain(
            /* rowIndex= */ chipGroup.getRowIndex(this),
            /* rowSpan= */ 1,
            /* columnIndex= */ columnIndex,
            /* columnSpan= */ 1,
            /* heading= */ false,
            /* selected= */ isChecked()));
  }
}
 
Example 9
Source File: AccessibilityNode.java    From talkback with Apache License 2.0 5 votes vote down vote up
/** Create and use compat wrapper on demand. */
private AccessibilityNodeInfoCompat getCompat() {
  if (isRecycled()) {
    throwError("getCompat() called on node already recycled by %s", recycledBy);
  }
  if (nodeCompat == null) {
    nodeCompat = AccessibilityNodeInfoCompat.wrap(nodeBare); // Available since compat 26.1.0
  }
  return nodeCompat;
}
 
Example 10
Source File: AccessibilityNodeInfoUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
/** Checks whether the given node is still in the window. */
public static boolean isInWindow(
    AccessibilityNodeInfoCompat checkingNode, @Nullable AccessibilityWindowInfo windowInfo) {
  if (windowInfo == null) {
    return false;
  }

  AccessibilityNodeInfoCompat root = AccessibilityNodeInfoCompat.wrap(windowInfo.getRoot());
  try {
    return hasDescendant(root, checkingNode);
  } finally {
    recycleNodes(root);
  }
}
 
Example 11
Source File: SwitchAccessNodeCompat.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the developer-provided text inside the current node.
 *
 * @return the developer-provided text inside the current node
 */
public CharSequence getNodeText() {
  if (!isOnScreenAndVisibleToUser()) {
    return "";
  }

  if (nodeTextUsingTextFromChildrenIfEmpty == null) {
    AccessibilityNodeInfoCompat compat = AccessibilityNodeInfoCompat.wrap(unwrap());
    nodeTextUsingTextFromChildrenIfEmpty = FeedbackUtils.getNodeText(compat);
  }

  return nodeTextUsingTextFromChildrenIfEmpty;
}
 
Example 12
Source File: AccessibilityNodeInfoUtils.java    From talkback with Apache License 2.0 3 votes vote down vote up
/**
 * A wrapper over AccessibilityNodeInfoCompat constructor, so that we can add any desired error
 * checking and memory management.
 *
 * @param nodeInfo The AccessibilityNodeInfo which will be wrapped. The caller retains the
 *     responsibility to recycle nodeInfo.
 * @return Encapsulating AccessibilityNodeInfoCompat, or null if input is null.
 */
public static @PolyNull AccessibilityNodeInfoCompat toCompat(
    @PolyNull AccessibilityNodeInfo nodeInfo) {
  if (nodeInfo == null) {
    return null;
  }
  return AccessibilityNodeInfoCompat.wrap(nodeInfo);
}