From 3c400f958e41cfef00e5c31aa58d1c58b564eaa0 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Thu, 6 Aug 2015 10:35:51 -0700 Subject: [PATCH] handle null emojify inputs better fixes #3889 Closes #3901 // FREEBIE --- .../thoughtcrime/securesms/components/emoji/EmojiFilter.java | 2 +- .../securesms/components/emoji/EmojiProvider.java | 5 ++++- .../securesms/components/emoji/EmojiTextView.java | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/org/thoughtcrime/securesms/components/emoji/EmojiFilter.java b/src/org/thoughtcrime/securesms/components/emoji/EmojiFilter.java index 9c93875f3b..fbb9c267cd 100644 --- a/src/org/thoughtcrime/securesms/components/emoji/EmojiFilter.java +++ b/src/org/thoughtcrime/securesms/components/emoji/EmojiFilter.java @@ -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; diff --git a/src/org/thoughtcrime/securesms/components/emoji/EmojiProvider.java b/src/org/thoughtcrime/securesms/components/emoji/EmojiProvider.java index 365d575ef4..8778d2cc10 100644 --- a/src/org/thoughtcrime/securesms/components/emoji/EmojiProvider.java +++ b/src/org/thoughtcrime/securesms/components/emoji/EmojiProvider.java @@ -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); diff --git a/src/org/thoughtcrime/securesms/components/emoji/EmojiTextView.java b/src/org/thoughtcrime/securesms/components/emoji/EmojiTextView.java index 36e001405b..68a27b3414 100644 --- a/src/org/thoughtcrime/securesms/components/emoji/EmojiTextView.java +++ b/src/org/thoughtcrime/securesms/components/emoji/EmojiTextView.java @@ -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); }