public void init(Context context, AttributeSet attrs) { // Inflate view from XML layout file LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.editor_view, this, true); // Get the views for the fragment mMentionsEditText = (MentionsEditText) findViewById(R.id.text_editor); mTextCounterView = (TextView) findViewById(R.id.text_counter); mSuggestionsList = (ListView) findViewById(R.id.suggestions_list); // Create the tokenizer to use for the editor // TODO: Allow customization of configuration via XML attributes WordTokenizerConfig config = new WordTokenizerConfig.Builder().build(); WordTokenizer tokenizer = new WordTokenizer(config); mMentionsEditText.setTokenizer(tokenizer); // Set various delegates on the MentionEditText to the RichEditorView mMentionsEditText.setSuggestionsVisibilityManager(this); mMentionsEditText.addTextChangedListener(this); mMentionsEditText.setQueryTokenReceiver(this); mMentionsEditText.setAvoidPrefixOnTap(true); // Set the suggestions adapter SuggestionsListBuilder listBuilder = new BasicSuggestionsListBuilder(); mSuggestionsAdapter = new SuggestionsAdapter(context, this, listBuilder); mSuggestionsList.setAdapter(mSuggestionsAdapter); // Set the item click listener mSuggestionsList.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Mentionable mention = (Mentionable) mSuggestionsAdapter.getItem(position); if (mMentionsEditText != null) { mMentionsEditText.insertMention(mention); mSuggestionsAdapter.clear(); } } }); // Display and update the editor text counter (starts it at 0) updateEditorTextCount(); // Wrap the EditText content height if necessary (ideally, allow this to be controlled via // custom XML attribute) setEditTextShouldWrapContent(mEditTextShouldWrapContent); mPrevEditTextBottomPadding = mMentionsEditText.getPaddingBottom(); }
/** * Sets the {@link Tokenizer} for the {@link MentionsEditText} to use. * * @param tokenizer the {@link Tokenizer} to use */ public void setTokenizer(final @NonNull Tokenizer tokenizer) { if (mMentionsEditText != null) { mMentionsEditText.setTokenizer(tokenizer); } }