2015-05-06 13:53:55 -07:00
|
|
|
package org.thoughtcrime.securesms.components.emoji;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.support.v7.widget.AppCompatEditText;
|
|
|
|
import android.util.AttributeSet;
|
2015-05-14 15:54:07 -07:00
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.components.emoji.EmojiProvider.InvalidatingPageLoadedListener;
|
2015-05-06 13:53:55 -07:00
|
|
|
|
|
|
|
public class EmojiEditText extends AppCompatEditText {
|
|
|
|
public EmojiEditText(Context context) {
|
|
|
|
super(context);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
public EmojiEditText(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
public EmojiEditText(Context context, AttributeSet attrs,
|
|
|
|
int defStyleAttr)
|
|
|
|
{
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void init() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void insertEmoji(int codePoint) {
|
2015-05-14 15:54:07 -07:00
|
|
|
final int start = getSelectionStart();
|
|
|
|
final int end = getSelectionEnd();
|
|
|
|
final char[] chars = Character.toChars(codePoint);
|
|
|
|
final CharSequence text = EmojiProvider.getInstance(getContext()).emojify(new String(chars),
|
|
|
|
EmojiProvider.EMOJI_SMALL,
|
|
|
|
new InvalidatingPageLoadedListener(this));
|
2015-05-06 13:53:55 -07:00
|
|
|
|
2015-05-14 15:54:07 -07:00
|
|
|
getText().replace(Math.min(start, end), Math.max(start, end), text);
|
2015-05-06 13:53:55 -07:00
|
|
|
setSelection(end + chars.length);
|
|
|
|
}
|
|
|
|
}
|