Google 致力于为黑人社区推动种族平等。查看具体举措

EmojiCompat

@AnyThread open class EmojiCompat
kotlin.Any
   ↳ androidx.emoji.text.EmojiCompat

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

EmojiCompat has to be initialized using init(EmojiCompat.Config) function before it can process a CharSequence.
<code>EmojiCompat.init(/* a config instance */);</code>

It is suggested to make the initialization as early as possible in your app. Please check 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 will throw an exception. You can use the 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.

<code>CharSequence processedSequence = EmojiCompat.get().process("some string")</code>

Summary

Nested classes
abstract

Configuration class for EmojiCompat.

abstract

Listener class for the initialization of the EmojiCompat.

abstract

Interface to load emoji metadata.

abstract

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

Constants
static String

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

static String

Key in EditorInfo#extras that represents configuration parameter.

static Int

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

static Int

An unrecoverable error occurred during initialization of EmojiCompat.

static Int

EmojiCompat is initializing.

static Int

EmojiCompat successfully initialized.

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

Public methods
open static EmojiCompat!
get()

Return singleton EmojiCompat instance.

open String

Returns signature for the currently loaded emoji assets.

open Int

Returns loading state of the EmojiCompat instance.

open static Boolean
handleDeleteSurroundingText(@NonNull inputConnection: InputConnection, @NonNull editable: Editable, @IntRange(0) beforeLength: Int, @IntRange(0) afterLength: Int, inCodePoints: Boolean)

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

open static Boolean
handleOnKeyDown(@NonNull editable: Editable, keyCode: Int, event: KeyEvent!)

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.

open Boolean
hasEmojiGlyph(@NonNull sequence: CharSequence)

Returns true if EmojiCompat is capable of rendering an emoji.

open Boolean
hasEmojiGlyph(@NonNull sequence: CharSequence, @IntRange(0) metadataVersion: Int)

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

open static EmojiCompat!
init(@NonNull config: EmojiCompat.Config)

Initialize the singleton instance with a configuration.

open Unit

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

open CharSequence!
process(@NonNull charSequence: CharSequence)

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

open CharSequence!
process(@NonNull charSequence: CharSequence, @IntRange(0) start: Int, @IntRange(0) end: Int)

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

open CharSequence!
process(@NonNull charSequence: CharSequence, @IntRange(0) start: Int, @IntRange(0) end: Int, @IntRange(0) maxEmojiCount: Int)

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

open CharSequence!
process(@NonNull charSequence: CharSequence, @IntRange(0) start: Int, @IntRange(0) end: Int, @IntRange(0) maxEmojiCount: Int, replaceStrategy: Int)

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

open Unit

Registers an initialization callback.

open Unit

Unregisters a callback that was added before.

Constants

EDITOR_INFO_METAVERSION_KEY

static val EDITOR_INFO_METAVERSION_KEY: String

Key in EditorInfo#extras that represents the emoji metadata version used by the widget. The existence of the value means that the widget is using EmojiCompat.

If exists, the value for the key is an int and can be used to query EmojiCompat to see whether the widget has the ability to display a certain emoji using hasEmojiGlyph(CharSequence, int).
Value: "android.support.text.emoji.emojiCompat_metadataVersion"

EDITOR_INFO_REPLACE_ALL_KEY

static val EDITOR_INFO_REPLACE_ALL_KEY: String

Key in EditorInfo#extras that represents configuration parameter. The key is added only if EmojiCompat is used by the widget. If exists, the value is a boolean.

Value: "android.support.text.emoji.emojiCompat_replaceAll"

LOAD_STATE_DEFAULT

static val LOAD_STATE_DEFAULT: Int

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

Value: 3

See Also

LOAD_STATE_FAILED

static val LOAD_STATE_FAILED: Int

An unrecoverable error occurred during initialization of EmojiCompat. Calls to functions such as process(CharSequence) will fail.

Value: 2

See Also

LOAD_STATE_LOADING

static val LOAD_STATE_LOADING: Int

EmojiCompat is initializing.

Value: 0

See Also

LOAD_STATE_SUCCEEDED

static val LOAD_STATE_SUCCEEDED: Int

EmojiCompat successfully initialized.

Value: 1

See Also

LOAD_STRATEGY_DEFAULT

static val LOAD_STRATEGY_DEFAULT: Int

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

Value: 0

LOAD_STRATEGY_MANUAL

static val LOAD_STRATEGY_MANUAL: Int

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

Value: 1

REPLACE_STRATEGY_ALL

static val REPLACE_STRATEGY_ALL: Int

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

Value: 1

REPLACE_STRATEGY_DEFAULT

static val REPLACE_STRATEGY_DEFAULT: Int

Replace strategy that uses the value given in