Back to project page Aviary-Android-SDK.
The source code is released under:
AVIARY API TERMS OF USE Full Legal Agreement The following terms and conditions and the terms and conditions at http://www.aviary.com/terms (collectively, the ?Terms??) govern your use of any and ...
If you think the Android project Aviary-Android-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.aviary.android.feather.utils; /*from ww w . j a va2s. c o m*/ import java.lang.ref.SoftReference; import java.util.HashMap; import android.content.res.AssetManager; import android.graphics.Typeface; public class TypefaceUtils { private static final HashMap<String, SoftReference<Typeface>> sTypeCache = new HashMap<String, SoftReference<Typeface>>(); public static Typeface createFromAsset( final AssetManager assets, final String fontname ) { Typeface result = null; SoftReference<Typeface> cachedFont = getFromCache( fontname ); if ( null != cachedFont && cachedFont.get() != null ) { result = cachedFont.get(); } else { result = Typeface.createFromAsset( assets, fontname ); putIntoCache( fontname, result ); } return result; } private static SoftReference<Typeface> getFromCache( final String fontname ) { synchronized ( sTypeCache ) { return sTypeCache.get( fontname ); } } private static void putIntoCache( final String fontname, final Typeface font ) { synchronized ( sTypeCache ) { sTypeCache.put( fontname, new SoftReference<Typeface>( font ) ); } } }