Java Code Examples for androidx.core.view.accessibility.AccessibilityNodeInfoCompat#setEnabled()
The following examples show how to use
androidx.core.view.accessibility.AccessibilityNodeInfoCompat#setEnabled() .
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: Chip.java From material-components-android with Apache License 2.0 | 6 votes |
@Override protected void onPopulateNodeForVirtualView( int virtualViewId, @NonNull AccessibilityNodeInfoCompat node) { if (virtualViewId == CLOSE_ICON_VIRTUAL_ID) { CharSequence closeIconContentDescription = getCloseIconContentDescription(); if (closeIconContentDescription != null) { node.setContentDescription(closeIconContentDescription); } else { CharSequence chipText = getText(); node.setContentDescription( getContext() .getString( R.string.mtrl_chip_close_icon_content_description, !TextUtils.isEmpty(chipText) ? chipText : "") .trim()); } node.setBoundsInParent(getCloseIconTouchBoundsInt()); node.addAction(AccessibilityActionCompat.ACTION_CLICK); node.setEnabled(isEnabled()); } else { node.setContentDescription(""); node.setBoundsInParent(EMPTY_BOUNDS); } }
Example 2
Source File: MonthView.java From MaterialDateTimePicker with Apache License 2.0 | 6 votes |
@Override protected void onPopulateNodeForVirtualView(int virtualViewId, @NonNull AccessibilityNodeInfoCompat node) { getItemBounds(virtualViewId, mTempRect); node.setContentDescription(getItemDescription(virtualViewId)); node.setBoundsInParent(mTempRect); node.addAction(AccessibilityNodeInfo.ACTION_CLICK); // Flag non-selectable dates as disabled node.setEnabled(!mController.isOutOfRange(mYear, mMonth, virtualViewId)); if (virtualViewId == mSelectedDay) { node.setSelected(true); } }
Example 3
Source File: NumberPicker.java From DateTimePicker with Apache License 2.0 | 5 votes |
private AccessibilityNodeInfo createAccessibilityNodeInfoForVirtualButton(int virtualViewId, String text, int left, int top, int right, int bottom) { AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); info.setClassName(Button.class.getName()); info.setPackageName(getContext().getPackageName()); info.setSource(NumberPicker.this, virtualViewId); info.setParent(NumberPicker.this); info.setText(text); info.setClickable(true); info.setLongClickable(true); info.setEnabled(NumberPicker.this.isEnabled()); 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); if (mAccessibilityFocusedView != virtualViewId) { info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } if (mAccessibilityFocusedView == virtualViewId) { info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } if (NumberPicker.this.isEnabled()) { info.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK); } return info.unwrap(); }
Example 4
Source File: SimpleMonthView.java From DateTimePicker with Apache License 2.0 | 5 votes |
@Override protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node) { final boolean hasBounds = getBoundsForDay(virtualViewId, mTempRect); if (!hasBounds) { // The day is invalid, kill the node. mTempRect.setEmpty(); node.setContentDescription(""); node.setBoundsInParent(mTempRect); node.setVisibleToUser(false); return; } node.setText(getDayText(virtualViewId)); node.setContentDescription(getDayDescription(virtualViewId)); node.setBoundsInParent(mTempRect); final boolean isDayEnabled = isDayEnabled(virtualViewId); if (isDayEnabled) { //node.addAction(AccessibilityAction.ACTION_CLICK); node.addAction(AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_CLICK); } node.setEnabled(isDayEnabled); if (virtualViewId == mActivatedDay) { // TODO: This should use activated once that's supported. node.setChecked(true); } }
Example 5
Source File: RadialMenuView.java From talkback with Apache License 2.0 | 5 votes |
@Override protected void populateNodeForItem(RadialMenuItem item, AccessibilityNodeInfoCompat node) { node.setContentDescription(item.getTitle()); node.setVisibleToUser(item.isVisible()); node.setCheckable(item.isCheckable()); node.setChecked(item.isChecked()); node.setEnabled(item.isEnabled()); node.setClickable(true); getLocalVisibleRect(tempRect); node.setBoundsInParent(tempRect); getGlobalVisibleRect(tempRect); node.setBoundsInScreen(tempRect); }
Example 6
Source File: TextSpec.java From litho with Apache License 2.0 | 4 votes |
@OnPopulateExtraAccessibilityNode static void onPopulateExtraAccessibilityNode( AccessibilityNodeInfoCompat node, int extraNodeIndex, int componentBoundsLeft, int componentBoundsTop, @Prop(resType = ResType.STRING) CharSequence text, @FromBoundsDefined Layout textLayout, @FromBoundsDefined ClickableSpan[] clickableSpans) { if (!(text instanceof Spanned)) { return; } final Spanned spanned = (Spanned) text; final ClickableSpan span = clickableSpans[extraNodeIndex]; final int start = spanned.getSpanStart(span); final int end = spanned.getSpanEnd(span); final int startLine = textLayout.getLineForOffset(start); final int endLine = textLayout.getLineForOffset(end); // The bounds for multi-line strings should *only* include the first line. This is because // Talkback triggers its click at the center point of these bounds, and if that center point // is outside the spannable, it will click on something else. There is no harm in not outlining // the wrapped part of the string, as the text for the whole string will be read regardless of // the bounding box. final int selectionPathEnd = startLine == endLine ? end : textLayout.getLineVisibleEnd(startLine); textLayout.getSelectionPath(start, selectionPathEnd, sTempPath); sTempPath.computeBounds(sTempRectF, /* unused */ true); sTempRect.set( componentBoundsLeft + (int) sTempRectF.left, componentBoundsTop + (int) sTempRectF.top, componentBoundsLeft + (int) sTempRectF.right, componentBoundsTop + (int) sTempRectF.bottom); if (sTempRect.isEmpty()) { // Text is not actually visible. // Override bounds so it doesn't crash ExploreByTouchHelper.java sTempRect.set(0, 0, 1, 1); node.setBoundsInParent(sTempRect); node.setContentDescription(""); // make node non-focusable return; } node.setBoundsInParent(sTempRect); node.setClickable(true); node.setFocusable(true); node.setEnabled(true); node.setVisibleToUser(true); node.setText(spanned.subSequence(start, end)); if (span instanceof AccessibleClickableSpan) { AccessibleClickableSpan accessibleClickableSpan = (AccessibleClickableSpan) span; String contentDescription = accessibleClickableSpan.getAccessibilityDescription(); String role = accessibleClickableSpan.getAccessibilityRole(); if (contentDescription != null) { node.setContentDescription(contentDescription); } if (role != null) { node.setClassName(role); } else { node.setClassName(AccessibilityRole.BUTTON); } } else { node.setClassName(AccessibilityRole.BUTTON); } }
Example 7
Source File: NumberPicker.java From DateTimePicker with Apache License 2.0 | 4 votes |
private AccessibilityNodeInfo createAccessibilityNodeInfoForNumberPicker(int left, int top, int right, int bottom) { AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); info.setClassName(NumberPicker.class.getName()); info.setPackageName(getContext().getPackageName()); info.setSource(NumberPicker.this); if (hasVirtualDecrementButton()) { info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_DECREMENT); } info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT); if (hasVirtualIncrementButton()) { info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INCREMENT); } //info.setParent((View) getParentForAccessibility()); info.setParent((View) ViewCompat.getParentForAccessibility(NumberPicker.this)); info.setEnabled(NumberPicker.this.isEnabled()); info.setScrollable(true); // FIXME final float applicationScale = getContext().getResources().getCompatibilityInfo().applicationScale; final float applicationScale = 1f; Rect boundsInParent = mTempRect; boundsInParent.set(left, top, right, bottom); //boundsInParent.scale(applicationScale); scaleRect(boundsInParent, applicationScale); info.setBoundsInParent(boundsInParent); info.setVisibleToUser(isVisibleToUser()); Rect boundsInScreen = boundsInParent; int[] locationOnScreen = mTempArray; getLocationOnScreen(locationOnScreen); boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]); // boundsInScreen.scale(applicationScale); scaleRect(boundsInScreen, applicationScale); info.setBoundsInScreen(boundsInScreen); if (mAccessibilityFocusedView != View.NO_ID) { info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } if (mAccessibilityFocusedView == View.NO_ID) { info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } if (NumberPicker.this.isEnabled()) { if (getWrapSelectorWheel() || getValue() < getMaxValue()) { info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD); } if (getWrapSelectorWheel() || getValue() > getMinValue()) { info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD); } } return info.unwrap(); }