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 TextFieldInfo FromTimeEntrySuggestion( this TextFieldInfo textFieldInfo, TimeEntrySuggestion timeEntrySuggestion) { var builder = ImmutableList.CreateBuilder <ISpan>(); builder.Add(new TextSpan(timeEntrySuggestion.Description)); if (timeEntrySuggestion.HasProject) { var projectSpan = new ProjectSpan( timeEntrySuggestion.ProjectId.Value, timeEntrySuggestion.ProjectName, timeEntrySuggestion.ProjectColor, timeEntrySuggestion.TaskId, timeEntrySuggestion.TaskName ); builder.Add(projectSpan); } builder.Add(new QueryTextSpan()); return(TextFieldInfo .Empty(timeEntrySuggestion.WorkspaceId) .ReplaceSpans(builder.ToImmutable())); }
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); }
private static void AppendProjectText(this SpannableStringBuilder spannable, ProjectSpan projectSpan) { /* HACK: This unbreakable space is needed because of a bug in * the way android handles ReplacementSpans. It makes sure that * all token boundaries can't be changed by the soft input once * they are set. */ var start = spannable.Length(); spannable.Append(unbreakableSpace); spannable.Append(projectSpan.ProjectName); if (!string.IsNullOrEmpty(projectSpan.TaskName)) { spannable.Append($": {projectSpan.TaskName}"); } spannable.Append(unbreakableSpace); var end = spannable.Length(); var projectTokenSpan = new ProjectTokenSpan( projectSpan.ProjectId, projectSpan.ProjectName, projectSpan.ProjectColor, projectSpan.TaskId, projectSpan.TaskName ); spannable.SetSpan(projectTokenSpan, start, end, SpanTypes.ExclusiveExclusive); spannable.SetSpan(new RelativeSizeSpan(spanSizeProportion), start, end, SpanTypes.ExclusiveExclusive); }
public TextFieldInfo WithProject(long workspaceId, long projectId, string projectName, string projectColor, long?taskId, string taskName) { var spanToAdd = new ProjectSpan(projectId, projectName, projectColor, taskId, taskName); var spansToReuse = workspaceId != WorkspaceId ? Spans.Where(span => span is TextSpan) : Spans.Where(span => (span is ProjectSpan) == false); return(addSpanToRelevantPosition(workspaceId, spanToAdd, spansToReuse.ToImmutableList())); }
private static void AppendProjectText(this SpannableStringBuilder mutableString, ProjectSpan projectSpan) { var start = mutableString.Length(); mutableString.Append(projectSpan.ProjectName); var end = mutableString.Length(); var projectTokenSpan = new ProjectTokenSpan( projectSpan.ProjectId, projectSpan.ProjectName, projectSpan.ProjectColor ); mutableString.SetSpan(projectTokenSpan, start, end, SpanTypes.ExclusiveExclusive); mutableString.SetSpan(new RelativeSizeSpan(spanSizeProportion), start, end, SpanTypes.ExclusiveExclusive); }