private static Map < String , String > getAssetFonts ( Context context ) { synchronized ( ASSET_FONTS_BY_NAME ) { /* * Let's do this only once because it's expensive and the result won't change in any case. */ if ( ASSET_FONTS_BY_NAME . isEmpty ( ) ) { AssetManager assets = context . getResources ( ) . getAssets ( ) ; Collection < String > fontFiles = AssetIndex . getAssetIndex ( context ) ; if ( fontFiles == null || fontFiles . isEmpty ( ) ) { fontFiles = listFontFiles ( context . getResources ( ) ) ; } for ( String filePath : fontFiles ) { if ( filePath . toLowerCase ( Locale . getDefault ( ) ) . endsWith ( "ttf" ) ) { String fontName = TTFAnalyzer . getFontName ( assets , filePath ) ; if ( fontName == null ) { fontName = getFileName ( filePath ) ; } ASSET_FONTS_BY_NAME . put ( fontName , filePath ) ; } } } return ASSET_FONTS_BY_NAME ; } }
Retrieve the fonts from the asset folder .