Example usage for android.text Spanned getSpanFlags

List of usage examples for android.text Spanned getSpanFlags

Introduction

In this page you can find the example usage for android.text Spanned getSpanFlags.

Prototype

public int getSpanFlags(Object tag);

Source Link

Document

Return the flags that were specified when Spannable#setSpan was used to attach the specified markup object, or 0 if the specified object has not been attached.

Usage

From source file:Main.java

public static boolean isFlaggedSpan(@NonNull Spanned spanned, Object span, int flags) {
    return (spanned.getSpanFlags(span) & flags) == flags;
}

From source file:Main.java

/**
 * Apply only the spans from src to dst specific by spans.
 *
 * @see {@link android.text.TextUtils#copySpansFrom}
 */// ww w  . ja  v a  2 s . c  o  m
public static void copySpans(@NonNull Spanned src, @NonNull Spannable dst, @NonNull Collection<Object> spans) {
    for (Object span : spans) {
        int start = src.getSpanStart(span);
        int end = src.getSpanEnd(span);
        int flags = src.getSpanFlags(span);
        dst.setSpan(span, start, end, flags);
    }
}

From source file:org.miaowo.miaowo.util.Html.java

private static void withinBlockquoteIndividual(StringBuilder out, Spanned text, int start, int end,
        Context context) {//from   w  w  w . ja v a2  s  . co  m
    boolean isInList = false;
    int next;
    for (int i = start; i <= end; i = next) {
        next = TextUtils.indexOf(text, '\n', i, end);
        if (next < 0) {
            next = end;
        }

        boolean isListItem = false;
        ParagraphStyle[] paragraphStyles = text.getSpans(i, next, ParagraphStyle.class);
        for (ParagraphStyle paragraphStyle : paragraphStyles) {
            final int spanFlags = text.getSpanFlags(paragraphStyle);
            if ((spanFlags & Spanned.SPAN_PARAGRAPH) == Spanned.SPAN_PARAGRAPH
                    && paragraphStyle instanceof BulletSpan) {
                isListItem = true;
                break;
            }
        }

        if (isListItem && !isInList) {
            // Current paragraph is the first item in a list
            isInList = true;
            out.append("<ul>\n");
        }

        if (isInList && !isListItem) {
            // Current paragraph is no longer a list item; close the previously opened list
            isInList = false;
            out.append("</ul>\n");
        }

        String tagType = isListItem ? "li" : "p";
        out.append("<").append(tagType).append(getTextDirection(text, start, next))
                .append(getTextStyles(text, start, next)).append(">");

        if (next - i == 0) {
            out.append("<br>");
        } else {
            withinParagraph(out, text, i, next, context);
        }

        out.append("</");
        out.append(tagType);
        out.append(">\n");

        if (next == end && isInList) {
            isInList = false;
            out.append("</ul>\n");
        }

        next++;
    }
}

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

private static void writeWhere(Parcel p, Spanned sp, Object o) {
    p.writeInt(sp.getSpanStart(o));//  w ww  .  j av a2  s.  c o m
    p.writeInt(sp.getSpanEnd(o));
    p.writeInt(sp.getSpanFlags(o));
}

From source file:com.taobao.weex.dom.WXTextDomObject.java

/**
 * Adjust span range after truncate due to the wrong span range during span copy and slicing.
 * @param beforeTruncate The span before truncate
 * @param afterTruncate The span after truncate
 *//*w w w  .  j  a  v a2  s  .  co m*/
private void adjustSpansRange(@NonNull Spanned beforeTruncate, @NonNull Spannable afterTruncate) {
    Object[] spans = beforeTruncate.getSpans(0, beforeTruncate.length(), Object.class);
    for (Object span : spans) {
        int start = beforeTruncate.getSpanStart(span);
        int end = beforeTruncate.getSpanEnd(span);
        if (start == 0 && end == beforeTruncate.length()) {
            afterTruncate.removeSpan(span);
            afterTruncate.setSpan(span, 0, afterTruncate.length(), beforeTruncate.getSpanFlags(span));
        }
    }
}

From source file:tk.wasdennnoch.androidn_ify.utils.NotificationColorUtil.java

/**
 * Inverts all the grayscale colors set by {@link TextAppearanceSpan}s on
 * the text./*from  w w w . j  a v a  2s  .  co  m*/
 *
 * @param charSequence The text to process.
 * @return The color inverted text.
 */
public CharSequence invertCharSequenceColors(CharSequence charSequence) {
    if (charSequence instanceof Spanned) {
        Spanned ss = (Spanned) charSequence;
        Object[] spans = ss.getSpans(0, ss.length(), Object.class);
        SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString());
        for (Object span : spans) {
            Object resultSpan = span;
            if (span instanceof TextAppearanceSpan) {
                resultSpan = processTextAppearanceSpan((TextAppearanceSpan) span);
            }
            builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), ss.getSpanFlags(span));
        }
        return builder;
    }
    return charSequence;
}

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

/**
 * Copies the spans from the region <code>start...end</code> in
 * <code>source</code> to the region
 * <code>destoff...destoff+end-start</code> in <code>dest</code>.
 * Spans in <code>source</code> that begin before <code>start</code>
 * or end after <code>end</code> but overlap this range are trimmed
 * as if they began at <code>start</code> or ended at <code>end</code>.
 *
 * @throws IndexOutOfBoundsException if any of the copied spans
 * are out of range in <code>dest</code>.
 *///from  w ww  .  j  a v a2  s .  co  m
public static void copySpansFrom(Spanned source, int start, int end, Class kind, Spannable dest, int destoff) {
    if (kind == null) {
        kind = Object.class;
    }

    Object[] spans = source.getSpans(start, end, kind);

    for (int i = 0; i < spans.length; i++) {
        int st = source.getSpanStart(spans[i]);
        int en = source.getSpanEnd(spans[i]);
        int fl = source.getSpanFlags(spans[i]);

        if (st < start)
            st = start;
        if (en > end)
            en = end;

        dest.setSpan(spans[i], st - start + destoff, en - start + destoff, fl);
    }
}

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

/**
 * Debugging tool to print the spans in a CharSequence.  The output will
 * be printed one span per line.  If the CharSequence is not a Spanned,
 * then the entire string will be printed on a single line.
 *//*ww  w.  j ava 2 s. c  o m*/
public static void dumpSpans(CharSequence cs, Printer printer, String prefix) {
    if (cs instanceof Spanned) {
        Spanned sp = (Spanned) cs;
        Object[] os = sp.getSpans(0, cs.length(), Object.class);

        for (int i = 0; i < os.length; i++) {
            Object o = os[i];
            printer.println(prefix + cs.subSequence(sp.getSpanStart(o), sp.getSpanEnd(o)) + ": "
                    + Integer.toHexString(System.identityHashCode(o)) + " " + o.getClass().getCanonicalName()
                    + " (" + sp.getSpanStart(o) + "-" + sp.getSpanEnd(o) + ") fl=#" + sp.getSpanFlags(o));
        }
    } else {
        printer.println(prefix + cs + ": (no spans)");
    }
}