public virtual void LayoutTokensAnimated(bool animated)
 {
     Wrap.Method("LayoutTokensAnimated", delegate()
     {
         float newHeight = this.LayoutTokensInternal();
         if (this.Bounds.Size.Height != newHeight)
         {
             // Animating this seems to invoke the triple-tap-delete-key-loop-problem-thing™
             UIView.Animate(
                 (animated ? 0.3 : 0),
                 delegate()  // animation
             {
                 Wrap.Method("LayoutTokensAnimated.Animate", delegate()
                 {
                     this.Frame = new RectangleF(this.Frame.X, this.Frame.Y, this.Bounds.Size.Width, newHeight);
                     this.SendActionForControlEvents((UIControlEvent)ControlEvents.FrameWillChange);
                 });
             },
                 delegate() // completion
             {
                 Wrap.Method("LayoutTokensAnimated.Completion", delegate()
                 {
                     this.SendActionForControlEvents((UIControlEvent)ControlEvents.FrameDidChange);
                     this.BoundsDidChange.Raise(this, EventArgs.Empty);
                 });
             }
                 );
         }
     });
 }
Beispiel #2
0
 protected virtual void tokenField_TextDidChange(object sender, EventArgs args)
 {
     Wrap.Method("tokenField_TextDidChange", delegate()
     {
         string text = this.TokenField.Text;
         if (!string.IsNullOrEmpty(text))
         {
             text = text.Replace(TITokenField.kTextEmpty, "").Replace(TITokenField.kTextHidden, "");
         }
         ;
         Task.Run(delegate()
         {
             this.ResultsForSearchString(text)
             .ContinueWith(delegate(Task arg)
             {
                 this.BeginInvokeOnMainThread(delegate()
                 {
                     Wrap.Method("Search_Callback", delegate()
                     {
                         if (this.ForcePickSearchResult)
                         {
                             this.SetSearchResultsVisible(true);
                         }
                         else
                         {
                             this.SetSearchResultsVisible(this.ResultsArray.Count > 0);
                         }
                     });
                 });
             });
         });
     });
 }
Beispiel #3
0
 protected virtual void SetSearchResultsVisible(bool visible)
 {
     Wrap.Method("SetSearchResultsVisible", delegate()
     {
         if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
         {
             if (visible)
             {
                 this.PresentPopoverAtTokenFieldCaretAnimated(true);
             }
             else
             {
                 if (_popoverController != null)
                 {
                     _popoverController.Dismiss(true);
                 }
             }
         }
         else
         {
             this.ResultsTable.Hidden = !visible;
             this.TokenField.SetResultsModeEnabled(visible);
         }
     });
 }
Beispiel #4
0
 protected virtual void tokenField_DidBeginEditing(object sender, EventArgs args)
 {
     Wrap.Method("tokenField_DidBeginEditing", delegate()
     {
         this.ResultsArray.Clear();
         this.ResultsTable.ReloadData();
     });
 }
Beispiel #5
0
 protected virtual void tokenField_FrameWillChange(object sender, EventArgs args)
 {
     Wrap.Method("tokenField_FrameWillChange", delegate()
     {
         float tokenFieldBottom  = this.TokenField.Frame.Bottom;
         this.Separator.Frame    = new RectangleF(new PointF(this.Separator.Frame.X, tokenFieldBottom), this.Separator.Bounds.Size);
         this.ResultsTable.Frame = new RectangleF(new PointF(this.ResultsTable.Frame.X, (tokenFieldBottom + 1)), this.ResultsTable.Bounds.Size);
         this.ContentView.Frame  = new RectangleF(new PointF(this.ContentView.Frame.X, (tokenFieldBottom + 1)), this.ContentView.Bounds.Size);
     });
 }
 protected virtual void Self_DidBeginEditing(object sender, EventArgs e)
 {
     Wrap.Method("Self_DidBeginEditing", delegate()
     {
         TIToken[] tokens = this.Tokens.ToArray();
         foreach (var item in tokens)
         {
             this.AddToken(item);
         }
     });
 }
Beispiel #7
0
 protected virtual void PresentPopoverAtTokenFieldCaretAnimated(bool animated)
 {
     Wrap.Method("PresentPopoverAtTokenFieldCaretAnimated", delegate()
     {
         UITextPosition position = this.TokenField.GetPosition(this.TokenField.BeginningOfDocument, 2);
         if (_popoverController != null)
         {
             _popoverController.PresentFromRect(this.TokenField.GetCaretRectForPosition(position), this.TokenField, UIPopoverArrowDirection.Up, animated);
         }
     });
 }
 public virtual void RemoveAllTokens()
 {
     Wrap.Method("RemoveAllTokens", delegate()
     {
         TIToken[] tokens = this.Tokens.ToArray();
         foreach (var item in tokens)
         {
             this.RemoveToken(item);
         }
     });
 }
        public virtual void AddToken(TIToken token)
        {
            Wrap.Method("AddToken.Object", delegate()
            {
                lock (_tokenSyncRoot)
                {
                    bool shouldAdd = true;
                    if (this.Delegate != null)
                    {
                        shouldAdd = this.Delegate.WillAddToken(this, token);
                    }
                    if (shouldAdd)
                    {
                        shouldAdd = this.WillAddToken.Raise(this, token);
                    }

                    if (shouldAdd)
                    {
                        token.TintColor = this.TokenTintColor;
                        token.MaxWidth  = this.MaxTokenWidth;
                        this.BecomeFirstResponder();

                        token.TouchDown     -= Token_TouchDown;     //safety
                        token.TouchUpInside -= Token_TouchUpInside; //safety

                        token.TouchDown     += Token_TouchDown;
                        token.TouchUpInside += Token_TouchUpInside;

                        this.AddSubview(token);

                        if (!this.Tokens.Contains(token))
                        {
                            this.Tokens.Add(token);

                            if (this.Delegate != null)
                            {
                                this.Delegate.DidAddToken(this, token);
                            }
                            this.DidAddToken.Raise(this, token);

                            if (_placeHolderLabel != null)
                            {
                                _placeHolderLabel.Hidden = true;
                            }
                        }

                        this.SetResultsModeEnabled(false);
                        this.DeselectSelectedToken();
                    }
                }
            });
        }
        public virtual void SelectToken(TIToken token)
        {
            Wrap.Method("SelectToken", delegate()
            {
                this.DeselectSelectedToken();

                this.SelectedToken          = token;
                this.SelectedToken.Selected = true;

                this.BecomeFirstResponder();
                this.Text = kTextHidden;
            });
        }
        public virtual void DeselectSelectedToken()
        {
            Wrap.Method("DeselectSelectedToken", delegate()
            {
                if (this.SelectedToken != null)
                {
                    this.SelectedToken.Selected = false;
                }
                this.SelectedToken = null;

                this.Text = kTextEmpty;
            });
        }
Beispiel #12
0
        public override void LayoutSubviews()
        {
            Wrap.Method("LayoutSubviews", delegate()
            {
                base.LayoutSubviews();

                float relativeFieldHeight = this.TokenField.Frame.Bottom - this.ContentOffset.Y;
                float newHeight           = this.Bounds.Size.Height - relativeFieldHeight;
                if (newHeight > -1)
                {
                    this.ResultsTable.Frame = new RectangleF(this.ResultsTable.Frame.Location, new SizeF(this.ResultsTable.Bounds.Size.Width, newHeight));
                }
            });
        }
 protected virtual void Token_TouchUpInside(object sender, EventArgs e)
 {
     Wrap.Method("Token_TouchUpInside", delegate()
     {
         TIToken token = sender as TIToken;
         if (token != null)
         {
             if (this.Editable)
             {
                 this.SelectToken(token);
             }
         }
     });
 }
 protected virtual void Token_TouchDown(object sender, EventArgs e)
 {
     Wrap.Method("Token_TouchDown", delegate()
     {
         TIToken token = sender as TIToken;
         if (token != null)
         {
             if (this.SelectedToken != null && this.SelectedToken != token)
             {
                 this.SelectedToken.Selected = false;
                 this.SelectedToken          = null;
             }
         }
     });
 }
Beispiel #15
0
            public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
            {
                Wrap.Method("RowSelected", delegate()
                {
                    object representedObject = this.Owner.ResultsArray[indexPath.Row];
                    TIToken token            = new TIToken()
                    {
                        Title             = this.Owner.TokenField.Delegate.DisplayStringForRepresentedObject(this.Owner.TokenField, representedObject),
                        RepresentedObject = representedObject
                    };
                    this.Owner.TokenField.AddToken(token);

                    tableView.DeselectRow(indexPath, true);
                    this.Owner.SetSearchResultsVisible(false);
                });
            }
        protected virtual void Self_EditingDidEnd(object sender, EventArgs e)
        {
            Wrap.Method("Self_EditingDidEnd", delegate()
            {
                if (this.SelectedToken != null)
                {
                    this.SelectedToken.Selected = false;
                }
                this.SelectedToken = null;

                this.TokenizeText();

                if (this.RemovesTokensOnEndEditing)
                {
                    TIToken[] tokens = this.Tokens.ToArray();
                    foreach (var item in tokens)
                    {
                        item.RemoveFromSuperview();
                    }

                    string untokenized = kTextEmpty;
                    if (this.Tokens.Count > 0)
                    {
                        List <string> titles = this.GetTokenTitles();

                        untokenized       = string.Join(", ", titles);
                        NSString nsString = new NSString(untokenized);

                        SizeF untokSize = nsString.StringSize(UIFont.SystemFontOfSize(this.FontSize));

                        float availableWidth = this.Bounds.Size.Width - this.LeftViewWidth - this.RightViewWidth;

                        if (this.Tokens.Count > 1 && untokSize.Width > availableWidth)
                        {
                            untokenized = string.Format("{0} recipients", titles.Count);
                        }
                    }
                    this.Text = untokenized;
                }

                this.SetResultsModeEnabled(false);
                if (this.Tokens.Count < 1 && this.ForcePickSearchResult)
                {
                    this.BecomeFirstResponder();
                }
            });
        }
        public override void SizeToFit()
        {
            Wrap.Method("SizeToFit", delegate()
            {
                float accessoryWidth = 0;

                if (this.AccessoryType == AccessoryType.DisclosureIndicator)
                {
                    this.CreateDisclosureIndicatorPath(PointF.Empty, this.Font.PointSize, kDisclosureThickness, out accessoryWidth);
                    accessoryWidth += (float)Math.Floor((double)hTextPadding / 2);
                }

                SizeF titleSize = new NSString(this.Title).StringSize(this.Font, (this.MaxWidth - hTextPadding - accessoryWidth), kLineBreakMode);
                float height    = (float)Math.Floor((double)(titleSize.Height + vTextPadding));
                float width     = Math.Max((float)Math.Floor((double)(titleSize.Width + hTextPadding + accessoryWidth)), height - 3);
                this.Frame      = new RectangleF(this.Frame.X, this.Frame.Y, width, height);
                this.SetNeedsDisplay();
            });
        }
        public virtual void RemoveToken(TIToken token)
        {
            Wrap.Method("RemoveToken", delegate()
            {
                if (token == null)
                {
                    return;
                }
                lock (_tokenSyncRoot)
                {
                    if (token == this.SelectedToken)
                    {
                        this.DeselectSelectedToken();
                    }

                    bool shouldRemove = true;
                    if (this.Delegate != null)
                    {
                        shouldRemove = this.Delegate.WillRemoveToken(this, token);
                    }
                    if (this.Delegate != null)
                    {
                        shouldRemove = this.WillRemoveToken.Raise(this, token);
                    }
                    if (shouldRemove)
                    {
                        token.RemoveFromSuperview();
                        this.Tokens.Remove(token);
                        token.TouchDown     -= Token_TouchDown;
                        token.TouchUpInside -= Token_TouchUpInside;

                        if (this.Delegate != null)
                        {
                            this.Delegate.DidRemoveToken(this, token);
                        }
                        this.DidRemoveToken.Raise(this, token);

                        this.SetResultsModeEnabled(this.ForcePickSearchResult);
                    }
                }
            });
        }
 protected virtual void Self_EditingChanged(object sender, EventArgs e)
 {
     Wrap.Method("Self_EditingChanged", delegate()
     {
         if (string.IsNullOrEmpty(this.Text))
         {
             this.Text = kTextEmpty;
             if (_placeHolderLabel != null)
             {
                 _placeHolderLabel.Hidden = false;
             }
         }
         else
         {
             if (_placeHolderLabel != null)
             {
                 _placeHolderLabel.Hidden = true;
             }
         }
     });
 }
        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);
            });
        }
Beispiel #23
0
        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();
                            }
                        });
                    });
                }
            }));
        }