summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FontCache.java
blob: 97bfb90d41fb9db5f7b61a0e8e03a966660d956f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.mapbox.mapboxsdk.testapp.utils;

import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;

import com.mapbox.mapboxsdk.constants.MapboxConstants;

import java.util.Hashtable;

public class FontCache {

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

    public static Typeface get(String name, Context context) {
        Typeface tf = fontCache.get(name);
        if (tf == null) {
            try {
                tf = Typeface.createFromAsset(context.getAssets(), name);
                fontCache.put(name, tf);
            } catch (Exception exception) {
                Log.e(MapboxConstants.TAG, "Font not found");
            }
        }
        return tf;
    }
}