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

The following examples show how to use androidx.core.view.accessibility.AccessibilityNodeInfoCompat#setCollectionItemInfo() . 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: PreferenceCategory.java    From MaterialPreference with Apache License 2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfoCompat info) {
    super.onInitializeAccessibilityNodeInfo(info);

    CollectionItemInfoCompat existingItemInfo = info.getCollectionItemInfo();
    if (existingItemInfo == null) {
        return;
    }

    final CollectionItemInfoCompat newItemInfo = CollectionItemInfoCompat.obtain(
            existingItemInfo.getRowIndex(),
            existingItemInfo.getRowSpan(),
            existingItemInfo.getColumnIndex(),
            existingItemInfo.getColumnSpan(),
            true /* heading */,
            existingItemInfo.isSelected());
    info.setCollectionItemInfo(newItemInfo);
}
 
Example 4
Source File: GridLayoutManager.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler,
        RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
    ViewGroup.LayoutParams lp = host.getLayoutParams();
    if (!(lp instanceof LayoutParams)) {
        super.onInitializeAccessibilityNodeInfoForItem(host, info);
        return;
    }
    LayoutParams glp = (LayoutParams) lp;
    int spanGroupIndex = getSpanGroupIndex(recycler, state, glp.getViewLayoutPosition());
    if (mOrientation == HORIZONTAL) {
        info.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(
                glp.getSpanIndex(), glp.getSpanSize(),
                spanGroupIndex, 1,
                mSpanCount > 1 && glp.getSpanSize() == mSpanCount, false));
    } else { // VERTICAL
        info.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(
                spanGroupIndex , 1,
                glp.getSpanIndex(), glp.getSpanSize(),
                mSpanCount > 1 && glp.getSpanSize() == mSpanCount, false));
    }
}
 
Example 5
Source File: StaggeredGridLayoutManager.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler,
        RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
    ViewGroup.LayoutParams lp = host.getLayoutParams();
    if (!(lp instanceof LayoutParams)) {
        super.onInitializeAccessibilityNodeInfoForItem(host, info);
        return;
    }
    LayoutParams sglp = (LayoutParams) lp;
    if (mOrientation == HORIZONTAL) {
        info.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(
                sglp.getSpanIndex(), sglp.mFullSpan ? mSpanCount : 1,
                -1, -1,
                sglp.mFullSpan, false));
    } else { // VERTICAL
        info.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(
                -1, -1,
                sglp.getSpanIndex(), sglp.mFullSpan ? mSpanCount : 1,
                sglp.mFullSpan, false));
    }
}
 
Example 6
Source File: GridLayoutManager.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler,
        RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
    ViewGroup.LayoutParams lp = host.getLayoutParams();
    if (!(lp instanceof LayoutParams)) {
        super.onInitializeAccessibilityNodeInfoForItem(host, info);
        return;
    }
    LayoutParams glp = (LayoutParams) lp;
    int spanGroupIndex = getSpanGroupIndex(recycler, state, glp.getViewLayoutPosition());
    if (mOrientation == HORIZONTAL) {
        info.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(
                glp.getSpanIndex(), glp.getSpanSize(),
                spanGroupIndex, 1,
                mSpanCount > 1 && glp.getSpanSize() == mSpanCount, false));
    } else { // VERTICAL
        info.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(
                spanGroupIndex , 1,
                glp.getSpanIndex(), glp.getSpanSize(),
                mSpanCount > 1 && glp.getSpanSize() == mSpanCount, false));
    }
}
 
Example 7
Source File: StaggeredGridLayoutManager.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler,
        RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
    ViewGroup.LayoutParams lp = host.getLayoutParams();
    if (!(lp instanceof LayoutParams)) {
        super.onInitializeAccessibilityNodeInfoForItem(host, info);
        return;
    }
    LayoutParams sglp = (LayoutParams) lp;
    if (mOrientation == HORIZONTAL) {
        info.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(
                sglp.getSpanIndex(), sglp.mFullSpan ? mSpanCount : 1,
                -1, -1,
                sglp.mFullSpan, false));
    } else { // VERTICAL
        info.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(
                -1, -1,
                sglp.getSpanIndex(), sglp.mFullSpan ? mSpanCount : 1,
                sglp.mFullSpan, false));
    }
}
 
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()));
  }
}