From d8384bf9670463766f902c7b5345e6a57ce95e62 Mon Sep 17 00:00:00 2001 From: danesfeder Date: Wed, 23 Jan 2019 11:41:16 -0500 Subject: [PATCH] Provide default LocationComponent style when not found --- .../ui/v5/map/NavigationMapboxMap.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/map/NavigationMapboxMap.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/map/NavigationMapboxMap.java index 4d7329ab749..8b0040a4cd6 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/map/NavigationMapboxMap.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/map/NavigationMapboxMap.java @@ -6,6 +6,7 @@ import android.location.Location; import android.os.Bundle; import android.os.PersistableBundle; +import android.support.annotation.AnyRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.FragmentActivity; @@ -542,15 +543,26 @@ private void initializeLocationComponent(MapView mapView, MapboxMap map) { map.setMinZoomPreference(NAVIGATION_MINIMUM_MAP_ZOOM); map.setMaxZoomPreference(NAVIGATION_MAXIMUM_MAP_ZOOM); Context context = mapView.getContext(); - int locationLayerStyleRes = ThemeSwitcher.retrieveNavigationViewStyle(context, - R.attr.navigationViewLocationLayerStyle); - LocationComponentOptions locationComponentOptions = - LocationComponentOptions.createFromAttributes(context, locationLayerStyleRes); - locationComponent.activateLocationComponent(context, map.getStyle(), null, locationComponentOptions); + int locationLayerStyleRes = findLayerStyleRes(context); + LocationComponentOptions options = LocationComponentOptions.createFromAttributes(context, locationLayerStyleRes); + locationComponent.activateLocationComponent(context, map.getStyle(), null, options); locationComponent.setLocationComponentEnabled(true); locationComponent.setRenderMode(RenderMode.GPS); } + private int findLayerStyleRes(Context context) { + int locationLayerStyleRes = ThemeSwitcher.retrieveNavigationViewStyle(context, + R.attr.navigationViewLocationLayerStyle); + if (!isValid(locationLayerStyleRes)) { + locationLayerStyleRes = R.style.NavigationLocationLayerStyle; + } + return locationLayerStyleRes; + } + + private boolean isValid(@AnyRes int resId) { + return resId != -1 && (resId & 0xff000000) != 0 && (resId & 0x00ff0000) != 0; + } + private void initializeMapPaddingAdjustor(MapView mapView, MapboxMap mapboxMap) { mapPaddingAdjustor = new MapPaddingAdjustor(mapView, mapboxMap); }