package com.eqot.fontawesome;

import android.content.Context;
import android.graphics.Typeface;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.TypefaceSpan;
import android.view.View;
import android.widget.TextView;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FontAwesome {
    private static final String FONT_FILENAME = "fontawesome-webfont.ttf";

    private static TypefaceSpan sTypefaceSpan = null;
    private static final Pattern pattern = Pattern.compile("([^\\{]*)\\{([\\w\\-]+)\\}(.*)");

    public static void apply(Context context, View view) {
        if (sTypefaceSpan == null) {
            final Typeface typeface = Typeface.createFromAsset(context.getAssets(), FONT_FILENAME);
            sTypefaceSpan = new CustomTypefaceSpan("", typeface);
        }

        final TextView textView = (TextView) view;
        String text = (String) textView.getText();

        final SpannableStringBuilder sb = new SpannableStringBuilder();
        while (true) {
            final Matcher matcher = pattern.matcher(text);
            if (!matcher.find()) {
                sb.append(text);
                break;
            }

            sb.append(matcher.group(1));

            final String orgCode = matcher.group(2);
            final String code = orgCode.replace("-", "_");
            final int id = context.getResources().getIdentifier(code, "string", context.getPackageName());
            final String string = context.getResources().getString(id);
            sb.append(string, sTypefaceSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

            text = matcher.group(3);
        }

        textView.setText(sb);
    }
}

@@ -167,48 +167,8 @@
 ed;%0A
-import android.text.style.TypefaceSpan;%0A
 impo
@@ -189,16 +189,16 @@
 w.View;%0A
+
 import a
@@ -417,20 +417,16 @@
 Typeface
-Span
  sTypefa
@@ -423,28 +423,24 @@
 ce sTypeface
-Span
  = null;%0A   
@@ -611,20 +611,16 @@
 Typeface
-Span
  == null
@@ -639,24 +639,10 @@
     
-final Typeface t
+sT
 ypef
@@ -713,74 +713,8 @@
 E);%0A
-            sTypefaceSpan = new CustomTypefaceSpan(%22%22, typeface);%0A
     
@@ -1446,17 +1446,26 @@
 string, 
-s
+new Custom
 Typeface
@@ -1468,16 +1468,31 @@
 faceSpan
+(%22%22, sTypeface)
 , Spanne

Fix issue when multiple icons exist