File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed
app/src/main/java/com/donnfelker/android/bootstrap/ui/view Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ public class CapitalizedTextView extends Button{
1919private static final boolean SANS_ICE_CREAM = Build .VERSION .SDK_INT < Build .VERSION_CODES .ICE_CREAM_SANDWICH ;
2020private 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+
2225public CapitalizedTextView (Context context ){
2326super ( 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}
You can’t perform that action at this time.
0 commit comments