summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FontCache.java
blob: a4352d0b1cd65438e4ce3e1180c9ff33ade7188e (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
package com.mapbox.mapboxsdk.testapp.utils;

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

import java.util.Hashtable;

import timber.log.Timber;

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) {
        Timber.e("Font not found");
      }
    }
    return tf;
  }
}