summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2019-08-19 15:03:26 +0200
committertobrun <tobrun.van.nuland@gmail.com>2019-08-20 09:31:30 +0200
commitefbea9af4e883ccf60fc67fdf49e7a21268581a6 (patch)
treeb64bc5ad6037a3d12ef085a660b4203455978dae
parent71a334152ad0332f93ed4cc0d7af89e2eb689496 (diff)
downloadqtlocation-mapboxgl-upstream/tvn-lolipop-fonts.tar.gz
[android] provide default font list for pre lollipopupstream/tvn-lolipop-fonts
-rw-r--r--platform/android/CHANGELOG.md1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/FontUtils.java31
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/FontUtilsTest.java2
3 files changed, 25 insertions, 9 deletions
diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md
index b7f7fa2bd8..051be7c5bb 100644
--- a/platform/android/CHANGELOG.md
+++ b/platform/android/CHANGELOG.md
@@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to
### Bug fixes
- Fixed use of objects after moving, potentially causing crashes. [#15408](https://github.com/mapbox/mapbox-gl-native/pull/1540)
- Fixed a possible crash that could be caused by invoking the wrong layer implementation casting function [#15398](https://github.com/mapbox/mapbox-gl-native/pull/15398).
+ - Font lookup on pre lollipop devices failed, provide default font list instead [#15410](https://github.com/mapbox/mapbox-gl-native/pull/15410).
## 8.3.0-alpha.3 - August 15, 2019
[Changes](https://github.com/mapbox/mapbox-gl-native/compare/android-v8.3.0-alpha.2...android-v8.3.0-alpha.3) since [Mapbox Maps SDK for Android v8.3.0-alpha.2](https://github.com/mapbox/mapbox-gl-native/releases/tag/android-v8.3.0-alpha.2):
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/FontUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/FontUtils.java
index 09064ee168..627b342179 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/FontUtils.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/FontUtils.java
@@ -1,7 +1,8 @@
package com.mapbox.mapboxsdk.utils;
import android.graphics.Typeface;
-
+import android.os.Build;
+import android.support.annotation.RequiresApi;
import com.mapbox.mapboxsdk.MapStrictMode;
import com.mapbox.mapboxsdk.log.Logger;
@@ -18,6 +19,14 @@ import static com.mapbox.mapboxsdk.constants.MapboxConstants.DEFAULT_FONT;
public class FontUtils {
private static final String TAG = "Mbgl-FontUtils";
+ private static final String TYPEFACE_FONTMAP_FIELD_NAME = "sSystemFontMap";
+ private static final List<String> DEFAULT_FONT_STACKS = new ArrayList<>();
+
+ static {
+ DEFAULT_FONT_STACKS.add("sans-serif");
+ DEFAULT_FONT_STACKS.add("serif");
+ DEFAULT_FONT_STACKS.add("monospace");
+ }
private FontUtils() {
// no instance
@@ -34,7 +43,13 @@ public class FontUtils {
return null;
}
- List<String> validFonts = getAvailableFonts();
+ List<String> validFonts;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ validFonts = getDeviceFonts();
+ } else {
+ validFonts = DEFAULT_FONT_STACKS;
+ }
+
for (String fontName : fontNames) {
if (validFonts.contains(fontName)) {
return fontName;
@@ -47,16 +62,18 @@ public class FontUtils {
return DEFAULT_FONT;
}
- private static List<String> getAvailableFonts() {
+ @SuppressWarnings( {"JavaReflectionMemberAccess", "unchecked"})
+ @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
+ private static List<String> getDeviceFonts() {
List<String> fonts = new ArrayList<>();
try {
Typeface typeface = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL);
- Field f = Typeface.class.getDeclaredField("sSystemFontMap");
- f.setAccessible(true);
- Map<String, Typeface> fontMap = (Map<String, Typeface>) f.get(typeface);
+ Field field = Typeface.class.getDeclaredField(TYPEFACE_FONTMAP_FIELD_NAME);
+ field.setAccessible(true);
+ Map<String, Typeface> fontMap = (Map<String, Typeface>) field.get(typeface);
fonts.addAll(fontMap.keySet());
} catch (Exception exception) {
- Logger.e(TAG,"Couldn't load fonts from Typeface", exception);
+ Logger.e(TAG, "Couldn't load fonts from Typeface", exception);
MapStrictMode.strictModeViolation("Couldn't load fonts from Typeface", exception);
}
return fonts;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/FontUtilsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/FontUtilsTest.java
index 694215d16f..fa068cb973 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/FontUtilsTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/utils/FontUtilsTest.java
@@ -1,9 +1,7 @@
package com.mapbox.mapboxsdk.utils;
import android.support.test.runner.AndroidJUnit4;
-
import com.mapbox.mapboxsdk.constants.MapboxConstants;
-
import org.junit.Test;
import org.junit.runner.RunWith;