Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public NavigationView(Context context, @Nullable AttributeSet attrs, int defStyl
*/
public void onCreate(@Nullable Bundle savedInstanceState) {
resumeState = savedInstanceState != null;
mapView.setStyleUrl(ThemeSwitcher.retrieveMapStyle(getContext()));
mapView.onCreate(savedInstanceState);
navigationViewModel.onCreate(resumeState);
}
Expand Down Expand Up @@ -213,19 +214,14 @@ public void onStop() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
map = mapboxMap;
ThemeSwitcher.setMapStyle(getContext(), map, new MapboxMap.OnStyleLoadedListener() {
@Override
public void onStyleLoaded(String style) {
initRoute();
initLocationLayer();
initMapPadding();
initLocationLayerObserver();
initNavigationPresenter();
initClickListeners();
map.addOnScrollListener(NavigationView.this);
onNavigationReadyCallback.onNavigationReady();
}
});
initRoute();
initLocationLayer();
initMapPadding();
initLocationLayerObserver();
initNavigationPresenter();
initClickListeners();
map.addOnScrollListener(NavigationView.this);
onNavigationReadyCallback.onNavigationReady();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.services.android.navigation.v5.navigation.NavigationConstants;

/**
Expand All @@ -29,7 +27,7 @@ public class ThemeSwitcher {
* @return color resource identifier for primary theme color
*/
public static int retrieveNavigationViewThemeColor(Context context, int resId) {
TypedValue outValue = obtainTypedValue(context, resId);
TypedValue outValue = resolveAttributeFromId(context, resId);
if (outValue.type >= TypedValue.TYPE_FIRST_COLOR_INT
&& outValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
return outValue.data;
Expand Down Expand Up @@ -71,16 +69,9 @@ static void setTheme(Context context, AttributeSet attrs) {
context.setTheme(darkThemeEnabled ? darkTheme : lightTheme);
}

/**
* Sets the {@link MapView} style based on the current theme setting.
*
* @param context to retrieve {@link SharedPreferences}
* @param map the style will be set on
*/
static void setMapStyle(Context context, MapboxMap map, MapboxMap.OnStyleLoadedListener listener) {
TypedValue mapStyleAttr = obtainTypedValue(context, R.attr.navigationViewMapStyle);
String styleUrl = mapStyleAttr.string.toString();
map.setStyleUrl(styleUrl, listener);
static String retrieveMapStyle(Context context) {
TypedValue mapStyleAttr = resolveAttributeFromId(context, R.attr.navigationViewMapStyle);
return mapStyleAttr.string.toString();
}

/**
Expand All @@ -90,7 +81,7 @@ static void setMapStyle(Context context, MapboxMap map, MapboxMap.OnStyleLoadedL
* @return {@link Icon} map marker dark or light
*/
static Icon retrieveMapMarker(Context context) {
TypedValue destinationMarkerResId = obtainTypedValue(context, R.attr.navigationViewDestinationMarker);
TypedValue destinationMarkerResId = resolveAttributeFromId(context, R.attr.navigationViewDestinationMarker);
int markerResId = destinationMarkerResId.resourceId;
IconFactory iconFactory = IconFactory.getInstance(context);
return iconFactory.fromResource(markerResId);
Expand All @@ -105,12 +96,12 @@ static Icon retrieveMapMarker(Context context) {
* @return resolved style resource Id
*/
static int retrieveNavigationViewStyle(Context context, int styleResId) {
TypedValue outValue = obtainTypedValue(context, styleResId);
TypedValue outValue = resolveAttributeFromId(context, styleResId);
return outValue.resourceId;
}

@NonNull
private static TypedValue obtainTypedValue(Context context, int resId) {
private static TypedValue resolveAttributeFromId(Context context, int resId) {
TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(resId, outValue, true);
return outValue;
Expand Down