Java 类android.text.Editable 实例源码
项目:superglue
文件:BugReportView.java
@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);
}
项目:OSchina_resources_android
文件:TeamTweetDetailFragment.java
@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());
}
项目:oma-riista-android
文件:HarvestSpecimenView.java
@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();
}
}
}
项目:GitHub
文件:CodeUnlockActivity.java
@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 {
// 清除 对应 标识位
}
}
项目:civify-app
文件:PasswordTextWatcherTest.java
@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);
}
项目:PeSanKita-android
文件:RegistrationActivity.java
@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);
}
}
项目:EasyAndroid
文件:NewAuthEditText.java
/**
* 文本变化处理
*/
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);
}
}
项目:RLibrary
文件:ExEditText.java
/**
* 删除最后一个字符,用来当@的人, 已经存在时,调用
*/
public void deleteLast(int position) {
Editable text = getText();
if (text != null && text.length() >= position) {
text.delete(position - 1, position);
}
}
项目:HtmlCompat
文件:HtmlToSpannedConverter.java
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);
}
项目:Autocomplete
文件:MainActivity.java
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();
}
项目:keepass2android
文件:AfcSearchView.java
@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());
}
项目:FastAndroid
文件:RecognizePlugin.java
@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();
}
项目:revolution-irc
文件:ChatAutoCompleteEditText.java
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();
}
项目:ZeroKit-Android-SDK
文件:PasswordEditText.java
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;
}
项目:SimpleUILauncher
文件:AllAppsSearchBarController.java
@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);
}
}
项目:markor
文件:PlainHighlighter.java
@Override
protected Editable run(final HighlightingEditor editor, final Editable editable) {
try {
clearSpans(editable);
} catch (Exception ex) {
// Ignoring errors
}
return editable;
}
项目:floating_calc
文件:CalculatorEditText.java
@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();
}
项目:javaide
文件:BracketHighlighter.java
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);
}
}
项目:Mingnote
文件:NoteEdit.java
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中光标在最后面显示
}
项目:thesis-project
文件:ExamAdapter.java
@Override
public void afterTextChanged(Editable s) {
if (textViewTitle.getText().toString().trim().equals("")) {
btnSave.setEnabled(false);
}else{
btnSave.setEnabled(true);
}
}
项目:thesis-project
文件:QuizResultAdapter.java
@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);
}
项目:RNLearn_Project1
文件:ReactEditText.java
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;
}
项目:OSchina_resources_android
文件:OnKeyArrivedListenerAdapter.java
@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;
}
项目:sealtalk-android-master
文件:GroupNoticeActivity.java
@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);
}
}
项目:PeSanKita-android
文件:ConversationActivity.java
@Override
public void afterTextChanged(Editable s) {
calculateCharactersRemaining();
if (composeText.getText().length() == 0 || beforeLength == 0) {
composeText.postDelayed(new Runnable() {
@Override
public void run() {
updateToggleButtonState();
}
}, 50);
}
}
项目:xmrwallet
文件:ExchangeView.java
@Override
public void onBackSpacePressed() {
Editable editable = etAmount.getEditText().getText();
int length = editable.length();
if (length > 0) {
editable.delete(length - 1, length);
}
}
项目:thesis-project
文件:QuizAdapter.java
@Override
public void afterTextChanged(Editable s) {
if (textViewTitle.getText().toString().trim().equals("")) {
btnSave.setEnabled(false);
}else{
btnSave.setEnabled(true);
}
}
项目:Tribe
文件:EaseChatPrimaryMenu.java
@Override
public void onTextInsert(CharSequence text) {
int start = editText.getSelectionStart();
Editable editable = editText.getEditableText();
editable.insert(start, text);
setModeKeyboard();
}
项目:RNLearn_Project1
文件:ReactEditText.java
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;
}
项目:EasyEmoji
文件:EmojiTextWatcher.java
@Override
public void afterTextChanged(Editable s) {
if(s.length()>0) {
EmojiHandler.getInstance().handleEmojis(context, s, mEmojiconSize,
mEmojiconAlignment, mEmojiconTextSize, start, count, mUseSystemDefault);
}
}
项目:EditCodeView
文件:EditCodeView.java
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);
}
项目:chromium-for-android-56-debug-video
文件:UrlBar.java
/**
* 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());
}
项目:rongyunDemo
文件:GroupNoticeActivity.java
@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);
}
}
项目:Ghost-Android
文件:EditTextUtils.java
private static int insertAtEnd(EditTextSelectionState selectionState,
CharSequence textToInsert) {
Editable editableText = selectionState.getEditText().getEditableText();
int insertPos = editableText.length();
editableText.append(textToInsert);
return insertPos;
}
项目:OSchina_resources_android
文件:TeamDiscussDetailFragment.java
@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);
}
项目:OSchina_resources_android
文件:OnKeyArrivedListenerAdapterV2.java
@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;
}
项目:LaunchEnr
文件:AllAppsSearchBarController.java
@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);
}
}
项目:BlackList
文件:MessageLengthCounter.java
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);
}
项目:MyCalendar
文件:AddEditDetailLocationActivity.java
@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);
}
}
}
项目:KTalk
文件:EaseChatPrimaryMenu.java
@Override
public void onTextInsert(CharSequence text) {
int start = editText.getSelectionStart();
Editable editable = editText.getEditableText();
editable.insert(start, text);
setModeKeyboard();
}