Java Code Examples for android.text.NoCopySpan

The following examples show how to use android.text.NoCopySpan. These examples are extracted from open source projects.
Example 1
Project: PowerFileExplorer   File: SpannableStringBuilder.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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);
            }
        }
    }
}
 
Example 2
Project: revolution-irc   File: SpannableStringHelper.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static CharSequence copyCharSequence(CharSequence msg) {
    SpannableString str = new SpannableString(msg);
    for (Object o : str.getSpans(0, str.length(), NoCopySpan.class))
        str.removeSpan(o);
    return str;
}
 
Example 3
Project: JotaTextEditor   File: SpannableStringBuilder.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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);
            }
        }
    }
}