Skip to content

Commit

Permalink
Add enable / disable off route detections to Launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Mar 26, 2018
1 parent 1ec5fa9 commit fabfe57
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,18 @@ protected void onDestroy() {

@Override
public void onNavigationReady() {
MapboxNavigationOptions.Builder navigationOptions = MapboxNavigationOptions.builder();
NavigationViewOptions.Builder options = NavigationViewOptions.builder();
options.navigationListener(this);
if (!isRunning) {
extractRoute(options);
extractCoordinates(options);
}
extractConfiguration(options);
extractLocale(options);
extractConfiguration(options, navigationOptions);
extractLocale(navigationOptions);
extractUnitType(navigationOptions);

options.navigationOptions(navigationOptions.build());
navigationView.startNavigation(options.build());
isRunning = true;
}
Expand Down Expand Up @@ -114,22 +118,23 @@ private void extractCoordinates(NavigationViewOptions.Builder options) {
}
}

private void extractConfiguration(NavigationViewOptions.Builder options) {
private void extractConfiguration(NavigationViewOptions.Builder options,
MapboxNavigationOptions.Builder navigationOptions) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
options.awsPoolId(preferences
.getString(NavigationConstants.NAVIGATION_VIEW_AWS_POOL_ID, null));
options.shouldSimulateRoute(preferences
.getBoolean(NavigationConstants.NAVIGATION_VIEW_SIMULATE_ROUTE, false));
options.directionsProfile(preferences
.getString(NavigationConstants.NAVIGATION_VIEW_ROUTE_PROFILE_KEY, ""));
navigationOptions.enableOffRouteDetection(preferences
.getBoolean(NavigationConstants.NAVIGATION_VIEW_OFF_ROUTE_ENABLED_KEY, true));
}

private void extractLocale(NavigationViewOptions.Builder options) {
private void extractLocale(MapboxNavigationOptions.Builder navigationOptions) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

String country = preferences.getString(NavigationConstants.NAVIGATION_VIEW_LOCALE_COUNTRY, "");
String language = preferences.getString(NavigationConstants.NAVIGATION_VIEW_LOCALE_LANGUAGE, "");
int unitType = preferences.getInt(NavigationConstants.NAVIGATION_VIEW_UNIT_TYPE, NONE_SPECIFIED);

Locale locale;
if (!language.isEmpty()) {
Expand All @@ -138,10 +143,12 @@ private void extractLocale(NavigationViewOptions.Builder options) {
locale = LocaleUtils.getDeviceLocale(this);
}

MapboxNavigationOptions navigationOptions = MapboxNavigationOptions.builder()
.locale(locale)
.unitType(unitType)
.build();
options.navigationOptions(navigationOptions);
navigationOptions.locale(locale);
}

private void extractUnitType(MapboxNavigationOptions.Builder navigationOptions) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
int unitType = preferences.getInt(NavigationConstants.NAVIGATION_VIEW_UNIT_TYPE, NONE_SPECIFIED);
navigationOptions.unitType(unitType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private static void storeConfiguration(NavigationLauncherOptions options, Shared
editor.putString(NavigationConstants.NAVIGATION_VIEW_AWS_POOL_ID, options.awsPoolId());
editor.putBoolean(NavigationConstants.NAVIGATION_VIEW_SIMULATE_ROUTE, options.shouldSimulateRoute());
editor.putString(NavigationConstants.NAVIGATION_VIEW_ROUTE_PROFILE_KEY, options.directionsProfile());
editor.putBoolean(NavigationConstants.NAVIGATION_VIEW_OFF_ROUTE_ENABLED_KEY, options.enableOffRouteDetection());
}

private static void storeThemePreferences(NavigationLauncherOptions options, SharedPreferences.Editor editor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public abstract class NavigationLauncherOptions extends NavigationOptions {
@Nullable
public abstract Integer unitType();

public abstract boolean enableOffRouteDetection();

@AutoValue.Builder
public abstract static class Builder {

Expand All @@ -42,12 +44,15 @@ public abstract static class Builder {

public abstract Builder unitType(@NavigationUnitType.UnitType Integer unitType);

public abstract Builder enableOffRouteDetection(boolean enableOffRouteDetection);

public abstract NavigationLauncherOptions build();
}

public static NavigationLauncherOptions.Builder builder() {
return new AutoValue_NavigationLauncherOptions.Builder()
.awsPoolId(null)
.shouldSimulateRoute(false);
.shouldSimulateRoute(false)
.enableOffRouteDetection(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ private NavigationConstants() {
public static final String NAVIGATION_VIEW_UNIT_TYPE = "navigation_view_unit_type";
public static final String NAVIGATION_VIEW_SIMULATE_ROUTE = "navigation_view_simulate_route";
public static final String NAVIGATION_VIEW_ROUTE_PROFILE_KEY = "navigation_view_route_profile";
public static final String NAVIGATION_VIEW_OFF_ROUTE_ENABLED_KEY = "navigation_view_off_route_enabled";
public static final String NAVIGATION_VIEW_LOCALE_LANGUAGE = "navigation_view_locale_language";
public static final String NAVIGATION_VIEW_LOCALE_COUNTRY = "navigation_view_locale_country";
public static final String NAVIGATION_VIEW_REROUTING = "Rerouting";
Expand Down

0 comments on commit fabfe57

Please sign in to comment.