package com.gh4a.utils;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.util.SparseArray;

public class TypefaceCache {
    public static final int TF_REGULAR = 0;
    public static final int TF_MEDIUM = 1;
    public static final int TF_BOLD = 2;
    public static final int TF_ITALIC = 3;
    public static final int TF_CONDENSED = 4;
    public static final int TF_BOLDCONDENSED = 5;

    private static final String[] FONT_FILENAMES = new String[] {
        "fonts/Roboto-Regular.ttf",
        "fonts/Roboto-Medium.ttf",
        "fonts/Roboto-Bold.ttf",
        "fonts/Roboto-Italic.ttf",
        "fonts/Roboto-Condensed.ttf",
        "fonts/Roboto-BoldCondensed.ttf"
    };

    private static SparseArray<Typeface> sTypefaces = new SparseArray<>();

    public static Typeface getTypeface(Context context, int typeface, int style) {
        switch (style) {
            case Typeface.BOLD:
                switch (typeface) {
                    case TF_REGULAR: typeface = TF_BOLD; break;
                    case TF_CONDENSED: typeface = TF_BOLDCONDENSED; break;
                }
                break;
            case Typeface.ITALIC:
                switch (typeface) {
                    case TF_REGULAR: typeface = TF_ITALIC; break;
                }
                break;
        }
        return getTypeface(context, typeface);
    }

    public static Typeface getTypeface(Context context, int typeface) {
        if (typeface < TF_REGULAR || typeface > TF_BOLDCONDENSED) {
            return null;
        }

        Typeface tf = sTypefaces.get(typeface);
        if (tf == null) {
            AssetManager assets = context.getApplicationContext().getAssets();
            tf = Typeface.createFromAsset(assets, FONT_FILENAMES[typeface]);
            sTypefaces.put(typeface, tf);
        }

        return tf;
    }
}

@@ -125,16 +125,41 @@
 peface;%0A
+import android.os.Build;%0A
 import a
@@ -183,16 +183,16 @@
 eArray;%0A
-
 %0Apublic 
@@ -773,16 +773,456 @@
     %7D;%0A%0A
+    private static final String%5B%5D FONT_FAMILIES = new String%5B%5D %7B%0A        %22sans-serif%22,%0A        %22sans-serif-medium%22,%0A        %22sans-serif%22,%0A        %22sans-serif%22,%0A        %22sans-serif-condensed%22,%0A        %22sans-serif-condensed%22%0A    %7D;%0A    private static final int%5B%5D FONT_STYLES = new int%5B%5D %7B%0A        Typeface.NORMAL,%0A        Typeface.NORMAL,%0A        Typeface.BOLD,%0A        Typeface.ITALIC,%0A        Typeface.NORMAL,%0A        Typeface.BOLD%0A    %7D;%0A%0A
     priv
@@ -2132,24 +2132,306 @@
  == null) %7B%0A
+            if (Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.LOLLIPOP) %7B%0A                // L has all typefaces we need, use system fonts%0A                tf = Typeface.create(FONT_FAMILIES%5Btypeface%5D, FONT_STYLES%5Btypeface%5D);%0A            %7D else %7B%0A                // use our fonts%0A    
             
@@ -2501,32 +2501,36 @@
 ();%0A            
+    
 tf = Typeface.cr
@@ -2570,32 +2570,46 @@
 MES%5Btypeface%5D);%0A
+            %7D%0A
             sTyp

Use system fonts on API 21+.