简体   繁体   中英

How to extract text smileys from a string in android

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.

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, eg

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM