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);
            //            }
            //        }
            //    });
        }
예제 #2
0
 /// <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;
 }