public static UIImage CreateAvatarWithTextPlaceholder(string name, AvatarStyles styles) { var(text, backgroundColor) = AvatarPlaceholderBuilder.GetAbbreviationAndColor(name, styles.BackgroundHexColors); return(CreateCircleImage( styles.Size, backgroundColor.UIColorFromHex().CGColor, () => DrawText(text, styles.Size, styles.Font, styles.TextColor))); }
public static void LoadImageWithTextPlaceholder(this UIImageView imageView, string url, string name, AvatarStyles styles, Action <TaskParameter>?transform = null) { imageView.Image = CreateAvatarWithTextPlaceholder(name, styles); if (string.IsNullOrEmpty(url)) { return; } var loader = ImageService.Instance .LoadUrl(url) .DownSampleInDip(styles.Size.Width, styles.Size.Height); transform?.Invoke(loader); loader.IntoAsync(imageView); }
public static async void LoadImageWithTextPlaceholder(this ASImageNode imageView, string url, string name, AvatarStyles styles) { Execute.BeginOnUIThread(() => { imageView.Image = CreateAvatarWithTextPlaceholder(name, styles); }); if (string.IsNullOrEmpty(url)) { return; } var expr = ImageService.Instance .LoadUrl(url) .DownSampleInDip(styles.Size.Width, styles.Size.Height); UIImage image = null; try { image = await expr.AsUIImageAsync().ConfigureAwait(false); } catch { // do nothing } if (image != null) { Execute.BeginOnUIThread(() => { imageView.Image = image; }); } }
public AvatarPlaceholderDrawable(Context context, string name, AvatarStyles styles) { _context = context; var info = AvatarPlaceholderBuilder.GetAbbreviationAndColor(name, styles.BackgroundHexColors); _avatarText = info.Text; _textPaint = new Paint { AntiAlias = true, Color = Color.White }; _textPaint.SetTypeface(Typeface.Create("sans-serif", TypefaceStyle.Bold)); _backgroundPaint = new Paint { AntiAlias = true }; _backgroundPaint.SetStyle(Paint.Style.Fill); _backgroundPaint.Color = Color.ParseColor(info.Color); _size = Math.Min(styles.Size.Width, styles.Size.Height); }