Merge pull request #4924 from keymanapp/cherrypick/android/4905-dont-load-woff-on-n

fix(android/engine): Don't load woff fonts on Android N 🍒
This commit is contained in:
Darcy Wong 2021-04-20 12:49:20 +07:00 • committed by GitHub
commit 8f54b0c856
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1008,22 +1008,29 @@ public final class KMManager {
* Get the font typeface from a fully pathed font name
* @param context
* @param fontFilename String - full path to the font file
* @return Typeface
* @return Typeface - null if font file doesn't exist or is Woff on Android 7.0 / 7.1
*/
public static Typeface getFontTypeface(Context context, String fontFilename) {
Typeface font = null;
try {
if ((fontFilename != null) && FileUtils.hasFontExtension(fontFilename)) {
// Ignore .woff files if Android 7.0 / 7.1 (Issue #4896)
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) &&
(Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1) &&
fontFilename.toLowerCase().endsWith(FileUtils.WOFFFONT)) {
return null;
}
File file = new File(fontFilename);
if (file.exists()) {
font = Typeface.createFromFile(file);
return Typeface.createFromFile(file);
}
}
} catch (Exception e) {
KMLog.LogException(TAG, "Failed to create Typeface: " + fontFilename, e);
}
return font;
// No valid font to load
return null;
}
public static List<Keyboard> getKeyboardsList(Context context) {