public abstract class

EmojiCompat.Config

extends java.lang.Object

 java.lang.Object

↳androidx.emoji.text.EmojiCompat.Config

Subclasses:

BundledEmojiCompatConfig, FontRequestEmojiCompatConfig

Overview

Configuration class for EmojiCompat. Changes to the values will be ignored after EmojiCompat.init(EmojiCompat.Config) is called.

Summary

Constructors
protectedConfig(EmojiCompat.MetadataRepoLoader metadataLoader)

Default constructor.

Methods
protected final EmojiCompat.MetadataRepoLoadergetMetadataRepoLoader()

Returns the EmojiCompat.MetadataRepoLoader.

public EmojiCompat.ConfigregisterInitCallback(EmojiCompat.InitCallback initCallback)

Registers an initialization callback.

public EmojiCompat.ConfigsetEmojiSpanIndicatorColor(int color)

Sets the color used as emoji span indicator.

public EmojiCompat.ConfigsetEmojiSpanIndicatorEnabled(boolean emojiSpanIndicatorEnabled)

Determines whether a background will be drawn for the emojis that are found and replaced by EmojiCompat.

public EmojiCompat.ConfigsetGlyphChecker(EmojiCompat.GlyphChecker glyphChecker)

The interface that is used by EmojiCompat in order to check if a given emoji can be rendered by the system.

public EmojiCompat.ConfigsetMetadataLoadStrategy(int strategy)

Determines the strategy to start loading the metadata.

public EmojiCompat.ConfigsetReplaceAll(boolean replaceAll)

Determines whether EmojiCompat should replace all the emojis it finds with the EmojiSpans.

public EmojiCompat.ConfigsetUseEmojiAsDefaultStyle(boolean useEmojiAsDefaultStyle)

Determines whether EmojiCompat should use the emoji presentation style for emojis that have text style as default.

public EmojiCompat.ConfigsetUseEmojiAsDefaultStyle(boolean useEmojiAsDefaultStyle, java.util.List<java.lang.Integer> emojiAsDefaultStyleExceptions)

public EmojiCompat.ConfigunregisterInitCallback(EmojiCompat.InitCallback initCallback)

Unregisters a callback that was added before.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

protected Config(EmojiCompat.MetadataRepoLoader metadataLoader)

Default constructor.

Parameters:

metadataLoader: MetadataRepoLoader instance, cannot be null

Methods

public EmojiCompat.Config registerInitCallback(EmojiCompat.InitCallback initCallback)

Registers an initialization callback.

Parameters:

initCallback: the initialization callback to register, cannot be null

Returns:

EmojiCompat.Config instance

public EmojiCompat.Config unregisterInitCallback(EmojiCompat.InitCallback initCallback)

Unregisters a callback that was added before.

Parameters:

initCallback: the initialization callback to be removed, cannot be null

Returns:

EmojiCompat.Config instance

public EmojiCompat.Config setReplaceAll(boolean replaceAll)

Determines whether EmojiCompat should replace all the emojis it finds with the EmojiSpans. By default EmojiCompat tries its best to understand if the system already can render an emoji and do not replace those emojis.

Parameters:

replaceAll: replace all emojis found with EmojiSpans

Returns:

EmojiCompat.Config instance

public EmojiCompat.Config setUseEmojiAsDefaultStyle(boolean useEmojiAsDefaultStyle)

Determines whether EmojiCompat should use the emoji presentation style for emojis that have text style as default. By default, the text style would be used, unless these are followed by the U+FE0F variation selector. Details about emoji presentation and text presentation styles can be found here: http://unicode.org/reports/tr51/#Presentation_Style If useEmojiAsDefaultStyle is true, the emoji presentation style will be used for all emojis, including potentially unexpected ones (such as digits or other keycap emojis). If this is not the expected behaviour, method EmojiCompat.Config.setUseEmojiAsDefaultStyle(boolean, List) can be used to specify the exception emojis that should be still presented as text style.

Parameters:

useEmojiAsDefaultStyle: whether to use the emoji style presentation for all emojis that would be presented as text style by default

public EmojiCompat.Config setUseEmojiAsDefaultStyle(boolean useEmojiAsDefaultStyle, java.util.List<java.lang.Integer> emojiAsDefaultStyleExceptions)

Parameters:

emojiAsDefaultStyleExceptions: Contains the exception emojis which will be still presented as text style even if the useEmojiAsDefaultStyle flag is set to true. This list will be ignored if useEmojiAsDefaultStyle is false. Note that emojis with default emoji style presentation will remain emoji style regardless the value of useEmojiAsDefaultStyle or whether they are included in the exceptions list or not. When no exception is wanted, the method EmojiCompat.Config.setUseEmojiAsDefaultStyle(boolean) should be used instead.

See also: EmojiCompat.Config.setUseEmojiAsDefaultStyle(boolean)

public EmojiCompat.Config setEmojiSpanIndicatorEnabled(boolean emojiSpanIndicatorEnabled)

Determines whether a background will be drawn for the emojis that are found and replaced by EmojiCompat. Should be used only for debugging purposes. The indicator color can be set using EmojiCompat.Config.setEmojiSpanIndicatorColor(int).

Parameters:

emojiSpanIndicatorEnabled: when true a background is drawn for each emoji that is replaced

public EmojiCompat.Config setEmojiSpanIndicatorColor(int color)

Sets the color used as emoji span indicator. The default value is .

See also: EmojiCompat.Config.setEmojiSpanIndicatorEnabled(boolean)

public EmojiCompat.Config setMetadataLoadStrategy(int strategy)

Determines the strategy to start loading the metadata. By default EmojiCompat will start loading the metadata during EmojiCompat.init(EmojiCompat.Config). When set to EmojiCompat.LOAD_STRATEGY_MANUAL, you should call EmojiCompat.load() to initiate metadata loading.

Default implementations of EmojiCompat.MetadataRepoLoader start a thread during their EmojiCompat.MetadataRepoLoader.load(EmojiCompat.MetadataRepoLoaderCallback) functions. Just instantiating and starting a thread might take time especially in older devices. Since EmojiCompat.init(EmojiCompat.Config) has to be called before any EmojiCompat widgets are inflated, this results in time spent either on your Application.onCreate or Activity .onCreate. If you'd like to gain more control on when to start loading the metadata and be able to call EmojiCompat.init(EmojiCompat.Config) with absolute minimum time cost you can use EmojiCompat.LOAD_STRATEGY_MANUAL.

When set to EmojiCompat.LOAD_STRATEGY_MANUAL, EmojiCompat will wait for EmojiCompat.load() to be called by the developer in order to start loading metadata, therefore you should call EmojiCompat.load() to initiate metadata loading. EmojiCompat.load() can be called from any thread.

 EmojiCompat.Config config = new FontRequestEmojiCompatConfig(context, fontRequest)
         .setMetadataLoadStrategy(EmojiCompat.LOAD_STRATEGY_MANUAL);

 // EmojiCompat will not start loading metadata and MetadataRepoLoader#load(...)
 // will not be called
 EmojiCompat.init(config);

 // At any time (i.e. idle time or executorService is ready)
 // call EmojiCompat#load() to start loading metadata.
 executorService.execute(() -> EmojiCompat.get().load());
 

Parameters:

strategy: one of EmojiCompat.LOAD_STRATEGY_DEFAULT, EmojiCompat.LOAD_STRATEGY_MANUAL

public EmojiCompat.Config setGlyphChecker(EmojiCompat.GlyphChecker glyphChecker)

The interface that is used by EmojiCompat in order to check if a given emoji can be rendered by the system.

Parameters:

glyphChecker: EmojiCompat.GlyphChecker instance to be used.

protected final EmojiCompat.MetadataRepoLoader getMetadataRepoLoader()

Returns the EmojiCompat.MetadataRepoLoader.