Java Code Examples for android.widget.EditText#append()

The following examples show how to use android.widget.EditText#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: ExpressionTransformEngine.java    From android-expression with Apache License 2.0 6 votes vote down vote up
/**
 * 每次点击表情会调用,已经处理长按选择多个表情然后再输入表情的情况
 * @param editText
 * @param str
 */
public static void input(EditText editText, String str) {


    if (editText == null || str == null) {
        return;
    }
    String t = editText.getText().toString();
    int start = editText.getSelectionStart();
    int end = editText.getSelectionEnd();
    if (start < 0) {
        editText.append(str);
    } else {
        editText.getText().replace(Math.min(start, end), Math.max(start, end), str, 0, str.length());
    }
}
 
Example 2
Source File: SearchActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.activity_search, menu);
    final MenuItem searchActionMenuItem = menu.findItem(R.id.action_search);
    final EditText searchField = searchActionMenuItem.getActionView().findViewById(R.id.search_field);
    final String term = pendingSearchTerm.pop();
    if (term != null) {
        searchField.append(term);
        List<String> searchTerm = FtsUtils.parse(term);
        if (xmppConnectionService != null) {
            if (currentSearch.watch(searchTerm)) {
                xmppConnectionService.search(searchTerm, this);
            }
        } else {
            pendingSearch.push(searchTerm);
        }
    }
    searchField.addTextChangedListener(this);
    searchField.setHint(R.string.search_messages);
    searchField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
    showKeyboard(searchField);
    return super.onCreateOptionsMenu(menu);
}
 
Example 3
Source File: SignPostActivity.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 6 votes vote down vote up
private void initBodyText() {
    mBodyText = (EditText) findViewById(R.id.reply_body_edittext);
    mBodyText.setSelected(true);

    Intent intent = getIntent();
    String prefix = intent.getStringExtra("prefix");
    if (prefix != null) {
        if (prefix.startsWith("[quote][pid=")
                && prefix.endsWith("[/quote]\n")) {
            SpannableString spanString = new SpannableString(prefix);
            spanString.setSpan(new BackgroundColorSpan(-1513240), 0, prefix.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            spanString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), prefix.indexOf("[b]Post by"),
                    prefix.indexOf("):[/b]") + 5,
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            mBodyText.append(spanString);
        } else {
            mBodyText.append(prefix);
        }
        mBodyText.setSelection(prefix.length());
    }
}
 
Example 4
Source File: InputHelper.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
public static void input(EditText editText, Emojicon emojicon,
        String flagStart, String flagEnd) {
    if (editText == null || emojicon == null) {
        return;
    }
    int start = editText.getSelectionStart();
    int end = editText.getSelectionEnd();
    Spannable emojiString = displayEmoji(editText.getResources(),
            emojicon.getEmojiStr(), flagStart, flagEnd);
    // 没有多选时,直接在当前光标处添加
    if (start < 0) {
        editText.append(emojiString);
    } else {
        // 将已选中的部分替换为表情(当长按文字时会多选刷中很多文字)
        editText.getText().replace(Math.min(start, end),
                Math.max(start, end), emojiString, 0, emojiString.length());
    }
}
 
Example 5
Source File: SearchActivity.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
	getMenuInflater().inflate(R.menu.activity_search, menu);
	final MenuItem searchActionMenuItem = menu.findItem(R.id.action_search);
	final EditText searchField = searchActionMenuItem.getActionView().findViewById(R.id.search_field);
	final String term = pendingSearchTerm.pop();
	if (term != null) {
		searchField.append(term);
		List<String> searchTerm = FtsUtils.parse(term);
		if (xmppConnectionService != null) {
			if (currentSearch.watch(searchTerm)) {
				xmppConnectionService.search(searchTerm, this);
			}
		} else {
			pendingSearch.push(searchTerm);
		}
	}
	searchField.addTextChangedListener(this);
	searchField.setHint(R.string.search_messages);
	searchField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
	if (term == null) {
		showKeyboard(searchField);
	}
	return super.onCreateOptionsMenu(menu);
}
 
Example 6
Source File: Utils.java    From Emoji with Apache License 2.0 5 votes vote down vote up
static void input(@NonNull final EditText editText, @Nullable final Emoji emoji) {
  if (emoji != null) {
    final int start = editText.getSelectionStart();
    final int end = editText.getSelectionEnd();

    if (start < 0) {
      editText.append(emoji.getUnicode());
    } else {
      editText.getText().replace(Math.min(start, end), Math.max(start, end), emoji.getUnicode(), 0, emoji.getUnicode().length());
    }
  }
}
 
Example 7
Source File: EmojiconsFragment.java    From talk-android with MIT License 5 votes vote down vote up
public static void input(EditText editText, Emojicon emojicon) {
    if (editText == null || emojicon == null) {
        return;
    }

    int start = editText.getSelectionStart();
    int end = editText.getSelectionEnd();
    if (start < 0) {
        editText.append(emojicon.getEmoji());
    } else {
        editText.getText().replace(Math.min(start, end), Math.max(start, end), emojicon.getEmoji(), 0, emojicon.getEmoji().length());
    }
}
 
Example 8
Source File: EmojiconsFragment.java    From EmojiChat with Apache License 2.0 5 votes vote down vote up
public static void input(EditText editText, Emojicon emojicon) {
    if (editText == null || emojicon == null) {
        return;
    }

    int start = editText.getSelectionStart();
    int end = editText.getSelectionEnd();
    if (start < 0) {
        editText.append(emojicon.getEmoji());
    } else {
        editText.getText().replace(Math.min(start, end), Math.max(start, end), emojicon.getEmoji(), 0, emojicon.getEmoji().length());
    }
}
 
Example 9
Source File: EmojiconsFragment.java    From EmojiEverywhere with GNU General Public License v2.0 5 votes vote down vote up
public static void input(EditText editText, Emojicon emojicon) {
    if (editText == null || emojicon == null) {
        return;
    }

    int start = editText.getSelectionStart();
    int end = editText.getSelectionEnd();
    if (start < 0) {
        editText.append(emojicon.getEmoji());
    } else {
        editText.getText().replace(Math.min(start, end), Math.max(start, end), emojicon.getEmoji(), 0, emojicon.getEmoji().length());
    }
}
 
Example 10
Source File: EmojiconsFragment.java    From emojicon with Apache License 2.0 5 votes vote down vote up
public static void input(EditText editText, Emojicon emojicon) {
    if (editText == null || emojicon == null) {
        return;
    }

    int start = editText.getSelectionStart();
    int end = editText.getSelectionEnd();
    if (start < 0) {
        editText.append(emojicon.getEmoji());
    } else {
        editText.getText().replace(Math.min(start, end), Math.max(start, end), emojicon.getEmoji(), 0, emojicon.getEmoji().length());
    }
}
 
Example 11
Source File: AppendingTestsCustom.java    From PatternedTextWatcher with MIT License 4 votes vote down vote up
@Override void addTextAndAssert(EditText editText, String expected, String typed,
    String pattern) {
  editText.append(typed);
  assertText(editText, expected, typed, pattern);
}
 
Example 12
Source File: InsertionSameSymbols.java    From PatternedTextWatcher with MIT License 4 votes vote down vote up
private void appendTextAndAssert(EditText editText, String expected, String typed, String pattern) {
  editText.append(typed);
  assertText(editText, expected, typed, pattern);
}
 
Example 13
Source File: AppendingTestsDefault.java    From PatternedTextWatcher with MIT License 4 votes vote down vote up
@Override void addTextAndAssert(EditText editText, String expected, String typed,
    String pattern) {
  editText.append(typed);
  assertText(editText, expected, typed, pattern);
}
 
Example 14
Source File: GradualCustomizedDeletionTests.java    From PatternedTextWatcher with MIT License 4 votes vote down vote up
@Override void addText(EditText editText, String value) {
  editText.append(value);
}
 
Example 15
Source File: GradualDefaultDeletionTests.java    From PatternedTextWatcher with MIT License 4 votes vote down vote up
@Override void addText(EditText editText, String value) {
  editText.append(value);
}
 
Example 16
Source File: ReplyCommentFragment.java    From Ouroboros with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    isPosting = false;
    View view = inflater.inflate(R.layout.fragment_post_comment_activity, container, false);
    setActionBarTitle("Post a comment");

    networkHelper = new NetworkHelper();
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());

    reply = new Reply();
    if (savedInstanceState == null){
        reply.filePath = new ArrayList<>();
    } else {
        reply.filePath = savedInstanceState.getStringArrayList("filePath");
        for (String file : reply.filePath){
            addAttachmentPreview(file, view);
        }
    }
    reply.fileName = new ArrayList<String>();

    resto = getActivity().getIntent().getStringExtra(Util.INTENT_THREAD_NO);
    boardName = getActivity().getIntent().getStringExtra(Util.INTENT_BOARD_NAME);
    replyNo = getActivity().getIntent().getStringExtra(Util.INTENT_REPLY_NO);

    EditText nameText = (EditText) view.findViewById(R.id.post_comment_editText_name);
    final EditText emailText = (EditText) view.findViewById(R.id.post_comment_editText_email);
    CheckBox sageBox = (CheckBox) view.findViewById(R.id.post_comment_checkBox_sage);
    EditText subjetText = (EditText) view.findViewById(R.id.post_comment_editText_subject);
    EditText commentText = (EditText) view.findViewById(R.id.post_comment_editText_comment);

    String defaultName = SettingsHelper.getDefaultName(getActivity());
    String defaultEmail = SettingsHelper.getDefaultEmail(getActivity());

    nameText.setText(sharedPreferences.getString(SaveReplyText.nameEditTextKey, defaultName));
    emailText.setText(sharedPreferences.getString(SaveReplyText.emailEditTextKey, defaultEmail));
    subjetText.setText(sharedPreferences.getString(SaveReplyText.subjectEditTextKey, ""));
    commentText.setText(sharedPreferences.getString(SaveReplyText.commentEditTextKey, ""));

    nameText.addTextChangedListener(new SaveReplyText(sharedPreferences, SaveReplyText.nameEditTextKey));
    emailText.addTextChangedListener(new SaveReplyText(sharedPreferences, SaveReplyText.emailEditTextKey));
    subjetText.addTextChangedListener(new SaveReplyText(sharedPreferences, SaveReplyText.subjectEditTextKey));
    commentText.addTextChangedListener(new SaveReplyText(sharedPreferences, SaveReplyText.commentEditTextKey));
    sageBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            reply.sage = isChecked;
        }
    });

    if (replyNo != null){
        if (commentText.getText().toString().equals("")){
            commentText.append(">>" + replyNo + "\n");
        } else {
            commentText.append("\n>>" + replyNo + "\n");
        }
    }
    
    commentText.requestFocus();

    setHasOptionsMenu(true);
    return view;
}