public ICharSequence FilterFormatted(ICharSequence source,
                                             int start,
                                             int end,
                                             ISpanned dest,
                                             int dstart,
                                             int dend)
        {
            try
            {
                string val = dest.ToString().Insert(dstart,
                                                    source.ToString());
                int input = int.Parse(val);
                if (IsInRange(m_Min,
                              m_Max,
                              input))
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("FilterFormatted Error: " + ex.Message);
            }

            return(new String(string.Empty));
        }
 public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
 {
     if (System.Text.RegularExpressions.Regex.IsMatch(dest.ToString(), regex) || dest.ToString().Equals(""))
     {
         return new Java.Lang.String(source.ToString());
     }
     return new Java.Lang.String(string.Empty);
 }
 public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
 {
     if (!Regex.IsMatch(dest.ToString() + source.ToString(), @"^\d+(,|\.)?\d{0,3}?$"))
     {
         return(new String(string.Empty));
     }
     return(null);
 }
Ejemplo n.º 4
0
        public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
        {
            string val = dest.ToString().Insert(dstart, source.ToString());

            if (_regex.Match(val).Value.Equals(val))
            {
                return(source);
            }

            return(new Java.Lang.String(string.Empty));
        }
Ejemplo n.º 5
0
        public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart,
            int dend)
        {
            try
            {
                var val = dest.ToString().Insert(dstart, source.ToString());
                var input = int.Parse(val);
                if (IsInRange(_min, _max, input))
                    return null;
            }
            catch (Exception ex)
            {
            }

            return new String(string.Empty);
        }
 public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
 {
     try
     {
         int input = Int32.Parse(dest.ToString().Insert(dstart, source.ToString()));
         if (IsInRange(min, max, input))
         {
             return(null);
         }
     }
     catch (System.Exception)
     {
         // ignored
     }
     return(new Java.Lang.String(string.Empty));
 }
Ejemplo n.º 7
0
        public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest,
                                             int dstart, int dend)
        {
            string val = dest.ToString().Insert(dstart, source.ToString());

            if (!int.TryParse(val, out int input))
            {
                throw new System.Exception("Value is not a valid number");
            }

            if (InRange(input, min, max))
            {
                return(null);
            }

            return(new Java.Lang.String(string.Empty));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns a SpannableString containing interactive sources for subtitles.
        /// </summary>
        /// <param name="action">Action that should be started when the user interacts with the source.</param>
        /// <param name="textWithSubstitutes">The parsed text with substitutes</param>
        /// <param name="sources">The parsed sources</param>
        /// <returns>A SpannableString parsed from the textWithSubstitutes for the subtitles. Returns null, if the provided action is null.</returns>
        public SpannableString CreateSubtitlesText(IInteractiveSourceAction action, ISpanned textWithSubstitutes, List <Source> sources)
        {
            if (action == null)
            {
                return(null);
            }

            var sourcePositions = new Dictionary <Source, FinalSourcePosition>();

            // get the textpositions of each source and mark them
            foreach (var source in sources)
            {
                if (source == null)
                {
                    continue;
                }

                int startIndex = textWithSubstitutes.ToString().IndexOf(source.SubstituteText, StringComparison.Ordinal);
                sourcePositions.Add(source, new FinalSourcePosition
                {
                    Start = startIndex,
                    End   = startIndex + source.SubstituteText.Length
                });
            }

            var str = new SpannableString(textWithSubstitutes);

            foreach (var src in sourcePositions)
            {
                if (src.Key == null)
                {
                    continue;
                }

                str.SetSpan(
                    ConvertSrcToClickableSpan(src.Key, action),
                    src.Value.Start,
                    src.Value.End,
                    SpanTypes.ExclusiveExclusive);
            }

            return(str);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Converts HTML-formatted data to a string that contains the text content extracted from the HTML.
        /// </summary>
        /// <param name="html">A String containing HTML-formatted data.</param>
        /// <returns>A String of text content.</returns>
        public static string ConvertToText(string html)
        {
            // the platform implementations don't strip out unordered lists so we'll replace with bullet characters
            int i = 0;
            int i2;

            while (i > -1)
            {
                i = html.IndexOf("<li");
                if (i > -1)
                {
                    i2 = html.IndexOf(">", i);

                    if (i2 > -1)
                    {
                        html = html.Replace(html.Substring(i, (i2 - i) + 1), "<p>• ");
                    }
                }
            }

            i = 0;
            while (i > -1)
            {
                i = html.IndexOf("<ul");
                if (i > -1)
                {
                    i2 = html.IndexOf(">", i);

                    if (i2 > -1)
                    {
                        html = html.Replace(html.Substring(i, (i2 - i) + 1), "");
                    }
                }
            }

            i = 0;
            while (i > -1)
            {
                i = html.IndexOf("<img");
                if (i > -1)
                {
                    i2 = html.IndexOf(">", i);

                    if (i2 > -1)
                    {
                        html = html.Replace(html.Substring(i, (i2 - i) + 1), "");
                    }
                }
            }

            html = html.Replace("</ul>", "");
            html = html.Replace("</li>", "<p/>");

#if __ANDROID__
            ISpanned sp = Android.Text.Html.FromHtml(html, FromHtmlOptions.ModeLegacy);
            return(sp.ToString().Trim());
#elif __UNIFIED__
            byte[] data = global::System.Text.Encoding.UTF8.GetBytes(html);
            NSData d    = NSData.FromArray(data);
            NSAttributedStringDocumentAttributes importParams = new NSAttributedStringDocumentAttributes();
            importParams.DocumentType = NSDocumentType.HTML;
            NSError error = new NSError();
            error = null;
            NSDictionary dict = new NSDictionary();
#if __MAC__
            var attrString = new NSAttributedString(d, importParams, out dict, out error);
#else
            var attrString = new NSAttributedString(d, importParams, out dict, ref error);
#endif
            return(attrString.Value);
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
            return(Windows.Data.Html.HtmlUtilities.ConvertToText(html));
#elif WINDOWS_PHONE || WIN32
            return(global::System.Net.WebUtility.HtmlDecode(Regex.Replace(html, "<(.|\n)*?>", "")));
#else
            throw new global::System.PlatformNotSupportedException();
#endif
        }