本文整理汇总了Java中android.text.Editable.insert方法的典型用法代码示例。如果您正苦于以下问题:Java Editable.insert方法的具体用法?Java Editable.insert怎么用?Java Editable.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Editable
的用法示例。
在下文中一共展示了Editable.insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inputType
import android.text.Editable; //导入方法依赖的package包/类
public void inputType(String typeStart,String typeEnd,int n){
int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
Editable editable = editText.getText();
if (start == end) {
if (typeEnd == null){
editable.insert(start,typeStart);
}else {
editable.insert(start, typeStart + typeEnd);
}
editText.setSelection(start + n);
}else {
if (typeEnd == null){
String str = editText.getText().toString();
String str2 = str.substring(start,end);
str = str.replace(str2,typeStart);
editText.setText(str);
editText.setSelection(start + n);
return;
}
editable.insert(start,typeStart);
editable.insert(end+typeStart.length(),typeEnd);
}
}
示例2: addMap
import android.text.Editable; //导入方法依赖的package包/类
private void addMap(Uri uri, boolean append)
{
String mapText = String.format(MEDIA_TEMPLATE,
OSM,
uri.toString());
if (append)
textView.append(mapText);
else
{
Editable editable = textView.getEditableText();
int position = textView.getSelectionStart();
editable.insert(position, mapText);
}
loadMarkdown();
}
示例3: performAddEnter
import android.text.Editable; //导入方法依赖的package包/类
/**
* 处理回车操作
*
* @param editable
* @param source
* @param start
*/
private void performAddEnter(Editable editable, CharSequence source, int start) {
//获取回车之前的字符
String tempStr = source.subSequence(0, start).toString();
//查找最后一个回车
int lastEnter = tempStr.lastIndexOf(10);
if (lastEnter > 0) {
//最后一个回车到输入回车之间的字符
tempStr = tempStr.substring(lastEnter + 1, start);
}
String mString = tempStr.trim();
String startSpace = getStartChar(tempStr, ' ');
if (mString.startsWith("* ") && mString.length() > 2) {//* 开头
editable.insert(start + 1, startSpace + "* ");
} else if (mString.matches("\\s*[1-9]+[0-9]*\\.\\s.+")) {//1. 开头
int currentNum = Integer.parseInt(mString.substring(0, mString.indexOf('.')).trim());
editable.insert(start + 1, startSpace + (++currentNum + ". "));
} else if (mString.length() > 1) {
editable.insert(start + 1, startSpace);
}
}
示例4: addLink
import android.text.Editable; //导入方法依赖的package包/类
private void addLink(Uri uri, String title, boolean append)
{
if ((title == null) || (title.length() == 0))
title = uri.getLastPathSegment();
String url = uri.toString();
String linkText = String.format(LINK_TEMPLATE, title, url);
if (append)
textView.append(linkText);
else
{
Editable editable = textView.getEditableText();
int position = textView.getSelectionStart();
editable.insert(position, linkText);
}
loadMarkdown();
}
示例5: getCommonEmoticonClickListener
import android.text.Editable; //导入方法依赖的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);
}
}
}
};
}
示例6: getCommonEmoticonClickListener
import android.text.Editable; //导入方法依赖的package包/类
public static EmoticonClickListener getCommonEmoticonClickListener(final EditText editText) {
return new EmoticonClickListener() {
@Override
public void onEmoticonClick(Object o, int actionType, boolean isDelBtn) {
if (isDelBtn) {
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);
}
}
}
};
}
示例7: onTextInsert
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void onTextInsert(CharSequence text) {
int start = editText.getSelectionStart();
Editable editable = editText.getEditableText();
editable.insert(start, text);
setModeKeyboard();
}
示例8: insertSeparators
import android.text.Editable; //导入方法依赖的package包/类
public static void insertSeparators(Editable s) {
final int[] positions = {4, 9, 14 };
for (int i : positions) {
if (s.length() > i) {
s.insert(i, SEPARATOR);
}
}
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:9,代码来源:CreditCardNumberFormattingTextWatcher.java
示例9: insertIntoEditText
import android.text.Editable; //导入方法依赖的package包/类
private void insertIntoEditText(SpannableString ss)
//插入图片
{
Editable et = edit_content.getText();// 先获取Edittext中的内容
int start = edit_content.getSelectionStart();
et.insert(start, ss);// 设置ss要添加的位置
edit_content.setText(et);// 把et添加到Edittext中
edit_content.setSelection(start + ss.length());// 设置Edittext中光标在最后面显示
}
示例10: autoClose
import android.text.Editable; //导入方法依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
protected void autoClose(Editable e, int count) {
SpannableStringBuilder selectedStr = new SpannableStringBuilder(getText());
Integer startSelection = getSelectionStart();
Integer endSelection = getSelectionEnd();
if (startSelection.equals(endSelection) && selectedStr.length() == startSelection) {}
if (count > 0 && selectedStr.length() > 0 && startSelection > 0 && startSelection.equals(endSelection)) {
char c = selectedStr.charAt(startSelection - 1);
char nextC = 'x';
char prevC = 'x';
if (selectedStr.length() > startSelection) {
nextC = selectedStr.charAt(startSelection);
}
if (startSelection > 1) {
prevC = selectedStr.charAt(startSelection - 2);
}
if (!(c != '(' || nextC == ')' || prevC == '(')) {
e.insert(startSelection, ")");
setSelection(startSelection);
} else if (!(c != '{' || nextC == '}' || prevC == '{')) {
e.insert(startSelection, "}");
setSelection(startSelection);
} else if (!(c != '[' || nextC == ']' || prevC == '[')) {
e.insert(startSelection, "]");
setSelection(startSelection);
}
}
}
示例11: onKey
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void onKey(int primaryCode, int[] keyCodes) {
Editable editable = mEditText.getText();
int start = mEditText.getSelectionStart();
if (primaryCode == Keyboard.KEYCODE_CANCEL) { // cancel
hideKeyboard();
} else if (primaryCode == Keyboard.KEYCODE_DELETE) { // 回退
if (editable != null && editable.length() > 0) {
if (start > 0) {
editable.delete(start - 1, start);
}
}
} else if (primaryCode == Keyboard.KEYCODE_SHIFT) { // 大小写切换
// changeKeyboart();
// mKeyboardView.setKeyboard(mLetterKeyboard);
} else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE) { // 数字与字母键盘互换
// if (isNumber) {
// isNumber = false;
// mKeyboardView.setKeyboard(mLetterKeyboard);
// } else {
// isNumber = true;
mKeyboardView.setKeyboard(mNumberKeyboard);
// }
} else if (primaryCode == 57419) { // 左移
if (start > 0) {
mEditText.setSelection(start - 1);
}
} else if (primaryCode == 57419) { // 右移
if (start > mEditText.length()) {
mEditText.setSelection(start + 1);
}
} else { // 输入键盘值
editable.insert(start, Character.toString((char) primaryCode));
}
}
示例12: onItemClick
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void onItemClick(int facesPos, int viewIndex) {
int deleteId = (++viewIndex) * (SysConstant.pageSize - 1);
if (deleteId > Emoparser.getInstance(MessageActivity.this).getResIdList().length) {
deleteId = Emoparser.getInstance(MessageActivity.this).getResIdList().length;
}
if (deleteId == facesPos) {
String msgContent = messageEdt.getText().toString();
if (msgContent.isEmpty())
return;
if (msgContent.contains("["))
msgContent = msgContent.substring(0, msgContent.lastIndexOf("["));
messageEdt.setText(msgContent);
} else {
int resId = Emoparser.getInstance(MessageActivity.this).getResIdList()[facesPos];
String pharse = Emoparser.getInstance(MessageActivity.this).getIdPhraseMap()
.get(resId);
int startIndex = messageEdt.getSelectionStart();
Editable edit = messageEdt.getEditableText();
if (startIndex < 0 || startIndex >= edit.length()) {
if (null != pharse) {
edit.append(pharse);
}
} else {
if (null != pharse) {
edit.insert(startIndex, pharse);
}
}
}
Editable edtable = messageEdt.getText();
int position = edtable.length();
Selection.setSelection(edtable, position);
}
示例13: afterTextChanged
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void afterTextChanged(Editable s) {
removeTextChangedListener(this);
int length = s.length();
int nextGroupStart = 4;
for (int i = 0; i < length; i++) {
char c = s.charAt(i);
if (i == nextGroupStart) {
if (c != SPACING_CHAR) {
if (!Character.isDigit(c)) {
s.replace(i, i + 1, spacingString);
} else {
s.insert(i, spacingString);
length = s.length();
if (deleted) {
int selectionStart = getSelectionStart();
int selectionEnd = getSelectionEnd();
int newSelectionStart = selectionStart - 1 == i ? selectionStart - 1 : selectionStart;
int newSelectionEnd = selectionEnd - 1 == i ? selectionEnd - 1 : selectionEnd;
setSelection(newSelectionStart, newSelectionEnd);
}
}
}
nextGroupStart += 5;
} else {
if (!Character.isDigit(c)) {
s.delete(i, i + 1);
length = s.length();
}
}
}
addTextChangedListener(this);
int cvcLength = CVCEditText.CVC_MAX_LENGTH;
List<String> allowedCardsList = new ArrayList<>(allowedCardTypes.keySet());
CardType cardType = CardType.detect(s.toString().replace(" ", ""), allowedCardsList);
if (cardType == CardType.amex) {
cvcLength = CVCEditText.CVC_MAX_LENGTH_AMEX;
}
if (cardType != CardType.UNKNOWN) {
if (!StringUtils.isEmptyOrNull(baseURL)) {
final String imageUrl = IconUtil.addScaleFactorToIconUrl(getContext(), baseURL + cardType + ".png");
AsyncImageDownloader.downloadImage(getContext(), new AsyncImageDownloader.ImageListener() {
@Override
public void onImage(final Bitmap bitmap, final String url) {
setCCIcon(bitmap);
}
}, imageUrl, null);
}
numberOfDigits = cardType.getNumberOfDigits();
} else {
initializeLogo();
numberOfDigits = null;
}
if (cvcEditText != null) {
for (CVCFieldStatusListener cvcFieldStatusListener : cvcFieldStatusListeners) {
cvcFieldStatusListener.onCVCFieldStatusChanged(allowedCardTypes.get(cardType.name()));
}
cvcEditText.setMaxLength(cvcLength);
}
if (validator != null) {
validator.setReady(CreditCardEditText.this, isValidNr(s.toString()));
}
}
示例14: afterTextChanged
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void afterTextChanged(Editable s) {
removeTextChangedListener(this);
if (s.length() == 1 && s.charAt(0) > '1') {
s.insert(0, "0");
}
if (s.length() == 2 && !deleted) {
if (s.toString().matches("\\d[^\\d]")) {
s.insert(0, "0");
} else if (!s.toString().matches("\\d*[^\\d]\\d*")) {
s.append(SEPARATOR_CHAR);
}
}
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (i == 2) {
if (c != SEPARATOR_CHAR) {
if (!Character.isDigit(c)) {
s.replace(i, i + 1, separatorString);
} else {
s.insert(i, separatorString);
if (deleted) {
int selectionStart = getSelectionStart();
int selectionEnd = getSelectionEnd();
int newSelectionStart = selectionStart - 1 == i ? selectionStart - 1 : selectionStart;
int newSelectionEnd = selectionEnd - 1 == i ? selectionEnd - 1 : selectionEnd;
setSelection(newSelectionStart, newSelectionEnd);
}
}
}
} else {
if (!Character.isDigit(c)) {
s.delete(i, i + 1);
}
}
}
boolean inputDateValid = isInputDateValid(s.toString());
if (validator != null) {
validator.setReady(ExpiryDateEditText.this, inputDateValid);
}
if (inputDateValid) {
View next = focusSearch(View.FOCUS_RIGHT);
if (next != null) {
next.requestFocus();
}
}
addTextChangedListener(this);
}
示例15: getText
import android.text.Editable; //导入方法依赖的package包/类
public Spannable getText()
{
Editable text = formatColor(templates.get(type), args);
text.insert(0, timestampFormatter.format(timestamp));
return text;
}