public static Typeface Get(Context context, FontyConfiguration configuration, FontyTypo font) { try { List <string> pathStack = new List <string> (); string resourceFullPath; pathStack.Add(configuration.Path); if (configuration.FontEntityClazz.IsDefined(typeof(FontyPath), true)) { Log.Verbose(TAG, "FontPath in root entity: compose url"); FontyPath path = configuration.FontEntityClazz.GetCustomAttribute <FontyPath> (true); Log.Verbose(TAG, "entity annotated with FontPath annotation: " + path.Value); pathStack.Add(path.Value); } foreach (FieldInfo field in configuration.FontEntityClazz.GetFields()) { if (field.IsDefined(typeof(FontyIdentifier), true)) { Log.Verbose(TAG, "field: " + field.Name + " annotated with FontIdentifier"); } if (field.GetCustomAttribute <FontyIdentifier> (true).Value == font) { if (field.IsDefined(typeof(FontyPath), true)) { FontyPath path = field.GetCustomAttribute <FontyPath> (true); pathStack.Add(path.Value); } if (field.IsDefined(typeof(FontyName), true)) { FontyName name = field.GetCustomAttribute <FontyName> (true); resourceFullPath = joinPaths(pathStack) + name.Value; Log.Verbose(TAG, "field: " + field.Name + " annotated with FontName with value: " + name.Value); } else { Log.Verbose(TAG, "field: " + field.Name + " not annotated with FontName, use his name"); resourceFullPath = joinPaths(pathStack) + field.Name; } resourceFullPath += configuration.Extension; Log.Debug(TAG, resourceFullPath); return(Typeface.CreateFromAsset(context.Assets, resourceFullPath)); } } } catch (Exception e) { Log.Error(TAG, e.StackTrace); Log.Error(TAG, "can't load " + font.ToString() + " return default one"); } return(Typeface.Default); }
public override void OnCreate() { base.OnCreate(); FontyConfiguration configuration = new FontyConfiguration() { Extension = ".ttf", FontEntityClazz = typeof(MyFontyEntity), SourceTypo = FontySourceTypo.assets }; FontyLoader.GetInstance().Init(configuration); }
public static Typeface Get (Context context, FontyConfiguration configuration, FontyTypo font) { try { List<string> pathStack = new List<string> (); string resourceFullPath; pathStack.Add (configuration.Path); if (configuration.FontEntityClazz.IsDefined (typeof(FontyPath), true)) { Log.Verbose (TAG, "FontPath in root entity: compose url"); FontyPath path = configuration.FontEntityClazz.GetCustomAttribute<FontyPath> (true); Log.Verbose (TAG, "entity annotated with FontPath annotation: " + path.Value); pathStack.Add (path.Value); } foreach (FieldInfo field in configuration.FontEntityClazz.GetFields()) { if (field.IsDefined (typeof(FontyIdentifier), true)) { Log.Verbose (TAG, "field: " + field.Name + " annotated with FontIdentifier"); } if (field.GetCustomAttribute<FontyIdentifier> (true).Value == font) { if (field.IsDefined (typeof(FontyPath), true)) { FontyPath path = field.GetCustomAttribute<FontyPath> (true); pathStack.Add (path.Value); } if (field.IsDefined (typeof(FontyName), true)) { FontyName name = field.GetCustomAttribute<FontyName> (true); resourceFullPath = joinPaths (pathStack) + name.Value; Log.Verbose (TAG, "field: " + field.Name + " annotated with FontName with value: " + name.Value); } else { Log.Verbose (TAG, "field: " + field.Name + " not annotated with FontName, use his name"); resourceFullPath = joinPaths (pathStack) + field.Name; } resourceFullPath += configuration.Extension; Log.Debug (TAG, resourceFullPath); return Typeface.CreateFromAsset (context.Assets, resourceFullPath); } } } catch (Exception e) { Log.Error (TAG, e.StackTrace); Log.Error (TAG, "can't load " + font.ToString () + " return default one"); } return Typeface.Default; }
public FontyLoader Init(FontyConfiguration configuration) { this.configuration = configuration; return(this); }