class EmojiInputFilter implements android.text.InputFilter {

    @Override
    public CharSequence filter(final CharSequence source, final int sourceStart,
            final int sourceEnd, final Spanned dest, final int destStart, final int destEnd) {
        if (mTextView.isInEditMode()) {
            return source;
        }

        switch (EmojiCompat.get().getLoadState()){
            case EmojiCompat.LOAD_STATE_SUCCEEDED:
                boolean process = true;
                if (destEnd == 0 && destStart == 0 && dest.length() == 0) {
                    final CharSequence oldText = mTextView.getText();
                    if (source == oldText) {
                        process = false;
                    }
                }

                if (process && source != null) {
                    final CharSequence text;
                    if (sourceStart == 0 && sourceEnd == source.length()) {
                        text = source;
                    } else {
                        text = source.subSequence(sourceStart, sourceEnd);
                    }
                    return EmojiCompat.get().process(text, 0, text.length());
                }

                return source;
            case EmojiCompat.LOAD_STATE_LOADING:
            case EmojiCompat.LOAD_STATE_DEFAULT:
                EmojiCompat.get().registerInitCallback(getInitCallback());
                return source;

            case EmojiCompat.LOAD_STATE_FAILED:
            default:
                return source;
        }
    }

      EmojiInputFilter(@NonNull final TextView textView);

}