Exemplo n.º 1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

            if (Control == null ||
                Element == null)
            {
                return;
            }
            Control.Typeface = TypefaceFactory.GetTypefaceForFontAttribute(Context,
                                                                           Element.FontAttributes);
        }
Exemplo n.º 2
0
        protected override void OnElementChanged(ElementChangedEventArgs <Editor> e)
        {
            base.OnElementChanged(e);

            if (Control == null ||
                BaseElement == null)
            {
                return;
            }
            Control.Background = null;
            Control.Typeface   = TypefaceFactory.GetTypefaceForFontAttribute(Context,
                                                                             Element.FontAttributes);

            UpdateFont();
            UpdateMaxLength();
        }
Exemplo n.º 3
0
        protected override void OnElementChanged(ElementChangedEventArgs <Label> e)
        {
            base.OnElementChanged(e);

            if (Control == null ||
                Element == null)
            {
                return;
            }

            UpdateFont();
            UpdateFormattedText();

            if (_shouldOverwriteTypeface)
            {
                Control.Typeface = TypefaceFactory.GetTypefaceForFontAttribute(Context,
                                                                               Element.FontAttributes);
            }
        }
Exemplo n.º 4
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.DatePicker> e)
        {
            base.OnElementChanged(e);

            if (Control == null ||
                BaseElement == null)
            {
                return;
            }

            Control.Focusable  = false;
            Control.Background = null;
            Control.Gravity    = GravityFlags.CenterVertical;
            Control.Typeface   = TypefaceFactory.GetTypefaceForFontAttribute(Context,
                                                                             Element.FontAttributes);
            UpdatePadding();
            UpdateBackgroundDrawable();
            UpdateFont();
        }
Exemplo n.º 5
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);

            if (Control == null ||
                Element == null)
            {
                return;
            }

            Control.SetPadding(0, 0, 0, 0);
            Control.SetAllCaps(false);
            Control.Typeface = TypefaceFactory.GetTypefaceForFontAttribute(Context,
                                                                           Element.FontAttributes);

            UpdateBackgroundStateDrawable();
            UpdateTextColor();
            UpdateFont();
        }
        public static SpannableString ToAttributed(this FormattedString formattedString,
                                                   Android.Content.Context context,
                                                   FontAttributes attr,
                                                   Xamarin.Forms.Color defaultForegroundColor,
                                                   double textSize)
        {
            if (formattedString == null)
            {
                return(null);
            }

            var builder = new StringBuilder();

            for (int i = 0; i < formattedString.Spans.Count; i++)
            {
                Span span = formattedString.Spans[i];
                var  text = span.Text;
                if (text == null)
                {
                    continue;
                }

                builder.Append(text);
            }

            var spannable = new SpannableString(builder.ToString());

            var c = 0;

            for (int i = 0; i < formattedString.Spans.Count; i++)
            {
                Span span = formattedString.Spans[i];
                var  text = span.Text;
                if (text == null)
                {
                    continue;
                }

                int start = c;
                int end   = start + text.Length;
                c = end;

                if (span.TextColor != Xamarin.Forms.Color.Default)
                {
                    spannable.SetSpan(new ForegroundColorSpan(span.TextColor.ToAndroid()),
                                      start,
                                      end,
                                      SpanTypes.InclusiveExclusive);
                }
                else if (defaultForegroundColor != Xamarin.Forms.Color.Default)
                {
                    spannable.SetSpan(new ForegroundColorSpan(defaultForegroundColor.ToAndroid()),
                                      start,
                                      end,
                                      SpanTypes.InclusiveExclusive);
                }

                if (span.BackgroundColor != Xamarin.Forms.Color.Default)
                {
                    spannable.SetSpan(new BackgroundColorSpan(span.BackgroundColor.ToAndroid()),
                                      start,
                                      end,
                                      SpanTypes.InclusiveExclusive);
                }

                spannable.SetSpan(new TypefaceSpan(
                                      context,
                                      TypefaceFactory.GetTypefaceForFontAttribute(context, attr), textSize),
                                  start,
                                  end,
                                  SpanTypes.InclusiveInclusive);
            }
            return(spannable);
        }