I want to implement an emoji selector for my keyboard app Keyboard Designer. To do so I want to draw emojis based on unicodes in hexadecimal format. The emoji "\u1F636\u200D\u1F32B\uFE0F" is shown correctly when I write it in the text field (two eyes behind a cloud), but when I draw it on my canvas, it looks like two separate emojis (left top corner of the keyboard):
Hint: The hearts do nothing have to do with the question, they only mark favourite emojis
My source is nested in objects and methods, but to show you how it works, I change it to linear commands:
ArrayList<char[]> utf16Chars = new ArrayList<>();
String hexCode = "\\u1F636\\u200D\\u1F32B\\uFE0F";
int distance;
if (hexCode.startsWith("\\")) {
for (int i = 0; i < hexCode.length(); i += distance) {
distance = hexCode.indexOf("\\", i + 1) - i;
if (distance < 0)
distance = hexCode.length() - i;
String utf16Code = hexCode.substring(i, i + distance);
int decimalCode = Integer.parseInt(utf16Code.length() >= 6 ? utf16Code.substring(2) : utf16Code, 16);
char[] utf8Chars = Character.toChars(decimalCode);
utf16Chars.add(utf8Chars);
}
}
StringBuilder stringBuilder = new StringBuilder();
for(char[] utf8Chars : utf16Chars)
for(char character : utf8Chars)
stringBuilder.append(character);
String emoji = stringBuilder.toString();
canvas.drawText(emoji, 0, emoji.length(), x, y, paint);
Does anyone have an idea what I do wrong?


