Class FileEmojiCompatConfig


  • public class FileEmojiCompatConfig
    extends androidx.emoji2.text.EmojiCompat.Config
    A simple implementation of EmojiCompat.Config using typeface files. Based on: https://android.googlesource.com/platform/frameworks/support/+/master/emoji/bundled/src/main/java/android/support/text/emoji/bundled/BundledEmojiCompatConfig.java Changes are marked with comments. Formatting and other simple changes are not always marked.
    • Method Detail

      • init

        public static FileEmojiCompatConfig init​(@NonNull
                                                 Context context,
                                                 @Nullable
                                                 File fontFile,
                                                 @Nullable
                                                 String fallbackFontName)
        Create a new configuration for this EmojiCompat based on a file
        Parameters:
        context - Context instance
        fontFile - The file containing the EmojiCompat font
        fallbackFontName - The asset path of the fallback font
      • init

        public static FileEmojiCompatConfig init​(@NonNull
                                                 Context context,
                                                 @Nullable
                                                 File fontFile,
                                                 @Nullable
                                                 String fallbackFontName,
                                                 boolean dontWarnOnEmptyFileName)
        Create a new configuration for this EmojiCompat based on a file
        Parameters:
        context - Context instance
        fontFile - The file containing the EmojiCompat font
        fallbackFontName - The asset path of the fallback font
        dontWarnOnEmptyFileName - If set to true, don't log a warning (only info) if the empty file was given as fontFile. This is used in FilemojiCompat-UI when an asset is loaded
      • createFromAsset

        public static FileEmojiCompatConfig createFromAsset​(@NonNull
                                                            Context context,
                                                            @Nullable
                                                            String assetPath)
        Creates a new FileEmojiCompatConfig based on an asset. Will set the replacement strategy to treat the "normal" and the asset version equally.

        The default location for a substituting font is /sdcard/Android/data/your.apps.package/files/EmojiCompat.ttf.

        Parameters:
        context - The app's context is needed for several tasks
        assetPath - The path inside the assets folder for the default font file
        Returns:
        A FileEmojiCompatConfig which will use the given font by default
      • createFromAsset

        public static FileEmojiCompatConfig createFromAsset​(@NonNull
                                                            Context context)
        Creates a new FileEmojiCompatConfig based on an asset. Will set the replacement strategy to treat the "normal" and the asset version equally.

        The default location for a substituting font is /sdcard/Android/data/your.apps.package/files/EmojiCompat.ttf.

        The default name for the Assets font is NoEmojiCompat.ttf. If you wish to use a different name for this font, please use createFromAsset(Context, String).

        Parameters:
        context - The app's context is needed for several tasks
        Returns:
        A FileEmojiCompatConfig which will use the given font by default
      • setReplaceAll

        public FileEmojiCompatConfig setReplaceAll​(ReplaceStrategy strategy)
        Sets the strategy to use when it comes to replacing all or only unsupported emojis.
        Parameters:
        strategy - The strategy to use.
        Returns:
        This
      • setReplaceAll

        @NonNull
        public FileEmojiCompatConfig setReplaceAll​(boolean replaceAll)
        Specifies whether all emojis should be replaced even for the fallback/default emoji font.
        Overrides:
        setReplaceAll in class androidx.emoji2.text.EmojiCompat.Config
        Parameters:
        replaceAll - True if the provided emoji font should also replace all emojis (useful e.g., if you already provide a custom emoji font)
        Returns:
        This
      • isReplaceAll

        public boolean isReplaceAll()
        Returns:
        Whether all emojis are replaced. Note: This does not return the strategy used, but how the actual state is.