Android Question Android EmojiCompat

nwhitfield

Active Member
Licensed User
Longtime User
Is there an easy way to use EmojiCompat in B4A?

 
Last edited:
Upvote 0
So, no easy way to bring up to date emoji to user's devices, as far as I can see? My first thought was an attributed string, but I guess that once a character with an emoji codepoint is spotted, Android will just takeover and use the device emoji font, rather than any one that I bundle with the app.
 
Upvote 0
Well, two things. Firstly, I'd like to be able to use an updated emoji font that includes all the latest additions, so that people will see the emoji even on older devices.

Secondly, it would be preferable if we could use the same emojiset across website and apps, for consistency. On the website, we'll be using Joypixels 6 when the update goes live.

I thought the only way to substitute the emoji font was by using the emoji-compat tools?
 
Upvote 0
So, for a string that may have a mix of normal text and emoji, I'd have to iterate over each character to see if it was an emoji or not, and build the string character by character. Straightforward enough to do, but I shall have to see what the performance hit is on long messages.
 
Upvote 0
Well, I have this bit of code using CSBuilder and the JoyPixels Android font, which mostly works
Code: Copy
    For Each point In cp
        If IsEmojiCodePoint(point) Then
            If emojiFont Then
                cs.Append(UTS(point))
            Else
                cs.pop.Typeface(joypixels).Append(UTS(point))
                emojiFont = True
            End If
        Else
            If Not(emojiFont) Then
                cs.Append(Chr(point))
            Else
                cs.Pop.Typeface(default).Append(Chr(point))
                emojiFont = False
            End If
        End If
    Next

However while it's replacing most emoji with the JoyPixels one (at the cost of a 22Mb payload for the app), it's not handling them all. Specifically the first one message in this screenshot should be the Transgender Flag, which is included in JoyPixels 6, and is a UTF sequence with zero join width. So on devices without the right symbol in their emjoi font, this is what you're supposed to see - a blank flag, followed by a transgender symbol.

I'm not sure why, however, when I am using the right font, it doesn't collapse that UTF sequence to display the correct one.
 

Attachments

  • Screenshot_20200816-132830.png
    Screenshot_20200816-132830.png
    151.8 KB · Views: 434
Upvote 0
Aha; you're right - the font does include the basic characters, and using it that way instead of building the string one code point at a time does indeed display the new emoji, like the transgender flag, correctly (and, of course, the accordion, also new in Unicode 13)

However, when displaying ordinary text, it's doing something weird with the space character, which is irksome - see attached screen.

So, I think in the interests of processing speed the best compromise will be to use the JoyPIxels font only when a message is flagged 'bigemoji' by the server, which means it has 10 or fewer characters, so spacing won't matter so much (and I expect most of those messages to be largely emoji anyway)
 

Attachments

  • Screenshot_20200817-094020.png
    Screenshot_20200817-094020.png
    136.4 KB · Views: 471
Upvote 0
Back
Top