Android Context Get getTypeface(Context context, String name)

Here you can find the source of getTypeface(Context context, String name)

Description

Retrieve a type-face.

Declaration

public static Typeface getTypeface(Context context, String name) 

Method Source Code

//package com.java2s;
import java.util.HashMap;
import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;

public class Main {
    private static final String TAG = "NiftyTypefaceHelper";
    private static final HashMap<String, Typeface> TYPEFACE_CACHE = new HashMap<String, Typeface>();

    /** Retrieve a type-face. Does not load twice, uses lazy loading. */
    public static Typeface getTypeface(Context context, String name) {
        // ensure the global context is used. just in case.
        context = context.getApplicationContext();
        Log.d(TAG, "name=" + name);
        if (TYPEFACE_CACHE.containsKey(name)) {
            return TYPEFACE_CACHE.get(name);
        }//from ww  w . j  a  va 2  s. c  om

        Typeface typeface = Typeface.createFromAsset(context.getAssets(),
                name);

        if (typeface != null) {
            TYPEFACE_CACHE.put(name, typeface);
        }

        return typeface;
    }
}

Related

  1. getTCBoldFont(Context context)
  2. getTCFont(Context context)
  3. getTCItalicFont(Context context)
  4. getTempFile(Context context)
  5. getTimestamp(Context context)
  6. getUserAgentString(Context context)
  7. getVersion(Context context)
  8. getVersionCode(Context mContext)
  9. getVoiceSearchIMId(Context context)