void TapAndHoldHandler(string data)
        {
            UIActionSheet sheet;

            if (Tweet.IndexOfUrlStarter(data, 0) != -1)
            {
                sheet = Util.GetSheet(data);

                sheet.AddButton(Locale.GetText("Open"));
                sheet.AddButton(Locale.GetText("Open in Safari"));
                sheet.AddButton(Locale.GetText("Copy"));
                sheet.AddButton(Locale.GetText("Cancel"));
                sheet.CancelButtonIndex = 3;

                sheet.Clicked += delegate(object sender, UIButtonEventArgs e) {
                    if (e.ButtonIndex == 0)
                    {
                        AppDelegate.MainAppDelegate.Open(this, data);
                    }
                    else if (e.ButtonIndex == 1)
                    {
                        UIApplication.SharedApplication.OpenUrl(new NSUrl(data));
                    }
                    else if (e.ButtonIndex == 2)
                    {
                        UIPasteboard.General.SetValue(new NSString(data), "public.utf8-plain-text");
                    }
                };
            }
            else if (data [0] == '@')
            {
                sheet = Util.GetSheet(data);
                sheet.AddButton(Locale.GetText("Reply"));
                sheet.AddButton(Locale.GetText("Private Reply"));
                sheet.AddButton(Locale.GetText("Open profile"));
                sheet.AddButton(Locale.GetText("Search mentions"));
                sheet.AddButton(Locale.GetText("Cancel"));
                sheet.CancelButtonIndex = 4;

                sheet.Clicked += delegate(object sender, UIButtonEventArgs e) {
                    switch (e.ButtonIndex)
                    {
                    case 0:
                        Composer.Main.ReplyTo(this, tweet, data);
                        break;

                    case 1:
                        Composer.Main.Direct(this, data.Substring(1));
                        break;

                    case 2:
                        AppDelegate.MainAppDelegate.Open(this, data);
                        break;

                    case 3:
                        ActivateController(new SearchViewController(data)
                        {
                            Account = TwitterAccount.CurrentAccount
                        });
                        break;
                    }
                };
            }
            else if (data [0] == '#')
            {
                sheet = Util.GetSheet(data);
                sheet.AddButton(Locale.GetText("Search mentions"));
                sheet.AddButton(Locale.GetText("Post with topic"));
                sheet.AddButton(Locale.GetText("Cancel"));
                sheet.CancelButtonIndex = 2;

                sheet.Clicked += delegate(object sender, UIButtonEventArgs e) {
                    if (e.ButtonIndex == 0)
                    {
                        ActivateController(new SearchViewController(data)
                        {
                            Account = TwitterAccount.CurrentAccount
                        });
                    }
                    else if (e.ButtonIndex == 1)
                    {
                        Composer.Main.NewTweet(this, data + " ");
                    }
                };
            }
            else
            {
                return;
            }

            sheet.ShowInView(AppDelegate.MainAppDelegate.MainView);
        }
示例#2
0
        float Layout()
        {
            float  max = Bounds.Width, segmentLength, lastx = 0, x = 0, y = 0;
            int    p = 0;
            UIFont font = regular, lastFont = null;
            string line = "";

            blocks.Clear();
            while (p < text.Length)
            {
                int sidx = text.IndexOf(' ', p);
                if (sidx == -1)
                {
                    sidx = text.Length - 1;
                }

                var segment = text.Substring(p, sidx - p + 1);
                if (segment.Length == 0)
                {
                    break;
                }

                // if the word contains @ like ".@foo" or "foo@bar", split there as well
                int aidx = segment.IndexOf('@');
                if (aidx > 0)
                {
                    segment = segment.Substring(0, aidx);
                    sidx    = p + segment.Length - aidx;
                }

                var start = segment [0];
                if (start == '@' || start == '#' || Tweet.IndexOfUrlStarter(segment, 0) != -1)
                {
                    font = bold;
                }
                else
                {
                    font = regular;
                }

                segmentLength = StringSize(segment, font).Width;

                // If we would overflow the line.
                if (x + segmentLength >= max)
                {
                    // Push the text we have so far, go to next line
                    if (line != "")
                    {
                        blocks.Add(new Block()
                        {
                            Bounds = new RectangleF(lastx, y, x - lastx, lineHeight),
                            Value  = line,
                            Font   = lastFont ?? font,
                        });
                        lastFont = font;
                        y       += lineHeight;
                        lastx    = 0;
                    }

                    // Too long to fit even on its own line, stick it on its own line.
                    if (segmentLength >= max)
                    {
                        var dim = StringSize(segment, font, new SizeF(max, float.MaxValue), UILineBreakMode.WordWrap);
                        blocks.Add(new Block()
                        {
                            Bounds = new RectangleF(new PointF(0, y), dim),
                            Value  = segment,
                            Font   = lastFont ?? font
                        });
                        y   += dim.Height;
                        x    = 0;
                        line = "";
                    }
                    else
                    {
                        x    = segmentLength;
                        line = segment;
                    }
                    p        = sidx + 1;
                    lastFont = font;
                }
                else
                {
                    // append the segment if the font changed, or if the font
                    // is bold (so we can make a tappable element on its own).
                    if (x != 0 && (font != lastFont || font == bold))
                    {
                        blocks.Add(new Block()
                        {
                            Bounds = new RectangleF(lastx, y, x - lastx, lineHeight),
                            Value  = line,
                            Font   = lastFont
                        });
                        lastx    = x;
                        line     = segment;
                        lastFont = font;
                    }
                    else
                    {
                        lastFont = font;
                        line     = line + segment;
                    }
                    x += segmentLength;
                    p  = sidx + 1;
                }
                // remove duplicate spaces
                while (p < text.Length && text [p] == ' ')
                {
                    p++;
                }
                //Console.WriteLine ("p={0}", p);
            }
            if (line == "")
            {
                return(y);
            }

            blocks.Add(new Block()
            {
                Bounds = new RectangleF(lastx, y, x - lastx, lineHeight),
                Value  = line,
                Font   = font
            });

            return(y + lineHeight);
        }