Java Code Examples for android.text.Editable#getFilters()
The following examples show how to use
android.text.Editable#getFilters() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditMessage.java From Pix-Art-Messenger with GNU General Public License v3.0 | 6 votes |
@Override public boolean onTextContextMenuItem(int id) { if (id == android.R.id.paste) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return super.onTextContextMenuItem(android.R.id.pasteAsPlainText); } else { Editable editable = getEditableText(); InputFilter[] filters = editable.getFilters(); InputFilter[] tempFilters = new InputFilter[filters != null ? filters.length + 1 : 1]; if (filters != null) { System.arraycopy(filters, 0, tempFilters, 1, filters.length); } tempFilters[0] = SPAN_FILTER; editable.setFilters(tempFilters); try { return super.onTextContextMenuItem(id); } finally { editable.setFilters(filters); } } } else { return super.onTextContextMenuItem(id); } }
Example 2
Source File: ValorMonetarioWatcher.java From canarinho with Apache License 2.0 | 6 votes |
private void atualizaTexto(Editable editable, String valor) { mudancaInterna = true; final InputFilter[] oldFilters = editable.getFilters(); editable.setFilters(new InputFilter[] {}); editable.replace(0, editable.length(), valor); editable.setFilters(oldFilters); if (valor.equals(editable.toString())) { // TODO: estudar implantar a manutenção da posição do cursor Selection.setSelection(editable, valor.length()); } mudancaInterna = false; }
Example 3
Source File: SafePasteEditText.java From Dashchan with Apache License 2.0 | 6 votes |
@Override public boolean onTextContextMenuItem(int id) { if (id == android.R.id.paste) { Editable editable = getEditableText(); InputFilter[] filters = editable.getFilters(); InputFilter[] tempFilters = new InputFilter[filters != null ? filters.length + 1 : 1]; if (filters != null) { System.arraycopy(filters, 0, tempFilters, 1, filters.length); } tempFilters[0] = SPAN_FILTER; editable.setFilters(tempFilters); try { return super.onTextContextMenuItem(id); } finally { editable.setFilters(filters); } } else { return super.onTextContextMenuItem(id); } }
Example 4
Source File: EditMessage.java From Conversations with GNU General Public License v3.0 | 6 votes |
@Override public boolean onTextContextMenuItem(int id) { if (id == android.R.id.paste) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return super.onTextContextMenuItem(android.R.id.pasteAsPlainText); } else { Editable editable = getEditableText(); InputFilter[] filters = editable.getFilters(); InputFilter[] tempFilters = new InputFilter[filters != null ? filters.length + 1 : 1]; if (filters != null) { System.arraycopy(filters, 0, tempFilters, 1, filters.length); } tempFilters[0] = SPAN_FILTER; editable.setFilters(tempFilters); try { return super.onTextContextMenuItem(id); } finally { editable.setFilters(filters); } } } else { return super.onTextContextMenuItem(id); } }
Example 5
Source File: ViewUtils.java From PaymentKit-Droid with Apache License 2.0 | 5 votes |
public static void replaceAllText(Editable editable, CharSequence newString) { InputFilter[] filters = editable.getFilters(); editable.setFilters(new InputFilter[] { }); // We need to remove filters so we can add text with spaces. editable.replace(0, editable.length(), newString); editable.setFilters(filters); }
Example 6
Source File: FormattedEditText.java From FormatEditText with MIT License | 4 votes |
private void formatTextWhenDelete(final Editable editable, int start, int before) { mIsFormatted = true; final boolean filter = mFilterRestoreTextChangeEvent; super.removeTextChangedListener(mTextWatcher); InputFilter[] filters = editable.getFilters(); editable.setFilters(EMPTY_FILTERS); int selectionStart, selectionEnd; if (!filter) { selectionStart = Selection.getSelectionStart(editable); selectionEnd = Selection.getSelectionEnd(editable); editable.setSpan(SELECTION_SPAN, selectionStart, selectionEnd, Spanned.SPAN_MARK_MARK); } if (mMode < MODE_MASK) { final boolean deletedLast = start >= editable.length(); if (!deletedLast) { formatDefined(editable, start, true); } else { for (int i = start; i > 0; i--) { final char sub = editable.charAt(i - 1); final char place = findPlaceholder(i - 1); if (sub == place) { editable.delete(i - 1, i); } else { break; } } } } else { formatMask(editable, start, true); } if (!filter) { selectionStart = editable.getSpanStart(SELECTION_SPAN); selectionEnd = editable.getSpanEnd(SELECTION_SPAN); editable.removeSpan(SELECTION_SPAN); editable.setFilters(filters); Editable text = getText(); Selection.setSelection(text, selectionStart, selectionEnd); } else { setFilters(filters); } mIsFormatted = false; super.addTextChangedListener(mTextWatcher); }
Example 7
Source File: FormattedEditText.java From FormatEditText with MIT License | 4 votes |
private void formatTextWhenAppend(final Editable editable, int start, int before, int count) { mIsFormatted = true; final boolean filter = mFilterRestoreTextChangeEvent; super.removeTextChangedListener(mTextWatcher); InputFilter[] filters = editable.getFilters(); editable.setFilters(EMPTY_FILTERS); int selectionStart, selectionEnd; if (!filter) { selectionStart = Selection.getSelectionStart(editable); selectionEnd = Selection.getSelectionEnd(editable); editable.setSpan(SELECTION_SPAN, selectionStart, selectionEnd, Spanned.SPAN_MARK_MARK); } if (mMode < MODE_MASK) { boolean appendedLast = start > mHolders[mHolders.length - 1].index; if (!appendedLast) { formatDefined(editable, start, false); } } else { formatMask(editable, start, false); } if (!filter) { selectionStart = editable.getSpanStart(SELECTION_SPAN); selectionEnd = editable.getSpanEnd(SELECTION_SPAN); editable.removeSpan(SELECTION_SPAN); editable.setFilters(filters); if (mLengthFilterDelegate != null) { CharSequence out = mLengthFilterDelegate.mFilter.filter( editable, 0, editable.length(), EMPTY_SPANNED, 0, 0); if (out != null) { editable.delete(out.length(), editable.length()); } } Selection.setSelection( editable, Math.min(selectionStart, editable.length()), Math.min(selectionEnd, editable.length())); } else { editable.setFilters(filters); } mIsFormatted = false; super.addTextChangedListener(mTextWatcher); }
Example 8
Source File: SolveTimeNumberTextWatcher.java From TwistyTimer with GNU General Public License v3.0 | 4 votes |
@Override public void afterTextChanged(Editable s) { if (isFormatting) return; isFormatting = true; // Since the keyboard input type is "number", we can't punctuation with the actual // filters, so we clear them and restore once we finish formatting InputFilter[] filters = s.getFilters(); // save filters s.setFilters(new InputFilter[] {}); // clear filters // Clear all formatting from editable // Regex matches the characters ':', '.', 'h' and a leading zero, if present mUnformatted = s.toString().replaceAll("^0+|[h]|:|\\.", ""); mLen = mUnformatted.length(); s.clear(); s.insert(0, mUnformatted); if (mLen <= 2 && mLen > 0) { // 12 -> 0.12 s.insert(0, "0."); } else if (mLen == 3) { // 123 -> 1.23 s.insert(1, "."); } else if (mLen == 4) { // 1234 -> 12.34 s.insert(2, "."); } else if (mLen == 5) { // 12345 -> 1:23.45 s.insert(1, ":"); s.insert(4, "."); } else if (mLen == 6) { // 123456 -> 12:34.56 s.insert(2, ":"); s.insert(5, "."); } else if (mLen == 7) { // 1234567 -> 1:23:45.67 s.insert(1, "h"); s.insert(4, ":"); s.insert(7, "."); } else if (mLen == 8) { // 12345678 -> 12:34:56.78 s.insert(2, "h"); s.insert(5, ":"); s.insert(8, "."); } isFormatting = false; // Restore filters s.setFilters(filters); }
Example 9
Source File: MaskedEditText.java From FormattEditText with Apache License 2.0 | 4 votes |
private void formatMask(@NonNull Editable value) { InputFilter[] inputFilters = value.getFilters(); value.setFilters(new InputFilter[0]); int indexInMask = 0; int indexInText = 0; int maskLength = 0; int inputLength = 0; boolean treatNextCharAsLiteral = false; boolean maskIsNotNumeric = false; Object selection = new Object(); value.setSpan(selection, Selection.getSelectionStart(value), Selection.getSelectionEnd(value), Spanned.SPAN_MARK_MARK); while (indexInMask < mask.length()) { char charInMask = mask.charAt(indexInMask); if (!treatNextCharAsLiteral && isMaskChar(charInMask)) { // Found mask character, try to parse text maskIsNotNumeric |= charInMask != NUMBER_MASK; if (indexInText >= value.length()) { // Add trailing placeholders value.insert(indexInText, placeholder); value.setSpan(new PlaceholderSpan(), indexInText, indexInText + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ++indexInText; ++inputLength; ++maskLength; ++indexInMask; } else if (!matchMask(charInMask, value.charAt(indexInText))) { // Skip bad character in text value.delete(indexInText, indexInText + 1); } else { // Character in text is acceptable, go to next character in mask ++indexInText; ++inputLength; ++maskLength; ++indexInMask; } } else if (!treatNextCharAsLiteral && charInMask == ESCAPE_CHAR) { // Next character in mask must be escaped treatNextCharAsLiteral = true; ++indexInMask; } else { // Found a literal or escaped character in mask value.insert(indexInText, String.valueOf(charInMask)); value.setSpan(new LiteralSpan(), indexInText, indexInText + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); treatNextCharAsLiteral = false; ++indexInText; ++maskLength; ++indexInMask; } } while (value.length() > maskLength) { int pos = value.length() - 1; value.delete(pos, pos + 1); } Selection.setSelection(value, value.getSpanStart(selection), value.getSpanEnd(selection)); value.removeSpan(selection); value.setFilters(inputFilters); int newInputType = inputLength > 0 ? (maskIsNotNumeric ? InputType.TYPE_CLASS_TEXT : InputType.TYPE_CLASS_NUMBER) : 0; if (getInputType() != newInputType) setInputType(newInputType); }