Skip to content

Commit 437e13b

Browse files
Alexander.IljushkinAlexander.Iljushkin
authored andcommitted
Fixed bug "Native typeface cannot be made" on som devices.
1 parent 5e02afa commit 437e13b

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
privatestaticfinalbooleanSANS_ICE_CREAM = Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH;
2020
privatestaticfinalbooleanIS_GINGERBREAD = Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD;
2121

22+
privatestaticfinalStringTAG = "Typefaces";
23+
privatestaticfinalHashtable<String, Typeface> cache = newHashtable<String, Typeface>();
24+
2225
publicCapitalizedTextView(Contextcontext){
2326
super( context );
2427

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

55-
privatevoidsetTF(Contextcontext){
56-
setTypeface( Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf") );
58+
publicstaticTypefacegetTypeFace(Contextc, StringassetPath){
59+
synchronized (cache){
60+
if (!cache.containsKey(assetPath)){
61+
try{
62+
Typefacet = Typeface.createFromAsset(c.getAssets(),
63+
assetPath);
64+
cache.put(assetPath, t);
65+
} catch (Exceptione){
66+
Log.e(TAG, "Could not get typeface '" + assetPath
67+
+ "' because " + e.getMessage());
68+
returnnull;
69+
}
70+
}
71+
returncache.get(assetPath);
72+
}
5773
}
5874

59-
75+
privatevoidsetTF(Contextcontext){
76+
Typefacetf = getTypeFace(context, "fonts/Roboto-Regular.ttf");
77+
setTypeface( tf );
78+
}
6079
}

0 commit comments

Comments
(0)