Created
June 10, 2017 09:29
-
-
Save chowaikong/be83b22cc36a722fd0d5eb3b87b3d700 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmojiExcludedEditText : EditText { | |
constructor(context: Context) : super(context) { | |
init() | |
} | |
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { | |
init() | |
} | |
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, | |
defStyleAttr) { | |
init() | |
} | |
private fun init() { | |
filters = arrayOf<InputFilter>(EmojiExcludeFilter()) | |
} | |
private inner class EmojiExcludeFilter : InputFilter { | |
override fun filter(source: CharSequence, start: Int, end: Int, dest: Spanned, dstart: Int, | |
dend: Int): CharSequence? { | |
return if ((start..end - 1) | |
.map { Character.getType(source[it]) } | |
.any { it == Character.SURROGATE.toInt() || it == Character.OTHER_SYMBOL.toInt() }) "" else null | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment