public static SortedSet < RTTypeface > getFonts ( Context context ) { /* * Fonts from the assets folder */ Map < String , String > assetFonts = getAssetFonts ( context ) ; AssetManager assets = context . getResources ( ) . getAssets ( ) ; for ( String fontName : assetFonts . keySet ( ) ) { String filePath = assetFonts . get ( fontName ) ; if ( ! ALL_FONTS . contains ( fontName ) ) { try { Typeface typeface = Typeface . createFromAsset ( assets , filePath ) ; ALL_FONTS . add ( new RTTypeface ( fontName , typeface ) ) ; } catch ( Exception e ) { // this can happen if we don't have access to the font or it's not a font or... } } } /* * Fonts from the system */ Map < String , String > systemFonts = getSystemFonts ( ) ; for ( String fontName : systemFonts . keySet ( ) ) { String filePath = systemFonts . get ( fontName ) ; if ( ! ALL_FONTS . contains ( fontName ) ) { try { Typeface typeface = Typeface . createFromFile ( filePath ) ; ALL_FONTS . add ( new RTTypeface ( fontName , typeface ) ) ; } catch ( Exception e ) { // this can happen if we don't have access to the font or it's not a font or... } } } return ALL_FONTS ; }
Retrieve the fonts from the asset and the system folder .