public virtual void SetResultsModeEnabled(bool enabled, bool animated = true) { Wrap.Method("SetResultsModeEnabled", delegate() { this.LayoutTokensAnimated(animated); if (_resultsModeEnabled != enabled) { //Hide / show the shadow this.Layer.MasksToBounds = !enabled; UIScrollView scrollView = this.GetScrollView(); scrollView.ScrollsToTop = !enabled; scrollView.ScrollEnabled = !enabled; float offset = ((this.NumberOfLines == 1 || !enabled) ? 0 : _tokenCaret.Y - (float)Math.Floor(this.Font.LineHeight * 4 / 7) + 1); scrollView.SetContentOffset(new PointF(0, this.Frame.Y + offset), animated); } _resultsModeEnabled = enabled; }); }
public virtual void TokenizeText() { Wrap.Method("TokenizeText", delegate() { bool textChanged = false; if ((this.Text != kTextEmpty) && (this.Text != kTextHidden) && !this.ForcePickSearchResult) { string trimmed = this.Text.Replace(kTextEmpty, string.Empty).Replace(kTextHidden, string.Empty); string[] tokens = trimmed.Split(this.TokenizingCharacters); foreach (var item in tokens) { this.AddToken(item.Trim()); textChanged = true; } } if (textChanged) { this.SendActionForControlEvents(UIControlEvent.EditingChanged); } }); }
public override void Draw(RectangleF rect) { Wrap.Method("Draw", delegate() { CGContext context = UIGraphics.GetCurrentContext(); // Draw the outline. context.SaveState(); CGPath outlinePath = this.CreateTokenPath(this.Bounds.Size, false); context.AddPath(outlinePath); bool drawHighlighted = (this.Selected || this.Highlighted); CGColorSpace colorspace = CGColorSpace.CreateDeviceRGB(); PointF endPoint = new PointF(0, this.Bounds.Size.Height); float red = 1; float green = 1; float blue = 1; float alpha = 1; this.GetTintColorRed(ref red, ref green, ref blue, ref alpha); if (drawHighlighted) { context.SetFillColor(new float[] { red, green, blue, 1 }); context.FillPath(); } else { context.Clip(); float[] location = new float[] { 0f, 0.95f }; float[] components = new float[] { red + 0.2f, green + 0.2f, blue + 0.2f, alpha, red, green, blue, 0.8f }; CGGradient gradients = new CGGradient(colorspace, components, location); context.DrawLinearGradient(gradients, PointF.Empty, endPoint, 0); } context.RestoreState(); CGPath innerPath = CreateTokenPath(this.Bounds.Size, true); // Draw a white background so we can use alpha to lighten the inner gradient context.SaveState(); context.AddPath(innerPath); context.SetFillColor(new float[] { 1f, 1f, 1f, 1f }); context.FillPath(); context.RestoreState(); // Draw the inner gradient. context.SaveState(); context.AddPath(innerPath); context.Clip(); float[] locations = new float[] { 0f, (drawHighlighted ? 0.9f : 0.6f) }; float[] highlightedComp = new float[] { red, green, blue, 0.7f, red, green, blue, 1f }; float[] nonHighlightedComp = new float[] { red, green, blue, 0.15f, red, green, blue, 0.3f }; CGGradient gradient = new CGGradient(colorspace, (drawHighlighted ? highlightedComp : nonHighlightedComp), locations); context.DrawLinearGradient(gradient, Point.Empty, endPoint, 0); context.RestoreState(); float accessoryWidth = 0; float ignore = 0; if (_accessoryType == AccessoryType.DisclosureIndicator) { PointF arrowPoint = new PointF(this.Bounds.Size.Width - (float)Math.Floor(hTextPadding / 2), (this.Bounds.Size.Height / 2) - 1); CGPath disclosurePath = this.CreateDisclosureIndicatorPath(arrowPoint, _font.PointSize, kDisclosureThickness, out accessoryWidth); accessoryWidth += (float)Math.Floor(hTextPadding / 2); context.AddPath(disclosurePath); context.SetFillColor(new float[] { 1, 1, 1, 1 }); if (drawHighlighted) { context.FillPath(); } else { context.SaveState(); context.SetShadowWithColor(new SizeF(0, 1), 1, UIColor.White.ColorWithAlpha(0.6f).CGColor); context.FillPath(); context.RestoreState(); context.SaveState(); context.AddPath(disclosurePath); context.Clip(); CGGradient disclosureGradient = new CGGradient(colorspace, highlightedComp, null); context.DrawLinearGradient(disclosureGradient, PointF.Empty, endPoint, 0); arrowPoint.Y += 0.5f; CGPath innerShadowPath = this.CreateDisclosureIndicatorPath(arrowPoint, _font.PointSize, kDisclosureThickness, out ignore); context.AddPath(innerShadowPath); context.SetStrokeColor(new float[] { 0f, 0f, 0f, 0.3f }); context.StrokePath(); context.RestoreState(); } } NSString title = new NSString(this.Title); SizeF titleSize = title.StringSize(this.Font, (_maxWidth - hTextPadding - accessoryWidth), kLineBreakMode); float vPadding = (float)Math.Floor((this.Bounds.Size.Height - titleSize.Height) / 2f); float titleWidth = (float)Math.Ceiling(this.Bounds.Size.Width - hTextPadding - accessoryWidth); RectangleF textBounds = new RectangleF((float)Math.Floor(hTextPadding / 2), vPadding - 1, titleWidth, (float)Math.Floor(this.Bounds.Size.Height - (vPadding * 2))); context.SetFillColorWithColor((drawHighlighted ? this.HighlightedTextColor : this.TextColor).CGColor); title.DrawString(textBounds, this.Font, kLineBreakMode); }); }
protected Task ResultsForSearchString(string searchString) { return(Wrap.MethodAsync("ResultsForSearchString", async delegate() { this.InvokeOnMainThread(delegate() { this.ResultsArray.Clear(); this.ResultsTable.ReloadData(); }); if (string.IsNullOrWhiteSpace(searchString)) { searchString = string.Empty; } searchString = searchString.Trim().ToLower(); if (SearchMethodAsync != null) { List <object> results = await SearchMethodAsync(searchString); this.InvokeOnMainThread(delegate() { lock (_searchResultRoot) { // ensure same search is still pending string currentText = this.TokenField.Text; if (!string.IsNullOrEmpty(currentText)) { currentText = currentText.Replace(TITokenField.kTextEmpty, "").Replace(TITokenField.kTextHidden, ""); } ; if (currentText == searchString) { this.ResultsArray.Clear(); foreach (object item in results) { this.ResultsArray.Add(item); } if (this.ResultsArray.Count > 0) { this.ResultsTable.ReloadData(); } } } }); } else { this.InvokeOnMainThread(delegate() { Wrap.Method("ResultsForSearchString", delegate() { if (!string.IsNullOrEmpty(searchString) || ForcePickSearchResult) { foreach (var sourceObject in this.SourceArray) { string title = this._tokenDelegateShim.SearchResultStringForRepresentedObject(this.TokenField, sourceObject); string subTitle = this._tokenDelegateShim.SearchResultSubtitleForRepresentedObject(this.TokenField, sourceObject); if (!SearchSubtitles || string.IsNullOrEmpty(subTitle)) { subTitle = string.Empty; } if ((this.ForcePickSearchResult && string.IsNullOrEmpty(searchString)) || title.IndexOf(searchString, StringComparison.OrdinalIgnoreCase) > -1 || subTitle.IndexOf(searchString, StringComparison.OrdinalIgnoreCase) > -1) { bool shouldAdd = !this.ResultsArray.Contains(sourceObject); if (shouldAdd && !ShowAlreadyTokenized) { foreach (var token in this.TokenField.Tokens) { if (token.RepresentedObject == sourceObject) { shouldAdd = false; break; } } } if (shouldAdd) { this.ResultsArray.Add(sourceObject); } } } } if (this.ResultsArray.Count > 0) { this.ResultsArray.Sort(delegate(object l, object r) { string left = this._tokenDelegateShim.SearchResultStringForRepresentedObject(this.TokenField, l); string right = this._tokenDelegateShim.SearchResultStringForRepresentedObject(this.TokenField, r); return left.CompareTo(right); }); } if (this.ResultsArray.Count > 0) { this.ResultsTable.ReloadData(); } }); }); } })); }