public override Java.Lang.ICharSequence FilterFormatted(Java.Lang.ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend) { for (var x = start; x < end; x++) { if (char.IsUpper(source.ElementAt(x))) { var v = new char[end - start]; TextUtils.GetChars(source.ToString(), start, end, v, 0); var s = new string(v).ToLower(CultureInfo.InvariantCulture); if (source is ISpanned sourceSpanned) { var sp = new SpannableString(s); TextUtils.CopySpansFrom(sourceSpanned, start, end, null, sp, 0); return(sp); } else { return(new Java.Lang.String(s)); } } } return(null); }
public override IEditable Replace(int start, int end, ICharSequence tb, int tbstart, int tbend) { // Create a copy of this string builder to preview the change, allowing the TextBox's event handlers to act on the modified text. var copy = new SpannableStringBuilder(this); copy.Replace(start, end, tb, tbstart, tbend); var previewText = copy.ToString(); var finalText = Owner.ProcessTextInput(previewText); if (Owner._wasLastEditModified = previewText != finalText) { // Text was modified. Use new text as the replacement string, re-applying spans to ensure EditText's and keyboard's internals aren't disrupted. ICharSequence replacement; if (tb is ISpanned spanned) { var spannable = new SpannableString(finalText); TextUtils.CopySpansFrom(spanned, tbstart, Min(tbend, spannable.Length()), null, spannable, 0); replacement = spannable; } else { replacement = new Java.Lang.String(finalText); } base.Replace(0, Length(), replacement, 0, finalText.Length); } else { // Text was not modified, use original replacement ICharSequence base.Replace(start, end, tb, tbstart, tbend); } return(this); }
public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend) { if (source != null && source.Length() > 0) { var includesInvalidCharacter = false; var destLength = dend - dstart + 1; var adjustStart = source.Length() - destLength; var sb = new StringBuilder(end - start); for (var i = start; i < end; i++) { var c = source.CharAt(i); if (IsCharAllowed(c)) { if (i >= adjustStart) { sb.Append(source, i, i + 1); } } else { includesInvalidCharacter = true; } } if (!includesInvalidCharacter) { return(null); } if (source is ISpanned spanned) { var sp = new SpannableString(sb); TextUtils.CopySpansFrom(spanned, start, sb.Length(), null, sp, 0); return(sp); } return(sb); } return(null); }