i was wondering if someone knows or has a way to dynamically load all fonts .ttf and .otf from assets folder and classify it by family, i have a static way (which is not completely done), i have a method that returns a List with all the font families, hardcoded, so i have this other method to return a typeface given the font family (string) given and it's style:
public Typeface getTypeface(Context context, String name, int textStyle)
{
String fontFileName = "";
switch (name)
{
case "ComicNeue-Angular":
{
switch (textStyle)
{
case Typeface.NORMAL: {} break;
case Typeface.BOLD: {} break;
case Typeface.ITALIC: {} break;
case Typeface.BOLD_ITALIC: {} break;
}
} break;
case "ComicNeue":
{
switch (textStyle)
{
case Typeface.NORMAL: {} break;
case Typeface.BOLD: {} break;
case Typeface.ITALIC: {} break;
case Typeface.BOLD_ITALIC: {} break;
}
} break;
case "Impact":
{
switch (textStyle)
{
case Typeface.NORMAL: {} break;
case Typeface.BOLD: {} break;
case Typeface.ITALIC: {} break;
case Typeface.BOLD_ITALIC: {} break;
}
} break;
case "LiberationSans":
{
switch (textStyle)
{
case Typeface.NORMAL: {} break;
case Typeface.BOLD: {} break;
case Typeface.ITALIC: {} break;
case Typeface.BOLD_ITALIC: {} break;
}
} break;
case "Roboto":
{
switch (textStyle)
{
case Typeface.NORMAL: {} break;
case Typeface.BOLD: {} break;
case Typeface.ITALIC: {} break;
case Typeface.BOLD_ITALIC: {} break;
}
} break;
}
return Typeface.createFromAsset(context.getAssets(), fontFileName);
}
i want to add all fonts and classify it by family, so i can load a spinner with all font families. so i don't have to add lines to this code if i add another font family to the folder. (I have to add like 7 more font families to the project)
any ideas?
thanks in advance!