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 EmojiSpan
s to a given . It is a singleton class that can be configured using a instance.
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 |
static String |
Key in |
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 |
|
static Int |
|
static Int |
Replace strategy to add |
static Int |
Replace strategy that uses the value given in |
static Int |
Replace strategy to add |
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 |
open static Boolean |
handleOnKeyDown(@NonNull editable: Editable, keyCode: Int, event: KeyEvent!) Handles onKeyDown commands from a |
open Boolean |
hasEmojiGlyph(@NonNull sequence: CharSequence) Returns |
open Boolean |
hasEmojiGlyph(@NonNull sequence: CharSequence, @IntRange(0) metadataVersion: Int) Returns |
open static EmojiCompat! |
init(@NonNull config: EmojiCompat.Config) Initialize the singleton instance with a configuration. |
open Unit |
load() When |
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 |
registerInitCallback(@NonNull initCallback: EmojiCompat.InitCallback) Registers an initialization callback. |
open Unit |
unregisterInitCallback(@NonNull initCallback: EmojiCompat.InitCallback) 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.
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
See Also
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
See Also
REPLACE_STRATEGY_ALL
static val REPLACE_STRATEGY_ALL: Int
Replace strategy to add EmojiSpan
s 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 EmojiCompat.Config
.
Value: 0
REPLACE_STRATEGY_NON_EXISTENT
static val REPLACE_STRATEGY_NON_EXISTENT: Int
Replace strategy to add EmojiSpan
s only for emoji that do not exist in the system.
Value: 2