Java Code Examples for com.mapbox.services.android.navigation.v5.utils.LocaleUtils

The following examples show how to use com.mapbox.services.android.navigation.v5.utils.LocaleUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_launcher);
    Mapbox.getInstance(this.getApplicationContext(), getString(R.string.mapbox_access_token));
    Telemetry.disableOnUserRequest();
    ButterKnife.bind(this);
    mapView.setStyleUrl(getString(R.string.map_view_styleUrl));
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(this);
    localeUtils = new LocaleUtils();
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle("");
    }
    showFirstStartIfNecessary();
}
 
Example 2
Source Project: graphhopper-navigation-android   Source File: NavigationView.java    License: MIT License 5 votes vote down vote up
private void establishDistanceFormatter(LocaleUtils localeUtils, NavigationViewOptions options) {
  String unitType = establishUnitType(localeUtils, options);
  String language = establishLanguage(localeUtils, options);
  int roundingIncrement = establishRoundingIncrement(options);
  DistanceFormatter distanceFormatter = new DistanceFormatter(getContext(), language, unitType, roundingIncrement);

  instructionView.setDistanceFormatter(distanceFormatter);
  summaryBottomSheet.setDistanceFormatter(distanceFormatter);
}
 
Example 3
Source Project: graphhopper-navigation-android   Source File: InstructionView.java    License: MIT License 5 votes vote down vote up
/**
 * Inflates this layout needed for this view and initializes the locale as the device locale.
 */
private void initialize() {
  LocaleUtils localeUtils = new LocaleUtils();
  String language = localeUtils.inferDeviceLanguage(getContext());
  String unitType = localeUtils.getUnitTypeForDeviceLocale(getContext());
  int roundingIncrement = NavigationConstants.ROUNDING_INCREMENT_FIFTY;
  distanceFormatter = new DistanceFormatter(getContext(), language, unitType, roundingIncrement);
  inflate(getContext(), R.layout.instruction_view_layout, this);
}
 
Example 4
private void initializeDistanceFormatter() {
  LocaleUtils localeUtils = new LocaleUtils();
  String language = localeUtils.inferDeviceLanguage(getContext());
  String unitType = localeUtils.getUnitTypeForDeviceLocale(getContext());
  int roundingIncrement = NavigationConstants.ROUNDING_INCREMENT_FIFTY;
  distanceFormatter = new DistanceFormatter(getContext(), language, unitType, roundingIncrement);
}
 
Example 5
public NavigationViewModel(Application application) {
  super(application);
  this.accessToken = Mapbox.getAccessToken();
  initializeConnectivityManager(application);
  initializeNavigationRouteEngine();
  initializeNavigationLocationEngine();
  routeUtils = new RouteUtils();
  localeUtils = new LocaleUtils();
}
 
Example 6
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_navigation_launcher);
  ButterKnife.bind(this);
  mapView.onCreate(savedInstanceState);
  mapView.getMapAsync(this);
  localeUtils = new LocaleUtils();
}
 
Example 7
Source Project: graphhopper-navigation-android   Source File: NavigationRoute.java    License: MIT License 5 votes vote down vote up
static Builder builder(Context context, LocaleUtils localeUtils) {
  return new Builder()
    .annotations(DirectionsCriteria.ANNOTATION_CONGESTION, DirectionsCriteria.ANNOTATION_DISTANCE)
    .language(context, localeUtils)
    .voiceUnits(context, localeUtils)
    .profile(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC);
}
 
Example 8
private void initializeDistanceFormatter(Context context, MapboxNavigation mapboxNavigation) {
  RouteOptions routeOptions = mapboxNavigation.getRoute().routeOptions();
  LocaleUtils localeUtils = new LocaleUtils();
  String language = localeUtils.inferDeviceLanguage(context);
  String unitType = localeUtils.getUnitTypeForDeviceLocale(context);
  if (routeOptions != null) {
    language = routeOptions.language();
    unitType = routeOptions.voiceUnits();
  }
  MapboxNavigationOptions mapboxNavigationOptions = mapboxNavigation.options();
  distanceFormatter = new DistanceFormatter(context, language, unitType, mapboxNavigationOptions.roundingIncrement());
}
 
Example 9
Source Project: graphhopper-navigation-android   Source File: NavigationView.java    License: MIT License 4 votes vote down vote up
private void establish(NavigationViewOptions options) {
  LocaleUtils localeUtils = new LocaleUtils();

  establishDistanceFormatter(localeUtils, options);
  establishTimeFormat(options);
}
 
Example 10
Source Project: graphhopper-navigation-android   Source File: NavigationView.java    License: MIT License 4 votes vote down vote up
private String establishLanguage(LocaleUtils localeUtils, NavigationViewOptions options) {
  return localeUtils.getNonEmptyLanguage(getContext(), options.directionsRoute().voiceLanguage());
}
 
Example 11
Source Project: graphhopper-navigation-android   Source File: NavigationView.java    License: MIT License 4 votes vote down vote up
private String establishUnitType(LocaleUtils localeUtils, NavigationViewOptions options) {
  RouteOptions routeOptions = options.directionsRoute().routeOptions();
  String voiceUnits = routeOptions == null ? null : routeOptions.voiceUnits();
  return localeUtils.retrieveNonNullUnitType(getContext(), voiceUnits);
}
 
Example 12
Source Project: graphhopper-navigation-android   Source File: NavigationRoute.java    License: MIT License 4 votes vote down vote up
Builder language(Context context, LocaleUtils localeUtils) {
  directionsBuilder.language(localeUtils.inferDeviceLocale(context));
  return this;
}
 
Example 13
Source Project: graphhopper-navigation-android   Source File: NavigationRoute.java    License: MIT License 4 votes vote down vote up
Builder voiceUnits(Context context, LocaleUtils localeUtils) {
  directionsBuilder.voiceUnits(localeUtils.getUnitTypeForDeviceLocale(context));
  return this;
}
 
Example 14
private void initializeDistanceFormatter(Context context) {
    LocaleUtils localeUtils = new LocaleUtils();
    String language = localeUtils.inferDeviceLanguage(context);
    String unitType = localeUtils.getUnitTypeForDeviceLocale(context);
    distanceFormatter = new DistanceFormatter(context, language, unitType);
}
 
Example 15
Source Project: graphhopper-navigation-android   Source File: NavigationRoute.java    License: MIT License 2 votes vote down vote up
/**
 * Build a new {@link NavigationRoute} object with the proper navigation parameters already setup.
 *
 * @return a {@link Builder} object for creating this object
 * @since 0.5.0
 */
public static Builder builder(Context context) {
  return builder(context, new LocaleUtils());
}