下面列出了android.text.Selection#SELECTION_END 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void setSpan(Object what, int start, int end, int flags) {
// Do not add any spans that affect the character appearance of a mention (i.e. they overlap
// with a MentionSpan). This helps prevent mentions from having a red underline due to the spell
// checker. Note: SuggestionSpan was added in ICS, and different keyboards may use other kinds
// of spans (i.e. the Motorola SpellCheckerMarkupSpan). Therefore, we cannot just filter out
// SuggestionSpans, but rather, any span that would change the appearance of our MentionSpans.
if (what instanceof CharacterStyle) {
MentionSpan[] mentionSpans = getSpans(start, end, MentionSpan.class);
if (mentionSpans != null && mentionSpans.length > 0) {
return;
}
}
// Ensure that the start and end points are set at zero initially
// Note: This issue was seen on a Gingerbread device (start and end were both -1) and
// prevents the device from crashing.
if ((what == Selection.SELECTION_START || what == Selection.SELECTION_END) && length() == 0) {
start = 0;
end = 0;
}
super.setSpan(what, start, end, flags);
}
public void onSpanChanged(Spannable buf,
Object what, int s, int e, int start, int stop) {
if (what == Selection.SELECTION_END) {
buf.removeSpan(TextKeyListener.ACTIVE);
removeTimeouts(buf);
}
}
@Override
public void onSpanChanged(Spannable text, Object what, int ostart, int oend, int nstart, int nend) {
if (disabled || block) return;
if (what == Selection.SELECTION_END) {
// Selection end changed from ostart to nstart. Trigger a check.
log("onSpanChanged: selection end moved from "+ostart+" to "+nstart);
log("onSpanChanged: block is "+block);
boolean b = block;
block = true;
if (!isPopupShowing() && policy.shouldShowPopup(text, nstart)) {
showPopup(policy.getQuery(text));
}
block = b;
}
}
public void onSpanChanged(Spannable s, Object what, int start, int end,
int st, int en) {
if (what == Selection.SELECTION_END) {
s.removeSpan(ACTIVE);
}
}
private boolean isNonIntermediateSelectionSpan(final Spanned text, final Object span) {
return (Selection.SELECTION_START == span || Selection.SELECTION_END == span)
&& (text.getSpanFlags(span) & Spanned.SPAN_INTERMEDIATE) == 0;
}