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
|
|
|
|
2015-05-06 13:53:55 -07:00
|
|
|
|
|
|
|
public class EmojiEditText extends AppCompatEditText {
|
|
|
|
public EmojiEditText(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public EmojiEditText(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
public EmojiEditText(Context context, AttributeSet attrs,
|
|
|
|
int defStyleAttr)
|
|
|
|
{
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
}
|
|
|
|
|
2015-05-14 21:08:37 -07:00
|
|
|
@Override public void setText(CharSequence text, BufferType type) {
|
|
|
|
super.setText(EmojiProvider.getInstance(getContext()).emojify(text, EmojiProvider.EMOJI_SMALL, new PostInvalidateCallback(this)),
|
|
|
|
BufferType.SPANNABLE);
|
2015-05-06 13:53:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2015-05-14 21:08:37 -07:00
|
|
|
new PostInvalidateCallback(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);
|
|
|
|
}
|
|
|
|
}
|