handle null emojify inputs better

fixes #3889
Closes #3901
// FREEBIE
This commit is contained in:
Jake McGinty 2015-08-06 10:35:51 -07:00 committed by Moxie Marlinspike
parent 973ed7686b
commit 3c400f958e
3 changed files with 8 additions and 4 deletions

View File

@ -19,7 +19,7 @@ public class EmojiFilter implements InputFilter {
char[] v = new char[end - start];
TextUtils.getChars(source, start, end, v, 0);
Spannable emojified = EmojiProvider.getInstance(view.getContext()).emojify(new String(v), view);
if (source instanceof Spanned) {
if (source instanceof Spanned && emojified != null) {
TextUtils.copySpansFrom((Spanned) source, start, end, null, emojified, 0);
}
return emojified;

View File

@ -12,6 +12,8 @@ import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.util.Log;
@ -78,7 +80,8 @@ public class EmojiProvider {
}
}
public Spannable emojify(CharSequence text, TextView tv) {
public @Nullable Spannable emojify(@Nullable CharSequence text, @NonNull TextView tv) {
if (text == null) return null;
Matcher matches = EMOJI_RANGE.matcher(text);
SpannableStringBuilder builder = new SpannableStringBuilder(text);

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.Paint.FontMetricsInt;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
@ -28,12 +29,12 @@ public class EmojiTextView extends AppCompatTextView {
super(context, attrs, defStyleAttr);
}
@Override public void setText(CharSequence text, BufferType type) {
@Override public void setText(@Nullable CharSequence text, BufferType type) {
source = EmojiProvider.getInstance(getContext()).emojify(text, this);
setTextEllipsized(source);
}
public void setTextEllipsized(final CharSequence source) {
public void setTextEllipsized(final @Nullable CharSequence source) {
super.setText(needsEllipsizing ? ViewUtil.ellipsize(source, this) : source, BufferType.SPANNABLE);
}