Search in sources :

Example 1 with IIcon

use of com.mikepenz.iconics.typeface.IIcon in project Android-Iconics by mikepenz.

the class IconicsUtils method placeFontIcon.

/**
     * @param editable
     * @param iconStart
     * @param iconEnd
     * @param fonts
     * @return
     */
private static StyleContainer placeFontIcon(Editable editable, int iconStart, int iconEnd, HashMap<String, ITypeface> fonts) {
    //make sure to check only for possible icons
    if (iconEnd - iconStart >= 6) {
        //build the iconString
        String iconString = editable.subSequence(iconStart + 1, iconEnd).toString().replace("-", "_");
        //find out the fontKey
        String fontKey = editable.subSequence(iconStart + 1, iconStart + 4).toString();
        try {
            //get the correct character for this Font and Icon
            ITypeface typeface = fonts.get(fontKey);
            if (typeface != null) {
                //get the icon for the iconString
                IIcon icon = typeface.getIcon(iconString);
                //we can only add an icon which is a font
                if (icon != null) {
                    //get and add the mapped char to the string
                    char fontChar = icon.getCharacter();
                    editable.replace(iconStart, iconEnd + 1, String.valueOf(fontChar));
                    //add the current icon to the container
                    return new StyleContainer(iconStart, iconStart + 1, iconString, fonts.get(fontKey));
                } else {
                    Log.e(Iconics.TAG, "Wrong icon name: " + iconString);
                }
            } else {
                Log.e(Iconics.TAG, "Wrong fontId: " + iconString);
            }
        } catch (IllegalArgumentException e) {
            Log.e(Iconics.TAG, "Wrong icon name: " + iconString);
        }
    }
    return null;
}
Also used : IIcon(com.mikepenz.iconics.typeface.IIcon) ITypeface(com.mikepenz.iconics.typeface.ITypeface)

Example 2 with IIcon

use of com.mikepenz.iconics.typeface.IIcon in project Android-Iconics by mikepenz.

the class IconicsUtils method placeFontIcon.

/**
     * @param spannedString
     * @param tempIconString
     * @param fonts
     * @return
     */
private static StyleContainer placeFontIcon(SpannableStringBuilder spannedString, SpannableStringBuilder tempIconString, HashMap<String, ITypeface> fonts) {
    //make sure to check only for possible icons
    if (tempIconString.length() >= 6) {
        //build the iconString
        String iconString = tempIconString.subSequence(1, tempIconString.length() - 1).toString().replace("-", "_");
        //find out the fontKey
        String fontKey = tempIconString.subSequence(1, 4).toString();
        try {
            //get the correct character for this Font and Icon
            ITypeface typeface = fonts.get(fontKey);
            if (typeface != null) {
                //get the icon for the iconString
                IIcon icon = typeface.getIcon(iconString);
                //we can only add an icon which is a font
                if (icon != null) {
                    //get and add the mapped char to the string
                    char fontChar = icon.getCharacter();
                    spannedString.append(fontChar);
                    //add the current icon to the container
                    return new StyleContainer(spannedString.length() - 1, spannedString.length(), iconString, fonts.get(fontKey));
                } else {
                    Log.e(Iconics.TAG, "Wrong icon name: " + iconString);
                }
            } else {
                Log.e(Iconics.TAG, "Wrong fontId: " + iconString);
            }
        } catch (IllegalArgumentException e) {
            Log.e(Iconics.TAG, "Wrong icon name: " + iconString);
        }
    }
    //if this was no working icon we add the tempIconString and return null
    spannedString.append(tempIconString);
    return null;
}
Also used : IIcon(com.mikepenz.iconics.typeface.IIcon) ITypeface(com.mikepenz.iconics.typeface.ITypeface)

Aggregations

IIcon (com.mikepenz.iconics.typeface.IIcon)2 ITypeface (com.mikepenz.iconics.typeface.ITypeface)2