本文整理匯總了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);
}