Example usage for android.text ParcelableSpan getSpanTypeId

List of usage examples for android.text ParcelableSpan getSpanTypeId

Introduction

In this page you can find the example usage for android.text ParcelableSpan getSpanTypeId.

Prototype

int getSpanTypeId();

Source Link

Document

Return a special type identifier for this span class.

Usage

From source file:com.jecelyin.editor.v2.core.text.TextUtils.java

/**
 * Flatten a CharSequence and whatever styles can be copied across processes
 * into the parcel./*from w  w w.  ja va2  s. c o  m*/
 */
public static void writeToParcel(CharSequence cs, Parcel p, int parcelableFlags) {
    if (cs instanceof Spanned) {
        p.writeInt(0);
        p.writeString(cs.toString());

        Spanned sp = (Spanned) cs;
        Object[] os = sp.getSpans(0, cs.length(), Object.class);

        // note to people adding to this: check more specific types
        // before more generic types.  also notice that it uses
        // "if" instead of "else if" where there are interfaces
        // so one object can be several.

        for (int i = 0; i < os.length; i++) {
            Object o = os[i];
            Object prop = os[i];

            if (prop instanceof CharacterStyle) {
                prop = ((CharacterStyle) prop).getUnderlying();
            }

            if (prop instanceof ParcelableSpan) {
                ParcelableSpan ps = (ParcelableSpan) prop;
                int spanTypeId = ps.getSpanTypeId();
                if (spanTypeId < FIRST_SPAN || spanTypeId > LAST_SPAN) {
                    Log.e(TAG, "external class \"" + ps.getClass().getSimpleName()
                            + "\" is attempting to use the frameworks-only ParcelableSpan" + " interface");
                } else {
                    p.writeInt(spanTypeId);
                    ps.writeToParcel(p, parcelableFlags);
                    writeWhere(p, sp, o);
                }
            }
        }

        p.writeInt(0);
    } else {
        p.writeInt(1);
        if (cs != null) {
            p.writeString(cs.toString());
        } else {
            p.writeString(null);
        }
    }
}