Code example for LruCache

 * @author Tristan Waddington 
public class TypefaceSpan extends MetricAffectingSpan {
	private static LruCache<String, Typeface> sTypefaceCache =
            new LruCache<String, Typeface>(12);
    private Typeface mTypeface;
     * Load the {@link Typeface} and apply to a {@link Spannable}. 
    public TypefaceSpan(Context context, String typefaceName) {
        mTypeface = sTypefaceCache.get(typefaceName);
        if (mTypeface == null) {
            mTypeface = Typeface.createFromAsset(context.getApplicationContext()
                    .getAssets(), typefaceName);
            // Cache the loaded Typeface 
Experience pair programming with AI  Get Codota for Java