EmojiCompat

public class EmojiCompat
extends Object

java.lang.Object
   ↳ androidx.emoji.text.EmojiCompat


Main class to keep Android devices up to date with the newest emojis by adding EmojiSpans to a given CharSequence. It is a singleton class that can be configured using a EmojiCompat.Config instance.

EmojiCompat has to be initialized using init(EmojiCompat.Config) function before it can process a CharSequence.

EmojiCompat.init(/* a config instance */);

It is suggested to make the initialization as early as possible in your app. Please check EmojiCompat.Config for more configuration parameters. Once init(EmojiCompat.Config) is called a singleton instance will be created. Any call after that will not create a new instance and will return immediately.

During initialization information about emojis is loaded on a background thread. Before the EmojiCompat instance is initialized, calls to functions such as process(CharSequence) will throw an exception. You can use the EmojiCompat.InitCallback class to be informed about the state of initialization.

After initialization the get() function can be used to get the configured instance and the process(CharSequence) function can be used to update a CharSequence with emoji EmojiSpans.

CharSequence processedSequence = EmojiCompat.get().process("some string")

Summary

Nested classes

class EmojiCompat.Config

Configuration class for EmojiCompat. 

interface EmojiCompat.GlyphChecker

Interface to check if a given emoji exists on the system. 

class EmojiCompat.InitCallback

Listener class for the initialization of the EmojiCompat. 

interface EmojiCompat.MetadataRepoLoader

Interface to load emoji metadata. 

class EmojiCompat.MetadataRepoLoaderCallback

Callback to inform EmojiCompat about the state of the metadata load. 

Constants

String EDITOR_INFO_METAVERSION_KEY

Key in EditorInfo.extras that represents the emoji metadata version used by the widget.

String EDITOR_INFO_REPLACE_ALL_KEY

Key in EditorInfo.extras that represents EmojiCompat.Config.setReplaceAll(boolean) configuration parameter.

int LOAD_STATE_DEFAULT

EmojiCompat instance is constructed, however the initialization did not start yet.

int LOAD_STATE_FAILED

An unrecoverable error occurred during initialization of EmojiCompat.

int LOAD_STATE_LOADING

EmojiCompat is initializing.

int LOAD_STATE_SUCCEEDED

EmojiCompat successfully initialized.

int LOAD_STRATEGY_DEFAULT

EmojiCompat will start loading metadata when init(Config) is called.

int LOAD_STRATEGY_MANUAL

EmojiCompat will wait for load() to be called by developer in order to start loading metadata.

int REPLACE_STRATEGY_ALL

Replace strategy to add EmojiSpans for all emoji that were found.

int REPLACE_STRATEGY_DEFAULT

Replace strategy that uses the value given in EmojiCompat.Config.

int REPLACE_STRATEGY_NON_EXISTENT

Replace strategy to add EmojiSpans only for emoji that do not exist in the system.

Public methods

static EmojiCompat get()

Return singleton EmojiCompat instance.

String getAssetSignature()

Returns signature for the currently loaded emoji assets.

int getLoadState()

Returns loading state of the EmojiCompat instance.

static boolean handleDeleteSurroundingText(InputConnection inputConnection, Editable editable, int beforeLength, int afterLength, boolean inCodePoints)

Handles deleteSurroundingText commands from InputConnection and tries to delete an EmojiSpan from an Editable.

static boolean handleOnKeyDown(Editable editable, int keyCode, KeyEvent event)

Handles onKeyDown commands from a KeyListener and if keyCode is one of KeyEvent.KEYCODE_DEL or KeyEvent.KEYCODE_FORWARD_DEL it tries to delete an EmojiSpan from an Editable.

boolean hasEmojiGlyph(CharSequence sequence)

Returns true if EmojiCompat is capable of rendering an emoji.

boolean hasEmojiGlyph(CharSequence sequence, int metadataVersion)

Returns true if EmojiCompat is capable of rendering an emoji at the given metadata version.

static EmojiCompat init(EmojiCompat.Config config)

Initialize the singleton instance with a configuration.

void load()

When EmojiCompat.Config.setMetadataLoadStrategy(int) is set to LOAD_STRATEGY_MANUAL, this function starts loading the metadata.

CharSequence process(CharSequence charSequence)

Checks a given CharSequence for emojis, and adds EmojiSpans if any emojis are found.

CharSequence process(CharSequence charSequence, int start, int end, int maxEmojiCount, int replaceStrategy)