List of usage examples for android.text Layout getPrimaryHorizontal
public float getPrimaryHorizontal(int offset)
From source file:io.plaidapp.core.ui.transitions.ReflowText.java
/** * Calculate the right boundary for this run (harder than it sounds). As we're a letter ahead, * need to grab either current letter start or the end of the previous line. Also need to * consider maxLines case, which inserts ellipses at the overflow point don't include these. *//*w ww . java 2s . c o m*/ private int getRunRight(Layout unrestrictedLayout, Layout maxLinesLayout, int currentLine, int index, int line, boolean withinMax, boolean isMaxEllipsis, boolean isLastChar) { int runRight; if (line != currentLine || isLastChar) { if (isMaxEllipsis) { runRight = (int) maxLinesLayout.getPrimaryHorizontal(index); } else { runRight = (int) unrestrictedLayout.getLineMax(currentLine); } } else { if (withinMax) { runRight = (int) maxLinesLayout.getPrimaryHorizontal(index); } else { runRight = (int) unrestrictedLayout.getPrimaryHorizontal(index); } } return runRight; }
From source file:com.nttec.everychan.ui.presentation.BoardFragment.java
private Point getSpanCoordinates(View widget, ClickableURLSpan span) { TextView parentTextView = (TextView) widget; Rect parentTextViewRect = new Rect(); // Initialize values for the computing of clickedText position SpannableString completeText = (SpannableString) (parentTextView).getText(); Layout textViewLayout = parentTextView.getLayout(); int startOffsetOfClickedText = completeText.getSpanStart(span); int endOffsetOfClickedText = completeText.getSpanEnd(span); double startXCoordinatesOfClickedText = textViewLayout.getPrimaryHorizontal(startOffsetOfClickedText); double endXCoordinatesOfClickedText = textViewLayout.getPrimaryHorizontal(endOffsetOfClickedText); // Get the rectangle of the clicked text int currentLineStartOffset = textViewLayout.getLineForOffset(startOffsetOfClickedText); int currentLineEndOffset = textViewLayout.getLineForOffset(endOffsetOfClickedText); boolean keywordIsInMultiLine = currentLineStartOffset != currentLineEndOffset; textViewLayout.getLineBounds(currentLineStartOffset, parentTextViewRect); // Update the rectangle position to his real position on screen int[] parentTextViewLocation = { 0, 0 }; parentTextView.getLocationOnScreen(parentTextViewLocation); double parentTextViewTopAndBottomOffset = (parentTextViewLocation[1] - parentTextView.getScrollY() + parentTextView.getCompoundPaddingTop()); Rect windowRect = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(windowRect); parentTextViewTopAndBottomOffset -= windowRect.top; parentTextViewRect.top += parentTextViewTopAndBottomOffset; parentTextViewRect.bottom += parentTextViewTopAndBottomOffset; parentTextViewRect.left += (parentTextViewLocation[0] + startXCoordinatesOfClickedText + parentTextView.getCompoundPaddingLeft() - parentTextView.getScrollX()); parentTextViewRect.right = (int) (parentTextViewRect.left + endXCoordinatesOfClickedText - startXCoordinatesOfClickedText); int x = (parentTextViewRect.left + parentTextViewRect.right) / 2; int y = (parentTextViewRect.top + parentTextViewRect.bottom) / 2; if (keywordIsInMultiLine) { x = parentTextViewRect.left;//from ww w. j ava 2 s. co m } return new Point(x, y); }