Reputation: 5121
I am working on an android application in which I want to convert all keyboard types smileys into emoji icons.
I am already using this library https://github.com/ankushsachdeva/emojicon to show Emoticons in my app.
Now, I want to convert the smileys which users will type using keyboard into emoticons.
Ex: If user type the string Hello World :) :P: 1. Then I need to first extract these smiley symbols and for that I need a regex pattern which will extract all these types of symbols from a string. 2. I need to find Unicode of these symbols and then convert these symbols in emoticons using the above library.
Please help me, so that I can proceed here.
Upvotes: 1
Views: 857
Reputation: 19253
this lib is using ImageSpan
s and SpannableStringBuilder
like here:
EmojiconTextView
public void setText(CharSequence text, BufferType type) {
SpannableStringBuilder builder = new SpannableStringBuilder(text);
EmojiconHandler.addEmojis(getContext(), builder, mEmojiconSize, mTextStart, mTextLength);
super.setText(builder, type);
}
you can always remove spans from current SpannableStringBuilder
and get plain text
if you want to set spans "in fly" just use TextWatcher
for your EditText
, smth like here: EmojiconEditText
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
EmojiconHandler.addEmojis(getContext(), getText(), mEmojiconSize);
}
this lib seems to do all work for you, just use View
s from lib (Emojicon
prefix) instead usual ones, e.g.
<ankushsachdeva.emojicon.EmojiconTextView
android:id="@+id/emojicon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
emojicon:emojiconSize="24dip"
android:gravity="center"/>
instead EditText
in XML layout files
Upvotes: 1