using Android.Content; using Android.OS; using Android.Text; using Android.Views; using Android.Widget; using Microsoft.Maui.Controls.Compatibility; using Microsoft.Maui.Controls.Platform; using Microsoft.Maui.Handlers; using System; using System.ComponentModel; using System.Text.RegularExpressions; using Xamarin.Forms; using Xamarin.Forms.Clinical6.UI.Controls; namespace Xamarin.Forms.Clinical6.Android.Renderers { public class HtmlLabelHandler : LabelHandler { public HtmlLabelHandler() : base(Mapper) { } public static new IPropertyMapper Mapper = new PropertyMapper(LabelHandler.Mapper) { [nameof(Label.Text)] = MapHtmlText, [nameof(HtmlLabel.HtmlText)] = MapHtmlText }; public static void MapHtmlText(LabelHandler handler, ILabel label) { if (handler.PlatformView is TextView textView && label is HtmlLabel htmlLabel) { var text = string.IsNullOrEmpty(htmlLabel.HtmlText) ? label.Text : htmlLabel.HtmlText; if (string.IsNullOrEmpty(text)) { textView.Text = string.Empty; return; } if ((int)Build.VERSION.SdkInt >= 24) { text = htmlLabel.GetStyledHtml(); if (!string.IsNullOrEmpty(htmlLabel.HtmlText)) { text = htmlLabel.HtmlText; } // Convert rgb() colors to hex format text = Regex.Replace(text, @"rgb\([ ]*(\d+)[ ]*,[ ]*(\d+)[ ]*,[ ]*(\d+)[ ]*\)", m => { return "#" + int.Parse(m.Groups[1].Value).ToString("X2") + int.Parse(m.Groups[2].Value).ToString("X2") + int.Parse(m.Groups[3].Value).ToString("X2"); }); textView.TextFormatted = Html.FromHtml(text, FromHtmlOptions.ModeLegacy); } else { textView.SetText(Html.FromHtml(text, FromHtmlOptions.ModeLegacy), TextView.BufferType.Spannable); } } } } } /// /// Html label renderer. /// //public class HtmlLabelRenderer : LabelRenderer //{ // public HtmlLabelRenderer(Context context) : base(context) { } // /// // /// Ons the element changed. // /// // /// E. // protected override void OnElementChanged(ElementChangedEventArgs