diff --git a/emojicompat/FileMojiCompat/filemojicompat/build.gradle b/emojicompat/FileMojiCompat/filemojicompat/build.gradle index b1fc0a299..e53adb7b1 100644 --- a/emojicompat/FileMojiCompat/filemojicompat/build.gradle +++ b/emojicompat/FileMojiCompat/filemojicompat/build.gradle @@ -33,8 +33,8 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 27 - versionCode 11 - versionName "1.0.11" + versionCode 12 + versionName "1.0.12" } diff --git a/emojicompat/FileMojiCompat/filemojicompat/src/main/java/de/c1710/filemojicompat/AssetEmojiCompatConfig.java b/emojicompat/FileMojiCompat/filemojicompat/src/main/java/de/c1710/filemojicompat/AssetEmojiCompatConfig.java index ddf85e2b1..803df987d 100644 --- a/emojicompat/FileMojiCompat/filemojicompat/src/main/java/de/c1710/filemojicompat/AssetEmojiCompatConfig.java +++ b/emojicompat/FileMojiCompat/filemojicompat/src/main/java/de/c1710/filemojicompat/AssetEmojiCompatConfig.java @@ -23,15 +23,16 @@ import android.support.annotation.NonNull; import android.support.annotation.RequiresApi; import android.support.text.emoji.EmojiCompat; import android.support.text.emoji.MetadataRepo; -import android.util.Log; -import android.support.v4.util.Preconditions; /** * A simple implementation of EmojiCompat.Config using typeface assets. * 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. + * @deprecated Please use {@link FileEmojiCompatConfig#createFromAsset(Context, String)} instead + * for greater flexibility. */ +@Deprecated public class AssetEmojiCompatConfig extends EmojiCompat.Config { // The class name is obviously changed from the original file diff --git a/emojicompat/FileMojiCompat/filemojicompat/src/main/java/de/c1710/filemojicompat/FileEmojiCompatConfig.java b/emojicompat/FileMojiCompat/filemojicompat/src/main/java/de/c1710/filemojicompat/FileEmojiCompatConfig.java index 1ab579142..8ce3e60bb 100644 --- a/emojicompat/FileMojiCompat/filemojicompat/src/main/java/de/c1710/filemojicompat/FileEmojiCompatConfig.java +++ b/emojicompat/FileMojiCompat/filemojicompat/src/main/java/de/c1710/filemojicompat/FileEmojiCompatConfig.java @@ -55,6 +55,52 @@ public class FileEmojiCompatConfig extends EmojiCompat.Config { */ private static final String FONT_FALLBACK = "NoEmojiCompat.ttf"; + /** + * Creates a new FileEmojiCompatConfig based on an asset. + *

+ * This means that you can have the flexibility of {@link AssetEmojiCompatConfig} + * while giving your users the choice to optionally override the font. + *

+ * The default location for a substituting font is + * {@code /sdcard/Android/data/your.apps.package/files/EmojiCompat.ttf}. + * + * @param context The app's context is needed for several tasks + * @param assetPath The path inside the {@code assets} folder for the default font file + * @return A FileEmojiCompatConfig which will use the given font by default + */ + public FileEmojiCompatConfig createFromAsset(@NonNull Context context, + @Nullable String assetPath) { + if (assetPath != null) { + FileEmojiCompatConfig config = new FileEmojiCompatConfig(context, + new File(context.getExternalFilesDir(null), "EmojiCompat.ttf"), + assetPath); + config.replaceAllOnFallback = true; + return config; + } else { + return createFromAsset(context); + } + } + + /** + * Creates a new FileEmojiCompatConfig based on an asset. + *

+ * This means that you can have the flexibility of {@link AssetEmojiCompatConfig} + * while giving your users the choice to optionally override the font. + *

+ * The default location for a substituting font is + * {@code /sdcard/Android/data/your.apps.package/files/EmojiCompat.ttf}. + *

+ * The default name for the Assets font is {@code NoEmojiCompat.ttf}. + * If you wish to use a different name for this font, please use + * {@link #createFromAsset(Context, String)}. + * + * @param context The app's context is needed for several tasks + * @return A FileEmojiCompatConfig which will use the given font by default + */ + public FileEmojiCompatConfig createFromAsset(@NonNull Context context) { + return createFromAsset(context, FONT_FALLBACK); + } + /** * Create a new configuration for this EmojiCompat * @param path The file name/path of the requested font