Java Code Examples for android.text.Editable#append()
The following examples show how to use
android.text.Editable#append() .
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: 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 2
Source File: MaskedEditText.java From star-dns-changer with MIT License | 6 votes |
public String getUnmaskedText() { Editable text = super.getText(); if (mask != null && !mask.isEmpty()) { Editable unMaskedText = new SpannableStringBuilder(); for (Integer index : listValidCursorPositions) { if (text != null) { unMaskedText.append(text.charAt(index)); } } if (format != null && !format.isEmpty()) return formatText(unMaskedText.toString(), format); else return unMaskedText.toString().trim(); } return text.toString().trim(); }
Example 3
Source File: AKHtml.java From Mupdf with Apache License 2.0 | 6 votes |
private static void startImg(Editable text, Attributes attributes, Html.ImageGetter img) { String src = attributes.getValue("", "src"); Drawable d = null; if (img != null) { d = img.getDrawable(src); } if (d == null) { //d = Resources.getSystem(). // getDrawable(R.drawable.seek_thumb); //d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); return; } int len = text.length(); text.append("\uFFFC"); text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
Example 4
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 5
Source File: SourceEditActivity.java From a with GNU General Public License v3.0 | 5 votes |
private void insertTextToEditText(String txt) { if (isEmpty(txt)) return; View view = getWindow().getDecorView().findFocus(); if (view instanceof EditText) { EditText editText = (EditText) view; int start = editText.getSelectionStart(); int end = editText.getSelectionEnd(); Editable edit = editText.getEditableText();//获取EditText的文字 if (start < 0 || start >= edit.length()) { edit.append(txt); } else { edit.replace(start, end, txt);//光标所在位置插入文字 } } }
Example 6
Source File: FragmentReceiveResultSupport.java From V.FlyoutTest with MIT License | 5 votes |
/** * This method is called when the sending activity has finished, with the * result it supplied. */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // You can use the requestCode to select between multiple child // activities you may have started. Here there is only one thing // we launch. if (requestCode == GET_CODE) { // We will be adding to our text. Editable text = (Editable)mResults.getText(); // This is a standard resultCode that is sent back if the // activity doesn't supply an explicit result. It will also // be returned if the activity failed to launch. if (resultCode == RESULT_CANCELED) { text.append("(cancelled)"); // Our protocol with the sending activity is that it will send // text in 'data' as its result. } else { text.append("(okay "); text.append(Integer.toString(resultCode)); text.append(") "); if (data != null) { text.append(data.getAction()); } } text.append("\n"); } }
Example 7
Source File: HtmlTagHandler.java From RichText with MIT License | 5 votes |
@SuppressWarnings("unused") private void reallyHandler(int start, int end, String tag, Editable out, XMLReader reader) { switch (tag.toLowerCase()) { case "code": CodeSpan cs = new CodeSpan(code_color); out.setSpan(cs, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); break; case "ol": case "ul": out.append('\n'); if (!list.isEmpty()) list.pop(); break; case "li": boolean isUl = list.peek(); int i; if (isUl) { index = 0; i = -1; } else { i = ++index; } out.append('\n'); TextView textView = textViewSoftReference.get(); if (textView == null) { return; } MarkDownBulletSpan bulletSpan = new MarkDownBulletSpan(list.size() - 1, h1_color, i, textView); out.setSpan(bulletSpan, start, out.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); break; } }
Example 8
Source File: CustomTagHandler.java From KinoCast with MIT License | 5 votes |
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { // you may add more tag handler which are not supported by android here if("li".equals(tag)){ if(opening){ output.append(" \u2022 "); }else{ output.append("\n"); } } }
Example 9
Source File: ChatActivity.java From emoji with Apache License 2.0 | 5 votes |
@Override public void onEmoticonTap(String drawableId) { Editable editable = mChatEditorTxt.getText(); int index = mChatEditorTxt.getSelectionEnd(); String emo = EmojiParser.getInstance(this).convertToUnicode(drawableId); SpannableStringBuilder builder = new SpannableStringBuilder(emo); int resId = getResources().getIdentifier("emoji_" + drawableId, "drawable", getPackageName()); Drawable d = getResources().getDrawable(resId); d.setBounds(0, 0, 30, 30); ImageSpan span = new ImageSpan(d); builder.setSpan(span, 0, emo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); if (index < mChatEditorTxt.length()) { editable.insert(index, builder); }else { editable.append(builder); } mChatEditorTxt.setSelection(index + emo.length()); // drawableSrc = "emoji_" + drawableId; // ImageGetter imageGetter = new ImageGetter() { // public Drawable getDrawable(String source) { // int id = ChatActivity.this.getResources().getIdentifier(source, "drawable", getPackageName()); // Drawable d = ChatActivity.this.getResources().getDrawable(id); // d.setBounds(0, 0, 24, 24); // return d; // } // }; // CharSequence cs1 = Html.fromHtml("<img src='" + drawableSrc + "'/>", imageGetter, null); // int index = mChatEditorTxt.getSelectionStart(); // Editable etb = mChatEditorTxt.getText(); // int length = etb.length(); // if (index < length) { // etb.insert(index, cs1); // } else { // mChatEditorTxt.append(cs1); // } // mChatEditorTxt.setSelection(index + 1); }
Example 10
Source File: MentionsEditTextTest.java From Spyglass with Apache License 2.0 | 5 votes |
private void testMention(String hello, Mentionable mention) { Editable editable = mEditText.getEditableText(); editable.append(hello); mEditText.setSelection(hello.length() - 1); mEditText.insertMention(mention); // ensure mention does not clobber existing text assertTrue(mEditText.getText().toString().startsWith("Hello ")); }
Example 11
Source File: ColorChooser.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
private void changeColor() { Editable editable = edit.getText(); int i = editable.toString().indexOf('#'); if (i != -1) // should start with a # { editable.delete(i, i + 1); } editable.insert(0, "#"); while (editable.length() < 3) // supply an alpha value (FF) { editable.insert(1, "F"); } if (editable.length() == 7) { editable.insert(1, "FF"); } while (editable.length() < 9) // fill rest with "0" { editable.append("0"); } //Log.d("DEBUG", "color is " + editable.toString()); edit.setText(editable); setColor(editable.toString()); onColorChanged(getColor()); }
Example 12
Source File: SourceEditActivity.java From HaoReader with GNU General Public License v3.0 | 5 votes |
private void insertTextToEditText(String txt) { if (TextUtils.isEmpty(txt)) return; View view = getWindow().getDecorView().findFocus(); if (view instanceof EditText) { EditText editText = (EditText) view; int start = editText.getSelectionStart(); int end = editText.getSelectionEnd(); Editable edit = editText.getEditableText();//获取EditText的文字 if (start < 0 || start >= edit.length()) { edit.append(txt); } else { edit.replace(start, end, txt);//光标所在位置插入文字 } } }
Example 13
Source File: WifiSkillViewFragment.java From Easer with GNU General Public License v3.0 | 5 votes |
private void addESSID(String essid) { Editable text = editText_ssid.getText(); if (!Utils.isBlank(text.toString())) text.append("\n"); if (essid.startsWith("\"")) { essid = essid.substring(1, essid.length() - 1); } text.append(essid); }
Example 14
Source File: ConverterHtmlToText.java From memoir with Apache License 2.0 | 5 votes |
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { tag = tag.toLowerCase(Locale.US); if (tag.equals("hr") && opening) { // In the case of an <hr>, replace it with a bunch of underscores. This is roughly // the behaviour of Outlook in Rich Text mode. output.append("_____________________________________________\n"); } else if (TAGS_WITH_IGNORED_CONTENT.contains(tag)) { handleIgnoredTag(opening, output); } }
Example 15
Source File: PbChatActivity.java From imsdk-android with MIT License | 5 votes |
@Override public void onEmoticonClick(EmoticonEntity entity, String pkgId) { StringBuilder text = new StringBuilder(); text.append((char) 0). append(pkgId). append((char) 1). append(entity.shortCut).append((char) 255); int index = edit_msg.getSelectionStart(); Editable edit = edit_msg.getEditableText(); if (index < 0 || index > edit.length()) { edit.append(text); } else { edit.insert(index, text); } }
Example 16
Source File: ExpirationDateEditTextTest.java From android-card-form with MIT License | 5 votes |
private ExpirationDateEditTextTest type(char... chars) { Editable editable = mView.getText(); for (char c : chars) { editable.append(c); } return this; }
Example 17
Source File: CardFormTest.java From android-card-form with MIT License | 5 votes |
private void setText(EditText editText, String text) { editText.setText(""); Editable editable = editText.getText(); for (char c : text.toCharArray()) { editable.append(c); } }
Example 18
Source File: HtmlToSpannedConverter.java From HtmlCompat with Apache License 2.0 | 4 votes |
private void handleBr(Editable text) { text.append('\n'); }
Example 19
Source File: AKHtml.java From Mupdf with Apache License 2.0 | 4 votes |
private static void handleBr(Editable text) { text.append('\n'); }
Example 20
Source File: BaseChatActivity.java From yiim_v2 with GNU General Public License v2.0 | 4 votes |
@Override public void processHandlerMessage(Message msg) { // TODO Auto-generated method stub switch (msg.what) { case MSG_INIT: init(); break; case MSG_RECV: clearConversationDealFlag(); break; case MSG_RECORD_READED: if (mAdapter != null && mAdapter.getCursor() != null) { mListView.setAdapter(null); mAdapter.getCursor().close(); mAdapter = null; } initAdapter(msg.obj); mAdapter.setOnAudioClickListener(new NativeAudioClickListener()); mAdapter.setOnImageClickListener(new ImageClickListener()); mAdapter.setOnVideoClickListener(new NativeVideoClickListener()); mAdapter.setResendClickListener(new ResendImageClickListener()); mAdapter.setIsMultiChat(YiIMUtils.isMultChat(mUserTo)); mListView.setAdapter(mAdapter); mAdapter.notifyDataSetChanged(); // mListView.setSelection(mAdapter.getCount() - 1); break; case MSG_SEND_EMOTION: try { YiIMMessage message = new YiIMMessage(); message.setType(MsgType.BIG_EMOTION); message.setBody((String) msg.obj); sendYiIMMessage(message.toString()); } catch (Exception e) { // TODO: handle exception } mFooterView.setVisibility(View.GONE); break; case MSG_SEND_AUDIO: sendAudioMsg(); break; case MSG_SEND_CLASSICAL_EMOTION: if ("[DEL]".equals((String) msg.obj)) { int keyCode = KeyEvent.KEYCODE_DEL; KeyEvent keyEventDown = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode); KeyEvent keyEventUp = new KeyEvent(KeyEvent.ACTION_UP, keyCode); mEditTextContent.onKeyDown(keyCode, keyEventDown); mEditTextContent.onKeyUp(keyCode, keyEventUp); } else { int index = mEditTextContent.getSelectionStart(); Editable editable = mEditTextContent.getEditableText(); if (index < 0 || index >= editable.length()) { editable.append((String) msg.obj); } else { editable.insert(index, (String) msg.obj); } mGifEmotionUtils.setSpannableText(mEditTextContent, mEditTextContent.getText().toString(), getHandler()); } break; case MSG_CHECK_NATWORK_TYPE: if (getXmppBinder().isAVCallOK()) { cancelProgressDialog(); } else { getHandler().sendEmptyMessageDelayed(MSG_CHECK_NATWORK_TYPE, 200); } break; default: break; } }