8

I have a piece of code which adds some image into an EditText using SpannableString as follow:

SpannableString ss = new SpannableString("Some random String in my application.");
Drawable d = getResources().getDrawable(R.drawable.emoticon_0001);
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
ss.setSpan(span, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

There is some index calculation in between that I did not include because they are not important. The code works fine. Here are some image of it:

Portrait and Landscape in non editing mode:

Portrait Landscape

However, once I start editing in Landscape mode, the text behind image appears:

My name is problem, BIG problem

As most people know, the weird String represents the Unicode for the Emoticon in iPhone. Has anyone encountered this problem before?

EDIT: Tested with android:imeOptions="actionDone|flagNoExtractUi", does not work, word suggestion will cover up my EditText.

Community
  • 1
  • 1
Chor Wai Chun
  • 3,226
  • 25
  • 41
  • I haven't seen this, but I've done enough work with keyboards to have a good guess on what's happening. It looks like when the ExtractView is shown (the extract view is the part of the landscape edit above the keyboard, its actually drawn by the Android framework and is part of your app from the keyboard's POV) you're losing your image span and just the plain text is being put there. Why and how you'd fix it I don't have good ideas on at the moment. Is it happening in other apps as well? Say the messaging app? Whay about editing in portrait? – Gabe Sechan May 13 '13 at 06:42
  • Thank you for the information, I've tested with well known messaging app Whatsapp. And it is displaying an empty space on those emoticons. It makes sense because those characters represents Unicode which will be empty space if they cannot find a proper symbol attached to the code. Just like sending the emoji from iPhone SMS to Android device, empty space will be displayed too. – Chor Wai Chun May 13 '13 at 06:48
  • 1
    @GabeSechan Sorry did not answered your question, editing in Portrait mode works fine. The problem only happens on Landscape edit, and same goes to Whatsapp. – Chor Wai Chun May 13 '13 at 06:56
  • Definitely sounds like you're losing your spans in extract mode then. But if Whatsapp is also losing the image only in extract mode, that sounds like a framework bug rather than something you're doing. – Gabe Sechan May 13 '13 at 06:59
  • @GabeSechan yep but just checking if anybody has solution or workaround to this. Well they are not perfect too, so would be good if I can solve something they not yet. – Chor Wai Chun May 13 '13 at 07:03

1 Answers1

0

I would suggest you to convert the HTML code in your spannable string into pure UNICODE string before showing editing keyboard. If the emoticons in UNICODE are supported, then it should show in editing. After done with editing convert it back to HTML.

android html decoding

Community
  • 1
  • 1
nio
  • 5,141
  • 2
  • 24
  • 35
  • not very sure whether Android supports those emoji's unicode now, during the time i asked this question, emoji unicodes are only "legit" on iPhone. Say if you send a SMS from iphone to android, with emoji in it, android sees nothing.. – Chor Wai Chun Oct 29 '13 at 01:17