Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
C1710 authored Oct 13, 2018
1 parent 9a6afca commit 866dbe9
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,29 @@ In this case, there won't be a visible difference to not using EmojiCompat.
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`](https://github.com/C1710/blobmoji/blob/filemojicompat/emojicompat/FileMojiCompat/filemojicompat/src/main/assets/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.
is much smaller than most of the EmojiCompat font files (less than 7kiB). 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](https://github.com/googlei18n/noto-emoji) and they are only used to _fill_ the font
file with something.
file with something.~~
_These are not the emojis that are used in this font anymore._
#### 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.
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 (at least that's very unlikely).
#### But I did `setReplaceAll(true)`?!
This won't change anything as `FileEmojiCompatConfig` will detect if the font file is not valid and it will simply ignore `setReplaceAll(true)`.
## I want to let my users only choose another font if they don't like my current one
This is easily possible with the introduction of `FileMojiCompat 1.0.6`.
In this case you override the fallback font by putting your font into the `assets` folder of your app using the name `NoEmojiCompat.ttf`.
Whenever the fallback font is needed (which is the case if the user doesn't specify another one), this font is being used.
In order to prevent blocking the `setReplaceAll` method, you'll have to call it with `setReplaceAll(true, true)`.
Since `setReplaceAll` would normally be ignored if no external font is found, you'll have to change it to `setReplaceAll(true, true)`, which basically says "replace all emojis, even if the fallback font is used".
The second argument indicates that you want to ignore this `replaceAll`-prevention (if set to `true`. Setting it to `false` won't change anything).
So here's a short example of using this very flexible, yet easy to use method.
But please be aware that changing the emoji font using this snippet isn't very easy as it needs the user to copy (and potentially rename) some files:
But please be aware that changing the emoji font using this snippet isn't very convenient as it needs the user to copy (and potentially rename) some files:
```java
Context context = getContext();
File fontFile = new File(context.getExternalFilesDir(null), "emoji.ttf");
EmojiCompat.Config config = new FileEmojiCompatConfig(context, fontFile)
.setReplaceAll(true, true);
```
In this case, the font specified in `assets/NoEmojiCompat.ttf` will be used until `/storage/emulated/0/Android/[yourpackage]/files/emoji.ttf` exists and includes a valid `EmojiCompat` font.
In this case, the font specified in `assets/NoEmojiCompat.ttf` will be used until `/storage/emulated/0/Android/data/[yourpackage]/files/emoji.ttf` exists and includes a valid `EmojiCompat` font.
This method combines the easy approach of `AssetEmojiCompatConfig` and the flexibility of `FileEmojiCompatConfig` with some tradeoffs on the usability side.
If you need a different asset path for your fallback file, you can simply add it as another argument for `FileEmojiCompatConfig`. This feature has been introduced in `1.0.7`.
**_PLEASE use at least this method in your app. It's always better to give the users a choice._**

0 comments on commit 866dbe9

Please sign in to comment.