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.

Community
  • 1
  • 1
Xar-e-ahmer Khan
  • 1,314
  • 15
  • 23

1 Answers1

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

Sulabh Jain
  • 342
  • 1
  • 9
  • I want to create a keyboard with custom Emoji (my own images) . Not build in like http://apps.timwhitlock.info/emoji/tables/unicode – Zar E Ahmer Mar 06 '15 at 13:16