Allow EmojiTextView to redraw after changing emoji setting.

Also just fixed some minor formatting issues.
This commit is contained in:
Greyson Parrelli 2018-05-28 17:20:28 -04:00
parent ceafb0d130
commit f0e5aa312e

View File

@ -25,6 +25,7 @@ public class EmojiTextView extends AppCompatTextView {
private CharSequence originalText;
private float originalFontSize;
private boolean useSystemEmoji;
public EmojiTextView(Context context) {
this(context, null);
@ -47,11 +48,12 @@ public class EmojiTextView extends AppCompatTextView {
}
@Override public void setText(@Nullable CharSequence text, BufferType type) {
if (Util.equals(originalText, text)) {
if (Util.equals(originalText, text) && useSystemEmoji == useSystemEmoji()) {
return;
}
originalText = text;
useSystemEmoji = useSystemEmoji();
EmojiProvider provider = EmojiProvider.getInstance(getContext());
EmojiParser.CandidateList candidates = provider.getCandidates(text);
@ -59,16 +61,18 @@ public class EmojiTextView extends AppCompatTextView {
if (scaleEmojis && candidates != null && candidates.allEmojis) {
int emojis = candidates.size();
float scale = 1.0f;
if (emojis <= 8) scale += 0.25f;
if (emojis <= 6) scale += 0.25f;
if (emojis <= 4) scale += 0.25f;
if (emojis <= 2) scale += 0.25f;
super.setTextSize(TypedValue.COMPLEX_UNIT_PX, originalFontSize * scale);
} else if (scaleEmojis) {
super.setTextSize(TypedValue.COMPLEX_UNIT_PX, originalFontSize);
}
if (useSystemEmoji() || candidates == null || candidates.size() == 0) {
if (useSystemEmoji || candidates == null || candidates.size() == 0) {
super.setText(text, BufferType.NORMAL);
return;
}
@ -85,7 +89,7 @@ public class EmojiTextView extends AppCompatTextView {
private void ellipsize() {
post(() -> {
if (getLayout() == null || getLineCount() == 0) {
if (getLayout() == null) {
ellipsize();
return;
}