Android Open Source - FontPagerTitleStrip Typefaces






From Project

Back to project page FontPagerTitleStrip.

License

The source code is released under:

GNU General Public License

If you think the Android project FontPagerTitleStrip listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package me.alexrs.fontpagertitlestrip.lib;
//from w  w  w.j a  va2  s.  c om
import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;

import java.util.Hashtable;

public class Typefaces {

    private static final String TAG = "Typefaces";

    private static final Hashtable<String, Typeface> CACHE = new Hashtable<String, Typeface>();


    public static Typeface get(String fontFamily) {
        Typeface t = get(fontFamily, Typeface.NORMAL);
        return cachedTypeface(fontFamily, t);
    }


    public static Typeface get(String familyName, int style) {
        Typeface t = Typeface.create(familyName, style);
        return cachedTypeface(familyName, t);
    }


    public static Typeface get(Typeface typeface, String id) {
        return cachedTypeface(id, typeface);
    }


    public static Typeface get(Context context, String assetPath) {
        Typeface t = Typeface.createFromAsset(context.getAssets(), assetPath);
        return cachedTypeface(assetPath, t);

    }


    private static Typeface cachedTypeface(String assetPath, Typeface t) {
        synchronized (CACHE) {
            if (!CACHE.containsKey(assetPath)) {
                try {
                    CACHE.put(assetPath, t);
                } catch (Exception e) {
                    Log.e(TAG, "Could not get typeface '" + assetPath
                            + "' because " + e.getMessage());
                    return null;
                }
            }
            return CACHE.get(assetPath);
        }
    }
}




Java Source Code List

me.alexrs.fontpagertitlestrip.MainActivity.java
me.alexrs.fontpagertitlestrip.ViewPagerActivity.java
me.alexrs.fontpagertitlestrip.lib.FontPagerTitleStrip.java
me.alexrs.fontpagertitlestrip.lib.Typefaces.java