Java Code Examples for androidx.core.view.accessibility.AccessibilityNodeInfoCompat#getCollectionItemInfo()
The following examples show how to use
androidx.core.view.accessibility.AccessibilityNodeInfoCompat#getCollectionItemInfo() .
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: MaterialButtonToggleGroupTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @Config(sdk = 23) public void onInitializeAccessibilityNodeInfo() { AccessibilityNodeInfoCompat groupInfoCompat = AccessibilityNodeInfoCompat.obtain(); ViewCompat.onInitializeAccessibilityNodeInfo(toggleGroup, groupInfoCompat); CollectionInfoCompat collectionInfo = groupInfoCompat.getCollectionInfo(); assertEquals(3, collectionInfo.getColumnCount()); assertEquals(1, collectionInfo.getRowCount()); MaterialButton secondChild = (MaterialButton) toggleGroup.getChildAt(1); secondChild.setChecked(true); AccessibilityNodeInfoCompat buttonInfoCompat = AccessibilityNodeInfoCompat.obtain(); ViewCompat.onInitializeAccessibilityNodeInfo(secondChild, buttonInfoCompat); CollectionItemInfoCompat itemInfo = buttonInfoCompat.getCollectionItemInfo(); assertEquals(1, itemInfo.getColumnIndex()); assertEquals(0, itemInfo.getRowIndex()); assertTrue(itemInfo.isSelected()); }
Example 2
Source File: ChipGroupTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @Config(minSdk = 23, maxSdk = 28) public void isSingleLine_initializesAccessibilityNodeInfo() { chipgroup.setSingleLine(true); AccessibilityNodeInfoCompat groupInfoCompat = AccessibilityNodeInfoCompat.obtain(); // onLayout must be triggered for rowCount chipgroup.layout(0, 0, 100, 100); ViewCompat.onInitializeAccessibilityNodeInfo(chipgroup, groupInfoCompat); CollectionInfoCompat collectionInfo = groupInfoCompat.getCollectionInfo(); assertEquals(chipgroup.getChildCount(), collectionInfo.getColumnCount()); assertEquals(1, collectionInfo.getRowCount()); Chip secondChild = (Chip) chipgroup.getChildAt(1); secondChild.setChecked(true); AccessibilityNodeInfoCompat chipInfoCompat = AccessibilityNodeInfoCompat.obtain(); ViewCompat.onInitializeAccessibilityNodeInfo(secondChild, chipInfoCompat); CollectionItemInfoCompat itemInfo = chipInfoCompat.getCollectionItemInfo(); assertEquals(1, itemInfo.getColumnIndex()); assertEquals(0, itemInfo.getRowIndex()); assertTrue(itemInfo.isSelected()); }
Example 3
Source File: ChipGroupTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @Config(minSdk = 23, maxSdk = 28) public void isNotSingleLine_initializesAccessibilityNodeInfo() { AccessibilityNodeInfoCompat groupInfoCompat = AccessibilityNodeInfoCompat.obtain(); // onLayout must be triggered for rowCount chipgroup.layout(0, 0, 10, 100); ViewCompat.onInitializeAccessibilityNodeInfo(chipgroup, groupInfoCompat); CollectionInfoCompat collectionInfo = groupInfoCompat.getCollectionInfo(); assertEquals(-1, collectionInfo.getColumnCount()); assertEquals(2, collectionInfo.getRowCount()); Chip secondChild = (Chip) chipgroup.getChildAt(2); secondChild.setChecked(true); AccessibilityNodeInfoCompat chipInfoCompat = AccessibilityNodeInfoCompat.obtain(); ViewCompat.onInitializeAccessibilityNodeInfo(secondChild, chipInfoCompat); CollectionItemInfoCompat itemInfo = chipInfoCompat.getCollectionItemInfo(); assertEquals(-1, itemInfo.getColumnIndex()); assertEquals(1, itemInfo.getRowIndex()); assertTrue(itemInfo.isSelected()); }
Example 4
Source File: PreferenceCategory.java From MaterialPreference with Apache License 2.0 | 6 votes |
@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 5
Source File: CollectionState.java From talkback with Apache License 2.0 | 6 votes |
private static boolean updateSingleTableHeader( @Nullable AccessibilityNodeInfoCompat node, CollectionInfoCompat collectionInfo, SparseArray<CharSequence> rowHeaders, SparseArray<CharSequence> columnHeaders) { if (node == null) { return false; } CharSequence headingName = getHeaderText(node); CollectionItemInfoCompat itemInfo = node.getCollectionItemInfo(); if (itemInfo != null && headingName != null) { @RowColumnTransition int headingType = getTableHeading(node, itemInfo, collectionInfo); if ((headingType & TYPE_ROW) != 0) { rowHeaders.put(itemInfo.getRowIndex(), headingName); } if ((headingType & TYPE_COLUMN) != 0) { columnHeaders.put(itemInfo.getColumnIndex(), headingName); } return headingType != TYPE_NONE; } return false; }
Example 6
Source File: NodeDescription.java From talkback with Apache License 2.0 | 6 votes |
public boolean indexMatches(AccessibilityNodeInfoCompat node) { if (node == null) { return false; } if (indexType == INDEX_TYPE_COLLECTION) { CollectionItemInfoCompat itemInfo = node.getCollectionItemInfo(); return (itemInfo != null) && (itemInfo.getRowIndex() == rowIndex) && (itemInfo.getColumnIndex() == columnIndex); } else { AccessibilityNodeInfoCompat parent = null; AccessibilityNodeInfoCompat child = null; try { parent = node.getParent(); if (parent == null || parent.getChildCount() <= rawIndexInParent) { return false; } child = parent.getChild(rawIndexInParent); return node.equals(child); } finally { AccessibilityNodeInfoUtils.recycleNodes(parent, child); } } }
Example 7
Source File: BottomNavigationViewTest.java From material-components-android with Apache License 2.0 | 5 votes |
@UiThreadTest @Test @SmallTest @SdkSuppress(minSdkVersion = Build.VERSION_CODES.M) public void testOnInitializeAccessibilityNodeInfo() { BottomNavigationMenuView menuView = bottomNavigation.menuView; AccessibilityNodeInfoCompat groupInfoCompat = AccessibilityNodeInfoCompat.obtain(); ViewCompat.onInitializeAccessibilityNodeInfo(menuView, groupInfoCompat); CollectionInfoCompat collectionInfo = groupInfoCompat.getCollectionInfo(); Assert.assertEquals(3, collectionInfo.getColumnCount()); Assert.assertEquals(1, collectionInfo.getRowCount()); BottomNavigationItemView secondChild = (BottomNavigationItemView) menuView.getChildAt(1); secondChild.setSelected(true); AccessibilityNodeInfoCompat buttonInfoCompat = AccessibilityNodeInfoCompat.obtain(); ViewCompat.onInitializeAccessibilityNodeInfo(secondChild, buttonInfoCompat); // A tab that is currently selected won't be clickable by a11y assertFalse(buttonInfoCompat.isClickable()); assertFalse( AccessibilityUtils.hasAction(buttonInfoCompat, AccessibilityActionCompat.ACTION_CLICK)); CollectionItemInfoCompat itemInfo = buttonInfoCompat.getCollectionItemInfo(); Assert.assertEquals(1, itemInfo.getColumnIndex()); Assert.assertEquals(0, itemInfo.getRowIndex()); assertTrue(itemInfo.isSelected()); }
Example 8
Source File: TabLayoutTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test @SdkSuppress(minSdkVersion = Build.VERSION_CODES.M) public void initializesAccessibilityNodeInfo() { final LayoutInflater inflater = LayoutInflater.from(activityTestRule.getActivity()); final TabLayout tabs = (TabLayout) inflater.inflate(R.layout.design_tabs, null); final TabLayout.Tab tab1 = tabs.newTab(); tabs.addTab(tab1); final TabLayout.Tab tab2 = tabs.newTab(); tabs.addTab(tab2, true); tabs.getTabAt(0).setCustomView(R.layout.design_tab_item_custom); tabs.getTabAt(1).setCustomView(R.layout.design_tab_item_custom); AccessibilityNodeInfoCompat groupInfoCompat = AccessibilityNodeInfoCompat.obtain(); ViewCompat.onInitializeAccessibilityNodeInfo(tabs, groupInfoCompat); CollectionInfoCompat collectionInfo = groupInfoCompat.getCollectionInfo(); assertEquals(2, collectionInfo.getColumnCount()); assertEquals(1, collectionInfo.getRowCount()); TabView secondChild = tabs.getTabAt(1).view; secondChild.setSelected(true); AccessibilityNodeInfoCompat tabInfoCompat = AccessibilityNodeInfoCompat.obtain(); ViewCompat.onInitializeAccessibilityNodeInfo(secondChild, tabInfoCompat); // A tab that is currently selected won't be clickable assertFalse(tabInfoCompat.isClickable()); assertFalse( AccessibilityUtils.hasAction(tabInfoCompat, AccessibilityActionCompat.ACTION_CLICK)); CollectionItemInfoCompat itemInfo = tabInfoCompat.getCollectionItemInfo(); assertEquals(1, itemInfo.getColumnIndex()); assertEquals(0, itemInfo.getRowIndex()); assertTrue(itemInfo.isSelected()); }
Example 9
Source File: CollectionState.java From talkback with Apache License 2.0 | 5 votes |
@Nullable private static ListItemState getListItemState( AccessibilityNodeInfoCompat collectionRoot, AccessibilityNodeInfoCompat announcedNode, boolean computeNumbering) { if (collectionRoot == null || collectionRoot.getCollectionInfo() == null) { return null; } // Checking the ancestors should incur zero performance penalty in the typical case // where list items are direct descendants. Assuming list items are not deeply // nested, any performance penalty would be minimal. AccessibilityNodeInfoCompat collectionItem = AccessibilityNodeInfoUtils.getSelfOrMatchingAncestor( announcedNode, collectionRoot, FILTER_COLLECTION_ITEM); if (collectionItem == null) { return null; } CollectionInfoCompat collection = collectionRoot.getCollectionInfo(); CollectionItemInfoCompat item = collectionItem.getCollectionItemInfo(); boolean heading = AccessibilityNodeInfoUtils.isHeading(collectionItem); int index; if (getCollectionAlignmentInternal(collection) == ALIGNMENT_VERTICAL) { index = getRowIndex(item, collection); } else { index = getColumnIndex(item, collection); } collectionItem.recycle(); return new ListItemState(heading, index, computeNumbering); }
Example 10
Source File: CollectionState.java From talkback with Apache License 2.0 | 5 votes |
@Nullable private static TableItemState getTableItemState( AccessibilityNodeInfoCompat collectionRoot, AccessibilityNodeInfoCompat announcedNode, SparseArray<CharSequence> rowHeaders, SparseArray<CharSequence> columnHeaders, boolean computeHeaders, boolean computeNumbering) { if (collectionRoot == null || collectionRoot.getCollectionInfo() == null) { return null; } // Checking the ancestors should incur zero performance penalty in the typical case // where list items are direct descendants. Assuming list items are not deeply // nested, any performance penalty would be minimal. AccessibilityNodeInfoCompat collectionItem = AccessibilityNodeInfoUtils.getSelfOrMatchingAncestor( announcedNode, collectionRoot, FILTER_COLLECTION_ITEM); if (collectionItem == null) { return null; } CollectionInfoCompat collection = collectionRoot.getCollectionInfo(); CollectionItemInfoCompat item = collectionItem.getCollectionItemInfo(); int heading = computeHeaders ? getTableHeading(collectionItem, item, collection) : TYPE_NONE; int rowIndex = getRowIndex(item, collection); int columnIndex = getColumnIndex(item, collection); CharSequence rowName = rowIndex != -1 ? rowHeaders.get(rowIndex) : null; CharSequence columnName = columnIndex != -1 ? columnHeaders.get(columnIndex) : null; collectionItem.recycle(); return new TableItemState( heading, rowName, columnName, rowIndex, columnIndex, computeNumbering); }
Example 11
Source File: NodeDescription.java From talkback with Apache License 2.0 | 5 votes |
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 12
Source File: CollectionState.java From talkback with Apache License 2.0 | 4 votes |
@Override public boolean accept(AccessibilityNodeInfoCompat node) { return node != null && node.getCollectionItemInfo() != null; }