bool ImageSourceLoaded(ButtonHandler buttonHandler)
        {
            var image = buttonHandler.PlatformView.Icon ??
                        TextViewCompat.GetCompoundDrawablesRelative(buttonHandler.PlatformView)[3];

            return(image != null);
        }
示例#2
0
        /// <summary>
        /// Add a new group that will display a header in this AboutPage
        /// A header will be displayed in the order it was added.
        /// </summary>
        /// <param name="name">the title for this group</param>
        /// <returns>AboutPage instance for builder pattern support</returns>
        public AboutPage AddGroup(string name)
        {
            var textView = new TextView(_mContext);

            textView.Text = name;
            TextViewCompat.SetTextAppearance(textView, Resource.Style.about_groupTextAppearance);
            var textParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);

            if (_mCustomFont != null)
            {
                textView.Typeface = _mCustomFont;
            }

            int padding = _mContext.Resources.GetDimensionPixelSize(Resource.Dimension.about_group_text_padding);

            textView.SetPadding(padding, padding, padding, padding);

            if (_mIsRtl)
            {
                textView.Gravity   = GravityFlags.Right | GravityFlags.CenterVertical;
                textParams.Gravity = GravityFlags.Right | GravityFlags.CenterVertical;
            }
            else
            {
                textView.Gravity   = GravityFlags.Left | GravityFlags.CenterVertical;
                textParams.Gravity = GravityFlags.Left | GravityFlags.CenterVertical;
            }
            textView.LayoutParameters = textParams;

            ((LinearLayout)_mView.FindViewById(Resource.Id.about_providers)).AddView(textView);
            return(this);
        }
示例#3
0
        public BaseCellView(Context context, Cell cell) : base(context)
        {
            _cell = cell;
            SetMinimumWidth((int)context.ToPixels(25));
            SetMinimumHeight((int)context.ToPixels(25));
            Orientation = Orientation.Horizontal;

            var padding = (int)context.FromPixels(8);

            SetPadding(padding, padding, padding, padding);

            _imageView = new ImageView(context);
            var imageParams = new LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.MatchParent)
            {
                Width       = (int)context.ToPixels(60),
                Height      = (int)context.ToPixels(60),
                RightMargin = 0,
                Gravity     = GravityFlags.Center
            };

            using (imageParams)
                AddView(_imageView, imageParams);

            var textLayout = new LinearLayout(context)
            {
                Orientation = Orientation.Vertical
            };

            _mainText = new TextView(context);
            _mainText.SetSingleLine(true);
            _mainText.Ellipsize = TextUtils.TruncateAt.End;
            _mainText.SetPadding((int)context.ToPixels(15), padding, padding, padding);
            TextViewCompat.SetTextAppearance(_mainText, global::Android.Resource.Style.TextAppearanceSmall);

            using (var lp = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent))
                textLayout.AddView(_mainText, lp);

            _detailText = new TextView(context);
            _detailText.SetSingleLine(true);
            _detailText.Ellipsize = TextUtils.TruncateAt.End;
            _detailText.SetPadding((int)context.ToPixels(15), padding, padding, padding);
            _detailText.Visibility = ViewStates.Gone;
            TextViewCompat.SetTextAppearance(_detailText, global::Android.Resource.Style.TextAppearanceSmall);

            using (var lp = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent))
                textLayout.AddView(_detailText, lp);

            var layoutParams = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent)
            {
                Width = 0, Weight = 1, Gravity = GravityFlags.Center
            };

            using (layoutParams)
                AddView(textLayout, layoutParams);

            SetMinimumHeight((int)context.ToPixels(DefaultMinHeight));
            _androidDefaultTextColor  = Color.FromUint((uint)_mainText.CurrentTextColor);
            _mainText.TextAlignment   = global::Android.Views.TextAlignment.ViewStart;
            _detailText.TextAlignment = global::Android.Views.TextAlignment.ViewStart;
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            typography_example_body_2 = FindViewById <TextView>(Resource.Id.typography_example_body_2);

            TextViewCompat.SetTextAppearance(typography_example_body_2, Resource.Style.TextAppearance_UIFabric_Body2);
        }
示例#5
0
        protected override void OnAttached()
        {
            try
            {
                var textView = this.Control as TextView;
                if (textView == null)
                {
                    return;
                }

                if (AutoFitFontSizeEffectParameters.GetMinFontSize(this.Element) == NamedSize.Default &&
                    AutoFitFontSizeEffectParameters.GetMaxFontSize(this.Element) == NamedSize.Default)
                {
                    return;
                }

                var min = (int)AutoFitFontSizeEffectParameters.MinFontSizeNumeric(this.Element);
                var max = (int)AutoFitFontSizeEffectParameters.MaxFontSizeNumeric(this.Element);

                if (max <= min)
                {
                    return;
                }



                TextViewCompat.SetAutoSizeTextTypeWithDefaults(textView, TextViewCompat.AutoSizeTextTypeNone);
                //textView.SetAutoSizeTextTypeUniformWithConfiguration(min, max, 1, (int)ComplexUnitType.Sp);
                //text.SetAutoSizeTextTypeUniformWithConfiguration(min, max, 1, (int)ComplexUnitType.Sp);
            }
            catch (Exception e)
            {
            }


            //if (this.Control is AppCompatTextView textView)
            //{
            //    if (AutoFitFontSizeEffectParameters.GetMinFontSize(this.Element) == NamedSize.Default &&
            //        AutoFitFontSizeEffectParameters.GetMaxFontSize(this.Element) == NamedSize.Default)
            //        return;

            //    var min = (int)AutoFitFontSizeEffectParameters.MinFontSizeNumeric(this.Element);
            //    var max = (int)AutoFitFontSizeEffectParameters.MaxFontSizeNumeric(this.Element);

            //    if (max <= min)
            //        return;

            //    //if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            //    //{
            //        textView.SetAutoSizeTextTypeUniformWithConfiguration(min, max, 1, (int)ComplexUnitType.Sp);
            //    //}
            //    //else
            //    //{

            //    //}

            //}
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Label> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                TextViewCompat.SetAutoSizeTextTypeWithDefaults(Control, (int)AutoSizeTextType.Uniform);
            }
        }
示例#7
0
        public static void UpdateContentLayout(this MaterialButton materialButton, Button button)
        {
            var context = materialButton.Context;

            if (context == null)
            {
                return;
            }

            var icon = materialButton.Icon ??
                       TextViewCompat.GetCompoundDrawablesRelative(materialButton)[3];

            if (icon != null &&
                !String.IsNullOrEmpty(button.Text))
            {
                var contentLayout = button.ContentLayout;

                // IconPadding calls materialButton.CompoundDrawablePadding
                // Which is why we don't have to worry about calling setCompoundDrawablePadding
                // ourselves for our custom implemented IconGravityBottom
                materialButton.IconPadding = (int)context.ToPixels(contentLayout.Spacing);

                switch (contentLayout.Position)
                {
                case ButtonContentLayout.ImagePosition.Top:
                    materialButton.Icon        = icon;
                    materialButton.IconGravity = MaterialButton.IconGravityTop;
                    break;

                case ButtonContentLayout.ImagePosition.Bottom:
                    materialButton.Icon = null;
                    TextViewCompat.SetCompoundDrawablesRelative(materialButton, null, null, null, icon);
                    materialButton.IconGravity = MauiMaterialButton.IconGravityBottom;
                    break;

                case ButtonContentLayout.ImagePosition.Left:
                    materialButton.Icon        = icon;
                    materialButton.IconGravity = MaterialButton.IconGravityStart;
                    break;

                case ButtonContentLayout.ImagePosition.Right:
                    materialButton.Icon        = icon;
                    materialButton.IconGravity = MaterialButton.IconGravityEnd;
                    break;
                }
            }
            else
            {
                // Don't remove this otherwise the button occasionally measures wrong
                // on first load
                materialButton.Icon        = icon;
                materialButton.IconPadding = 0;
                materialButton.IconGravity = MaterialButton.IconGravityTextStart;
            }
        }
示例#8
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var baseView = base.GetView(position, convertView, parent);

            if (baseView is TextView tv)
            {
                TextViewCompat.SetTextAppearance(tv, Resource.Style.LightGrayTextMedium);
            }

            return(baseView);
        }
示例#9
0
        private void TokenValuesGlobalLayout(object sender, EventArgs e)
        {
            if (!IsInitialized || IsDetached)
            {
                return;
            }

            var commonTextSize = (int)(Math.Min(_tokenOneValue.TextSize, _tokenTwoValue.TextSize) / Activity.Resources.DisplayMetrics.ScaledDensity);

            TextViewCompat.SetAutoSizeTextTypeUniformWithConfiguration(_tokenOneValue, 2, commonTextSize, 2, (int)AutoSizeTextType.Uniform);
            TextViewCompat.SetAutoSizeTextTypeUniformWithConfiguration(_tokenTwoValue, 2, commonTextSize, 2, (int)AutoSizeTextType.Uniform);
        }
示例#10
0
        public override View GetDropDownView(int position, View convertView, ViewGroup parent)
        {
            var baseView = base.GetDropDownView(position, convertView, parent);

            if (baseView is TextView tv)
            {
                var style = position == spinner.SelectedItemPosition ? Resource.Style.SpinnerItemSelected : Resource.Style.SpinnerItem;
                TextViewCompat.SetTextAppearance(tv, style);
                tv.SetBackgroundResource(Resource.Color.LightGreyFillColor1);
            }

            return(baseView);
        }
示例#11
0
        protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
        {
            // These are hacks that seem to force the button to measure correctly
            // when using top or bottom positioning.
            if (IconGravity == IconGravityBottom)
            {
                var drawable = TextViewCompat.GetCompoundDrawablesRelative(this)[3];
                drawable?.SetBounds(0, 0, drawable.IntrinsicWidth, drawable.IntrinsicHeight);
            }
            else if (IconGravity == MaterialButton.IconGravityTop)
            {
                var drawable = TextViewCompat.GetCompoundDrawablesRelative(this)[1];
                drawable?.SetBounds(0, 0, drawable.IntrinsicWidth, drawable.IntrinsicHeight);
            }

            base.OnLayout(changed, left, top, right, bottom);
        }
        public EventAdapterViewHolder(View itemView, Action <EventAdapterClickEventArgs> clickListener, Action <EventAdapterClickEventArgs> longClickListener) : base(itemView)
        {
            try
            {
                MainView             = itemView;
                Image                = itemView.FindViewById <ImageView>(Resource.Id.Image);
                TxtEventTitle        = itemView.FindViewById <TextView>(Resource.Id.event_titile);
                TxtEventDescription  = itemView.FindViewById <TextView>(Resource.Id.event_description);
                TxtEventTime         = itemView.FindViewById <TextView>(Resource.Id.event_time);
                TxtEventLocation     = itemView.FindViewById <TextView>(Resource.Id.event_location);
                PostLinkLinearLayout = itemView.FindViewById <CardView>(Resource.Id.card_view);

                if (TxtEventTitle != null)
                {
                    TxtEventTitleTextMetrics = TextViewCompat.GetTextMetricsParams(TxtEventTitle);
                }
                if (TxtEventDescription != null)
                {
                    TxtEventDescriptionTextMetrics = TextViewCompat.GetTextMetricsParams(TxtEventDescription);
                }
                if (TxtEventLocation != null)
                {
                    TxtEventLocationTextMetrics = TextViewCompat.GetTextMetricsParams(TxtEventLocation);
                }

                //Event
                itemView.Click += (sender, e) => clickListener(new EventAdapterClickEventArgs {
                    View = itemView, Position = AdapterPosition
                });
                itemView.LongClick += (sender, e) => longClickListener(new EventAdapterClickEventArgs {
                    View = itemView, Position = AdapterPosition
                });
            }
            catch (Exception exception)
            {
                Methods.DisplayReportResultTrack(exception);
            }
        }
        private void setTextViewTextColorFallbackColorWhenMissingStyleAttrs(AppCompatTextView textView)
        {
            var useDefaultColor = false;

            try
            {
                TextViewCompat.SetTextAppearance(textView, textHelperTextAppearance);
                if (MarshmallowApis.AreAvailable && textView.TextColors.DefaultColor == fallbackTextColorAfterMarshmallow)
                {
                    useDefaultColor = true;
                }
            }
            catch (Exception e)
            {
                useDefaultColor = true;
            }

            if (useDefaultColor)
            {
                TextViewCompat.SetTextAppearance(textView, Resource.Style.TextAppearance_AppCompat_Caption);
                Color defaultTextColor = new Color(ContextCompat.GetColor(Context, Resource.Color.defaultText));
                textView.SetTextColor(defaultTextColor);
            }
        }
示例#14
0
        public EntryCellView(Context context, Cell cell) : base(context)
        {
            _cell = cell;
            SetMinimumWidth((int)context.ToPixels(50));
            SetMinimumHeight((int)context.ToPixels(85));
            Orientation = Orientation.Horizontal;

            var padding = (int)context.ToPixels(8);

            SetPadding((int)context.ToPixels(15), padding, padding, padding);

            _label = new TextView(context);
            TextViewCompat.SetTextAppearance(_label, global::Android.Resource.Style.TextAppearanceSmall);

            var layoutParams = new LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)
            {
                Gravity = GravityFlags.CenterVertical
            };

            using (layoutParams)
                AddView(_label, layoutParams);

            EditText = new EntryCellEditText(context);
            EditText.AddTextChangedListener(this);
            EditText.OnFocusChangeListener = this;
            EditText.SetOnEditorActionListener(this);
            EditText.ImeOptions         = ImeAction.Done;
            EditText.BackButtonPressed += OnBackButtonPressed;
            //editText.SetBackgroundDrawable (null);
            layoutParams = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent)
            {
                Width = 0, Weight = 1, Gravity = GravityFlags.FillHorizontal | GravityFlags.Center
            };
            using (layoutParams)
                AddView(EditText, layoutParams);
        }
示例#15
0
        void UpdateImage()
        {
            if (_disposed || _renderer == null || _element == null)
            {
                return;
            }

            AButton view = View;

            if (view == null)
            {
                return;
            }

            ImageSource elementImage = _element.ImageSource;

            if (elementImage == null || elementImage.IsEmpty)
            {
                view.SetCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
                return;
            }

            // No text, so no need for relative position; just center the image
            // There's no option for just plain-old centering, so we'll use Top
            // (which handles the horizontal centering) and some tricksy padding (in OnLayout)
            // to handle the vertical centering
            var layout = string.IsNullOrEmpty(_element.Text) ? _imageOnlyLayout : _element.ContentLayout;

            if (_maintainLegacyMeasurements)
            {
                view.CompoundDrawablePadding = (int)layout.Spacing;
            }
            else
            {
                view.CompoundDrawablePadding = (int)Context.ToPixels(layout.Spacing);
            }

            Drawable existingImage = null;
            var      images        = TextViewCompat.GetCompoundDrawablesRelative(view);

            for (int i = 0; i < images.Length; i++)
            {
                if (images[i] != null)
                {
                    existingImage = images[i];
                    break;
                }
            }

            if (_renderer is IVisualElementRenderer visualElementRenderer)
            {
                visualElementRenderer.ApplyDrawableAsync(Button.ImageSourceProperty, Context, image =>
                {
                    if (image == existingImage)
                    {
                        return;
                    }

                    switch (layout.Position)
                    {
                    case Button.ButtonContentLayout.ImagePosition.Top:
                        TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, image, null, null);
                        break;

                    case Button.ButtonContentLayout.ImagePosition.Right:
                        TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, null, image, null);
                        break;

                    case Button.ButtonContentLayout.ImagePosition.Bottom:
                        TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, null, null, image);
                        break;

                    default:
                        // Defaults to image on the left
                        TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, image, null, null, null);
                        break;
                    }

                    if (_hasLayoutOccurred)
                    {
                        _element?.InvalidateMeasureNonVirtual(InvalidationTrigger.MeasureChanged);
                    }
                });
            }
        }
示例#16
0
        public void OnLayout(bool changed, int left, int top, int right, int bottom)
        {
            if (_disposed || _renderer == null || _element == null)
            {
                return;
            }

            AButton view = View;

            if (view == null)
            {
                return;
            }

            Drawable drawable = null;

            Drawable[] drawables = TextViewCompat.GetCompoundDrawablesRelative(view);
            if (drawables != null)
            {
                foreach (var compoundDrawable in drawables)
                {
                    if (compoundDrawable != null)
                    {
                        drawable = compoundDrawable;
                        break;
                    }
                }
            }

            if (drawable != null)
            {
                int iconWidth = drawable.IntrinsicWidth;
                drawable.CopyBounds(_drawableBounds);

                // Center the drawable in the button if there is no text.
                // We do not need to undo this as when we get some text, the drawable recreated
                if (string.IsNullOrEmpty(_element.Text))
                {
                    var newLeft = (right - left - iconWidth) / 2 - view.PaddingLeft;

                    _drawableBounds.Set(newLeft, _drawableBounds.Top, newLeft + iconWidth, _drawableBounds.Bottom);
                    drawable.Bounds = _drawableBounds;
                }
                else
                {
                    if (_alignIconWithText && _element.ContentLayout.IsHorizontal())
                    {
                        var buttonText = view.TextFormatted;

                        // if text is transformed, add that transformation to to ensure correct calculation of icon padding
                        if (view.TransformationMethod != null)
                        {
                            buttonText = view.TransformationMethod.GetTransformationFormatted(buttonText, view);
                        }

                        var measuredTextWidth = view.Paint.MeasureText(buttonText, 0, buttonText.Length());
                        var textWidth         = Math.Min((int)measuredTextWidth, view.Layout.Width);
                        var contentsWidth     = ViewCompat.GetPaddingStart(view) + iconWidth + view.CompoundDrawablePadding + textWidth + ViewCompat.GetPaddingEnd(view);

                        var newLeft = (view.MeasuredWidth - contentsWidth) / 2;
                        if (_element.ContentLayout.Position == Button.ButtonContentLayout.ImagePosition.Right)
                        {
                            newLeft = -newLeft;
                        }
                        if (ViewCompat.GetLayoutDirection(view) == ViewCompat.LayoutDirectionRtl)
                        {
                            newLeft = -newLeft;
                        }

                        _drawableBounds.Set(newLeft, _drawableBounds.Top, newLeft + iconWidth, _drawableBounds.Bottom);
                        drawable.Bounds = _drawableBounds;
                    }
                }
            }

            _hasLayoutOccurred = true;
        }
示例#17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        private View CreateItem(Element element)
        {
            var wrapper = new LinearLayout(_mContext);

            wrapper.Orientation = Orientation.Horizontal;
            wrapper.Clickable   = true;

            if (element.ClickHandler != null)
            {
                wrapper.Click += element.ClickHandler;
            }
            else if (element.Intent != null)
            {
                wrapper.Click += (sender, args) =>
                {
                    try
                    {
                        _mContext.StartActivity(element.Intent);
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                };
            }

            var outValue = new TypedValue();

            _mContext.Theme.ResolveAttribute(Android.Resource.Attribute.SelectableItemBackground, outValue, true);
            wrapper.SetBackgroundResource(outValue.ResourceId);

            int padding = _mContext.Resources.GetDimensionPixelSize(Resource.Dimension.about_text_padding);

            wrapper.SetPadding(padding, padding, padding, padding);
            var wrapperParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);

            wrapper.LayoutParameters = wrapperParams;

            var textView = new TextView(_mContext);

            TextViewCompat.SetTextAppearance(textView, Resource.Style.about_elementTextAppearance);
            var textParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);

            textView.LayoutParameters = textParams;
            if (_mCustomFont != null)
            {
                textView.Typeface = _mCustomFont;
            }

            ImageView iconView = null;

            if (element.IconDrawable != 0)
            {
                iconView = new ImageView(_mContext);
                int size       = _mContext.Resources.GetDimensionPixelSize(Resource.Dimension.about_icon_size);
                var iconParams = new LinearLayout.LayoutParams(size, size);
                iconView.LayoutParameters = iconParams;

                int iconPadding = _mContext.Resources.GetDimensionPixelSize(Resource.Dimension.about_icon_padding);
                iconView.SetPadding(iconPadding, 0, iconPadding, 0);

                if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
                {
                    var drawable = VectorDrawableCompat.Create(iconView.Resources, element.IconDrawable, iconView.Context.Theme);
                    iconView.SetImageDrawable(drawable);
                }
                else
                {
                    iconView.SetImageResource(element.IconDrawable);
                }

                var wrappedDrawable = DrawableCompat.Wrap(iconView.Drawable);
                wrappedDrawable = wrappedDrawable.Mutate();

                if (element.AutoApplyIconTint)
                {
                    // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
                    var currentNightMode = _mContext.Resources.Configuration.UiMode & UiMode.NightMask;
                    if (currentNightMode != UiMode.NightYes)
                    {
                        if (element.IconTint != 0)
                        {
                            DrawableCompat.SetTint(wrappedDrawable, ContextCompat.GetColor(_mContext, element.IconTint));
                        }
                        else
                        {
                            DrawableCompat.SetTint(wrappedDrawable, ContextCompat.GetColor(_mContext, Resource.Color.about_item_icon_color));
                        }
                    }
                    else if (element.IconNightTint != 0)
                    {
                        DrawableCompat.SetTint(wrappedDrawable, ContextCompat.GetColor(_mContext, element.IconNightTint));
                    }
                    else
                    {
                        DrawableCompat.SetTint(wrappedDrawable, AboutPageUtils.GetThemeAccentColor(_mContext));
                    }
                }
            }
            else
            {
                int iconPadding = _mContext.Resources.GetDimensionPixelSize(Resource.Dimension.about_icon_padding);
                textView.SetPadding(iconPadding, iconPadding, iconPadding, iconPadding);
            }

            textView.Text = element.Title;

            if (_mIsRtl)
            {
                var gravity = element.Gravity != GravityFlags.NoGravity ? element.Gravity : GravityFlags.Right;

                wrapper.SetGravity(gravity | GravityFlags.CenterVertical);
                textParams.Gravity = gravity | GravityFlags.CenterVertical;
                wrapper.AddView(textView);
                if (element.IconDrawable != 0)
                {
                    wrapper.AddView(iconView);
                }
            }
            else
            {
                var gravity = element.Gravity != GravityFlags.NoGravity ? element.Gravity : GravityFlags.Left;

                wrapper.SetGravity(gravity | GravityFlags.CenterVertical);
                textParams.Gravity = gravity | GravityFlags.CenterVertical;
                if (element.IconDrawable != 0)
                {
                    wrapper.AddView(iconView);
                }
                wrapper.AddView(textView);
            }

            return(wrapper);
        }
示例#18
0
        void UpdateImage()
        {
            if (_disposed || _renderer == null || _element == null)
            {
                return;
            }

            AppCompatButton view = View;

            if (view == null)
            {
                return;
            }

            FileImageSource elementImage = _element.Image;
            string          imageFile    = elementImage?.File;

            if (elementImage == null || string.IsNullOrEmpty(imageFile))
            {
                view.SetCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
                return;
            }

            using (var image = Context.GetDrawable(imageFile))
            {
                // No text, so no need for relative position; just center the image
                // There's no option for just plain-old centering, so we'll use Top
                // (which handles the horizontal centering) and some tricksy padding (in OnLayout)
                // to handle the vertical centering
                var layout = string.IsNullOrEmpty(_element.Text) ? _imageOnlyLayout : _element.ContentLayout;

                if (_maintainLegacyMeasurements)
                {
                    view.CompoundDrawablePadding = (int)layout.Spacing;
                }
                else
                {
                    view.CompoundDrawablePadding = (int)Context.ToPixels(layout.Spacing);
                }

                switch (layout.Position)
                {
                case Button.ButtonContentLayout.ImagePosition.Top:
                    TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, image, null, null);
                    break;

                case Button.ButtonContentLayout.ImagePosition.Right:
                    TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, null, image, null);
                    break;

                case Button.ButtonContentLayout.ImagePosition.Bottom:
                    TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, null, null, image);
                    break;

                default:
                    // Defaults to image on the left
                    TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, image, null, null, null);
                    break;
                }
            }
        }
        void UpdateImage()
        {
            if (_disposed || _renderer == null || _element == null)
            {
                return;
            }

            AppCompatButton view = View;

            if (view == null)
            {
                return;
            }

            ImageSource elementImage = _element.ImageSource;

            if (elementImage == null || elementImage.IsEmpty)
            {
                view.SetCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
                return;
            }

            // No text, so no need for relative position; just center the image
            // There's no option for just plain-old centering, so we'll use Top
            // (which handles the horizontal centering) and some tricksy padding (in OnLayout)
            // to handle the vertical centering
            var layout = string.IsNullOrEmpty(_element.Text) ? _imageOnlyLayout : _element.ContentLayout;

            if (_maintainLegacyMeasurements)
            {
                view.CompoundDrawablePadding = (int)layout.Spacing;
            }
            else
            {
                view.CompoundDrawablePadding = (int)Context.ToPixels(layout.Spacing);
            }

            _renderer.ApplyDrawableAsync(Button.ImageSourceProperty, Context, image =>
            {
                switch (layout.Position)
                {
                case Button.ButtonContentLayout.ImagePosition.Top:
                    TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, image, null, null);
                    break;

                case Button.ButtonContentLayout.ImagePosition.Right:
                    TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, null, image, null);
                    break;

                case Button.ButtonContentLayout.ImagePosition.Bottom:
                    TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, null, null, image);
                    break;

                default:
                    // Defaults to image on the left
                    TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, image, null, null, null);
                    break;
                }

                // Invalidating here causes a crazy amount of increased measure invalidations
                // when I tested with Issue4484 it caused about 800 calls to invalidate measure vs the 8 without this
                // I'm pretty sure it gets into a layout / invalidation loop where these are invalidating mid layout
                //_element?.InvalidateMeasureNonVirtual(InvalidationTrigger.MeasureChanged);
            });
        }
示例#20
0
 public static void SetTextAppearanceCompat(this TextView textView, Context context, int resId)
 {
     TextViewCompat.SetTextAppearance(textView, resId);
 }