Skip to content

Commit f07f10d

Browse files
committed
Add default style handling for ThemeSwitcher
1 parent 87036c8 commit f07f10d

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/ThemeSwitcher.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44
import android.content.SharedPreferences;
55
import android.content.res.Configuration;
6+
import android.content.res.Resources;
67
import android.content.res.TypedArray;
78
import android.graphics.drawable.Drawable;
89
import android.preference.PreferenceManager;
@@ -68,12 +69,17 @@ public static Drawable retrieveThemeOverviewDrawable(Context context) {
6869
* for the given resId set in the theme.
6970
*
7071
* @param context to retrieve the resolved attribute
71-
* @param styleResId for the given style
72+
* @param attributeId for the given style
7273
* @return resolved style resource Id
7374
*/
74-
public static int retrieveNavigationViewStyle(Context context, int styleResId) {
75-
TypedValue outValue = resolveAttributeFromId(context, styleResId);
76-
return outValue.resourceId;
75+
public static int retrieveNavigationViewResId(Context context, int attributeId, int defaultStyleId) {
76+
TypedValue outValue = new TypedValue();
77+
Resources.Theme theme = context.getTheme();
78+
if (theme.resolveAttribute(attributeId, outValue, true)) {
79+
return outValue.resourceId;
80+
} else {
81+
return defaultStyleId;
82+
}
7783
}
7884

7985
/**

libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/map/NavigationMapboxMap.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,11 @@ private void initializeLocationComponent(MapView mapView, MapboxMap map) {
551551
}
552552

553553
private int findLayerStyleRes(Context context) {
554-
int locationLayerStyleRes = ThemeSwitcher.retrieveNavigationViewStyle(context,
555-
R.attr.navigationViewLocationLayerStyle);
556-
if (locationLayerStyleRes == INVLAID_LAYER_STYLE) {
557-
locationLayerStyleRes = R.style.NavigationLocationLayerStyle;
558-
}
559-
return locationLayerStyleRes;
554+
return ThemeSwitcher.retrieveNavigationViewResId(
555+
context,
556+
R.attr.navigationViewLocationLayerStyle,
557+
R.style.NavigationLocationLayerStyle
558+
);
560559
}
561560

562561
private void initializeMapPaddingAdjustor(MapView mapView, MapboxMap mapboxMap) {
@@ -605,7 +604,9 @@ private Source findSourceByUrl(List<Source> sources, String streetsUrl) {
605604

606605
private void initializeRoute(MapView mapView, MapboxMap map) {
607606
Context context = mapView.getContext();
608-
int routeStyleRes = ThemeSwitcher.retrieveNavigationViewStyle(context, R.attr.navigationViewRouteStyle);
607+
int routeStyleRes = ThemeSwitcher.retrieveNavigationViewResId(
608+
context, R.attr.navigationViewRouteStyle, R.style.NavigationMapRoute
609+
);
609610
mapRoute = new NavigationMapRoute(null, mapView, map, routeStyleRes);
610611
}
611612

0 commit comments

Comments
 (0)