public static LinkedList<StyleContainer> findIconsFromEditable(Editable editable, HashMap<String, ITypeface> fonts) {
        LinkedList<StyleContainer> styleContainers = new LinkedList<>();
        LinkedList<StyleContainer> existingSpans = new LinkedList<>();

        // remember the previous style spans
        for (ParcelableSpan span : editable.getSpans(0, editable.length(), ParcelableSpan.class)) {
            existingSpans.add(new StyleContainer(editable.getSpanStart(span), editable.getSpanEnd(span), span, editable.getSpanFlags(span)));
        }
        for (CharacterStyle span : editable.getSpans(0, editable.length(), CharacterStyle.class)) {
            existingSpans.add(new StyleContainer(editable.getSpanStart(span), editable.getSpanEnd(span), span, editable.getSpanFlags(span)));
        }
        try {
            editable.clearSpans();
        } catch (Exception ex) {
            //SpannableStringBuilder has an issue which causes this to crash
            //https://github.com/mikepenz/Android-Iconics/issues/155#issue-141629137
        }

        int iconStart = -1;
        for (int i = 0; i < editable.length(); i++) {
            Character c = editable.charAt(i);
            if (c == ICON_START) {
                iconStart = i;
            } else if (c == ICON_END) {
                if (iconStart > -1) {
                    StyleContainer styleContainer = placeFontIcon(editable, iconStart, i, fonts);

                    if (styleContainer != null) {
                        styleContainers.add(styleContainer);

                        //adjust existing spans to new position
                        for (StyleContainer existingStyleContainer : existingSpans) {
                            if (existingStyleContainer.startIndex > i) {
                                existingStyleContainer.startIndex = existingStyleContainer.startIndex - (i - iconStart);
                                existingStyleContainer.endIndex = existingStyleContainer.endIndex - (i - iconStart);
                            } else if (existingStyleContainer.endIndex > i) {
                                existingStyleContainer.endIndex = existingStyleContainer.endIndex - (i - iconStart);
                            }
                        }

                        //remember how many chars were removed already so we can remove the correct characters
                        i = iconStart;
                    }
                }

                iconStart = -1;
            }
        }

        //add the existing spans
        styleContainers.addAll(existingSpans);

        return styleContainers;
    }
public static LinkedList < StyleContainer > findIconsFromEditable ( Editable editable , HashMap < String , ITypeface > fonts ) { LinkedList < StyleContainer > styleContainers = new LinkedList < > ( ) ; LinkedList < StyleContainer > existingSpans = new LinkedList < > ( ) ; for ( ParcelableSpan span : editable . getSpans ( 0 , editable . length ( ) , ParcelableSpan . class ) ) { existingSpans . add ( new StyleContainer ( editable . getSpanStart ( span ) , editable . getSpanEnd ( span ) , span , editable . getSpanFlags ( span ) ) ) ; } for ( CharacterStyle span : editable . getSpans ( 0 , editable . length ( ) , CharacterStyle . class ) ) { existingSpans . add ( new StyleContainer ( editable . getSpanStart ( span ) , editable . getSpanEnd ( span ) , span , editable . getSpanFlags ( span ) ) ) ; } try { editable . clearSpans ( ) ; } catch ( Exception ex ) { } int iconStart = - 1 ; for ( int i = 0 ; i < editable . length ( ) ; i ++ ) { Character c = editable . charAt ( i ) ; if ( c == ICON_START ) { iconStart = i ; } else if ( c == ICON_END ) { if ( iconStart > - 1 ) { StyleContainer styleContainer = placeFontIcon ( editable , iconStart , i , fonts ) ; if ( styleContainer != null ) { styleContainers . add ( styleContainer ) ; for ( StyleContainer existingStyleContainer : existingSpans ) { if ( existingStyleContainer . startIndex > i ) { existingStyleContainer . startIndex = existingStyleContainer . startIndex - ( i - iconStart ) ; existingStyleContainer . endIndex = existingStyleContainer . endIndex - ( i - iconStart ) ; } else if ( existingStyleContainer . endIndex > i ) { existingStyleContainer . endIndex = existingStyleContainer . endIndex - ( i - iconStart ) ; } } i = iconStart ; } } iconStart = - 1 ; } } styleContainers . addAll ( existingSpans ) ; return styleContainers ; }
finds the icons within a Editable, and tries to map the the available (given via the fonts param) icons on it
Use this whenever possible, as this method does update the Editable, and does not have to create a new Spanned

@param editable
@param fonts
@return