本文整理汇总了Java中android.text.Editable.removeSpan方法的典型用法代码示例。如果您正苦于以下问题:Java Editable.removeSpan方法的具体用法?Java Editable.removeSpan怎么用?Java Editable.removeSpan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Editable
的用法示例。
在下文中一共展示了Editable.removeSpan方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleIgnoredTag
import android.text.Editable; //导入方法依赖的package包/类
/**
* When we come upon an ignored tag, we mark it with an Annotation object with a specific key
* and value as above. We don't really need to be checking these values since Html.fromHtml()
* doesn't use Annotation spans, but we should do it now to be safe in case they do start using
* it in the future.
* @param opening If this is an opening tag or not.
* @param output Spannable string that we're working with.
*/
private void handleIgnoredTag(boolean opening, Editable output) {
int len = output.length();
if (opening) {
output.setSpan(new Annotation(IGNORED_ANNOTATION_KEY, IGNORED_ANNOTATION_VALUE), len,
len, Spannable.SPAN_MARK_MARK);
} else {
Object start = getOpeningAnnotation(output);
if (start != null) {
int where = output.getSpanStart(start);
// Remove the temporary Annotation span.
output.removeSpan(start);
// Delete everything between the start of the Annotation and the end of the string
// (what we've generated so far).
output.delete(where, len);
}
}
}
示例2: setTextSize
import android.text.Editable; //导入方法依赖的package包/类
/**
* 设置字体大小
* @param textSize textSize
*/
void setTextSize(int textSize) {
Editable edit = getEditableText();
int index = getSelectionIndex();
int star = getSectionStart();
int end = getSectionEnd();
if (star >= end)
return;
if (index >= 0 && index < mSections.size()) {
TextSection section = mSections.get(index);
section.setTextSize(textSize);
if (mListener != null) {
mListener.onSectionChange(section);
}
}
AbsoluteSizeSpan[] styleSpans = edit.getSpans(star, end, AbsoluteSizeSpan.class);
for (AbsoluteSizeSpan span : styleSpans) {
edit.removeSpan(span);
}
edit.setSpan(new AbsoluteSizeSpan(UI.dipToPx(getContext(), textSize)), star, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
update(index);
}
示例3: undo
import android.text.Editable; //导入方法依赖的package包/类
public void undo() {
EditItem edit = mEditHistory.getPrevious();
if (edit == null) {
return;
}
Editable editable = mTextView.getEditableText();
int start = edit.start;
int end = start + (edit.after != null ? edit.after.length() : 0);
mIsUndoOrRedo = true;
editable.replace(start, end, edit.before);
mIsUndoOrRedo = false;
for (Object o : editable.getSpans(0, editable.length(), UnderlineSpan.class)) {
editable.removeSpan(o);
}
Selection.setSelection(editable, edit.before == null ? start : (start + edit.before.length()));
}
示例4: redo
import android.text.Editable; //导入方法依赖的package包/类
public void redo() {
EditItem edit = mEditHistory.getNext();
if (edit == null) {
return;
}
Editable text = mTextView.getEditableText();
int start = edit.start;
int end = start + (edit.before != null ? edit.before.length() : 0);
mIsUndoOrRedo = true;
text.replace(start, end, edit.after);
mIsUndoOrRedo = false;
// This will get rid of underlines inserted when editor tries to come
// up with a suggestion.
for (Object o : text.getSpans(0, text.length(), UnderlineSpan.class)) {
text.removeSpan(o);
}
Selection.setSelection(text, edit.after == null ? start
: (start + edit.after.length()));
}
示例5: undo
import android.text.Editable; //导入方法依赖的package包/类
public void undo() {
EditItem edit = mEditHistory.getPrevious();
if (edit == null) {
return;
}
Editable editable = mTextView.getEditableText();
int start = edit.start;
int end = start + (edit.after != null ? edit.after.length() : 0);
mIsUndoOrRedo = true;
editable.replace(start, end, edit.before);
mIsUndoOrRedo = false;
for (Object o : editable.getSpans(0, editable.length(), UnderlineSpan.class)) {
editable.removeSpan(o);
}
Selection.setSelection(editable,
edit.before == null ? start : (start + edit.before.length()));
}
示例6: afterTextChanged
import android.text.Editable; //导入方法依赖的package包/类
@Override
public void afterTextChanged(Editable s) {
final RichEditText.TagSpan span = willDelSpan;
log("TagSpanTextWatcher#willRemove#span:" + (span == null ? "null" : span.toString()));
if (span != null && span.willRemove) {
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
// Remove the span
s.removeSpan(span);
// Remove the remaining emoticon text.
if (start != end) {
s.delete(start, end);
}
}
}
示例7: setBold
import android.text.Editable; //导入方法依赖的package包/类
void setBold(boolean isBold) {
int index = getSelectionIndex();
if (index >= 0 && index < mSections.size()) {
mSections.get(index).setBold(isBold);
}
Editable edit = getEditableText();
int star = getSectionStart();
int end = getSectionEnd();
if (isBold) {
edit.setSpan(new StyleSpan(Typeface.BOLD),
star,
end,
Typeface.BOLD);
} else {
StyleSpan[] styleSpans = edit.getSpans(star,
end, StyleSpan.class);
for (CharacterStyle span : styleSpans) {
if (span instanceof StyleSpan && ((StyleSpan) span).getStyle() == Typeface.BOLD)
edit.removeSpan(span);
}
}
}
示例8: setItalic
import android.text.Editable; //导入方法依赖的package包/类
void setItalic(boolean isItalic, int index) {
if (index >= 0 && index < mSections.size()) {
mSections.get(index).setItalic(isItalic);
}
Editable edit = getEditableText();
int star = getSectionStart();
int end = getSectionEnd();
if (isItalic) {
edit.setSpan(new StyleSpan(Typeface.ITALIC),
star,
end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
StyleSpan[] styleSpans = edit.getSpans(star,
end, StyleSpan.class);
for (CharacterStyle span : styleSpans) {
if (span instanceof StyleSpan && ((StyleSpan) span).getStyle() == Typeface.ITALIC)
edit.removeSpan(span);
}
}
}
示例9: setMidLine
import android.text.Editable; //导入方法依赖的package包/类
/**
* 中横线,即删除线
*
* @param isMidLine isMidLine
*/
void setMidLine(boolean isMidLine) {
int index = getSelectionIndex();
if (index >= 0 && index < mSections.size()) {
mSections.get(index).setMidLine(isMidLine);
}
Editable edit = getEditableText();
int star = getSectionStart();
int end = getSectionEnd();
if (isMidLine) {
edit.setSpan(new StrikethroughSpan(),
star,
end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
StrikethroughSpan[] styleSpans = edit.getSpans(star,
end, StrikethroughSpan.class);
for (StrikethroughSpan span : styleSpans) {
edit.removeSpan(span);
}
}
}
示例10: endBlockElement
import android.text.Editable; //导入方法依赖的package包/类
private void endBlockElement(String tag, Editable text) {
Newline n = getLast(text, Newline.class);
if (n != null) {
appendNewlines(text, n.mNumNewlines);
text.removeSpan(n);
}
Alignment a = getLast(text, Alignment.class);
if (a != null) {
setSpanFromMark(tag, text, a, new AlignmentSpan.Standard(a.mAlignment));
}
}
示例11: setTextSizeSpan
import android.text.Editable; //导入方法依赖的package包/类
private void setTextSizeSpan(int textSize, int index) {
Editable edit = getEditableText();
int star = getSectionStart(index);
int end = getSectionEnd(index);
if (star >= end)
return;
AbsoluteSizeSpan[] styleSpans = edit.getSpans(star, end, AbsoluteSizeSpan.class);
for (AbsoluteSizeSpan span : styleSpans) {
edit.removeSpan(span);
}
edit.setSpan(new AbsoluteSizeSpan(UI.dipToPx(getContext(), textSize)), star, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
示例12: setSpan
import android.text.Editable; //导入方法依赖的package包/类
/**
* Adds the span to the current text.
* @param userText The user entered text.
* @param autocompleteText The autocomplete text being appended.
*/
public void setSpan(CharSequence userText, CharSequence autocompleteText) {
Editable text = getText();
text.removeSpan(this);
mAutocompleteText = autocompleteText;
mUserText = userText;
text.setSpan(
this,
userText.length(),
text.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
示例13: setColorSpan
import android.text.Editable; //导入方法依赖的package包/类
void setColorSpan(int color, int index) {
Editable edit = getEditableText();
int star = getSectionStart(index);
int end = getSectionEnd(index);
if (star >= end)
return;
ForegroundColorSpan[] styleSpans = edit.getSpans(star, end, ForegroundColorSpan.class);
for (ForegroundColorSpan span : styleSpans) {
edit.removeSpan(span);
}
edit.setSpan(new ForegroundColorSpan(color), star, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
示例14: redo
import android.text.Editable; //导入方法依赖的package包/类
/**
* Perform redo.
*/
public void redo() {
EditItem edit = mEditHistory.getNext();
if (edit == null) {
return;
}
Editable text = getEditableText();
int start = edit.mmStart;
int end = start + (edit.mmBefore != null
? edit.mmBefore.length() : 0);
mIsUndoOrRedo = true;
text.replace(start, end, edit.mmAfter);
mIsUndoOrRedo = false;
// This will get rid of underlines inserted when editor tries to come
// up with a suggestion.
for (Object o : text.getSpans(0,
text.length(), UnderlineSpan.class)) {
text.removeSpan(o);
}
Selection.setSelection(text,
edit.mmAfter == null ? start
: (start + edit.mmAfter.length()));
}
示例15: findClose
import android.text.Editable; //导入方法依赖的package包/类
private void findClose(char open, int selEnd) {
Log.d(TAG, "findClose() called with: open = [" + open + "], selEnd = [" + selEnd + "]");
Editable text = editText.getText();
int cursor = selEnd + 1;
int count = 1;
char close = getClose(open);
boolean find = false;
while (cursor < text.length()) {
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);
}
}