本文整理汇总了Java中android.widget.EditText.getSelectionStart方法的典型用法代码示例。如果您正苦于以下问题:Java EditText.getSelectionStart方法的具体用法?Java EditText.getSelectionStart怎么用?Java EditText.getSelectionStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.EditText
的用法示例。
在下文中一共展示了EditText.getSelectionStart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: input
import android.widget.EditText; //导入方法依赖的package包/类
public static void input(EditText editText, String emoji) {
if (editText == null || TextUtils.isEmpty(emoji)) {
return;
}
int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
if (start < 0) {
editText.append(emoji);
} else {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
int length = getEditTextMaxLength(editText);
if(length>0 && start+emoji.length() > length){
return;
}
}
editText.getText().replace(Math.min(start, end), Math.max(start, end), emoji, 0, emoji.length());
if(editText.getText().length() < start+emoji.length()){
editText.getText().delete(Math.min(start, end), editText.getText().length());
}
}
}
示例2: onBackPress
import android.widget.EditText; //导入方法依赖的package包/类
private void onBackPress(EditText editText) {
int selection = editText.getSelectionStart();
if (selection == 0) {
int viewIndex = allLayout.indexOfChild(editText);
View v = allLayout.getChildAt(viewIndex - 1);
if (v != null) {
if (v instanceof EditText) {
if ((int) v.getTag() != 1) {
String s1 = editText.getText().toString();
EditText q = (EditText) v;
String s2 = q.getText().toString();
allLayout.removeView(editText);
q.setText(s1 + s2);
q.requestFocus();
q.setSelection(s2.length(), s2.length());
lastEditText = q;
}
} else if (v instanceof ImageView) {
allLayout.removeView(v);
}
}
}
}
示例3: getSelectionRange
import android.widget.EditText; //导入方法依赖的package包/类
@JSMethod
public void getSelectionRange(String callbackId) {
EditText hostView;
Map<String, Object> result = new HashMap<>(2);
if ((hostView = getHostView()) != null) {
int start = hostView.getSelectionStart();
int end = hostView.getSelectionEnd();
if (!hostView.hasFocus()) {
//The default behavior, same as iOS and web
start = 0;
end = 0;
}
result.put(Constants.Name.SELECTION_START, start);
result.put(Constants.Name.SELECTION_END, end);
}
WXBridgeManager.getInstance().callback(getInstanceId(), callbackId, result, false);
}
示例4: getStatement
import android.widget.EditText; //导入方法依赖的package包/类
/**
* " Search back from the cursor position till meeting '{' or ';'.
* " '{' means statement start, ';' means end of a previous statement.
*
* @return statement before cursor
* " Note: It's the base for parsing. And It's OK for most cases.
*/
@NonNull
private String getStatement(EditText editor) {
String lineBeforeCursor = getCurrentLine(editor);
if (lineBeforeCursor.matches("^\\s*(import|package)\\s+")) {
return lineBeforeCursor;
}
int oldCursor = editor.getSelectionStart();
int newCursor = oldCursor;
while (true) {
if (newCursor == 0) break;
char c = editor.getText().charAt(newCursor);
if (c == '{' || c == '}' || c == ';') {
newCursor++;
break;
}
newCursor--;
}
String statement = editor.getText().subSequence(newCursor, oldCursor).toString();
return mergeLine(statement);
}
示例5: input2OSC
import android.widget.EditText; //导入方法依赖的package包/类
public static void input2OSC(EditText editText, Emojicon emojicon) {
if (editText == null || emojicon == null) {
return;
}
int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
if (start < 0) {
// 没有多选时,直接在当前光标处添加
editText.append(emojicon.getRemote());
} else {
// 将已选中的部分替换为表情(当长按文字时会多选刷中很多文字)
String str = emojicon.getRemote();
editText.getText().replace(Math.min(start, end),
Math.max(start, end), str, 0, str.length());
}
}
示例6: addCode
import android.widget.EditText; //导入方法依赖的package包/类
public static void addCode(@NonNull EditText editText) {
try {
String source = editText.getText().toString();
int selectionStart = editText.getSelectionStart();
int selectionEnd = editText.getSelectionEnd();
String substring = source.substring(selectionStart, selectionEnd);
String result;
if (hasNewLine(source, selectionStart))
result = "```\n" + substring + "\n```\n";
else
result = "\n```\n" + substring + "\n```\n";
editText.getText().replace(selectionStart, selectionEnd, result);
editText.setSelection(result.length() + selectionStart - 5);
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: input2OSC
import android.widget.EditText; //导入方法依赖的package包/类
/**
* 输入Emoji表情到 EditText
*
* @param editText EditText
* @param emojicon Emojicon
*/
public static void input2OSC(EditText editText, Emojicon emojicon) {
if (editText == null || emojicon == null) {
return;
}
int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
if (start < 0) {
// 没有多选时,直接在当前光标处添加
editText.append(displayEmoji(editText.getResources(),
emojicon.getRemote(), (int) editText.getTextSize()));
} else {
// 将已选中的部分替换为表情(当长按文字时会多选刷中很多文字)
Spannable str = displayEmoji(editText.getResources(),
emojicon.getRemote(), (int) editText.getTextSize());
editText.getText().replace(Math.min(start, end),
Math.max(start, end), str, 0, str.length());
}
}
示例8: addQuote
import android.widget.EditText; //导入方法依赖的package包/类
public static void addQuote(@NonNull EditText editText) {
String source = editText.getText().toString();
int selectionStart = editText.getSelectionStart();
int selectionEnd = editText.getSelectionEnd();
String substring = source.substring(selectionStart, selectionEnd);
String result;
if (hasNewLine(source, selectionStart)) {
result = "> " + substring;
} else {
result = "\n> " + substring;
}
editText.getText().replace(selectionStart, selectionEnd, result);
editText.setSelection(result.length() + selectionStart);
}
示例9: getCommonEmoticonClickListener
import android.widget.EditText; //导入方法依赖的package包/类
public static EmoticonClickListener getCommonEmoticonClickListener(final EditText editText) {
return new EmoticonClickListener() {
@Override
public void onEmoticonClick(Object o, int actionType, boolean isDelBtn) {
if (isDelBtn) {
PublishUtils.delClick(editText);
} else {
if (o == null) {
return;
}
if (actionType == Constants.EMOTICON_CLICK_TEXT) {
String content = null;
// if (o instanceof EmojiBean) {
// content = ((EmojiBean) o).emoji;
// } else
if (o instanceof EmoticonEntity) {
content = ((EmoticonEntity) o).getContent();
}
if (TextUtils.isEmpty(content)) {
return;
}
int index = editText.getSelectionStart();
Editable editable = editText.getText();
editable.insert(index, content);
}
}
}
};
}
示例10: EditTextSelectionState
import android.widget.EditText; //导入方法依赖的package包/类
public EditTextSelectionState(@NonNull EditText editText) {
mEditText = editText;
mFocused = editText.hasFocus();
int selectionStart = editText.getSelectionStart();
int selectionEnd = editText.getSelectionEnd();
if (selectionStart > selectionEnd && selectionStart != -1 && selectionEnd != -1) {
mSelectionStart = selectionEnd;
mSelectionEnd = selectionStart;
} else {
mSelectionStart = selectionStart;
mSelectionEnd = selectionEnd;
}
}
示例11: replaceBodySelectionTextTo
import android.widget.EditText; //导入方法依赖的package包/类
@Override
public void replaceBodySelectionTextTo(String replyText) {
if (nonNull(mInputController)) {
EditText edit = mInputController.getInputField();
int selectionStart = edit.getSelectionStart();
int selectionEnd = edit.getSelectionEnd();
edit.getText().replace(selectionStart, selectionEnd, replyText);
}
}
示例12: input
import android.widget.EditText; //导入方法依赖的package包/类
public static void input(EditText editText, Emojicon emojicon) {
if (editText == null || emojicon == null) {
return;
}
int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
if (start < 0) {
editText.append(emojicon.getEmoji());
} else {
editText.getText().replace(Math.min(start, end), Math.max(start, end), emojicon.getEmoji(), 0, emojicon.getEmoji().length());
}
}
示例13: insertChip
import android.widget.EditText; //导入方法依赖的package包/类
private void insertChip(int type) {
EditText editText = mTextFormatBar.getEditText();
int sStart = editText.getSelectionStart();
int sEnd = editText.getSelectionEnd();
SpannableString ss = new SpannableString(" ");
ss.setSpan(new MessageBuilder.MetaChipSpan(this, type), 0, 1, MessageBuilder.FORMAT_SPAN_FLAGS);
editText.getText().replace(sStart, sEnd, ss);
refreshExamples();
}
示例14: insert2Input
import android.widget.EditText; //导入方法依赖的package包/类
void insert2Input(String strToInsert) {
EditText txtInput = (EditText)findViewById(R.id.edtSmartMathInput);
int nSelectionStart = txtInput.getSelectionStart();
int nSelectionEnd = txtInput.getSelectionEnd();
if (nSelectionStart < 0 || nSelectionEnd < 0
|| nSelectionStart > txtInput.getText().length()
|| nSelectionEnd > txtInput.getText().length()
|| nSelectionStart > nSelectionEnd) { // invalid selection
txtInput.setText(strToInsert);
txtInput.setSelection(txtInput.getText().length());
} else { // valid selection, insert the text
txtInput.getText().replace(nSelectionStart, nSelectionEnd, strToInsert);
txtInput.setSelection(nSelectionStart + strToInsert.length());
}
}
示例15: addItalic
import android.widget.EditText; //导入方法依赖的package包/类
public static void addItalic(@NonNull EditText editText) {
String source = editText.getText().toString();
int selectionStart = editText.getSelectionStart();
int selectionEnd = editText.getSelectionEnd();
String substring = source.substring(selectionStart, selectionEnd);
String result = "_" + substring + "_ ";
editText.getText().replace(selectionStart, selectionEnd, result);
editText.setSelection(result.length() + selectionStart - 2);
}