Skip to content

Instantly share code, notes, and snippets.

@Jaymo
Created March 19, 2018 08:47
Show Gist options
  • Save Jaymo/1ef1f6b0f5f856693a244922dd5f7853 to your computer and use it in GitHub Desktop.
Save Jaymo/1ef1f6b0f5f856693a244922dd5f7853 to your computer and use it in GitHub Desktop.
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