List of usage examples for android.text Layout getSelectionPath
public void getSelectionPath(int start, int end, Path dest)
From source file:com.facebook.litho.widget.TextSpec.java
@GetExtraAccessibilityNodeAt static int getExtraAccessibilityNodeAt(int x, int y, @Prop(resType = STRING) CharSequence text, @FromBoundsDefined Layout textLayout, @FromBoundsDefined ClickableSpan[] clickableSpans) { final Spanned spanned = (Spanned) text; for (int i = 0; i < clickableSpans.length; i++) { final ClickableSpan span = clickableSpans[i]; final int start = spanned.getSpanStart(span); final int end = spanned.getSpanEnd(span); textLayout.getSelectionPath(start, end, sTempPath); sTempPath.computeBounds(sTempRectF, /* unused */true); if (sTempRectF.contains(x, y)) { return i; }/* ww w . j ava 2 s. c o m*/ } return INVALID_ID; }
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 ww w . j av 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)); } }