Skip to content

Commit e0a12a9

Browse files
committed
Merge pull request #59 from PositiveAlex/master
Fixed bug "Native typeface cannot be made" on some devices.
2 parents adcc7bb + 437e13b commit e0a12a9

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

app/src/main/java/com/donnfelker/android/bootstrap/ui/view/CapitalizedTextView.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class CapitalizedTextView extends Button {
1919
private static final boolean SANS_ICE_CREAM = Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH;
2020
private static final boolean IS_GINGERBREAD = Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD;
2121

22+
private static final String TAG = "Typefaces";
23+
private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>();
24+
2225
public CapitalizedTextView(Context context) {
2326
super( context );
2427

@@ -52,9 +55,25 @@ public void setText(CharSequence text, BufferType type) {
5255
}
5356
}
5457

55-
private void setTF(Context context) {
56-
setTypeface( Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf") );
58+
public static Typeface getTypeFace(Context c, String assetPath) {
59+
synchronized (cache) {
60+
if (!cache.containsKey(assetPath)) {
61+
try {
62+
Typeface t = Typeface.createFromAsset(c.getAssets(),
63+
assetPath);
64+
cache.put(assetPath, t);
65+
} catch (Exception e) {
66+
Log.e(TAG, "Could not get typeface '" + assetPath
67+
+ "' because " + e.getMessage());
68+
return null;
69+
}
70+
}
71+
return cache.get(assetPath);
72+
}
5773
}
5874

59-
75+
private void setTF(Context context) {
76+
Typeface tf = getTypeFace(context, "fonts/Roboto-Regular.ttf");
77+
setTypeface( tf );
78+
}
6079
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy