Java Code Examples for android.widget.TextView#getSelectionEnd()

The following examples show how to use android.widget.TextView#getSelectionEnd() . 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: ArrowKeyMovementMethod.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** {@hide} */
@Override
protected boolean leftWord(TextView widget, Spannable buffer) {
    final int selectionEnd = widget.getSelectionEnd();
    final WordIterator wordIterator = widget.getWordIterator();
    wordIterator.setCharSequence(buffer, selectionEnd, selectionEnd);
    return Selection.moveToPreceding(buffer, wordIterator, isSelecting(buffer));
}
 
Example 2
Source File: ArrowKeyMovementMethod.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** {@hide} */
@Override
protected boolean rightWord(TextView widget, Spannable buffer) {
    final int selectionEnd = widget.getSelectionEnd();
    final WordIterator wordIterator = widget.getWordIterator();
    wordIterator.setCharSequence(buffer, selectionEnd, selectionEnd);
    return Selection.moveToFollowing(buffer, wordIterator, isSelecting(buffer));
}
 
Example 3
Source File: LogsActivity.java    From android with MIT License 5 votes vote down vote up
@Override
protected void onPostExecute(String s) {
    TextView content = findViewById(R.id.log_content);
    if (content.getSelectionStart() == content.getSelectionEnd()) {
        content.setText(s);
    }
    super.onPostExecute(s);
}
 
Example 4
Source File: CopyActivity.java    From timecat with Apache License 2.0 5 votes vote down vote up
private String getSelectedTextViewText(TextView textView) {
    if (textView == null) {
        return getSelectedText();
    } else {
        CharSequence text = textView.getText();
        if (textView.getSelectionStart() == textView.getSelectionEnd()) {
            return text.toString();
        } else {
            CharSequence selected = text.subSequence(textView.getSelectionStart(), textView.getSelectionEnd());
            return selected != null ? selected.toString() : text.toString();
        }
    }
}
 
Example 5
Source File: CopyActivity.java    From aedict with GNU General Public License v3.0 5 votes vote down vote up
public static String getSelection(TextView tv) {
	final int e=tv.getSelectionEnd();
	final int s=tv.getSelectionStart();
	if (e < 0 || s < 0 || s == e) {
		return tv.getText().toString();
	}
	return tv.getText().toString().substring(s, e);
}