summaryrefslogtreecommitdiffstats
path: root/src/com/cyngn/theme/util/TypefaceHelperCache.java
blob: ced93be9bb781f19e3fc8aae4692706f142d6910 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Copyright (C) 2014 Cyanogen, Inc.
 */
package com.cyngn.theme.util;

import android.content.Context;

import java.util.HashMap;
import java.util.Map;

public class TypefaceHelperCache {
    private static TypefaceHelperCache sHelperCache;
    private final Map<String, ThemedTypefaceHelper> mCache;

    private TypefaceHelperCache() {
        mCache = new HashMap<String, ThemedTypefaceHelper>();
    }

    public static synchronized TypefaceHelperCache getInstance() {
        if (sHelperCache == null) {
            sHelperCache = new TypefaceHelperCache();
        }
        return sHelperCache;
    }

    public ThemedTypefaceHelper getHelperForTheme(Context context, String pkgName) {
        synchronized (mCache) {
            ThemedTypefaceHelper helper = mCache.get(pkgName);
            if (helper == null) {
                helper = new ThemedTypefaceHelper();
                helper.load(context, pkgName);
                mCache.put(pkgName, helper);
            }
            return helper;
        }
    }

    public int getTypefaceCount() {
        synchronized (mCache) {
            return mCache.size();
        }
    }
}