Android Question [B4X] Emoticons and MQTT

udg

Expert
Licensed User
Longtime User
Hi all,
I'd like to enable the use of emoji/emoticons/smileys (well, I don't know how to call them) in a chat program I developed for B4A and B4J. Messages are exchanged by means of an external MQTT server.

My first idea was to convert the whole message to UTF32 so any char would consume 4 bytes, but it sounds like a wasting of space.

Another option was to use a kind of start/stop sentinel char to delimit positions in the message where the smileys had to appear, but since any of the 4 bytes constituting a smiley (Unicode 32) could have the same value as mine start/stop sentinel that's not the solution.

Now I'm planning to add a couple of separate fields to my MQTT message, where the first one contains the 4-bytes emoticons encoding while the other is used to record the position in the general message where to show each of the emoticons (if any).

It sounds a bit complex, so I prefer to ask here how you eventually solved anything similar before going to the drawing board.

ps: I started reading this thread.
pps: using B4J 6.00 it seems that the loading of a specific font is not necessary anymore
 

udg

Expert
Licensed User
Longtime User
Hi,
I didn't test any of the three options. I asked here in the hope others have done something similar before and they are willing to share their experience.
From your reply I understand that, based on the expected size of a chat message, you suggest to go the UTF32 way for the whole message.
Can you comment on my last point: using B4J it seems unnecessary to add a specific font in order to show emoticons? I tried code from the linked thread and I could show a 0x1F601 symbol using the Default font.
TIA
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
From your reply I understand that, based on the expected size of a chat message, you suggest to go the UTF32 way for the whole message.
1. Use B4XSerializator to convert the data to bytes. I expect it to work with the emoji icons as it works with any regular string.

2. If you do need to use UTF32 then you shouldn't worry about the size.

Can you comment on my last point: using B4J it seems unnecessary to add a specific font in order to show emoticons?
This is not really related to this thread, however it depends on whether the default font has glyphs for emojis. It doesn't on Windows 7.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Thanks Erel.
I did a quick test and it seems to work properly. From my quick test it doubled the original message size, but emoji where encoded/decode flawlessly even when interspersed inside regular text.
So now I've to change the "body" part of my MQTT message from its string type to a byte array in order to accomodate the buffer from B4XSerializator.
On the receivinhg end I will revert from buffer to string and display the message.

Font: I will open a new thread for it but it's unfortunate that each OS and OS version has a different default that may or may not include common glyphs.
 
Upvote 0
Top