Update README.md

This commit is contained in:
Constantin A 2018-05-05 16:21:15 +02:00 committed by GitHub
parent e7c8f303a4
commit 52abbd5844
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,7 @@ EmojiCompat fonts which are stored anywhere on the device's local storage.
## How do I get this library?
That's relatively easy: Just add the following line to your module's `build.gradle` inside `dependencies`:
```
implementation 'de.c1710:filemojicompat:1.0.1'
implementation 'de.c1710:filemojicompat:1.0.6'
```
## How do I use it?
There are two different methods included in this library:
@ -18,17 +18,17 @@ There are two different methods included in this library:
EmojiCompat.Config config = new AssetEmojiCompatConfig(getContext(), "Blobmoji.ttf");
```
This will create a new EmojiCompat configuration using the file provided in `assets/Blobmoji.ttf`.
2. ### [`FileEmojiCOmpatConfig`](https://github.com/C1710/blobmoji/blob/filemojicompat/emojicompat/FileMojiCompat/filemojicompat/src/main/java/de/c1710/filemojicompat/FileEmojiCompatConfig.java)
2. ### [`FileEmojiCompatConfig`](https://github.com/C1710/blobmoji/blob/filemojicompat/emojicompat/FileMojiCompat/filemojicompat/src/main/java/de/c1710/filemojicompat/FileEmojiCompatConfig.java)
This is the more complex and interesting option.
Instead of providing a short String containing the font's name, you can provide a [`File`](https://developer.android.com/reference/java/io/File)
(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.
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:
```java
Context context = getContext();
File fontFile = new File(context.getExternalFilesDir(null), "emoji/Blobmoji.ttf"),
File fontFile = new File(context.getExternalFilesDir(null), "emoji/Blobmoji.ttf");
EmojiCompat.Config config = new FileEmojiCompatConfig(context, fontFile);
```
In this example, your app would try to load the font file `Blobmoji.ttf` located at `/storage/emulated/0/Android/data/[your.app.package]/files/Blobmoji.ttf`.
@ -46,10 +46,25 @@ To prevent this case, `FileEmojiCompatConfig` includes a fallback solution - ins
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](https://github.com/googlei18n/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?
#### 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.
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)`.
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:
```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.
This method combines the easy approach of `AssetEmojiCompatConfig` and the flexibility of `FileEmojiCompatConfig` with some tradeoffs on the usability side.
**_PLEASE use at least this method in your app. It's always better to give the users a choice._**