GlyphChecker
interface GlyphChecker
androidx.emoji.text.EmojiCompat.GlyphChecker |
Interface to check if a given emoji exists on the system.
Summary
Public methods | |
---|---|
abstract Boolean |
hasGlyph(@NonNull charSequence: CharSequence, @IntRange(0) start: Int, @IntRange(0) end: Int, @IntRange(0) sdkAdded: Int) Return |
Public methods
hasGlyph
abstract fun hasGlyph(
@NonNull charSequence: CharSequence,
@IntRange(0) start: Int,
@IntRange(0) end: Int,
@IntRange(0) sdkAdded: Int
): Boolean
Return true
if the emoji that is in charSequence
between start
(inclusive) and end
(exclusive) can be rendered on the system using the default Typeface.
This function is called after an emoji is identified in the given charSequence
and EmojiCompat wants to know if that emoji can be rendered on the system. The result of this call will be cached and the same emoji sequence won't be asked for the same EmojiCompat instance.
When the function returns true
, it will mean that the system can render the emoji. In that case if Config#setReplaceAll
is set to false
, then no EmojiSpan
will be added in the final emoji processing result.
When the function returns false
, it will mean that the system cannot render the given emoji, therefore an EmojiSpan
will be added to the final emoji processing result.
The default implementation of this class uses androidx.core.graphics.PaintCompat#hasGlyph(Paint, String)
function to check if the emoji can be rendered on the system. This is required even if EmojiCompat knows about the SDK Version that the emoji was added on AOSP. Just the sdkAdded
information is not enough to reliably decide if emoji can be rendered since this information may not be consistent across all the OEMs and all the Android versions.
With this interface you can apply your own heuristics to check if the emoji can be rendered on the system. For example, if you'd like to rely on the sdkAdded
information, and some predefined OEMs, it is possible to write the following code snippet.
Parameters | |
---|---|
charSequence |
CharSequence: the CharSequence that is being processed |
start |
Int: the inclusive starting offset for the emoji in the charSequence |
end |
Int: the exclusive end offset for the emoji in the charSequence |
sdkAdded |
Int: the API version that the emoji was added in AOSP |
Return | |
---|---|
Boolean |
true if the given sequence can be rendered as a single glyph, otherwise false. |