Embedding emoji(emoticons images) to custom softkeyboard android
Asked Answered
J

1

3

I have created a custom soft Keyboard(IME) where we can add custom emoji.

Whenever i try to add my emoticons to it. it override the last text entered. i mean it dont append the emoticons unless it override it. how can i add emoji to currentInputConnection

for example

i image write  hello image abcimage          ///where image represents emoji

it becomes

i image write hello image image

// and i can add image after space easily or i can repeatedly add images easily .

when i add text it appends to emoji but when i add emoji after entering some text it remove the text and then add it self(emoji image).

Just for testing purpose i put emoji code to shift key

Problem code

else if (primaryCode == Keyboard.KEYCODE_SHIFT) 
        {
        //  this.handleShift();

            //this.mComposing.append(getSmiledText(getApplicationContext(), ":)"));

             ImageGetter imageGetter = new ImageGetter() 
                {
                    public Drawable getDrawable(String source) {
                        Drawable d = getResources().getDrawable(R.drawable.e041);
                        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
                        return d;
                    }
                };

                Spanned cs = Html.fromHtml("<img src='" + getResources().getDrawable(R.drawable.e041) + "'/>", imageGetter, null);

              //  getCurrentInputConnection().commitText(cs, 1);

               // this.mComposing.append(cs);


            //getCurrentInputConnection().commitText(getSmiledText(getApplicationContext(), ":)"), 1);


             getCurrentInputConnection().beginBatchEdit();


             getCurrentInputConnection().commitText(cs, 1);

             getCurrentInputConnection().endBatchEdit();


            //getCurrentInputConnection().setComposingText(cs, 1); // it is giving wrong 


        } 

And tried multiple ways to solve it ,some tried codes are shown in comments

Simple Words : I want to append emoji image to text, but when i add image to text, it remove the written text, how can i solve. full source can't be shown it is lengthy. Ask me if you need any method in my class

Related link :

add custom image as Emoji in android

https://stackoverflow.com/questions/24100615/cannot-add-an-image-to-my-keyboard-service

Implementations of Emoji (Emoticon) View/Keyboard Layouts

Thanks in Advance.

Jahveh answered 22/12, 2014 at 13:52 Comment(3)
Is your text committed or is it composing text? In the second case you would have to commit the text before adding the image.Pirogue
this method only shows how to add image to softkeyboard,Jahveh
I know that. When you previously added the text, was it added as composing text? Because if so, the text disappearing when the image is added is as designed.Pirogue
M
1

I also tried for the same but always got "obj".Atlast I found a solution try this.

Instead of adding drawables just add emoticons by their uniCodes like this..

getCurrentInputConnection().commitText((CharSequence)"\ud83c\udfb5", 1);

Its working for me perfectly.and also remove beginBatchEdit and endBatchEdit from your code.

Thanks

Misty answered 2/3, 2015 at 6:4 Comment(1)
I want to create a keyboard with custom Emoji (my own images) . Not build in like apps.timwhitlock.info/emoji/tables/unicodeInterlude

© 2022 - 2024 — McMap. All rights reserved.