Java 类android.text.NoCopySpan 实例源码

项目:revolution-irc    文件:ServerConnectionInfo.java   
public void addHistoryMessage(CharSequence msg) {
    SpannableString str = new SpannableString(msg);
    for (Object o : str.getSpans(0, str.length(), NoCopySpan.class))
        str.removeSpan(o);
    mSentMessageHistory.add(str);
    if (mSentMessageHistory.size() >= HISTORY_MAX_COUNT)
        mSentMessageHistory.remove(0);
}
项目:JotaTextEditor    文件:SpannableStringBuilder.java   
/**
 * Create a new SpannableStringBuilder containing a copy of the
 * specified slice of the specified text, including its spans if any.
 */
public SpannableStringBuilder(CharSequence text, int start, int end) {
    int srclen = end - start;

    int len = ArrayUtils.idealCharArraySize(srclen + 1);
    mText = new char[len];
    mGapStart = srclen;
    mGapLength = len - srclen;

    TextUtils.getChars(text, start, end, mText, 0);

    mSpanCount = 0;
    int alloc = ArrayUtils.idealIntArraySize(0);
    mSpans = new Object[alloc];
    mSpanStarts = new int[alloc];
    mSpanEnds = new int[alloc];
    mSpanFlags = new int[alloc];

    if (text instanceof Spanned) {
        Spanned sp = (Spanned) text;
        Object[] spans = sp.getSpans(start, end, Object.class);

        for (int i = 0; i < spans.length; i++) {
            if (spans[i] instanceof NoCopySpan) {
                continue;
            }

            int st = sp.getSpanStart(spans[i]) - start;
            int en = sp.getSpanEnd(spans[i]) - start;
            int fl = sp.getSpanFlags(spans[i]);

            if (st < 0)
                st = 0;
            if (st > end - start)
                st = end - start;

            if (en < 0)
                en = 0;
            if (en > end - start)
                en = end - start;

            if ( st <= en ) {
                setSpan(spans[i], st, en, fl);
            }
        }
    }
}