Use Emojicons with SoftKeyboard
orenafek opened this issue · 0 comments
orenafek commented
How can I determine if an integer represents a legal Emojicon?
I'm trying to dynamically add an Emoji key, and then detect it when its pressed.
This is my key addition snippet
private void registerEmoji (Keyboard keyboard, @DrawableRes int emojiRes) {
List<Keyboard.Key> keys = keyboard.getKeys();
Keyboard.Row row = new Keyboard.Row(keyboard);
Drawable emoji = getResources().getDrawable(emojiRes);
Emojicon emojicon = Emojicon.fromResource(emojiRes, 0);
Keyboard.Key key = new Keyboard.Key(row);
key.codes = new int[]{emojiRes};
key.gap = 10;
key.height = emoji.getMinimumWidth();
key.width = emoji.getMinimumWidth();
key.icon = emoji;
keys.add(key);
}
And here I'm trying to detect it
public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection();
playClick(primaryCode);
switch (primaryCode) {
...
default: {
if (isEmoji(primaryCode)) {
...
} else {
char c = (char) primaryCode;
ic.commitText(String.valueOf(Character.isLetter(c) && capsLock ?
c : Character.toUpperCase(c)), 1);
}
}
}
How can I implement the isEmoji
method?