Created
March 19, 2018 08:47
-
-
Save Jaymo/1ef1f6b0f5f856693a244922dd5f7853 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.graphics.Typeface; | |
import android.support.v4.util.SimpleArrayMap; | |
public class TypefaceHelper { | |
private static final SimpleArrayMap<String, Typeface> cache = new SimpleArrayMap<>(); | |
public static Typeface get(Context c, String name) { | |
synchronized (cache) { | |
if (!cache.containsKey(name)) { | |
Typeface t = Typeface.createFromAsset(c.getAssets(), String.format("fonts/%s.ttf", name)); | |
cache.put(name, t); | |
return t; | |
} | |
return cache.get(name); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment