Add emojicon in between text when required; fixes#19
This commit is contained in:
parent
5854534419
commit
7284b7d423
1 changed files with 26 additions and 34 deletions
|
@ -39,26 +39,6 @@ public class MainActivity extends Activity {
|
|||
//Will automatically set size according to the soft keyboard size
|
||||
popup.setSizeForSoftKeyboard();
|
||||
|
||||
//Set on emojicon click listener
|
||||
popup.setOnEmojiconClickedListener(new OnEmojiconClickedListener() {
|
||||
|
||||
@Override
|
||||
public void onEmojiconClicked(Emojicon emojicon) {
|
||||
emojiconEditText.append(emojicon.getEmoji());
|
||||
}
|
||||
});
|
||||
|
||||
//Set on backspace click listener
|
||||
popup.setOnEmojiconBackspaceClickedListener(new OnEmojiconBackspaceClickedListener() {
|
||||
|
||||
@Override
|
||||
public void onEmojiconBackspaceClicked(View v) {
|
||||
KeyEvent event = new KeyEvent(
|
||||
0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
|
||||
emojiconEditText.dispatchKeyEvent(event);
|
||||
}
|
||||
});
|
||||
|
||||
//If the emoji popup is dismissed, change emojiButton to smiley icon
|
||||
popup.setOnDismissListener(new OnDismissListener() {
|
||||
|
||||
|
@ -88,7 +68,19 @@ public class MainActivity extends Activity {
|
|||
|
||||
@Override
|
||||
public void onEmojiconClicked(Emojicon emojicon) {
|
||||
if (emojiconEditText == null || emojicon == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int start = emojiconEditText.getSelectionStart();
|
||||
int end = emojiconEditText.getSelectionEnd();
|
||||
if (start < 0) {
|
||||
emojiconEditText.append(emojicon.getEmoji());
|
||||
} else {
|
||||
emojiconEditText.getText().replace(Math.min(start, end),
|
||||
Math.max(start, end), emojicon.getEmoji(), 0,
|
||||
emojicon.getEmoji().length());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue