private static void addProjectAttachmentsIfNeeded(TextFieldInfo info, NSMutableAttributedString finalString) { if (string.IsNullOrEmpty(info.ProjectColor)) { return; } var color = MvxColor.ParseHexString(info.ProjectColor).ToNativeColor(); var projectName = new NSAttributedString(info.ProjectName.TruncatedAt(maxTextLength), new UIStringAttributes { Font = tokenFont, ForegroundColor = color }); var textAttachment = new TokenTextAttachment( projectName, textVerticalOffset, color, regularFont.Descender, textFieldInfoTokenLeftMargin, textFieldInfoTokenRightMargin ); var tokenString = new NSMutableAttributedString(NSAttributedString.FromAttachment(textAttachment)); var attributes = new UIStringAttributes { ParagraphStyle = paragraphStyle }; attributes.Dictionary[Project] = new NSObject(); tokenString.AddAttributes(attributes, new NSRange(0, tokenString.Length)); finalString.Append(tokenString); }
protected override object Convert(VehicleTypes value, Type targetType, object parameter, CultureInfo culture) { MvxColor color; switch (value) { case VehicleTypes.Bus: color = new MvxColor(0xFF2B9A79); break; case VehicleTypes.Trolley: color = new MvxColor(0xFF2C8DDE); break; case VehicleTypes.Tram: color = new MvxColor(0xFFF10945); break; case VehicleTypes.MiniBus: color = new MvxColor(0xFFF59808); break; default: color = new MvxColor(0xFFFFFFFF); break; } var nativeColorConv = Mvx.Resolve <IMvxNativeColor>(); return(nativeColorConv.ToNative(color)); }
public void MvxColorComponentConstructorTests() { var tests = new uint[, ] { { 0, 0, 0, 0 }, { 0, 0, 0, 0xFF }, { 0, 0, 0xFF, 0 }, { 0, 0xFF, 0, 0 }, { 0xFF, 0, 0, 0 }, { 0x12, 0x34, 0x56, 0x78 }, { 0xFF, 0xFF, 0xFF, 0xFF }, }; for (var i = 0; i < tests.GetUpperBound(0); i++) { var c = new MvxColor((int)tests[i, 1], (int)tests[i, 2], (int)tests[i, 3], (int)tests[i, 0]); Assert.AreEqual(tests[i, 0], c.A); Assert.AreEqual(tests[i, 1], c.R); Assert.AreEqual(tests[i, 2], c.G); Assert.AreEqual(tests[i, 3], c.B); var argb = tests[i, 0] & 0xFF; argb <<= 8; argb |= (tests[i, 1] & 0xFF); argb <<= 8; argb |= (tests[i, 2] & 0xFF); argb <<= 8; argb |= (tests[i, 3] & 0xFF); Assert.AreEqual(argb, (uint)c.ARGB); } }
protected override void UpdateView() { // Text var projectColor = MvxColor.ParseHexString(Item.ProjectColor).ToNativeColor(); DescriptionLabel.Text = Item.HasDescription ? Item.Description : Resources.AddDescription; ProjectTaskClientLabel.AttributedText = projectTaskClientToAttributedString.Convert(Item.ProjectName, Item.TaskName, Item.ClientName, projectColor); TimeLabel.Text = Item.Duration.HasValue ? DurationAndFormatToString.Convert(Item.Duration.Value, Item.DurationFormat) : ""; // Colors DescriptionLabel.TextColor = Item.HasDescription ? UIColor.Black : Color.TimeEntriesLog.AddDescriptionTextColor.ToNativeColor(); // Visibility ProjectTaskClientLabel.Hidden = !Item.HasProject; SyncErrorImageView.Hidden = Item.CanContinue; UnsyncedImageView.Hidden = !Item.NeedsSync; ContinueButton.Hidden = !Item.CanContinue; ContinueImageView.Hidden = !Item.CanContinue; BillableIcon.Hidden = !Item.IsBillable; TagIcon.Hidden = !Item.HasTags; // Grouping BackgroundColor = UIColor.White; GroupSizeBackground.Layer.CornerRadius = 14; GroupSizeLabel.Text = "1"; setupSingleEntity(); }
public void MvxColorRGBAndAlphaConstructorTests() { var tests = new uint[, ] { { 0, 0, 0, 0 }, { 0XFF, 0, 0, 0xFF }, { 0xFF00, 0, 0xFF, 0 }, { 0xFF0000, 0xFF, 0, 0 }, { 0xFF000000, 0, 0, 0 }, { 0x12345678, 0x34, 0x56, 0x78 }, { 0xFFFFFFFF, 0xFF, 0xFF, 0xFF }, }; for (var i = 0; i < tests.GetUpperBound(0); i++) { for (uint alpha = 0; alpha < 256; alpha++) { var c = new MvxColor((int)tests[i, 0], (int)alpha); Assert.AreEqual(alpha, c.A); Assert.AreEqual(tests[i, 1], c.R); Assert.AreEqual(tests[i, 2], c.G); Assert.AreEqual(tests[i, 3], c.B); var argb = (tests[i, 0] & 0x00FFFFFF) | ((alpha & 0xFF) << 24); Assert.AreEqual(argb, (uint)c.ARGB); } } }
public void MvxAColorComponentTests() { var tests = new uint[, ] { { 0, 0, 0, 0 }, { 0, 0, 0, 0xFF }, { 0, 0, 0xFF, 0 }, { 0, 0xFF, 0, 0 }, { 0xFF, 0, 0, 0 }, { 0x12, 0x34, 0x56, 0x78 }, { 0xFF, 0xFF, 0xFF, 0xFF }, }; for (var i = 0; i < tests.GetUpperBound(0); i++) { var c = new MvxColor((int)tests[i, 1], (int)tests[i, 2], (int)tests[i, 3], (int)tests[i, 0]); for (int j = 0; j < 256; j++) { c.A = j; Assert.AreEqual(j, c.A); Assert.AreEqual(tests[i, 1], c.R); Assert.AreEqual(tests[i, 2], c.G); Assert.AreEqual(tests[i, 3], c.B); var argb = (uint)j & 0xFF; argb <<= 8; argb |= tests[i, 1] & 0xFF; argb <<= 8; argb |= tests[i, 2] & 0xFF; argb <<= 8; argb |= tests[i, 3] & 0xFF; Assert.AreEqual(argb, (uint)c.ARGB); } } }
private static NSMutableAttributedString AsAttributedString(this ProjectSpan projectSpan) { var projectColor = MvxColor.ParseHexString(projectSpan.ProjectColor).ToNativeColor(); var projectName = new NSAttributedString(projectSpan.ProjectName.TruncatedAt(maxTextLength), new UIStringAttributes { Font = tokenFont, ForegroundColor = projectColor }); var textAttachment = new TokenTextAttachment( projectName, textVerticalOffset, projectColor, regularFont.Descender, textFieldInfoTokenLeftMargin, textFieldInfoTokenRightMargin ); var tokenString = new NSMutableAttributedString(NSAttributedString.FromAttachment(textAttachment)); var attributes = createBasicAttributes(); attributes.Dictionary[ProjectId] = new NSNumber(projectSpan.ProjectId); attributes.Dictionary[ProjectName] = new NSString(projectSpan.ProjectName); attributes.Dictionary[ProjectColor] = new NSString(projectSpan.ProjectColor); if (projectSpan.TaskId.HasValue) { attributes.Dictionary[TaskId] = new NSNumber(projectSpan.TaskId.Value); attributes.Dictionary[TaskName] = new NSString(projectSpan.TaskName); } tokenString.AddAttributes(attributes, new NSRange(0, tokenString.Length)); return(tokenString); }
public SelectableColorViewModel(MvxColor color, bool selected) { Ensure.Argument.IsNotNull(color, nameof(color)); Color = color; Selected = selected; }
public override bool TryGetValue(IEnumerable <IMvxSourceStep> steps, out object value) { var stepList = steps.ToList(); if (stepList.Count < 4) { throw new ArgumentException($"{nameof(ProjectTaskClientValueCombiner)} needs at least 4 values to work - project, task, client and project color"); } var project = stepList[0].GetValue()?.ToString() ?? ""; var task = stepList[1].GetValue()?.ToString() ?? ""; var client = stepList[2].GetValue()?.ToString() ?? ""; var projectColor = stepList[3].GetValue()?.ToString() ?? ""; var color = string.IsNullOrEmpty(projectColor) ? null : MvxColor.ParseHexString(projectColor).ToNativeColor(); var clone = new NSMutableAttributedString(cachedDotString); var dotString = tryAddColorToDot(clone, color); var projectInfo = buildString(project, task, client, color); dotString.Append(projectInfo); value = dotString; return(true); }
protected override void UpdateView() { // Text var projectColor = MvxColor.ParseHexString(Item.ProjectColor).ToNativeColor(); DescriptionLabel.Text = Item.Description; ProjectTaskClientLabel.AttributedText = projectTaskClientToAttributedString.Convert(Item.ProjectName, Item.TaskName, Item.ClientName, projectColor); TimeLabel.Text = Item.Duration.HasValue ? DurationAndFormatToString.Convert(Item.Duration.Value, Item.DurationFormat) : ""; // Constraints DescriptionTopDistanceConstraint.Constant = Item.HasProject ? hasProjectDistance : noProjectDistance; AddDescriptionTopDistanceConstraint.Constant = Item.HasProject ? hasProjectDistance : noProjectDistance; FadeViewTrailingConstraint.Constant = calculateFadeViewConstraint(Item.IsBillable, Item.HasTags); BillableImageViewSpacingConstraint.Constant = Item.HasTags ? hasTagsBillableSpacing : noTagsBillableSpacing; // Visibility ProjectTaskClientLabel.Hidden = !Item.HasProject; AddDescriptionLabel.Hidden = Item.HasDescription; SyncErrorImageView.Hidden = Item.CanSync; UnsyncedImageView.Hidden = !Item.NeedsSync; ContinueButton.Hidden = !Item.CanSync; ContinueImageView.Hidden = !Item.CanSync; BillableImageView.Hidden = !Item.IsBillable; TagsImageView.Hidden = !Item.HasTags; }
private static NSMutableAttributedString AsAttributedString(this ProjectSpan projectSpan) { var projectColor = MvxColor.ParseHexString(projectSpan.ProjectColor).ToNativeColor(); var projectNameString = projectSpan.ProjectName; if (!string.IsNullOrEmpty(projectSpan.TaskName)) { projectNameString = $"{projectNameString}: {projectSpan.TaskName}"; } var textAttachment = new ProjectTextAttachment( projectNameString, projectColor, tokenFont); var tokenString = new NSMutableAttributedString(NSAttributedString.FromAttachment(textAttachment)); var attributes = createBasicAttributes(); attributes.Dictionary[ProjectId] = new NSNumber(projectSpan.ProjectId); attributes.Dictionary[ProjectName] = new NSString(projectSpan.ProjectName); attributes.Dictionary[ProjectColor] = new NSString(projectSpan.ProjectColor); if (projectSpan.TaskId.HasValue) { attributes.Dictionary[TaskId] = new NSNumber(projectSpan.TaskId.Value); attributes.Dictionary[TaskName] = new NSString(projectSpan.TaskName); } tokenString.AddAttributes(attributes, new NSRange(0, tokenString.Length)); return(tokenString); }
public static MvxColor ForegroundColor(this CalendarItem calendarItem) { var color = MvxColor.ParseHexString(calendarItem.Color); var luma = (0.2126 * color.R + 0.7152 * color.G + 0.0722 * color.B) / 255; return(luma < 0.5 ? MvxColors.White : MvxColors.Black); }
public static Windows.UI.Color ToNativeColor(this MvxColor mvxColor) { var color = Windows.UI.Color.FromArgb((byte)mvxColor.A, (byte)mvxColor.R, (byte)mvxColor.G, (byte)mvxColor.B); return(color); }
public static float GetHue(this MvxColor self) { if (self.R == self.G && self.G == self.B) { return(0); // 0 makes as good an UNDEFINED value as any } float r = (float)self.R / 255.0f; float g = (float)self.G / 255.0f; float b = (float)self.B / 255.0f; float max, min; float delta; float hue = 0.0f; max = r; min = r; if (g > max) { max = g; } if (b > max) { max = b; } if (g < min) { min = g; } if (b < min) { min = b; } delta = max - min; if (r == max) { hue = (g - b) / delta; } else if (g == max) { hue = 2 + (b - r) / delta; } else if (b == max) { hue = 4 + (r - g) / delta; } hue *= 60; if (hue < 0.0f) { hue += 360.0f; } return(hue / 360); }
// Taken from http://referencesource.microsoft.com/#System.Drawing/commonui/System/Drawing/Color.cs,23adaaa39209cc1f public static (float hue, float saturation, float value) GetHSV(this MvxColor color) { var max = Max(color.R, Max(color.G, color.B)); var min = Min(color.R, Min(color.G, color.B)); return( hue : color.GetHue(), saturation : (float)((max <= 0) ? 0 : 1d - (1d * min / max)), value : (float)(max / 255d)); }
public static NSAttributedString GetAttributedText(this TextFieldInfo self) { var projectName = self.PaddedProjectAndTaskName(); var tags = self.TagsText(); var fullText = $"{self.Text}{projectName}{tags}"; var result = new NSMutableAttributedString(fullText); var baselineOffset = string.IsNullOrEmpty(self.Text) ? 5 : 3; result.AddAttributes(new UIStringAttributes { ParagraphStyle = paragraphStyle, Font = UIFont.SystemFontOfSize(16, UIFontWeight.Regular), }, new NSRange(0, self.Text.Length)); if (!string.IsNullOrEmpty(self.ProjectColor)) { var color = MvxColor.ParseHexString(self.ProjectColor).ToNativeColor(); var attributes = new UIStringAttributes { ForegroundColor = color, StrokeColor = strokeColor, BaselineOffset = baselineOffset, ParagraphStyle = paragraphStyle, Font = UIFont.SystemFontOfSize(12, UIFontWeight.Regular), }; attributes.Dictionary[TimeEntryTagsTextView.RoundedBackground] = color.ColorWithAlpha(0.12f); result.AddAttributes(attributes, new NSRange(self.Text.Length, projectName.Length)); } if (!string.IsNullOrEmpty(tags)) { var startingPosition = self.Text.Length + projectName.Length; for (int i = 0; i < self.Tags.Length; i++) { var tagLength = self.Tags[i].Name.Length + 6; var attributes = new UIStringAttributes { BaselineOffset = baselineOffset, ParagraphStyle = paragraphStyle, Font = UIFont.SystemFontOfSize(12, UIFontWeight.Regular), }; attributes.Dictionary[TimeEntryTagsTextView.TagIndex] = new NSNumber(i); attributes.Dictionary[TimeEntryTagsTextView.RoundedBorders] = strokeColor; result.AddAttributes(attributes, new NSRange(startingPosition, tagLength)); startingPosition += tagLength; } } return(result); }
public void FillRectangle(int fromX, int fromY, int toX, int toY, MvxColor color) { for (var y = fromY; y < toY; y++) { var offset = y * Width; for (var x = fromX; x < toX; x++) { Pixels[x + offset] = color.ARGB; } } }
internal Item(CharacterList list, bool isDefault = false) { List = list; Name = list.Name; TextColor = new MvxColor(list.TextColor); UnderlineColor = new MvxColor(list.UnderlineColor); SortOrder = list.SortingOrder; HideAds = list.HideAds; HideInSearch = list.HideInSearch; IsDefault = isDefault; }
protected override Cirrious.CrossCore.UI.MvxColor Convert(VehicleStatus value, object parameter, System.Globalization.CultureInfo culture) { var green = new MvxColor(0x43, 0xa7, 0x2e); var red = new MvxColor(0xec, 0x67, 0x4d); var returnColor = value == VehicleStatus.Free ? green : red; return(returnColor); }
protected override void OnCommandSuccess(ISpheroMessage message) { if (message is GetColorLedCommand.ColorMessage) { var colorMessage = message as GetColorLedCommand.ColorMessage; Color = colorMessage.Color; RaisePropertyChanged(() => Red); RaisePropertyChanged(() => Green); RaisePropertyChanged(() => Blue); } base.OnCommandSuccess(message); }
public void ShouldReturnTheExpectedForegroundColor(string color, string expectedColor) { var timeEntry = new MockTimeEntry { Project = new MockProject { Color = color } }; var calendarItem = CalendarItem.From(timeEntry); var foregroundColor = calendarItem.ForegroundColor(); foregroundColor.Should().BeEquivalentTo(MvxColor.ParseHexString(expectedColor)); }
private void UpdateColor() { rbg_red = 0; rbg_green = 128; rbg_blue = 0; if (UserStatus == "Has not responded") { rbg_red = 195; rbg_green = 195; rbg_blue = 195; } CurrentColor = new MvxColor(rbg_red, rbg_green, rbg_blue); }
protected override void UpdateView() { //Text DescriptionLabel.Text = Item.Description; ProjectLabel.AttributedText = projectTaskClientToAttributedString.Convert( Item.ProjectName, Item.TaskName, Item.ClientName, MvxColor.ParseHexString(Item.ProjectColor).ToNativeColor()); //Visibility DescriptionTopDistanceConstraint.Constant = Item.HasProject ? HasProjectDistance : NoProjectDistance; ProjectLabel.Hidden = !Item.HasProject; }
public BoardControlState() { _pointerOverPosition = Position.Undefined; _shiningPosition = Position.Undefined; _boardLineThickness = 1; _boardWidth = 1; _boardHeight = 1; _boardColor = new MvxColor(0xFD, 0xD2, 0x70, 0xFF); _highlightColor = new MvxColor(0xFF, 0xFF, 0xFF, 0x60); IsShadowDrawingEnabled = true; }
public FirstViewModel() { var random = new Random(); var colors = new List <MvxColor>(); for (var i = 0; i < 10; i++) { var color = new MvxColor(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); colors.Add(color); } Colors = colors; SelectedColor = Colors.First(); }
protected override MvxColor Convert(TicketPriority value, object parameter, CultureInfo culture) { var Color = new MvxColor(0, 0, 0); switch (value) { case TicketPriority.Low: Color = new MvxColor(121, 196, 69); break; case TicketPriority.Medium: Color = new MvxColor(247, 148, 22); break; case TicketPriority.Top: Color = new MvxColor(255, 0, 0); break; } return(Color); }
public MenuViewModel(IMvxNavigationService navigationService, IMvxTrace trace) : base(navigationService, trace) { MenuItems = new List <MenuItem> { new MenuItem { Title = "Instagram", ImageName = "instagram", Color = MvxColor.ParseHexString("#517FA3") }, new MenuItem { Title = "Twitter", ImageName = "twitter", Color = MvxColor.ParseHexString("#55ACEF") }, new MenuItem { Title = "Facebook", ImageName = "facebook", Color = MvxColor.ParseHexString("#385B9B") }, //new MenuItem { Title = "YouTube", ImageName = "youtube", Color = MvxColor.ParseHexString("#E32D2A") }, //new MenuItem { Title = "Alerts", ImageName = "menu-alert" }, new MenuItem { Title = "Contact", ImageName = "phone", Color = MvxColor.ParseHexString("#0d3982") }, }; }
protected override void UpdateView() { ProjectLabel.SetKerning(-0.2); ClientLabel.SetKerning(-0.2); TotalTimeLabel.SetKerning(-0.2); PercentageLabel.SetKerning(-0.2); //Text ProjectLabel.Text = Item.ProjectName; ClientLabel.Text = Item.ClientName; PercentageLabel.Text = $"{Item.Percentage:F2}%"; TotalTimeLabel.Text = Item.TrackedTime.ToFormattedString(Item.DurationFormat); ClientLabel.Hidden = !Item.HasClient; // Color var color = MvxColor.ParseHexString(Item.Color).ToNativeColor(); ProjectLabel.TextColor = color; CircleView.BackgroundColor = color; }
public static MvxColor Convert(ColorEnum value) { var color = new MvxColor(0, 0, 0); switch (value) { case ColorEnum.Blue: color = new MvxColor(19, 93, 230); break; case ColorEnum.Green: color = new MvxColor(13, 129, 21); break; case ColorEnum.White: color = new MvxColor(255, 255, 255); break; default: break; } return(color); }
public void MvxColorSimpleConstructorTests() { var tests = new uint[, ] { { 0, 0, 0, 0, 0 }, { 0XFF, 0, 0, 0, 0xFF }, { 0xFF00, 0, 0, 0xFF, 0 }, { 0xFF0000, 0, 0xFF, 0, 0 }, { 0xFF000000, 0xFF, 0, 0, 0 }, { 0x12345678, 0x12, 0x34, 0x56, 0x78 }, { 0xFFFFFFFF, 0xFF, 0xFF, 0xFF, 0xFF }, }; for (var i = 0; i < tests.GetUpperBound(0); i++) { var c = new MvxColor((int)tests[i, 0]); Assert.AreEqual(tests[i, 1], c.A); Assert.AreEqual(tests[i, 2], c.R); Assert.AreEqual(tests[i, 3], c.G); Assert.AreEqual(tests[i, 4], c.B); Assert.AreEqual(tests[i, 0], (uint)c.ARGB); } }
public ColorMessage(int r, int g, int b) { _color = new MvxColor(r, g, b); }
public global::Android.Graphics.Color ToAndroidColor(MvxColor mvxColor) { return new global::Android.Graphics.Color(mvxColor.R, mvxColor.G, mvxColor.B, mvxColor.A); }
public object ToNative(MvxColor mvxColor) { return ToAndroidColor(mvxColor); }
public object ToNative(MvxColor mvxColor) { var color = ToNativeColor(mvxColor); return new SolidColorBrush(color); }
public static System.Windows.Media.Color ToNativeColor(MvxColor mvxColor) { return System.Windows.Media.Color.FromArgb((byte) mvxColor.A, (byte) mvxColor.R, (byte) mvxColor.G, (byte) mvxColor.B); }
public object ToNative(MvxColor mvxColor) { return ToUIColor(mvxColor); }
public static UIColor ToUIColor(MvxColor mvxColor) { return new MonoTouch.UIKit.UIColor(mvxColor.R, mvxColor.G, mvxColor.B, mvxColor.A); }
private void UpdateColor() { Color = new MvxColor(Red, Green, Blue); }
public SetColorLedCommand(MvxColor color) : base(DeviceSphero, CommandSetRGBLed) { Color = color; }