本文整理汇总了Java中android.text.Editable.charAt方法的典型用法代码示例。如果您正苦于以下问题:Java Editable.charAt方法的具体用法?Java Editable.charAt怎么用?Java Editable.charAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Editable
的用法示例。
在下文中一共展示了Editable.charAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatColor
import android.text.Editable; //导入方法依赖的package包/类
private static Editable formatColor(Spannable format, String... args)
{
Editable text = editableFactory.newEditable(format);
for(int i = 0; i < text.length(); )
{
if(text.charAt(i) == '$' && i + 1 < text.length())
{
if(Character.isDigit(text.charAt(i + 1)))
{
int digit = Character.digit(text.charAt(i + 1), 10);
Spannable arg = digit < args.length ? IRCFormatting.parse(args[digit]) : new SpannableString("");
text.replace(i, i + 2, arg);
i += arg.length();
continue;
}
if(text.charAt(i + 1) == '$')
{
text.replace(i, i + 2, "$");
i++;
continue;
}
}
i++;
}
return text;
}
示例2: parseWordBefore
import android.text.Editable; //导入方法依赖的package包/类
private String[] parseWordBefore(Editable s, int position) {
if (position == 0)
return null;
int i;
for (i = position - 1; i >= 0; i--) {
if (position - i > KEY_WORD_LENGTH_MAX) {
return null;
}
char c = s.charAt(i);
if (c == '.') {
return new String[]{parseWordBeforeDot(s, i), s.subSequence(i + 1, position).toString()};
}
if (!Character.isLetter(s.charAt(i))) {
if (i < position - 1) {
return new String[]{s.subSequence(i + 1, position).toString(), null};
} else {
return null;
}
}
}
return new String[]{s.subSequence(0, position).toString(), null};
}
示例3: handleTag
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
if (tag.equals("ul")) {
if (opening) {
char lastChar = 0;
if (output.length() > 0) {
lastChar = output.charAt(output.length() - 1);
}
if (lastChar != '\n') {
output.append("\r\n");
}
} else {
output.append("\r\n");
}
}
if (tag.equals("li")) {
if (opening) {
output.append("\t• ");
} else {
output.append("\r\n");
}
}
}
示例4: afterTextChanged
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void afterTextChanged(Editable s) {
mNedConfirm.setTextColor(TextUtils.isEmpty(mEtNick.getText().toString().trim())
? context.getResources().getColor(R.color.forbid_click_color)
: context.getResources().getColor(R.color.base_blue));
if (inputType == INPUT_ZH) {
int l = s.length();
while (--l >= 0) {
if (TextUtils.isEmpty(s))
break;
if (s.charAt(l) < 0x4E00 || s.charAt(l) > 0x9FB0) {
s.delete(l, l + 1);
}
}
}
}
示例5: onSelectChange
import android.text.Editable; //导入方法依赖的package包/类
public void onSelectChange(int selStart, int selEnd) {
try {
if (selEnd > -1 && selEnd < editText.length()) {
Editable text = editText.getText();
char chatAtCursor = text.charAt(selEnd);
boolean bracket = isBracket(chatAtCursor);
if (bracket && isOpen(chatAtCursor)) { //open
findClose(chatAtCursor, selEnd);
} else if (bracket) { //close
findOpen(chatAtCursor, selEnd);
} else {
char before = selEnd > 0 ? text.charAt(selEnd - 1) : 0;
bracket = isBracket(before);
if (bracket && isOpen(before)) { //open
findClose(before, selEnd - 1);
} else if (bracket) {
findOpen(before, selEnd - 1);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: afterTextChanged
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void afterTextChanged(Editable s) {
SpannableStringBuilder spannableString = (SpannableStringBuilder) s;
int startPos = -1, endPos;
char curChar;
String keyword;
setUpColorSpan(s);
resultKeyWordSet.clear();
for (int i = 0; i < s.length(); i++) {
curChar = s.charAt(i);
endPos = i ;
if (curChar == Constants.TAG_FLAG_CHAR) {
keyword = spannableString.subSequence(startPos == -1 ? i : startPos + 1, endPos).toString();
if (isFlagChanged(startPos, i)
&& nameList.contains(keyword)) {
s.setSpan(new ForegroundColorSpan(textColor), startPos, endPos + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
resultKeyWordSet.add(keyword);
}
startPos = i;
}
}
if(null!=callback){
callback.onUpdate(resultKeyWordSet);
}
}
示例7: createPasswordSpans
import android.text.Editable; //导入方法依赖的package包/类
private void createPasswordSpans() {
Editable text = getText();
for (int start = 0; start < text.length(); start++) {
int end;
for (end = start; end < text.length(); end++) {
if (text.charAt(end) == '\n')
break;
}
CharSequence line = text.subSequence(start, end);
int passwordStart = getPasswordStart(line.toString());
if (passwordStart != -1 && (line.length() != passwordStart + 1 ||
line.charAt(passwordStart) != '-')) {
String replacedText = getTextWithPasswords(line.subSequence(passwordStart,
line.length()));
getText().replace(start + passwordStart, end, "-");
getText().setSpan(new PasswordSpan(getContext(), replacedText),
start + passwordStart, start + passwordStart + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
start = start + passwordStart + 2;
continue;
}
start = end;
}
}
示例8: afterTextChanged
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void afterTextChanged(Editable s) {
if (mPossiblyNotMultiline) {
boolean found = false;
for (int i = s.length() - 1; i >= 0; --i) {
if (s.charAt(i) == '\n') {
found = true;
break;
}
}
if (!found) {
mMultiline = false;
int pos = mEditText.getSelectionStart();
mEditText.setInputType(mEditText.getInputType()
& (~InputType.TYPE_TEXT_FLAG_MULTI_LINE));
mEditText.setSelection(pos);
}
}
}
示例9: applyMask
import android.text.Editable; //导入方法依赖的package包/类
private void applyMask(Editable text) {
if (TextUtils.isEmpty(text) || !hasMask()) {
return;
}
//remove input filters to ignore input type
InputFilter[] filters = text.getFilters();
text.setFilters(new InputFilter[0]);
int maskLen = mask.length();
int textLen = text.length();
int i = 0;
int notSymbolIndex = 0;
StringBuilder sb = new StringBuilder();
while (i < maskLen && notSymbolIndex < textLen) {
if (mask.charAt(i) == text.charAt(notSymbolIndex) || mask.charAt(i) == REPLACE_CHAR) {
sb.append(text.charAt(notSymbolIndex));
notSymbolIndex++;
} else {
sb.append(mask.charAt(i));
}
i++;
}
text.clear();
text.append(sb.toString());
//reset filters
text.setFilters(filters);
}
示例10: afterTextChanged
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void afterTextChanged(Editable s) {
if (inputType == INPUT_ZH) {
int l = s.length();
while (--l >= 0) {
if (s.charAt(l) < 0x4E00 || s.charAt(l) > 0x9FB0) {
s.delete(l, l + 1);
}
}
}
((TextView) findViewById(R.id.ced_confirm)).setTextColor(TextUtils.isEmpty(s.toString().trim())
? context.getResources().getColor(R.color.forbid_click_color)
: context.getResources().getColor(R.color.base_blue));
}
示例11: afterTextChanged
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void afterTextChanged(Editable s) {
if(inputType==INPUT_ZH){
int l=s.length();
while(--l>=0){
if(s.charAt(l)<0x4E00||s.charAt(l)>0x9FB0){
s.delete(l, l+1);
}
}
}
}
示例12: sameTextForSpan
import android.text.Editable; //导入方法依赖的package包/类
private static boolean sameTextForSpan(
final Editable oldText,
final SpannableStringBuilder newText,
final int start,
final int end) {
if (start > newText.length() || end > newText.length()) {
return false;
}
for (int charIdx = start; charIdx < end; charIdx++) {
if (oldText.charAt(charIdx) != newText.charAt(charIdx)) {
return false;
}
}
return true;
}
示例13: update
import android.text.Editable; //导入方法依赖的package包/类
private void update(Editable messageText) {
int messageLength = messageText.length();
// is there unicode character in the message?
boolean unicode = false;
for (int i = 0; i < messageLength; i++) {
char c = messageText.charAt(i);
if (Character.UnicodeBlock.of(c) != Character.UnicodeBlock.BASIC_LATIN) {
unicode = true;
break;
}
}
// get max length of sms part depending on encoding and full length
int length1 = (unicode ? SMS_LENGTH_UNICODE : SMS_LENGTH);
int length2 = (unicode ? SMS_LENGTH2_UNICODE : SMS_LENGTH2);
int partMaxLength = (messageLength > length1 ? length2 : length1);
// create current length status info
int partsNumber = messageLength / partMaxLength + 1;
int partLength = partMaxLength - messageLength % partMaxLength;
// correct length info for second part
if (partsNumber == 2 && partLength == partMaxLength) {
partLength = length1 - (length1 - length2) * 2;
}
// show current length status info
String counterText = "" + partLength + "/" + partsNumber;
counterTextView.setText(counterText);
}
示例14: afterTextChanged
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void afterTextChanged(Editable s) {
if (isActionInProgress()) return;
setActionInProgress(true);
boolean hasHiddenNewLine = s.length() > 0 && s.charAt(0) == NEWLINE;
if (mHasHiddenNewline && !hasHiddenNewLine && !isFirst()) {
// An hidden newline was removed! Pass stuff back.
// This might make us empty, and eventually, delete us.
LOG.w(logPrefix(), "afterTextChanged:",
"we had a hidden newline, but not anymore.",
"Passing \"isFirst line\" back.");
previous().acceptSpace(0);
}
setActionInProgress(false);
}
示例15: findOpen
import android.text.Editable; //导入方法依赖的package包/类
private void findOpen(char close, int selEnd) {
Editable text = editText.getText();
int cursor = selEnd - 1;
int count = 1;
boolean find = false;
char open = getOpen(close);
while (cursor > 0) {
char chatAtCursor = text.charAt(cursor);
if (chatAtCursor == open) {
count--;
} else if (chatAtCursor == close) {
count++;
}
if (count == 0) {
find = true;
break;
}
cursor--;
}
BracketSpan[] spans = text.getSpans(0, text.length(), BracketSpan.class);
for (BracketSpan span : spans) {
text.removeSpan(span);
}
text.setSpan(new BracketSpan(codeTheme.getBracketColor(),
codeTheme.getTextColor()), selEnd, selEnd + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
if (find) {
text.setSpan(new BracketSpan(codeTheme.getBracketColor(),
codeTheme.getTextColor()), cursor, cursor + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}