| .. | ||
| filemojicompat | ||
| gradle/wrapper | ||
| build.gradle | ||
| gradle.properties | ||
| gradlew | ||
| gradlew.bat | ||
| README.md | ||
| settings.gradle | ||
FileMojiCompat
What is this?
This is a library providing an easy solution to use EmojiCompat
with fonts that are either stored in the assets-folder with another name than NotoColorEmojiCompat.ttf or you can use
EmojiCompat fonts which are stored anywhere on the device's local storage.
How do I use it?
There are two different methods included in this library:
-
You can use this just like you would usually useAssetEmojiCompatConfigBundledEmojiCompatConfigexcept for the detail that you can choose the font's name as the second parameter.
Example:
This will create a new EmojiCompat configuration using the file provided inEmojiCompat.Config config = new AssetEmojiCompatConfig(getContext(), "Blobmoji.ttf");assets/Blobmoji.ttf. -
This is the more complex and interesting option.FileEmojiCOmpatConfig
Instead of providing a short String containing the font's name, you can provide aFile(or the String containing the full path of it).
This will try to load the font from this path.
In case it gets into any trouble - let's say because of missing permissions or a non-existent file, it will fallback to using no EmojiCOmpat at all.
(Technically this is wrong as leaving EmojiCompat uninitialized would crash the components using it. There's an explanation below).
Example:
In this example, your app would try to load the font fileContext context = getContext(); File fontFile = new File(context.getExternalFilesDir(null), "emoji/Blobmoji.ttf"), EmojiCompat.Config config = new FileEmojiCompatConfig(context, fontFile);Blobmoji.ttflocated at/storage/emulated/0/Android/data/[your.app.package]/files/Blobmoji.ttf. If this file is not available, EmojiCompat won't be visible.
Hint: When accessing a file inside your private directory (i.e. the one used in the example), you don't need storage permissions.
However, if you want to load the font from somewhere else - let's say theDownloaddirectory, you will need storage permissions.
But don't worry (too much) - your app won't crash (probably) as this missing file is just being ignored in this case.
What happens if I don't provide the font file in FileEmojiCompatConfig?
In this case, there won't be a visible difference to not using EmojiCompat.
But what does that mean exactly?
If you take a look at EmojiCompat itself, you'll notice that it isn't build with missing fonts in mind. If anything happens,
onLoadFailed is called and EmojiCompat crashes - and so do all components relying on it.
To prevent this case, FileEmojiCompatConfig includes a fallback solution - inside the assets folder, you'll find a file called NoEmojiCompat.ttf which
is much smaller than most of the EmojiCompat font files (~40kiB). That's because it only includes 10 characters which are the flags for China, Germany, Spain, France, United Kingdom, Italy, Japan, South Korea, Russia, USA.
These are the flags which where originally included in Noto Emoji and they are only used to fill the font
file with something.
WIll my users see these flags when the fallback font is used?
Yes, they will. But only if their device either doesn't support these flags (which is basically impossible) or if they use a device which already uses these assets as their default emojis. They won't replace any existing emojis.
But I did setReplaceAll(true)?!
This won't change anything as FileEmojiCompatConfig will detect if the font file doesn't exist (or can't be read) and it will simply ignore setReplaceAll(true).
However, this is currently not the case if something else goes wrong, e.g. if the file is not an EmojiCompat font.
But even in this case only these flags are affected.