protected override void Render(HtmlTextWriter writer) { if (BadgeStyle != BadgeType.NotSet) { writer.Write($"<div class='label-badge {BadgeStyle.GetStringValueClass()}'>"); } if (!string.IsNullOrWhiteSpace(LabelTitle)) { writer.Write($"<div class='form-group'><label class='control-label' for='{ID}'>{LabelTitle}</label><div class='controls'>"); } if (labeltype != LabelType.NotSet) { writer.AddAttribute(HtmlTextWriterAttribute.Class, labeltype.GetStringValueClass()); } base.Render(writer); if (!string.IsNullOrWhiteSpace(LabelTitle)) { writer.Write($"</div></div>"); } if (BadgeStyle != BadgeType.NotSet) { writer.Write($"</div>"); } }
internal static ViewModelBase GetViewModel( BadgeStyle style, string leftText, string rightText, string color = null, string labelColor = null, Uri leftLink = null, Uri rightLink = null) { leftText = leftText ?? ""; rightText = rightText ?? ""; leftText = leftText.Trim(); rightText = rightText.Trim(); var badgeData = new BadgeData( leftText: leftText, rightText: rightText, leftLink: leftLink, rightLink: rightLink, colorA: Color.Get(labelColor), colorB: Color.Get(color) ); return(GetViewModel(style, badgeData)); }
protected virtual string BadgeToSpriteLib(BadgeStyle badge) { switch (badge) { default: return("commonmenu"); } }
internal static string BadgeToSpriteLib(BadgeStyle badge) { switch (badge) { default: return("commonmenu"); } }
private string BadgeToSpriteLib(BadgeStyle badge) { switch (badge) { default: return("commonmenu"); } }
public TBuilder Badge(string value, BadgeStyle style = BadgeStyle.Secondary, bool condition = true) { if (condition) { Item.BadgeText = value; Item.BadgeStyle = (int)style; } return(this as TBuilder); }
public TBuilder Badge(string value, BadgeStyle style = BadgeStyle.Default, bool condition = true) { if (condition) { this.Item.BadgeText = value; this.Item.BadgeStyle = style; } return(this as TBuilder); }
internal static bool IsBagdeWhiteSprite(BadgeStyle badge /*, bool selected*/) { switch (badge) { case BadgeStyle.Lock: case BadgeStyle.Tick: case BadgeStyle.Crown: return(true); default: return(false); } }
internal static Color BadgeToColor(BadgeStyle badge, bool selected) { switch (badge) { case BadgeStyle.Lock: case BadgeStyle.Tick: case BadgeStyle.Crown: return(selected ? Color.FromArgb(255, 0, 0, 0) : Color.FromArgb(255, 255, 255, 255)); default: return(Color.FromArgb(255, 255, 255, 255)); } }
private static string GetBadgeHtml(XElement badge, BadgeStyle style, string leftText, string rightText, string color, string labelColor, string leftLink, string rightLink) { return($@"<!DOCTYPE html> <html> <head> <style> body {{ font-family: Arial, Helvetica, sans-serif; font-size: 80%; }} h1 {{ font-size: 14pt; }} thead {{ font-weight: bold }} table {{ border-collapse: collapse; }} table, th, td {{ border: 1px solid black; }} td {{ padding: 0 10px 0 5px; }} </style> </head> <body> <h1>Rendered Badge:</h1> {badge} <h1>Parameters:</h1> <table> <thead> <tr> <td>Name</td> <td>Value</td> </tr> </thead> <tbody> <tr> <td>Style</td> <td>{style}</td> </tr> <tr> <td>LeftText</td> <td>{leftText}</td> </tr> <tr> <td>RightText</td> <td>{rightText}</td> </tr> <tr> <td>Color</td> <td>{color}</td> </tr> <tr> <td>LabelColor</td> <td>{labelColor}</td> </tr> <tr> <td>LeftLink</td> <td>{leftLink}</td> </tr> <tr> <td>RightLink</td> <td>{rightLink}</td> </tr> </tbody> </table> </body> </html> "); }
/// <inheritdoc /> protected override string GetComponentCssClass() { var classList = new List <string>(); classList.Add("rz-badge"); classList.Add($"rz-badge-{BadgeStyle.ToString().ToLower()}"); if (IsPill) { classList.Add("rz-badge-pill"); } return(string.Join(" ", classList)); }
/// <summary> /// Creates a new badge using the specified settings. /// </summary> /// <param name="style">The style of badge to create.</param> /// <param name="leftText">The text to show in the left part of the badge.</param> /// <param name="rightText">The text to show in the right part of the badge.</param> /// <param name="color"> /// If set, specifies the primary color of the badge, usually shown in the right part of the badge. /// <para> /// Valid values are either a named color (see <see cref="NamedColor"/>), a Hex color code or a CSS color name. /// </para> /// </param> /// <param name="labelColor"> /// If set, specifies the badge's secondary color, usually shown in the left part of the badge. /// <para> /// Valid values are either a named color (see <see cref="NamedColor"/>), a Hex color code or a CSS color name. /// </para> /// </param> /// <param name="leftLink">If set, makes the badge a link to the specified target.</param> /// <param name="rightLink"> /// If set specifies a link target for the right part of the badge. /// By default, the right part uses the same link set by <paramref name="leftLink"/>. /// </param> /// <returns>Returns the generated badge as SVG image.</returns> public static XElement MakeBadge( BadgeStyle style, string leftText, string rightText, string color = null, string labelColor = null, Uri leftLink = null, Uri rightLink = null) { if (!Enum.IsDefined(typeof(BadgeStyle), style)) { throw new ArgumentException("Undefined badge style", nameof(style)); } var badgeData = GetViewModel(style, leftText, rightText, color, labelColor, leftLink, rightLink); return(RenderBadge(badgeData)); }
internal static string BadgeToSpriteLib(BadgeStyle badge) { switch (badge) { case BadgeStyle.Sale: return("mpshopsale"); case BadgeStyle.Audio1: case BadgeStyle.Audio2: case BadgeStyle.Audio3: case BadgeStyle.AudioInactive: case BadgeStyle.AudioMute: return("mpleaderboard"); default: return("commonmenu"); } }
private static string GetTestCaseFileName(BadgeStyle style, string leftText, string rightText, string color, string labelColor, string leftLink, string rightLink) { string GetSha256Hash(string value) { if (value == null) { return(null); } var crypt = new SHA256Managed(); var hash = crypt.ComputeHash(Encoding.UTF8.GetBytes(value)); var result = new StringBuilder(); foreach (var b in hash) { result.Append(b.ToString("x2")); } return(result.ToString()); } var nameBuilder = new StringBuilder(); nameBuilder.Append(style); nameBuilder.Append("_"); nameBuilder.Append(leftText ?? "[null]"); nameBuilder.Append("_"); nameBuilder.Append(rightText ?? "[null]"); nameBuilder.Append("_"); nameBuilder.Append(color ?? "[null]"); nameBuilder.Append("_"); nameBuilder.Append(labelColor ?? "[null]"); nameBuilder.Append("_"); // Links are urls and most likely not a valid in a file name // also, the full hash might result in long file names, so only the first 5 characters // are included in the name which should be sufficient to make file names unique in // the context of this test nameBuilder.Append(GetSha256Hash(leftLink)?.Substring(0, 5) ?? "[null]"); nameBuilder.Append("_"); nameBuilder.Append(GetSha256Hash(rightLink)?.Substring(0, 5) ?? "[null]"); return(nameBuilder.ToString()); }
public void MakeBadge_returns_expected_svg( BadgeStyle style, [CombinatorialValues("Hello")] string leftText, [CombinatorialValues("World")] string rightText, [CombinatorialValues("yellow", "red")] string color, [CombinatorialValues(null, "", "blue")] string labelColor, [CombinatorialValues(null, "http://example.com")] string leftLink, [CombinatorialValues(null, "http://github.com")] string rightLink) { var testId = GetTestCaseFileName(style, leftText, rightText, color, labelColor, leftLink, rightLink); var leftUri = leftLink != null ? new Uri(leftLink) : null; var rightUri = rightLink != null ? new Uri(rightLink) : null; var badge = Badge.MakeBadge(style, leftText, rightText, color, labelColor, leftUri, rightUri); var writer = new ApprovalTextWriter(GetBadgeHtml(badge, style, leftText, rightText, color, labelColor, leftLink, rightLink), "html"); Approvals.Verify(writer, new ApprovalNamer(testId), Approvals.GetReporter()); }
internal void UpdateMenuItemBadge(IMenuItem menuItem, BadgeToolbarItem item) { var color = item.BadgeColor.ToAndroid(); var colorPressed = item.BadgePressedColor.ToAndroid(); var textColor = item.BadgeTextColor.ToAndroid(); var badgeStyle = new BadgeStyle(BadgeStyle.Style.Default, Resource.Layout.menu_action_item_badge, color, colorPressed, textColor); var iconDrawable = GetFormsDrawable(item.Icon); IMenuItemController menuItemController = item; ActionItemBadge.Update(MainActivity, menuItem, iconDrawable, badgeStyle, item.BadgeText, new MenuClickListener(menuItemController.Activate)); }
private static ViewModelBase GetViewModel(BadgeStyle style, BadgeData data) { switch (style) { case BadgeStyle.Flat: return(new FlatViewModel(data)); case BadgeStyle.FlatSquare: return(new FlatSquareViewModel(data)); case BadgeStyle.Plastic: return(new PlasticViewModel(data)); case BadgeStyle.ForTheBadge: return(new ForTheBadgeViewModel(data)); case BadgeStyle.Social: return(new SocialViewModel(data)); default: throw new ArgumentException($"Unknown {nameof(BadgeStyle)} '{style}'"); } }
internal static string BadgeToSpriteName(BadgeStyle badge, bool selected) { switch (badge) { case BadgeStyle.None: return(""); case BadgeStyle.BronzeMedal: return("mp_medal_bronze"); case BadgeStyle.GoldMedal: return("mp_medal_gold"); case BadgeStyle.SilverMedal: return("medal_silver"); case BadgeStyle.Alert: return("mp_alerttriangle"); case BadgeStyle.Crown: return("mp_hostcrown"); case BadgeStyle.Ammo: return(selected ? "shop_ammo_icon_b" : "shop_ammo_icon_a"); case BadgeStyle.Armour: return(selected ? "shop_armour_icon_b" : "shop_armour_icon_a"); case BadgeStyle.Barber: return(selected ? "shop_barber_icon_b" : "shop_barber_icon_a"); case BadgeStyle.Clothes: return(selected ? "shop_clothing_icon_b" : "shop_clothing_icon_a"); case BadgeStyle.Franklin: return(selected ? "shop_franklin_icon_b" : "shop_franklin_icon_a"); case BadgeStyle.Bike: return(selected ? "shop_garage_bike_icon_b" : "shop_garage_bike_icon_a"); case BadgeStyle.Car: return(selected ? "shop_garage_icon_b" : "shop_garage_icon_a"); case BadgeStyle.Gun: return(selected ? "shop_gunclub_icon_b" : "shop_gunclub_icon_a"); case BadgeStyle.Heart: return(selected ? "shop_health_icon_b" : "shop_health_icon_a"); case BadgeStyle.Lock: return("shop_lock"); case BadgeStyle.Makeup: return(selected ? "shop_makeup_icon_b" : "shop_makeup_icon_a"); case BadgeStyle.Mask: return(selected ? "shop_mask_icon_b" : "shop_mask_icon_a"); case BadgeStyle.Michael: return(selected ? "shop_michael_icon_b" : "shop_michael_icon_a"); case BadgeStyle.Star: return("shop_new_star"); case BadgeStyle.Tatoo: return(selected ? "shop_tattoos_icon_b" : "shop_tattoos_icon_"); case BadgeStyle.Tick: return("shop_tick_icon"); case BadgeStyle.Trevor: return(selected ? "shop_trevor_icon_b" : "shop_trevor_icon_a"); default: return(""); } }
/// <summary> /// Set the right badge. Set it to None to remove the badge. /// </summary> /// <param name="badge"></param> public virtual void SetRightBadge(BadgeStyle badge) { RightBadge = badge; }
/// <summary> /// Set the left badge. Set it to None to remove the badge. /// </summary> /// <param name="badge"></param> public virtual void SetLeftBadge(BadgeStyle badge) { LeftBadge = badge; }
private Color BadgeToColor(BadgeStyle badge, bool selected) { switch (badge) { case BadgeStyle.Lock: case BadgeStyle.Tick: case BadgeStyle.Crown: return selected ? Color.FromArgb(255, 0, 0, 0) : Color.FromArgb(255, 255, 255, 255); default: return Color.FromArgb(255, 255, 255, 255); } }
private string BadgeToSpriteName(BadgeStyle badge, bool selected) { switch (badge) { case BadgeStyle.None: return ""; case BadgeStyle.BronzeMedal: return "mp_medal_bronze"; case BadgeStyle.GoldMedal: return "mp_medal_gold"; case BadgeStyle.SilverMedal: return "medal_silver"; case BadgeStyle.Alert: return "mp_alerttriangle"; case BadgeStyle.Crown: return "mp_hostcrown"; case BadgeStyle.Ammo: return selected ? "shop_ammo_icon_b" : "shop_ammo_icon_a"; case BadgeStyle.Armour: return selected ? "shop_armour_icon_b" : "shop_armour_icon_a"; case BadgeStyle.Barber: return selected ? "shop_barber_icon_b" : "shop_barber_icon_a"; case BadgeStyle.Clothes: return selected ? "shop_clothing_icon_b" : "shop_clothing_icon_a"; case BadgeStyle.Franklin: return selected ? "shop_franklin_icon_b" : "shop_franklin_icon_a"; case BadgeStyle.Bike: return selected ? "shop_garage_bike_icon_b" : "shop_garage_bike_icon_a"; case BadgeStyle.Car: return selected ? "shop_garage_icon_b" : "shop_garage_icon_a"; case BadgeStyle.Gun: return selected ? "shop_gunclub_icon_b" : "shop_gunclub_icon_a"; case BadgeStyle.Heart: return selected ? "shop_health_icon_b" : "shop_health_icon_a"; case BadgeStyle.Lock: return "shop_lock"; case BadgeStyle.Makeup: return selected ? "shop_makeup_icon_b" : "shop_makeup_icon_a"; case BadgeStyle.Mask: return selected ? "shop_mask_icon_b" : "shop_mask_icon_a"; case BadgeStyle.Michael: return selected ? "shop_michael_icon_b" : "shop_michael_icon_a"; case BadgeStyle.Star: return "shop_new_star"; case BadgeStyle.Tatoo: return selected ? "shop_tattoos_icon_b" : "shop_tattoos_icon_"; case BadgeStyle.Tick: return "shop_tick_icon"; case BadgeStyle.Trevor: return selected ? "shop_trevor_icon_b" : "shop_trevor_icon_a"; default: return ""; } }
private string BadgeToSpriteLib(BadgeStyle badge) { switch (badge) { default: return "commonmenu"; } }
internal static string BadgeToSpriteLib(BadgeStyle badge) { switch (badge) { default: return "commonmenu"; } }
protected virtual string BadgeToSpriteLib(BadgeStyle badge) { switch (badge) { default: return "commonmenu"; } }
public override void SetRightBadge(BadgeStyle badge) { throw new Exception("UIMenuListItem cannot have a right badge."); }
public override void SetRightBadge(BadgeStyle badge) { throw new Exception("UIMenuCheckboxItem cannot have a right badge."); }