@Override protected void onFinishInflate() { super.onFinishInflate(); ButterKnife.bind(this); titleView.setOnFocusChangeListener((v, hasFocus) -> { if (!hasFocus) { titleView.setError(Strings.isBlank(titleView.getText()) ? "Cannot be empty." : null); } }); titleView.addTextChangedListener(new EmptyTextWatcher() { @Override public void afterTextChanged(Editable s) { if (listener != null) { listener.onStateChanged(!Strings.isBlank(s)); } } }); screenshotView.setChecked(true); logsView.setChecked(true); }
@Override public void onClickSendButton(Editable str) { if (!TDevice.hasInternet()) { AppContext.showToastShort(R.string.tip_network_error); return; } if (!AccountHelper.isLogin()) { UIHelper.showLoginActivity(getActivity()); return; } if (TextUtils.isEmpty(str)) { AppContext.showToastShort(R.string.tip_comment_content_empty); return; } handleComment(str.toString()); }
@Override public void afterTextChanged(Editable s) { int selection = mTextInput.getSelectionEnd(); if (s != null && s.toString().contains(".")) { mTextInput.setText(s.toString().replace('.', ',')); mTextInput.setSelection(selection); } if (mSpecimen != null && mSpeciesId != Utils.MOOSE_ID && mSpeciesId != Utils.FALLOW_DEER_ID && mSpeciesId != Utils.WHITE_TAILED_DEER && mSpeciesId != Utils.WILD_FOREST_DEER) { mSpecimen.setWeight(getWeight()); refreshWeightRequiredIndicator(); if (mCallback != null) { mCallback.onSpecimenChanged(); } } }
@Override public void afterTextChanged(Editable s) { if (s != null && s.length() == 1) { if (index < 7) {// 焦点后移 Log.d("gaolei", "index------------------" + index); if (index < 6) { EditText editText = getEditTextFromIndex(index); editText.clearFocus(); getEditTextFromIndex(index + 1).requestFocusFromTouch(); } currentEditIndex = index; } else { // TODO 判断 // handler.sendEmptyMessage(1); } } else { // 清除 对应 标识位 } }
@Test public void testInvalidPassword() throws Resources.NotFoundException { Editable mockEditable = mock(Editable.class); int color = 50; String text = "message"; when(mockEditable.toString()).thenReturn("invalidpassword"); when(mUserAdapter.checkValidPassword("invalidpassword")) .thenReturn(false); when(mResources.getColor(R.color.red)).thenReturn(color); when(mContext.getString(R.string.invalid_password)).thenReturn(text); mPasswordTextWatcher.afterTextChanged(mockEditable); verify(mIcon).setImageResource(R.drawable.ic_cancel); verify(mText).setText(text); verify(mText).setTextColor(color); }
@Override public void afterTextChanged(Editable s) { if (countryFormatter == null) return; if (TextUtils.isEmpty(s)) return; countryFormatter.clear(); String number = s.toString().replaceAll("[^\\d.]", ""); String formattedNumber = null; for (int i=0;i<number.length();i++) { formattedNumber = countryFormatter.inputDigit(number.charAt(i)); } if (formattedNumber != null && !s.toString().equals(formattedNumber)) { s.replace(0, s.length(), formattedNumber); } }
/** * 文本变化处理 */ private void onTextChange(Editable s) { text = s.toString(); fillText(); if(onInputChangeListener != null) { if(s.length() == maxLength) { onInputChangeListener.onFinished(this, text); } onInputChangeListener.onTextChanged(text.length() == maxLength, text); } }
/** * 删除最后一个字符,用来当@的人, 已经存在时,调用 */ public void deleteLast(int position) { Editable text = getText(); if (text != null && text.length() >= position) { text.delete(position - 1, position); } }
private void startImg(Editable text, Attributes attributes, HtmlCompat.ImageGetter img) { String src = attributes.getValue("", "src"); Drawable d = null; if (img != null) { d = img.getDrawable(src, attributes); } if (d == null) { Resources res = mContext.getResources(); d = res.getDrawable(R.drawable.unknown_image); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } int len = text.length(); text.append("\uFFFC"); text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
private void setupUserAutocomplete() { EditText edit = (EditText) 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(Editable editable, 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(); }
@Override public void afterTextChanged(Editable s) { if (Utils.doLog()) Log.d(CLASSNAME, "afterTextChanged() >>> delayTimeSubmission = " + getDelayTimeSubmission()); if (TextUtils.isEmpty(mTextSearch.getText())) { if (!isClosable()) mButtonClear.setVisibility(GONE); } else mButtonClear.setVisibility(VISIBLE); if (getDelayTimeSubmission() > 0) mAutoSubmissionHandler.postDelayed(mAutoSubmissionRunnable, getDelayTimeSubmission()); }
@Override public void onClick(Fragment currentFragment, final RongExtension extension) { String[] permissions = {Manifest.permission.RECORD_AUDIO}; if (!PermissionCheckUtil.requestPermissions(currentFragment, permissions)) { return; } Recognizer recognizerView = new Recognizer(extension.getContext()); recognizerView.setResultCallBack(new IRecognizedResult() { @Override public void onResult(String data) { Editable editable = extension.getInputEditText().getText(); String str = editable.toString() + data; extension.getInputEditText().setText(str); extension.getInputEditText().setSelection(str.length()); } @Override public void onClearClick() { extension.getInputEditText().setText(""); } }); extension.addPluginPager(recognizerView); recognizerView.startRecognize(); }
private boolean enoughToFilter() { Editable s = getText(); int end = getSelectionEnd(); if (end < 0) return false; int start = findTokenStart(); boolean hasAt = s.length() > start && s.charAt(start) == '@'; updateCompletingCommandFlags(); return (mDoThresholdSuggestions && end - start >= THRESHOLD && (mDoAtSuggestions || !hasAt)) || (mDoAtSuggestions && hasAt) || (mDoChannelSuggestions && mChannelTypes != null && s.length() > start && mChannelTypes.contains(s.charAt(start))) || isCommandNameToken() || updateCompletingCommandFlags(); }
final char[] getCharArray(boolean clear) { Editable editable = super.getText(); char[] chars = new char[editable.length()]; editable.getChars(0, chars.length, chars, 0); if (clear) editable.clear(); return chars; }
@Override public void afterTextChanged(final Editable s) { mQuery = s.toString(); if (mQuery.isEmpty()) { mSearchAlgorithm.cancel(true); mCb.clearSearchResult(); } else { mSearchAlgorithm.cancel(false); mSearchAlgorithm.doSearch(mQuery, mCb); } }
@Override protected Editable run(final HighlightingEditor editor, final Editable editable) { try { clearSpans(editable); } catch (Exception ex) { // Ignoring errors } return editable; }
@Override public void backspace() { final int selectionHandle = getSelectionStart(); final Editable editable = getText(); if (selectionHandle > 0) { MathSpannable[] spans = editable.getSpans(selectionHandle, selectionHandle, MathSpannable.class); if (spans.length != 0) { String text = editable.toString(); String textBeforeInsertionHandle = text.substring(0, selectionHandle); String textAfterInsertionHandle = text.substring(selectionHandle, text.length()); int deletionLength = -1; if (selectionHandle == editable.getSpanEnd(spans[0]) && spans[0].removeOnBackspace()) { deletionLength = spans[0].getEquation().length(); } else if (selectionHandle != editable.getSpanStart(spans[0])) { deletionLength = spans[0].backspace(); } if (deletionLength != -1) { String newText = textBeforeInsertionHandle.substring(0, textBeforeInsertionHandle.length() - deletionLength) + textAfterInsertionHandle; setText(newText); setSelection(selectionHandle - deletionLength); return; } } } super.backspace(); }
private void findClose(char open, int selEnd) { Log.d(TAG, "findClose() called with: open = [" + open + "], selEnd = [" + selEnd + "]"); Editable text = editText.getText(); int cursor = selEnd + 1; int count = 1; char close = getClose(open); boolean find = false; while (cursor < text.length()) { char chatAtCursor = text.charAt(cursor); if (chatAtCursor == open) { count++; } else if (chatAtCursor == close) { count--; } if (count == 0) { find = true; break; } cursor++; } BracketSpan[] spans = text.getSpans(0, text.length(), BracketSpan.class); for (BracketSpan span : spans) { text.removeSpan(span); } text.setSpan(new BracketSpan(codeTheme.getBracketColor(), codeTheme.getTextColor()), selEnd, selEnd + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (find) { text.setSpan(new BracketSpan(codeTheme.getBracketColor(), codeTheme.getTextColor()), cursor, cursor + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } }
private void insertIntoEditText(SpannableString ss) //插入图片 { Editable et = edit_content.getText();// 先获取Edittext中的内容 int start = edit_content.getSelectionStart(); et.insert(start, ss);// 设置ss要添加的位置 edit_content.setText(et);// 把et添加到Edittext中 edit_content.setSelection(start + ss.length());// 设置Edittext中光标在最后面显示 }
@Override public void afterTextChanged(Editable s) { if (textViewTitle.getText().toString().trim().equals("")) { btnSave.setEnabled(false); }else{ btnSave.setEnabled(true); } }
@Override public void afterTextChanged(Editable s) { if(Integer.parseInt(txScore.getText().toString().trim().equals("") ? "0" : txScore.getText().toString().trim()) <= totalItem) { btnSave.setEnabled(true); }else btnSave.setEnabled(false); }
private static boolean sameTextForSpan( final Editable oldText, final SpannableStringBuilder newText, final int start, final int end) { if (start > newText.length() || end > newText.length()) { return false; } for (int charIdx = start; charIdx < end; charIdx++) { if (oldText.charAt(charIdx) != newText.charAt(charIdx)) { return false; } } return true; }
@Override public boolean onMentionKeyArrived(RichEditText editText) { Editable msg = editText.getText(); String msgStr = msg.toString(); if (TextUtils.isEmpty(msgStr)) return false; int selStartIndex = editText.getSelectionStart(); if (TextUtils.isEmpty(msgStr.trim()) || selStartIndex <= 0 || TextUtils.isEmpty(msgStr.substring(selStartIndex - 1, selStartIndex).trim())) { skipMention(editText); } return true; }
@Override public void afterTextChanged(Editable s) { if ( s != null) { int start = mEdit.getSelectionStart(); int end = mEdit.getSelectionEnd(); mEdit.removeTextChangedListener(this); mEdit.setText(AndroidEmoji.ensure(s.toString())); mEdit.addTextChangedListener(this); mEdit.setSelection(start, end); } }
@Override public void afterTextChanged(Editable s) { calculateCharactersRemaining(); if (composeText.getText().length() == 0 || beforeLength == 0) { composeText.postDelayed(new Runnable() { @Override public void run() { updateToggleButtonState(); } }, 50); } }
@Override public void onBackSpacePressed() { Editable editable = etAmount.getEditText().getText(); int length = editable.length(); if (length > 0) { editable.delete(length - 1, length); } }
@Override public void onTextInsert(CharSequence text) { int start = editText.getSelectionStart(); Editable editable = editText.getEditableText(); editable.insert(start, text); setModeKeyboard(); }
@Override public void afterTextChanged(Editable s) { if(s.length()>0) { EmojiHandler.getInstance().handleEmojis(context, s, mEmojiconSize, mEmojiconAlignment, mEmojiconTextSize, start, count, mUseSystemDefault); } }
private void initViewsOptions(Context context) { setOnClickListener(this); setFocusable(true); setFocusableInTouchMode(true); setOnFocusChangeListener(this); inputmethodmanager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); editable = Editable.Factory.getInstance().newEditable(""); editable.setSpan(textWatcher, 0, editable.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); Selection.setSelection(editable, 0); editCodeInputConnection = new EditCodeInputConnection(this, true, codeLength); }
/** * Emphasize the TLD and second domain of the URL. */ public void emphasizeUrl() { Editable url = getText(); if (OmniboxUrlEmphasizer.hasEmphasisSpans(url) || hasFocus()) { return; } if (url.length() < 1) { return; } // We retrieve the domain and registry from the full URL (the url bar shows a simplified // version of the URL). Tab currentTab = mUrlBarDelegate.getCurrentTab(); if (currentTab == null || currentTab.getProfile() == null) return; boolean isInternalPage = false; try { String tabUrl = currentTab.getUrl(); isInternalPage = UrlUtilities.isInternalScheme(new URI(tabUrl)); } catch (URISyntaxException e) { // Ignore as this only is for applying color } OmniboxUrlEmphasizer.emphasizeUrl(url, getResources(), currentTab.getProfile(), currentTab.getSecurityLevel(), isInternalPage, mUseDarkColors, mUrlBarDelegate.shouldEmphasizeHttpsScheme()); }
private static int insertAtEnd(EditTextSelectionState selectionState, CharSequence textToInsert) { Editable editableText = selectionState.getEditText().getEditableText(); int insertPos = editableText.length(); editableText.append(textToInsert); return insertPos; }
@Override public void onClickSendButton(Editable str) { if (TextUtils.isEmpty(str)) { AppContext.showToast("请先输入评论内容..."); return; } if (!AccountHelper.isLogin()) { UIHelper.showLoginActivity(getActivity()); return; } int uid = (int) AccountHelper.getUserId(); OSChinaTeamApi.pubTeamDiscussReply(uid, mTeamId, mDiscussId, str.toString(), mReplyHandler); }
private void update(Editable messageText) { int messageLength = messageText.length(); // is there unicode character in the message? boolean unicode = false; for (int i = 0; i < messageLength; i++) { char c = messageText.charAt(i); if (Character.UnicodeBlock.of(c) != Character.UnicodeBlock.BASIC_LATIN) { unicode = true; break; } } // get max length of sms part depending on encoding and full length int length1 = (unicode ? SMS_LENGTH_UNICODE : SMS_LENGTH); int length2 = (unicode ? SMS_LENGTH2_UNICODE : SMS_LENGTH2); int partMaxLength = (messageLength > length1 ? length2 : length1); // create current length status info int partsNumber = messageLength / partMaxLength + 1; int partLength = partMaxLength - messageLength % partMaxLength; // correct length info for second part if (partsNumber == 2 && partLength == partMaxLength) { partLength = length1 - (length1 - length2) * 2; } // show current length status info String counterText = "" + partLength + "/" + partsNumber; counterTextView.setText(counterText); }
@Override public void afterTextChanged(Editable s) { int hashCode = s.hashCode(); if (hashCode == mView_LocationName.getText().hashCode()) { String teacher_name = mView_LocationName.getText().toString(); if (!FunctionHelper.isEmpty(teacher_name)) { mView_LocationName.setError(null); } } }