protected ISpanned RemoveLastChar(ISpanned text) { var builder = new SpannableStringBuilder(text); builder.Delete(text.Length() - 1, text.Length()); return(builder); }
private void SetText(TextView control, string html) { var htmlLabel = (HtmlLabel)Element; // Set the type of content and the custom tag list handler using var listTagHandler = new ListTagHandler(htmlLabel.AndroidListIndent); // KWI-FIX: added AndroidListIndent parameter var imageGetter = new UrlImageParser(Control); FromHtmlOptions fromHtmlOptions = htmlLabel.AndroidLegacyMode ? FromHtmlOptions.ModeLegacy : FromHtmlOptions.ModeCompact; ISpanned sequence = Build.VERSION.SdkInt >= BuildVersionCodes.N ? Html.FromHtml(html, fromHtmlOptions, imageGetter, listTagHandler) : Html.FromHtml(html, imageGetter, listTagHandler); using var strBuilder = new SpannableStringBuilder(sequence); // Make clickable links if (!Element.GestureRecognizers.Any()) { control.MovementMethod = LinkMovementMethod.Instance; URLSpan[] urls = strBuilder .GetSpans(0, sequence.Length(), Class.FromType(typeof(URLSpan))) .Cast <URLSpan>() .ToArray(); foreach (URLSpan span in urls) { MakeLinkClickable(strBuilder, span); } } // Android adds an unnecessary "\n" that must be removed using ISpanned value = RemoveLastChar(strBuilder); // Finally sets the value of the TextView control.SetText(value, TextView.BufferType.Spannable); }
/// <summary> /// Gets the last instance of an Object /// </summary> /// <returns>Java.Lang.Object</returns> /// <param name="text">ISpanned</param> /// <param name="kind">Class</param> static Java.Lang.Object GetLast(ISpanned text, Class kind) { var length = text.Length(); var spans = text.GetSpans(0, length, kind); return(spans.Length > 0 ? spans.Last() : null); }
public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend) { string s_ = subString(source, start, end); string left_ = subString(dest, 0, dstart); string right_ = subString(dest, dend, dest.Length()); string full_ = left_ + s_ + right_; if (!HelperNumEdit.textValidate(full_, min, max)) { return(new Java.Lang.String(string.Empty)); } return(null); }
/// <summary> /// Gets the last instance of a given Spanned Object /// </summary> /// <returns>The instance of a Spanned Object</returns> /// <param name="text">The text contained within the span</param> /// <param name="kind">Object type</param> static Java.Lang.Object getLast(ISpanned text, Java.Lang.Class kind) { /* * This knows that the last returned object from getSpans() * will be the most recently added. */ Java.Lang.Object [] objs = text.GetSpans(0, text.Length(), kind); if (objs.Length == 0) { return(null); } else { return(objs [objs.Length - 1]); } }
public Java.Lang.ICharSequence FilterFormatted(Java.Lang.ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend) { string formatedSource = source.SubSequenceFormatted(start, end).ToString(); string destPrefix = dest.SubSequenceFormatted(0, dstart).ToString(); string destSuffix = dest.SubSequenceFormatted(dend, dest.Length()).ToString(); string result = destPrefix + formatedSource + destSuffix; Matcher matcher = mPattern.Matcher(result); if (!matcher.Matches()) { return(new Java.Lang.String(string.Empty)); } return(null); }
public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend) { var textToCheck = dest.SubSequence(0, dstart) + source.SubSequence(start, end) + dest.SubSequence(dend, dest.Length()); var matcher = pattern.Matcher(textToCheck); // Entered text does not match the pattern if (!matcher.Matches()) { // It does not match partially too if (!matcher.HitEnd()) { return(null); } } return(null); }
public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend) { if (_editor.Modified && end - start == 1 && start < source.Length() && dstart < dest.Length()) { char c = source.CharAt(start); if (c == '\n') { return(_editor.AutoIndent( source, dest, dstart, dend)); } } return(source); }
public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend) { if (maxLen > 0) { string s_ = subString(source, start, end); string left_ = subString(dest, 0, dstart); string right_ = subString(dest, dend, dest.Length()); string full_ = left_ + s_ + right_; if (full_.Length > maxLen) { int tail_ = full_.Length - maxLen; s_ = ToolString.left(s_, s_.Length - tail_); return(new Java.Lang.String(s_)); } } return(null); }
public override ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend) { // Borrowed heavily from the Android source ICharSequence filterFormatted = base.FilterFormatted(source, start, end, dest, dstart, dend); if (filterFormatted != null) { source = filterFormatted; start = 0; end = filterFormatted.Length(); } int sign = -1; int dec = -1; int dlen = dest.Length(); // Find out if the existing text has a sign or decimal point characters. for (var i = 0; i < dstart; i++) { char c = dest.CharAt(i); if (IsSignChar(c)) { sign = i; } else if (IsDecimalPointChar(c)) { dec = i; } } for (int i = dend; i < dlen; i++) { char c = dest.CharAt(i); if (IsSignChar(c)) { return(new String("")); // Nothing can be inserted in front of a sign character. } if (IsDecimalPointChar(c)) { dec = i; } } // If it does, we must strip them out from the source. // In addition, a sign character must be the very first character, // and nothing can be inserted before an existing sign character. // Go in reverse order so the offsets are stable. SpannableStringBuilder stripped = null; for (int i = end - 1; i >= start; i--) { char c = source.CharAt(i); var strip = false; if (IsSignChar(c)) { if (i != start || dstart != 0) { strip = true; } else if (sign >= 0) { strip = true; } else { sign = i; } } else if (IsDecimalPointChar(c)) { if (dec >= 0) { strip = true; } else { dec = i; } } if (strip) { if (end == start + 1) { return(new String("")); // Only one character, and it was stripped. } if (stripped == null) { stripped = new SpannableStringBuilder(source, start, end); } stripped.Delete(i - start, i + 1 - start); } } return(stripped ?? filterFormatted); }