mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 19:43:38 +00:00
parent
c7d2ed4f7d
commit
54db79bfdd
@ -8,13 +8,13 @@ import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiTextView;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
|
||||
public class FromTextView extends TextView {
|
||||
public class FromTextView extends EmojiTextView {
|
||||
|
||||
public FromTextView(Context context) {
|
||||
super(context);
|
||||
|
@ -3,6 +3,9 @@ package org.thoughtcrime.securesms.components.emoji;
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.AppCompatEditText;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiProvider.InvalidatingPageLoadedListener;
|
||||
|
||||
public class EmojiEditText extends AppCompatEditText {
|
||||
public EmojiEditText(Context context) {
|
||||
@ -23,16 +26,17 @@ public class EmojiEditText extends AppCompatEditText {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setTransformationMethod(new EmojiTransformationMethod());
|
||||
}
|
||||
|
||||
public void insertEmoji(int codePoint) {
|
||||
final char[] chars = Character.toChars(codePoint);
|
||||
final String text = new String(chars);
|
||||
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));
|
||||
|
||||
getText().replace(Math.min(start, end), Math.max(start, end), text, 0, text.length());
|
||||
getText().replace(Math.min(start, end), Math.max(start, end), text);
|
||||
setSelection(end + chars.length);
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,16 @@ package org.thoughtcrime.securesms.components.emoji;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.support.v7.widget.AppCompatTextView;
|
||||
import android.text.method.TransformationMethod;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
import android.view.View;
|
||||
|
||||
public class EmojiTextView extends TextView {
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiProvider.InvalidatingPageLoadedListener;
|
||||
|
||||
public class EmojiTextView extends AppCompatTextView {
|
||||
public EmojiTextView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
@ -22,13 +27,19 @@ public class EmojiTextView extends TextView {
|
||||
init();
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.LOLLIPOP)
|
||||
public EmojiTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setTransformationMethod(new EmojiTransformationMethod());
|
||||
}
|
||||
|
||||
private static class EmojiTransformationMethod implements TransformationMethod {
|
||||
|
||||
@Override public CharSequence getTransformation(CharSequence source, View view) {
|
||||
return EmojiProvider.getInstance(view.getContext()).emojify(source,
|
||||
EmojiProvider.EMOJI_SMALL,
|
||||
new InvalidatingPageLoadedListener(view));
|
||||
}
|
||||
|
||||
@Override public void onFocusChanged(View view, CharSequence sourceText, boolean focused,
|
||||
int direction, Rect previouslyFocusedRect) { }
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
package org.thoughtcrime.securesms.components.emoji;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.text.method.TransformationMethod;
|
||||
import android.view.View;
|
||||
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiProvider.InvalidatingPageLoadedListener;
|
||||
|
||||
class EmojiTransformationMethod implements TransformationMethod {
|
||||
|
||||
@Override public CharSequence getTransformation(CharSequence source, View view) {
|
||||
return EmojiProvider.getInstance(view.getContext()).emojify(source, EmojiProvider.EMOJI_SMALL, new InvalidatingPageLoadedListener(view));
|
||||
}
|
||||
|
||||
@Override public void onFocusChanged(View view, CharSequence sourceText, boolean focused,
|
||||
int direction, Rect previouslyFocusedRect) { }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user