Example usage for android.text Spanned getSpanEnd

List of usage examples for android.text Spanned getSpanEnd

Introduction

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

Prototype

public int getSpanEnd(Object tag);

Source Link

Document

Return the end of the range of text to which the specified markup object is attached, or -1 if the object is not attached.

Usage

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>.
 *//* w  w w .j  ava  2  s  .  c  om*/
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:tk.wasdennnoch.androidn_ify.utils.NotificationColorUtil.java

/**
 * Inverts all the grayscale colors set by {@link TextAppearanceSpan}s on
 * the text./*from  ww w .j a  v a 2s  .  com*/
 *
 * @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.googlecode.eyesfree.brailleback.DisplayManager.java

private boolean markSelection(Spanned spanned) {
    DisplaySpans.SelectionSpan[] spans = spanned.getSpans(0, spanned.length(),
            DisplaySpans.SelectionSpan.class);
    for (DisplaySpans.SelectionSpan span : spans) {
        int start = textToDisplayPosition(mTranslationResult, mCursorPosition, spanned.getSpanStart(span));
        int end = textToDisplayPosition(mTranslationResult, mCursorPosition, spanned.getSpanEnd(span));
        if (start == end) {
            end = start + 1;/*ww  w  .jav a 2 s.co  m*/
        }
        if (end > mBrailleContent.length) {
            extendContentForCursor();
        }
        copyOverlaidContent();
        for (int i = start; i < end && i < mOverlaidBrailleContent.length; ++i) {
            mOverlaidBrailleContent[i] |= SELECTION_DOTS;
        }
        if (mDisplayPosition < 0) {
            mDisplayPosition = fixDisplayPosition(start);
        }
    }
    return spans.length > 0;
}

From source file:com.eleybourn.bookcatalogue.utils.Utils.java

/**
 * Linkify partial HTML. Linkify methods remove all spans before building links, this
 * method preserves them.//  w ww .j  av a  2s .  c  o m
 * 
 * See: http://stackoverflow.com/questions/14538113/using-linkify-addlinks-combine-with-html-fromhtml
 * 
 * @param html         Partial HTML
 * @param linkifyMask   Linkify mask to use in Linkify.addLinks
 * 
 * @return            Spannable with all links
 */
public static Spannable linkifyHtml(String html, int linkifyMask) {
    // Get the spannable HTML
    Spanned text = Html.fromHtml(html);
    // Save the span details for later restoration
    URLSpan[] currentSpans = text.getSpans(0, text.length(), URLSpan.class);

    // Build an empty spannable then add the links
    SpannableString buffer = new SpannableString(text);
    Linkify.addLinks(buffer, linkifyMask);

    // Add back the HTML spannables
    for (URLSpan span : currentSpans) {
        int end = text.getSpanEnd(span);
        int start = text.getSpanStart(span);
        buffer.setSpan(span, start, end, 0);
    }
    return buffer;
}