List of usage examples for android.support.v4.view.accessibility AccessibilityNodeInfoCompat setText
public void setText(CharSequence text)
From source file:com.facebook.litho.widget.TextSpec.java
@OnPopulateAccessibilityNode static void onPopulateAccessibilityNode(AccessibilityNodeInfoCompat node, @Prop(resType = STRING) CharSequence text) { node.setText(text); }
From source file:com.google.android.apps.forscience.whistlepunk.review.GraphExploringSeekBar.java
private void init() { // Use an AccessibilityDelegate to add custom text to Accessibility events. ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() { @Override//from w w w.j a va2s.c om public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { super.onPopulateAccessibilityEvent(host, event); event.getText().clear(); event.getText().add(generateEventText()); } @Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); info.setText(generateEventText()); } }); Resources res = getContext().getResources(); mFormat = res.getString(R.string.graph_exploring_seekbar_content_description); // Always use LTR layout, since graphs are always LTR. setLayoutDirection(LAYOUT_DIRECTION_LTR); }
From source file:com.redinput.datetimepickercompat.AccessibleLinearLayout.java
private void installAccessibilityDelegate() { // The accessibility delegate enables customizing accessibility behavior // via composition as opposed as inheritance. The main benefit is that // one can write a backwards compatible application by setting the delegate // only if the API level is high enough i.e. the delegate is part of the APIs. // The easiest way to achieve that is by using the support library which // takes the burden of checking API version and knowing which API version // introduced the delegate off the developer. ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() { @Override/*from w w w. ja va 2 s.co m*/ public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { super.onInitializeAccessibilityEvent(host, event); // Note that View.onInitializeAccessibilityNodeInfo was introduced in // ICS and we would like to tweak a bit the text that is reported to // accessibility services via the AccessibilityNodeInfo. event.getText().add(Button.class.getName()); } @Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); // Note that View.onInitializeAccessibilityNodeInfo was introduced in // ICS and we would like to tweak a bit the text that is reported to // accessibility services via the AccessibilityNodeInfo. info.setText(Button.class.getName()); } }); }
From source file:com.facebook.litho.widget.TextSpec.java
@OnPopulateExtraAccessibilityNode static void onPopulateExtraAccessibilityNode(AccessibilityNodeInfoCompat node, int extraNodeIndex, int componentBoundsLeft, int componentBoundsTop, @Prop(resType = STRING) CharSequence text, @FromBoundsDefined Layout textLayout, @FromBoundsDefined ClickableSpan[] clickableSpans) { 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);//from w ww.j a v a 2s .c o m 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); if (span instanceof AccessibleClickableSpan) { node.setText(((AccessibleClickableSpan) span).getAccessibilityDescription()); } else { node.setText(spanned.subSequence(start, end)); } }