Java Code Examples for com.mapbox.core.utils.TextUtils#isEmpty()

The following examples show how to use com.mapbox.core.utils.TextUtils#isEmpty() . 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: NavigationTelemetry.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void validateAccessToken(String accessToken) {
  if (TextUtils.isEmpty(accessToken) || (!accessToken.toLowerCase(Locale.US).startsWith("pk.")
    && !accessToken.toLowerCase(Locale.US).startsWith("sk."))) {
    throw new NavigationException("A valid access token must be passed in when first initializing"
      + " MapboxNavigation");
  }
}
 
Example 2
Source File: MapboxSpeech.java    From mapbox-java with MIT License 5 votes vote down vote up
/**
 * This uses the provided parameters set using the {@link Builder} and first checks that all
 * values are valid, formats the values as strings for easier consumption by the API, and lastly
 * creates a new {@link MapboxSpeech} object with the values provided.
 *
 * @return a new instance of Mapbox Speech
 * @throws ServicesException when a provided parameter is detected to be incorrect
 * @since 3.0.0
 */
public MapboxSpeech build() {
  MapboxSpeech mapboxSpeech = autoBuild();

  if (TextUtils.isEmpty(mapboxSpeech.instruction())) {
    throw new ServicesException("Non-null, non-empty instruction text is required.");
  }

  return mapboxSpeech;
}
 
Example 3
Source File: TurnLaneView.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);

  if (isInEditMode()) {
    LanesStyleKit.drawLaneStraight(canvas, primaryColor, size);
    return;
  }

  if (drawData == null || TextUtils.isEmpty(drawData.getDrawMethod())) {
    return;
  }

  switch (drawData.getDrawMethod()) {
    case DRAW_LANE_STRAIGHT:
      LanesStyleKit.drawLaneStraight(canvas, primaryColor, size);
      break;
    case DRAW_LANE_UTURN:
      LanesStyleKit.drawLaneUturn(canvas, primaryColor, size);
      break;
    case DRAW_LANE_RIGHT:
      LanesStyleKit.drawLaneRight(canvas, primaryColor, size);
      break;
    case DRAW_LANE_SLIGHT_RIGHT:
      LanesStyleKit.drawLaneSlightRight(canvas, primaryColor, size);
      break;
    case DRAW_LANE_RIGHT_ONLY:
      LanesStyleKit.drawLaneRightOnly(canvas, primaryColor, secondaryColor, size);
      break;
    case DRAW_LANE_STRAIGHT_RIGHT:
      LanesStyleKit.drawLaneStraightRight(canvas, primaryColor, size);
      break;
    case DRAW_LANE_STRAIGHT_ONLY:
      LanesStyleKit.drawLaneStraightOnly(canvas, primaryColor, secondaryColor, size);
      break;
    default:
      LanesStyleKit.drawLaneStraight(canvas, primaryColor, size);
      break;
  }

  // Set alpha based on validity
  setAlpha(!isValid ? 0.4f : 1.0f);

  // Flip if needed
  setScaleX(drawData.shouldBeFlipped() ? -1 : 1);
}
 
Example 4
Source File: InstructionLoader.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
private boolean hasAbbreviation(BannerComponents components) {
  return !TextUtils.isEmpty(components.abbreviation());
}
 
Example 5
Source File: InstructionLoader.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
private boolean hasImageUrl(BannerComponents components) {
  return !TextUtils.isEmpty(components.imageBaseUrl());
}
 
Example 6
Source File: MapboxIsochrone.java    From mapbox-java with MIT License 4 votes vote down vote up
/**
 * Build a new {@link MapboxIsochrone} object.
 *
 * @return this builder for chaining options together
 * @since 4.6.0
 */
public MapboxIsochrone build() {

  if (contoursMinutes != null) {
    if (contoursMinutes.length < 1) {
      throw new ServicesException("A query with at least one specified "
        + "minute amount is required.");
    }

    if (contoursMinutes.length >= 2) {
      for (int x = 0; x < contoursMinutes.length - 1; x++) {
        if (contoursMinutes[x] > contoursMinutes[x + 1]) {
          throw new ServicesException("The minutes must be listed"
            + " in order from the lowest number to the highest number.");
        }
      }
    }
    contoursMinutes(TextUtils.join(",", contoursMinutes));
  }

  if (contoursColors != null) {
    contoursColors(TextUtils.join(",", contoursColors));
  }

  if (contoursColors != null
    && contoursMinutes != null
    && contoursColors.length != contoursMinutes.length) {
    throw new ServicesException("Number of color elements "
      + "must match number of minute elements provided.");
  }

  MapboxIsochrone isochrone = autoBuild();

  if (!MapboxUtils.isAccessTokenValid(isochrone.accessToken())) {
    throw new ServicesException("Using the Mapbox Isochrone API requires setting "
      + "a valid access token.");
  }

  if (TextUtils.isEmpty(isochrone.coordinates())) {
    throw new ServicesException("A query with longitude and latitude values is "
      + "required.");
  }

  if (TextUtils.isEmpty(isochrone.profile())) {
    throw new ServicesException("A query with a set Directions profile (cycling,"
      + " walking, or driving) is required.");
  }

  if (TextUtils.isEmpty(isochrone.contoursMinutes())) {
    throw new ServicesException("A query with at least one specified minute amount"
      + " is required.");
  }

  if (isochrone.contoursColors() != null) {
    if (isochrone.contoursColors().contains("#")) {
      throw new ServicesException("Make sure that none of the contour color HEX"
        + " values have a # in front of it. Provide a list of the HEX values "
        + "without any # symbols.");
    }
  }
  return isochrone;
}
 
Example 7
Source File: MapboxGeocoding.java    From mapbox-java with MIT License 4 votes vote down vote up
/**
 * Build a new {@link MapboxGeocoding} object.
 *
 * @return a new {@link MapboxGeocoding} using the provided values in this builder
 * @since 3.0.0
 */
public MapboxGeocoding build() {

  if (!countries.isEmpty()) {
    country(TextUtils.join(",", countries.toArray()));
  }

  if (intersectionStreets.size() == 2) {
    query(TextUtils.join(" and ", intersectionStreets.toArray()));
    geocodingTypes(GeocodingCriteria.TYPE_ADDRESS);
  }

  // Generate build so that we can check that values are valid.
  MapboxGeocoding geocoding = autoBuild();

  if (!MapboxUtils.isAccessTokenValid(geocoding.accessToken())) {
    throw new ServicesException("Using Mapbox Services requires setting a valid access token.");
  }
  if (geocoding.query().isEmpty()) {
    throw new ServicesException("A query with at least one character or digit is required.");
  }

  if (geocoding.reverseMode() != null
    && geocoding.limit() != null && !geocoding.limit().equals("1")) {
    throw new ServicesException("Limit must be combined with a single type parameter");
  }

  if (intersectionStreets.size() == 2) {
    if (!(geocoding.mode().equals(GeocodingCriteria.MODE_PLACES)
            || geocoding.mode().equals(GeocodingCriteria.MODE_PLACES_PERMANENT))) {
      throw new ServicesException("Geocoding mode must be GeocodingCriteria.MODE_PLACES "
              + "or GeocodingCriteria.MODE_PLACES_PERMANENT for intersection search.");
    }
    if (TextUtils.isEmpty(geocoding.geocodingTypes())
            || !geocoding.geocodingTypes().equals(GeocodingCriteria.TYPE_ADDRESS)) {
      throw new ServicesException("Geocoding type must be set to Geocoding "
              + "Criteria.TYPE_ADDRESS for intersection search.");
    }
    if (TextUtils.isEmpty(geocoding.proximity())) {
      throw new ServicesException("Geocoding proximity must be set for intersection search.");
    }
  }
  return geocoding;
}
 
Example 8
Source File: RouteUtils.java    From graphhopper-navigation-android with MIT License 2 votes vote down vote up
/**
 * Checks if the {@link String} route profile provided is a valid profile
 * that can be used with the directions API.
 *
 * @param routeProfile being validated
 * @return true if valid, false if not
 * @since 0.13.0
 */
public boolean isValidRouteProfile(String routeProfile) {
  return !TextUtils.isEmpty(routeProfile) && VALID_PROFILES.contains(routeProfile);
}