+ " " + staticLayout.getLineDescent(lineNumber) + " " + textCpy.subSequence(start, end) .toString());
/** Case insensitive search */ private static int getIndInRegion(Spannable spannable, Region region, String stringFound) { final String substr1 = spannable.subSequence(region.start, region.end).toString(); int indInRegion = substr1.indexOf(stringFound); if (indInRegion >= 0) return indInRegion; final String foundUpper = stringFound.toUpperCase(); int ind = 1; do { int ind2 = substr1.substring(ind).toUpperCase().indexOf(foundUpper); if (ind2 >= 0) return ind2; ind++; } while(ind + stringFound.length() < substr1.length()); return -1; }
private Region(Spannable spannable, int start, int end) { this.start = start; this.end = end; urlSpan = Optional.empty(); otherSpan = Optional.empty(); text = (start < end && spannable.length() >= end) ? spannable.subSequence(start, end) : ""; }
EditText editText = (EditText)findViewById(R.id.edittext); Spannable textSpan = editText.getText(); final int selection = editText.getSelectionStart(); final Pattern pattern = Pattern.compile("\\w+"); final Matcher matcher = pattern.matcher(textSpan); int start = 0; int end = 0; String currentWord = ""; while (matcher.find()) { start = matcher.start(); end = matcher.end(); if (start <= selection && selection <= end) { currentWord = textSpan.subSequence(start, end).toString(); } } Log.d("value", currentWord);
public String getCurrentWord(EditText editText) { Spannable textSpan = editText.getText(); final int selection = editText.getSelectionStart(); final Pattern pattern = Pattern.compile("\\w+"); final Matcher matcher = pattern.matcher(textSpan); int start = 0; int end = 0; String currentWord = ""; while (matcher.find()) { start = matcher.start(); end = matcher.end(); if (start <= selection && selection <= end) { currentWord = textSpan.subSequence(start, end).toString(); break; } } return currentWord; // This is current word }
@Override public void run() { // subSequence does something on the ui thread resultArray[0] = (Spannable) allText.subSequence(textToFindIndex, textToFindIndex + textToFind.length()); } });
/** * Copied from {@link PhoneNumberUtils#addTtsSpan} */ private static void addTtsSpanInternal(Spannable s, int start, int endExclusive) { s.setSpan(createTtsSpan(s.subSequence(start, endExclusive).toString()), start, endExclusive, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
private Region(Spannable spannable, Object span) { int spanStart = spannable.getSpanStart(span); // Sometimes "@" is not included in the span start = spanStart > 0 && "@#".indexOf(spannable.charAt(spanStart)) < 0 && "@#".indexOf(spannable.charAt(spanStart - 1)) >= 0 ? spanStart - 1 : spanStart; if (MyUrlSpan.class.isAssignableFrom(span.getClass())) { urlSpan = Optional.of((MyUrlSpan) span); otherSpan = Optional.empty(); } else { urlSpan = Optional.empty(); otherSpan = Optional.of(span); } end = spannable.getSpanEnd(span); text = spannable.subSequence(start, end); }
@NonNull private static Consumer<Region> modifySpansInRegion(Spannable spannable, Audience audience) { return region -> { if (region.start >= spannable.length() || region.end > spannable.length()) return; String text = spannable.subSequence(region.start, region.end).toString(); if (mentionAdded(spannable, audience, region, text)) return; hashTagAdded(spannable, audience, region, text); }; }
spec.textSpan = s.subSequence(start, end); spec.span = new InternalURLSpan(spec.textSpan.toString()); spec.start = start;
spec.textSpan = s.subSequence(start, end); spec.span = new InternalURLSpan(spec.textSpan.toString()); spec.start = start;
accountAddressTextView.setText(accountAddress, TextView.BufferType.SPANNABLE); stripUnderlines(accountAddressTextView); private void stripUnderlines(TextView textView) { Spannable entrySpan = (Spannable)textView.getText(); URLSpan[] spans = entrySpan.getSpans(0, entrySpan.length(), URLSpan.class); for (URLSpan span: spans) { int start = entrySpan.getSpanStart(span); int end = entrySpan.getSpanEnd(span); entrySpan.removeSpan(span); span = new URLSpanNoUnderline(entrySpan.subSequence(start, end).toString()); entrySpan.setSpan(span, start, end, 0); } }
private String getLinkText(RTEditText editor, RTSpan<String> span) { Spannable text = editor.getText(); final int spanStart = text.getSpanStart(span); final int spanEnd = text.getSpanEnd(span); String linkText = null; if (spanStart >= 0 && spanEnd >= 0 && spanEnd <= text.length()) { linkText = text.subSequence(spanStart, spanEnd).toString(); mLinkSelection = new Selection(spanStart, spanEnd); } else { mLinkSelection = editor.getSelection(); } return linkText; }
private String getLinkText(final TextView widget, final Spannable buffer, final MotionEvent event) { int x = (int) event.getX(); int y = (int) event.getY(); x -= widget.getTotalPaddingLeft(); y -= widget.getTotalPaddingTop(); x += widget.getScrollX(); y += widget.getScrollY(); Layout layout = widget.getLayout(); int line = layout.getLineForVertical(y); int off = layout.getOffsetForHorizontal(line, x); ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class); if (link.length != 0) { return buffer.subSequence(buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0])).toString(); } return buffer.toString(); } }
/** * @return the selected text (needed when creating links) */ String getSelectedText() { Spannable text = getText(); Selection sel = getSelection(); if (sel.start() >= 0 && sel.end() >= 0 && sel.end() <= text.length()) { return text.subSequence(sel.start(), sel.end()).toString(); } return null; }
private String getLinkText(final TextView widget, final Spannable buffer, final MotionEvent event) { int x = (int) event.getX(); int y = (int) event.getY(); x -= widget.getTotalPaddingLeft(); y -= widget.getTotalPaddingTop(); x += widget.getScrollX(); y += widget.getScrollY(); Layout layout = widget.getLayout(); int line = layout.getLineForVertical(y); int off = layout.getOffsetForHorizontal(line, x); ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class); if (link.length != 0) { return buffer.subSequence(buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0])).toString(); } return ""; } }
Matcher matcher = pattern.matcher(content.subSequence(start, end));