internal static void ApplyFontToTextView(Context context, TextView textView, CalligraphyConfig config, string textViewFont, bool deferred) { if (context == null || textView == null || config == null) { return; } if (!TextUtils.IsEmpty(textViewFont) && ApplyFontToTextView(context, textView, textViewFont, deferred)) { return; } ApplyFontToTextView(context, textView, config, deferred); }
internal static void ApplyFontToTextView(Context context, TextView textView, CalligraphyConfig config, bool deferred) { if (context == null || textView == null || config == null) { return; } if (!config.IsFontSet) { return; } ApplyFontToTextView(context, textView, config.FontPath, deferred); }
public static CalligraphyConfig Get() { return(instance ?? (instance = new CalligraphyConfig())); }
/// <summary> /// Define the default font and the custom attribute to lookup globally. /// </summary> /// <param name="defaultFontAssetPath">path to a font file in the assets folder, e.g. "fonts/Roboto-light.ttf",</param> /// <param name="defaultAttributeId">the custom attribute to look for.</param> /// <see cref="InitDefault(string)"/> /// <see cref="InitDefault(int)"/> public static void InitDefault(String defaultFontAssetPath, int defaultAttributeId) { instance = new CalligraphyConfig(defaultFontAssetPath, defaultAttributeId); }
/// <summary> /// Init only the custom attribute to lookup. /// </summary> /// <param name="defaultAttributeId">Ththe custom attribute to look for.</param> /// <see cref="InitDefault(string, int)"/> public static void InitDefault(int defaultAttributeId) { instance = new CalligraphyConfig(defaultAttributeId); }
/// <summary> /// Init the Calligraphy Config file. Each time you call this you set a new default. Of course setting this multiple /// times during runtime could have undesired effects. /// </summary> /// <param name="defaultFontAssetPath">a path to a font file in the assets folder, e.g. "fonts/roboto-light.ttf", /// passing null will default to the device font-family.</param> public static void InitDefault(string defaultFontAssetPath) { instance = new CalligraphyConfig(defaultFontAssetPath); }
/// <summary> /// Applies font to TextView. Will fall back to the default one if not set. /// </summary> /// <param name="context">The context.</param> /// <param name="textView"> textView to apply to.</param> /// <param name="config">Default Config.</param> /// <param name="textViewFont">nullable, will use Default Config if null or fails to find the defined font.</param> internal static void ApplyFontToTextView(Context context, TextView textView, CalligraphyConfig config, string textViewFont) { ApplyFontToTextView(context, textView, config, textViewFont, false); }
protected void OnViewCreated(View view, string name, Context context, IAttributeSet attrs) { if (!(view is TextView)) { return; } // Fast path the setting of TextView's font, means if we do some delayed setting of font, // which has already been set by use we skip this TextView (mainly for inflating custom, // TextView's inside the Toolbar/ActionBar). if (TypefaceUtils.IsLoaded(((TextView)view).Typeface)) { return; } // Try to get typeface attribute value // Since we're not using namespace it's a little bit tricky // Try view xml attributes var textViewFont = CalligraphyUtils.PullFontPathFromView(context, attrs, attributeId); // Try view style attributes if (TextUtils.IsEmpty(textViewFont)) { textViewFont = CalligraphyUtils.PullFontPathFromStyle(context, attrs, attributeId); } // Try View TextAppearance if (TextUtils.IsEmpty(textViewFont)) { textViewFont = CalligraphyUtils.PullFontPathFromTextAppearance(context, attrs, attributeId); } // Try theme attributes if (TextUtils.IsEmpty(textViewFont)) { var styleForTextView = GetStyleForTextView((TextView)view); if (styleForTextView[1] != -1) { textViewFont = CalligraphyUtils.PullFontPathFromTheme(context, styleForTextView[0], styleForTextView[1], attributeId); } else { textViewFont = CalligraphyUtils.PullFontPathFromTheme(context, styleForTextView[0], attributeId); } } // Still need to defer the Native action bar, appcompat-v7:21+ uses the Toolbar underneath. But won't match these anyway. var deferred = MatchesResourceIdName(view, ActionBarTitle) || MatchesResourceIdName(view, ActionBarSubtitle); CalligraphyUtils.ApplyFontToTextView(context, (TextView)view, CalligraphyConfig.Get(), textViewFont, deferred); // AppCompat API21+ The ActionBar doesn't inflate default Title/SubTitle, we need to scan the // Toolbar(Which underlies the ActionBar) for its children. //if (CalligraphyUtils.canCheckForV7Toolbar() && view is Android.Support.V7.Widget.Toolbar) { // ViewGroup parent = (ViewGroup) view; // parent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { // @Override // public void onGlobalLayout() { // // No children, do nuffink! // if (parent.getChildCount() <= 0) return; // // Process children, defer draw as it has set the typeface. // for (int i = 0; i < parent.getChildCount(); i++) { // onViewCreated(parent.getChildAt(i), null, context, null); // } // } // }); }
/// <summary> /// Uses the default configuration from <see cref="CalligraphyConfig"/>. /// Remember if you are defining default in the /// <see cref="CalligraphyConfig"/> make sure this is initialised before /// the activity is created. /// </summary> /// <param name="context">base ContextBase to Wrap.</param> public CalligraphyContextWrapper(Context context) : base(context) { attributeId = CalligraphyConfig.Get().AttrId; }