下面列出了怎么用android.text.SpanWatcher的API类实例代码及写法,或者点击链接到github查看源代码。
private void sendSpanAdded(Object what, int start, int end) {
if(VERBOSE_LOG) Logger.debug(TAG + ": in sendSpanAdded");
SpanWatcher[] recip = getSpans(start, end, SpanWatcher.class);
int n = recip.length;
for (int i = 0; i < n; i++) {
try
{
recip[i].onSpanAdded(this, what, start, end);
}
catch (Throwable e)
{
Logger.log(e);
}
}
}
private void sendSpanRemoved(Object what, int start, int end) {
if(VERBOSE_LOG) Logger.debug(TAG + ": in sendSpanRemoved");
SpanWatcher[] recip = getSpans(start, end, SpanWatcher.class);
int n = recip.length;
for (int i = 0; i < n; i++) {
try
{
recip[i].onSpanRemoved(this, what, start, end);
}
catch (Throwable e)
{
Logger.log(e);
}
}
}
private void sendSpanChanged(Object what, int oldStart, int oldEnd, int start, int end) {
if(VERBOSE_LOG) Logger.debug(TAG + ": in sendSpanChanged");
// The bounds of a possible SpanWatcher are guaranteed to be set before this method is
// called, so that the order of the span does not affect this broadcast.
SpanWatcher[] spanWatchers = getSpans(Math.min(oldStart, start),
Math.min(Math.max(oldEnd, end), length()), SpanWatcher.class);
int n = spanWatchers.length;
for (int i = 0; i < n; i++) {
try
{
spanWatchers[i].onSpanChanged(this, what, oldStart, oldEnd, start, end);
}
catch (Throwable e)
{
Logger.log(e);
}
}
}
private void invalidateSpanToClick() {
if (spanToClick == null) {
return;
}
CharSequence text = getText();
if (text instanceof Spannable) {
Spannable spannable = (Spannable) text;
int start = spannable.getSpanStart(spanToClick);
int end = spannable.getSpanEnd(spanToClick);
if (start >= 0 && end >= start) {
SpanWatcher[] watchers = spannable.getSpans(0, spannable.length(), SpanWatcher.class);
if (watchers != null && watchers.length >= 1) {
for (SpanWatcher watcher : watchers) {
if (watcher.getClass().getName().equals("android.widget.TextView$ChangeWatcher")) {
// Notify span changed to redraw it
watcher.onSpanChanged(spannable, spanToClick, start, end, start, end);
}
}
}
}
}
invalidate();
}
private void sendSpanAdded(Object what, int start, int end) {
SpanWatcher[] recip = getSpans(start, end, SpanWatcher.class);
int n = recip.length;
for (int i = 0; i < n; i++) {
recip[i].onSpanAdded(this, what, start, end);
}
}
private void sendSpanRemoved(Object what, int start, int end) {
SpanWatcher[] recip = getSpans(start, end, SpanWatcher.class);
int n = recip.length;
for (int i = 0; i < n; i++) {
recip[i].onSpanRemoved(this, what, start, end);
}
}
private void sendSpanChanged(Object what, int s, int e, int st, int en) {
SpanWatcher[] recip = getSpans(Math.min(s, st), Math.max(e, en),
SpanWatcher.class);
int n = recip.length;
for (int i = 0; i < n; i++) {
recip[i].onSpanChanged(this, what, s, e, st, en);
}
}
private void sendSpanAdded(Object what, int start, int end) {
SpanWatcher[] recip = getSpans(start, end, SpanWatcher.class);
int n = recip.length;
for (int i = 0; i < n; i++) {
recip[i].onSpanAdded(this, what, start, end);
}
}
private void sendSpanRemoved(Object what, int start, int end) {
SpanWatcher[] recip = getSpans(start, end, SpanWatcher.class);
int n = recip.length;
for (int i = 0; i < n; i++) {
recip[i].onSpanRemoved(this, what, start, end);
}
}
private void sendSpanChanged(Object what, int s, int e, int st, int en) {
SpanWatcher[] recip = getSpans(Math.min(s, st), Math.max(e, en),
SpanWatcher.class);
int n = recip.length;
for (int i = 0; i < n; i++) {
recip[i].onSpanChanged(this, what, s, e, st, en);
}
}