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

The following examples show how to use com.mapbox.services.android.navigation.v5.utils.LocaleUtils. 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
Source File: NavigationLauncherActivity.java    From graphhopper-navigation-example with Apache License 2.0 6 votes vote down vote up
@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 File: NavigationView.java    From graphhopper-navigation-android with 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 File: InstructionView.java    From graphhopper-navigation-android with 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
Source File: SummaryBottomSheet.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
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
Source File: NavigationViewModel.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
public NavigationViewModel(Application application) {
  super(application);
  this.accessToken = Mapbox.getAccessToken();
  initializeConnectivityManager(application);
  initializeNavigationRouteEngine();
  initializeNavigationLocationEngine();
  routeUtils = new RouteUtils();
  localeUtils = new LocaleUtils();
}
 
Example #6
Source File: NavigationLauncherActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@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 File: NavigationRoute.java    From graphhopper-navigation-android with 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
Source File: MapboxNavigationNotification.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
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 File: NavigationView.java    From graphhopper-navigation-android with 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 File: NavigationView.java    From graphhopper-navigation-android with 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 File: NavigationView.java    From graphhopper-navigation-android with 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 File: NavigationRoute.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
Builder language(Context context, LocaleUtils localeUtils) {
  directionsBuilder.language(localeUtils.inferDeviceLocale(context));
  return this;
}
 
Example #13
Source File: NavigationRoute.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
Builder voiceUnits(Context context, LocaleUtils localeUtils) {
  directionsBuilder.voiceUnits(localeUtils.getUnitTypeForDeviceLocale(context));
  return this;
}
 
Example #14
Source File: NaviBeeMapBoxNotification.java    From NaviBee with GNU General Public License v3.0 4 votes vote down vote up
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 File: NavigationRoute.java    From graphhopper-navigation-android with 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());
}