MCPcopy Create free account
hub / github.com/cinit/TMoe / getTypeface

Method getTypeface

app/src/main/java/cc/ioctl/tmoe/ui/LayoutHelper.java:81–130  ·  view source on GitHub ↗
(String assetPath)

Source from the content-addressed store, hash-verified

79 private static final HashMap<String, Typeface> typefaceCache = new HashMap<>();
80
81 public static Typeface getTypeface(String assetPath) {
82 synchronized (typefaceCache) {
83 if (!typefaceCache.containsKey(assetPath)) {
84 try {
85 Typeface t = null;
86 switch (assetPath) {
87 case "fonts/rmedium.ttf":
88 t = Typeface.create("sans-serif-medium", Typeface.NORMAL);
89 break;
90 case "fonts/ritalic.ttf":
91 t = Typeface.create("sans-serif", Typeface.ITALIC);
92 break;
93 case "fonts/rmediumitalic.ttf":
94 t = Typeface.create("sans-serif-medium", Typeface.ITALIC);
95 break;
96 case "fonts/rmono.ttf":
97 t = Typeface.MONOSPACE;
98 break;
99 case "fonts/mw_bold.ttf":
100 t = Typeface.create("serif", Typeface.BOLD);
101 break;
102 default:
103 // should not reach here
104 break;
105 }
106 if (t == null) {
107 if (Build.VERSION.SDK_INT >= 26) {
108 Typeface.Builder builder = new Typeface.Builder(HostInfo.getApplication().getAssets(), assetPath);
109 if (assetPath.contains("medium")) {
110 builder.setWeight(700);
111 }
112 if (assetPath.contains("italic")) {
113 builder.setItalic(true);
114 }
115 t = builder.build();
116 } else {
117 t = Typeface.createFromAsset(HostInfo.getApplication().getAssets(), assetPath);
118 }
119 }
120 typefaceCache.put(assetPath, t);
121 } catch (Exception e) {
122 if (BuildConfig.DEBUG) {
123 Utils.loge("Could not get typeface '" + assetPath + "' because " + e.getMessage());
124 }
125 return null;
126 }
127 }
128 return typefaceCache.get(assetPath);
129 }
130 }
131
132 public static void invalidate() {
133 // nothing to invalidate yet

Callers 2

FastScrollMethod · 0.95
HeaderCellMethod · 0.95

Calls 7

getApplicationMethod · 0.95
logeMethod · 0.95
createMethod · 0.80
containsMethod · 0.80
containsKeyMethod · 0.45
putMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected