diff options
Diffstat (limited to 'orgfoxttrss/src/main/java/org/fox/ttrss/util/TypefaceCache.java')
-rw-r--r-- | orgfoxttrss/src/main/java/org/fox/ttrss/util/TypefaceCache.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/orgfoxttrss/src/main/java/org/fox/ttrss/util/TypefaceCache.java b/orgfoxttrss/src/main/java/org/fox/ttrss/util/TypefaceCache.java new file mode 100644 index 00000000..752304ca --- /dev/null +++ b/orgfoxttrss/src/main/java/org/fox/ttrss/util/TypefaceCache.java @@ -0,0 +1,29 @@ +package org.fox.ttrss.util; + +import java.util.Hashtable; + +import android.content.Context; +import android.graphics.Typeface; +import android.util.Log; + +public class TypefaceCache { + private static final String TAG = "TypefaceCache"; + private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>(); + + public static Typeface get(Context c, String typefaceName, int style) { + synchronized (cache) { + String key = typefaceName + ":" + style; + + if (!cache.containsKey(key)) { + try { + Typeface t = Typeface.create(typefaceName, style); + cache.put(key, t); + } catch (Exception e) { + Log.e(TAG, "Could not get typeface '" + typefaceName + "' because " + e.getMessage()); + return null; + } + } + return cache.get(key); + } + } +}
\ No newline at end of file |