|
|
|
@ -11,11 +11,13 @@ import android.text.TextUtils.TruncateAt;
|
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.components.emoji.EmojiProvider.EmojiDrawable;
|
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
|
|
|
|
|
|
|
|
public class EmojiTextView extends AppCompatTextView {
|
|
|
|
|
private CharSequence source;
|
|
|
|
|
private boolean needsEllipsizing;
|
|
|
|
|
private boolean useSystemEmoji;
|
|
|
|
|
|
|
|
|
|
public EmojiTextView(Context context) {
|
|
|
|
|
this(context, null);
|
|
|
|
@ -27,14 +29,20 @@ public class EmojiTextView extends AppCompatTextView {
|
|
|
|
|
|
|
|
|
|
public EmojiTextView(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
|
this.useSystemEmoji = TextSecurePreferences.isSystemEmojiPreferred(getContext());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override public void setText(@Nullable CharSequence text, BufferType type) {
|
|
|
|
|
if (useSystemEmoji) {
|
|
|
|
|
super.setText(text, type);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source = EmojiProvider.getInstance(getContext()).emojify(text, this);
|
|
|
|
|
setTextEllipsized(source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setTextEllipsized(final @Nullable CharSequence source) {
|
|
|
|
|
private void setTextEllipsized(final @Nullable CharSequence source) {
|
|
|
|
|
super.setText(needsEllipsizing ? ViewUtil.ellipsize(source, this) : source, BufferType.SPANNABLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -46,7 +54,8 @@ public class EmojiTextView extends AppCompatTextView {
|
|
|
|
|
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
|
final int size = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
|
final int mode = MeasureSpec.getMode(widthMeasureSpec);
|
|
|
|
|
if (getEllipsize() == TruncateAt.END &&
|
|
|
|
|
if (!useSystemEmoji &&
|
|
|
|
|
getEllipsize() == TruncateAt.END &&
|
|
|
|
|
!TextUtils.isEmpty(source) &&
|
|
|
|
|
(mode == MeasureSpec.AT_MOST || mode == MeasureSpec.EXACTLY) &&
|
|
|
|
|
getPaint().breakText(source, 0, source.length()-1, true, size, null) != source.length())
|
|
|
|
@ -62,7 +71,7 @@ public class EmojiTextView extends AppCompatTextView {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
|
if (changed) setTextEllipsized(source);
|
|
|
|
|
if (changed && !useSystemEmoji) setTextEllipsized(source);
|
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|