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

The following examples show how to use androidx.core.view.accessibility.AccessibilityNodeInfoCompat#setRoleDescription() . 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: 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 2
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 3
Source File: ComponentAccessibilityDelegate.java    From litho with Apache License 2.0 4 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat node) {
  final MountItem mountItem = getAccessibleMountItem(mView);

  if (mNodeInfo != null && mNodeInfo.getOnInitializeAccessibilityNodeInfoHandler() != null) {
    EventDispatcherUtils.dispatchOnInitializeAccessibilityNodeInfoEvent(
        mNodeInfo.getOnInitializeAccessibilityNodeInfoHandler(), host, node, mSuperDelegate);
  } else if (mountItem != null) {
    super.onInitializeAccessibilityNodeInfo(host, node);
    // Coalesce the accessible mount item's information with the
    // the root host view's as they are meant to behave as a single
    // node in the accessibility framework.
    final Component component = getLayoutOutput(mountItem).getComponent();
    component.onPopulateAccessibilityNode(host, node);
  } else {
    super.onInitializeAccessibilityNodeInfo(host, node);
  }

  // If an accessibilityRole has been set, set the className here.  It's important that this
  // happens *after* any calls to super, since the super call will set a className of its own and
  // override this one.
  if (mNodeInfo != null && mNodeInfo.getAccessibilityRole() != null) {
    node.setClassName(mNodeInfo.getAccessibilityRole());
  }

  if (mNodeInfo != null && mNodeInfo.getAccessibilityRoleDescription() != null) {
    node.setRoleDescription(mNodeInfo.getAccessibilityRoleDescription());

    // if no role was explicitly specified, set a role of "NONE".  This allows the role
    // description to still be announced without changing any other behavior.
    if (mNodeInfo.getAccessibilityRole() == null) {
      node.setClassName(AccessibilityRole.NONE);
    }
  }

  if (mNodeInfo != null
      && mNodeInfo.getAccessibilityHeadingState() != NodeInfo.ACCESSIBILITY_HEADING_UNSET) {
    node.setHeading(
        mNodeInfo.getAccessibilityHeadingState() == NodeInfo.ACCESSIBILITY_HEADING_SET_TRUE);
  }
}