Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 2
0
        public void GetAbbreviationAndColor_WithoutColors_WithLettersName_ReturnsValidAbbreviationAndSomeColor(
            string name, string expectedAbbreviation)
        {
            var res = AvatarPlaceholderBuilder.GetAbbreviationAndColor(name);

            Assert.Equal(expectedAbbreviation, res.Text);

            Assert.NotNull(res.Color);
            Assert.NotEmpty(res.Color);
        }
Ejemplo n.º 3
0
        public void GetAbbreviationAndColor_WithNonEmptyColors_WithLettersName_ReturnsValidAbbreviationAndColorFromTheList(
            string name, string expectedAbbreviation)
        {
            var colors = new string[] { "Color1", "Color2", "Color3" };

            var res = AvatarPlaceholderBuilder.GetAbbreviationAndColor(name, colors);

            Assert.Equal(expectedAbbreviation, res.Text);
            Assert.Contains(res.Color, colors);
        }
Ejemplo n.º 4
0
        public void GetAbbreviationAndColor_WithoutColors_WithNoLettersName_ReturnsEmptyAbbreviationAndSomeColor(
            string name)
        {
            var res = AvatarPlaceholderBuilder.GetAbbreviationAndColor(name);

            Assert.NotNull(res.Text);
            Assert.Empty(res.Text);

            Assert.NotNull(res.Color);
            Assert.NotEmpty(res.Color);
        }
Ejemplo n.º 5
0
        public void GetAbbreviationAndColor_WithNonEmptyColors_WithNoLettersName_ReturnsEmptyAbbreviationAndColorFromTheList(
            string name)
        {
            var colors = new string[] { "Color1", "Color2", "Color3" };

            var res = AvatarPlaceholderBuilder.GetAbbreviationAndColor(name, colors);

            Assert.NotNull(res.Text);
            Assert.Empty(res.Text);

            Assert.Contains(res.Color, colors);
        }
        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);
        }
Ejemplo n.º 7
0
 public void GetAbbreviationAndColor_WithEmptyColors_WithNonNullName_ThrowsCorrectException(
     string name)
 {
     Assert.Throws <ArgumentException>(()
                                       => AvatarPlaceholderBuilder.GetAbbreviationAndColor(name, new string[] { }));
 }
Ejemplo n.º 8
0
 public void GetAbbreviationAndColor_WithAnyColors_WithNullName_ThrowsCorrectException(
     string[] colors)
 {
     Assert.Throws <ArgumentNullException>(()
                                           => AvatarPlaceholderBuilder.GetAbbreviationAndColor(null, colors));
 }