internal static bool ApplyFontToTextView(Context context, TextView textView, string filePath, bool deferred)
        {
            if (textView == null || context == null)
            {
                return(false);
            }

            var assetManager = context.Assets;
            var typeface     = TypefaceUtils.Load(assetManager, filePath);

            return(ApplyFontToTextView(textView, typeface, deferred));
        }
 /// <summary>
 /// Applies a custom typeface span to the text.
 /// </summary>
 /// <param name="s">text to apply it too.</param>
 /// <param name="typeface">typeface to apply.</param>
 /// <returns>Either the passed in Object or new Spannable with the typeface span applied.</returns>
 internal static ICharSequence ApplyTypefaceSpan(ICharSequence s, Typeface typeface)
 {
     if (s == null || s.Length() <= 0)
     {
         return(s);
     }
     if (!(s is ISpannable))
     {
         s = new SpannableString(s);
     }
     ((ISpannable)s).SetSpan(TypefaceUtils.GetSpan(typeface), 0, s.Length(), SpanTypes.ExclusiveExclusive);
     return(s);
 }
        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);
            //            }
            //        }
            //    });
        }