Java Code Examples for android.text.Editable#clear()
The following examples show how to use
android.text.Editable#clear() .
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: EnterPhoneNumberActivity.java From Conversations with GNU General Public License v3.0 | 6 votes |
private void onNextClick(View v) { final AlertDialog.Builder builder = new AlertDialog.Builder(this); try { final Editable number = this.binding.number.getText(); final String input = number.toString(); final Phonenumber.PhoneNumber phoneNumber = PhoneNumberUtilWrapper.getInstance(this).parse(input, region); this.binding.countryCode.setText(String.valueOf(phoneNumber.getCountryCode())); number.clear(); number.append(String.valueOf(phoneNumber.getNationalNumber())); final String formattedPhoneNumber = PhoneNumberUtilWrapper.getInstance(this).format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL).replace(' ','\u202F'); if (PhoneNumberUtilWrapper.getInstance(this).isValidNumber(phoneNumber)) { builder.setMessage(Html.fromHtml(getString(R.string.we_will_be_verifying, formattedPhoneNumber))); builder.setNegativeButton(R.string.edit, null); builder.setPositiveButton(R.string.ok, (dialog, which) -> onPhoneNumberEntered(phoneNumber)); } else { builder.setMessage(getString(R.string.not_a_valid_phone_number, formattedPhoneNumber)); builder.setPositiveButton(R.string.ok, null); } Log.d(Config.LOGTAG, phoneNumber.toString()); } catch (NumberParseException e) { builder.setMessage(R.string.please_enter_your_phone_number); builder.setPositiveButton(R.string.ok, null); } builder.create().show(); }
Example 2
Source File: DialerFilter.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Clears both the digits and the filter text. */ public void clearText() { Editable text; text = mLetters.getText(); text.clear(); text = mDigits.getText(); text.clear(); // Reset the mode based on the hardware type if (mIsQwerty) { setMode(DIGITS_AND_LETTERS); } else { setMode(DIGITS_ONLY); } }
Example 3
Source File: SafeHelperFactory.java From cwac-saferoom with Apache License 2.0 | 6 votes |
/** * Creates a SafeHelperFactory from an Editable, such as what you get by * calling getText() on an EditText. * * The Editable will be cleared as part of this call. * * @param editor the user's supplied passphrase * @param options options for pre-key, post-key SQL * @return a SafeHelperFactory */ public static SafeHelperFactory fromUser(Editable editor, Options options) { char[] passphrase=new char[editor.length()]; SafeHelperFactory result; editor.getChars(0, editor.length(), passphrase, 0); try { result=new SafeHelperFactory(passphrase, options); } finally { editor.clear(); } return(result); }
Example 4
Source File: MainActivity.java From Autocomplete with Apache License 2.0 | 6 votes |
private void setupUserAutocomplete() { EditText edit = findViewById(R.id.single); float elevation = 6f; Drawable backgroundDrawable = new ColorDrawable(Color.WHITE); AutocompletePresenter<User> presenter = new UserPresenter(this); AutocompleteCallback<User> callback = new AutocompleteCallback<User>() { @Override public boolean onPopupItemClicked(@NonNull Editable editable, @NonNull User item) { editable.clear(); editable.append(item.getFullname()); return true; } public void onPopupVisibilityChanged(boolean shown) {} }; userAutocomplete = Autocomplete.<User>on(edit) .with(elevation) .with(backgroundDrawable) .with(presenter) .with(callback) .build(); }
Example 5
Source File: BaseThreadAndArticleAdapter.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
public void setColoredAdContent(TextView contentText, final ForumAdJson forumAd) { String subject = StringUtils.get(forumAd.getContent()); Editable editable = contentText.getEditableText(); if (editable != null) { editable.clear(); editable.clearSpans(); } final String recomName = forumAd.getRecomName(); SpannableStringBuilder ssb = new SpannableStringBuilder(subject + recomName); Drawable bg = context.getResources().getDrawable(R.drawable.bg_recom); ImageSpan imageSpan = new ImageSpan(bg) { @Override public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { paint.setTypeface(Typeface.DEFAULT); int textSize = DensityUtils.dip2px(context, 12); paint.setTextSize(textSize); Rect bounds = new Rect(); paint.getTextBounds(text.toString(), start, end, bounds); getDrawable().setBounds(0, 0, bounds.width() + 10, bottom - top); super.draw(canvas, text, start, end, x, top, y, bottom, paint); paint.setColor(Color.TRANSPARENT); canvas.drawText(text.subSequence(start, end).toString(), x + 5, y, paint); } }; ssb.setSpan(imageSpan, subject.length(), subject.length() + recomName.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); contentText.setText(ssb); }
Example 6
Source File: CurrencyAmountView.java From bither-android with Apache License 2.0 | 5 votes |
@Override public void afterTextChanged(final Editable s) { // workaround for German keyboards final String original = s.toString(); final String replaced = original.replace(',', '.'); if (!replaced.equals(original)) { s.clear(); s.append(replaced); } WalletUtils.formatSignificant(s, smallerInsignificant ? WalletUtils.SMALLER_SPAN : null); }
Example 7
Source File: MarketListHeader.java From bither-android with Apache License 2.0 | 5 votes |
@Override public void afterTextChanged(final Editable s) { // workaround for German keyboards final String original = s.toString(); final String replaced = original.replace(',', '.'); if (!replaced.equals(original)) { s.clear(); s.append(replaced); } if (s.length() > 0) { WalletUtils.formatSignificant(s, true ? WalletUtils.SMALLER_SPAN : null); } }
Example 8
Source File: PinEntryWrapper.java From Conversations with GNU General Public License v3.0 | 5 votes |
public void setPin(String pin) { char[] chars = pin.toCharArray(); for (int i = 0; i < digits.size(); ++i) { if (i < chars.length) { final Editable editable = digits.get(i).getText(); editable.clear(); editable.append(Character.isDigit(chars[i]) ? String.valueOf(chars[i]) : ""); } } }
Example 9
Source File: ColorChooser.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
@Override public void afterTextChanged(Editable editable) { if (isRunning || isRemoving) return; isRunning = true; String text = editable.toString(); // should consist of [#][0-9][a-f] for (int j=text.length()-1; j>=0; j--) { if (!inputSet.contains(text.charAt(j))) { editable.delete(j, j+1); } } text = editable.toString(); // should start with a # int i = text.indexOf('#'); if (i != -1) { editable.delete(i, i + 1); } editable.insert(0, "#"); if (editable.length() > 8) // should be no longer than 8 { editable.delete(9, editable.length()); } text = editable.toString(); String toCaps = text.toUpperCase(Locale.US); editable.clear(); editable.append(toCaps); isRunning = false; }
Example 10
Source File: Database.java From kripton with Apache License 2.0 | 5 votes |
/** * Changes the passphrase associated with this database. The supplied * Editable is cleared as part of this operation. * * @param editor * source of passphrase, presumably from a user */ public void rekey(Editable editor) { char[] passphrase = new char[editor.length()]; editor.getChars(0, editor.length(), passphrase, 0); try { rekey(passphrase); } finally { editor.clear(); } }
Example 11
Source File: RecurrenceOptionCreator.java From SublimePicker with Apache License 2.0 | 5 votes |
@Override public void afterTextChanged(Editable s) { boolean updated = false; int value; try { value = Integer.parseInt(s.toString()); } catch (NumberFormatException e) { value = mDefault; } if (value < mMin) { value = mMin; updated = true; } else if (value > mMax) { updated = true; value = mMax; } // Update UI if (updated) { s.clear(); s.append(Integer.toString(value)); } updateDoneButtonState(); onChange(value); }
Example 12
Source File: ChipsView.java From android-material-chips with Apache License 2.0 | 5 votes |
@Override public void afterTextChanged(Editable s) { if (mIsPasteTextChange) { mIsPasteTextChange = false; // todo handle copy/paste text here } else { // no paste text change if (s.toString().contains("\n")) { String text = s.toString(); text = text.replace("\n", ""); while (text.contains(" ")) { text = text.replace(" ", " "); } if (text.length() > 1) { s.clear(); if (!onEnterPressed(text)) { s.append(text); } } else { s.clear(); s.append(text); } } } if (mChipsListener != null) { mChipsListener.onTextChanged(s); } }
Example 13
Source File: BaseInputConnection.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void sendCurrentText() { if (!mDummyMode) { return; } Editable content = getEditable(); if (content != null) { final int N = content.length(); if (N == 0) { return; } if (N == 1) { // If it's 1 character, we have a chance of being // able to generate normal key events... if (mKeyCharacterMap == null) { mKeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); } char[] chars = new char[1]; content.getChars(0, 1, chars, 0); KeyEvent[] events = mKeyCharacterMap.getEvents(chars); if (events != null) { for (int i=0; i<events.length; i++) { if (DEBUG) Log.v(TAG, "Sending: " + events[i]); sendKeyEvent(events[i]); } content.clear(); return; } } // Otherwise, revert to the special key event containing // the actual characters. KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(), content.toString(), KeyCharacterMap.VIRTUAL_KEYBOARD, 0); sendKeyEvent(event); content.clear(); } }
Example 14
Source File: FormattedEditText.java From FormatEditText with MIT License | 5 votes |
private void clearTextInTouch(MotionEvent event) { event.setAction(MotionEvent.ACTION_CANCEL); Editable editable = getText(); if (editable != null) { editable.clear(); } }
Example 15
Source File: MainActivity.java From Autocomplete with Apache License 2.0 | 5 votes |
private void setupMaleFemaleAutocomplete() { EditText edit = findViewById(R.id.topbar); float elevation = 6f; Drawable backgroundDrawable = new ColorDrawable(Color.WHITE); AutocompletePresenter<User> presenter = new MaleFemalePresenter(this); AutocompleteCallback<User> callback = new AutocompleteCallback<User>() { @Override public boolean onPopupItemClicked(@NonNull Editable editable, @NonNull User item) { editable.clear(); editable.append(item.getFullname()) .append(" ") .append(item.isFemale() ? "(Female)" : "(Male)"); editable.setSpan(new StyleSpan(Typeface.BOLD), 0, item.getFullname().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return true; } public void onPopupVisibilityChanged(boolean shown) {} }; maleFemaleAutocomplete = Autocomplete.<User>on(edit) .with(elevation) .with(backgroundDrawable) .with(presenter) .with(callback) .build(); }
Example 16
Source File: EditSB.java From edslite with GNU General Public License v2.0 | 5 votes |
@Override public void setText(CharSequence text, BufferType type) { Editable et = getEditableText(); if(et != null) et.clear(); super.setText(text, type); }
Example 17
Source File: Database.java From cwac-saferoom with Apache License 2.0 | 5 votes |
/** * Changes the passphrase associated with this database. The supplied * Editable is cleared as part of this operation. * * @param editor source of passphrase, presumably from a user */ public void rekey(Editable editor) { char[] passphrase=new char[editor.length()]; editor.getChars(0, editor.length(), passphrase, 0); try { rekey(passphrase); } finally { editor.clear(); } }
Example 18
Source File: TextKeyListener.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Clear all the input state (autotext, autocap, multitap, undo) * from the specified Editable, going beyond Editable.clear(), which * just clears the text but not the input state. * * @param e the buffer whose text and state are to be cleared. */ public static void clear(Editable e) { e.clear(); e.removeSpan(ACTIVE); e.removeSpan(CAPPED); e.removeSpan(INHIBIT_REPLACEMENT); e.removeSpan(LAST_TYPED); QwertyKeyListener.Replaced[] repl = e.getSpans(0, e.length(), QwertyKeyListener.Replaced.class); final int count = repl.length; for (int i = 0; i < count; i++) { e.removeSpan(repl[i]); } }
Example 19
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 20
Source File: KeyboardTextWatcher.java From BluetoothHidEmu with Apache License 2.0 | 3 votes |
@Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_START_COUNT: Editable content = (Editable) msg.obj; content.clear(); break; } }