Skip to content

Commit

Permalink
Merge branch 'master' into tvn-upgrade-androidx
Browse files Browse the repository at this point in the history
  • Loading branch information
Langston Smith authored Jan 8, 2020
2 parents 9aa84da + 93da3e6 commit fbc9a1e
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public abstract class BannerComponents extends DirectionsJsonObject
*/
public static final String LANE = "lane";

/**
* This view gives guidance through junctions and is used to complete maneuvers.
*
* @since 5.0.0
*/
public static final String GUIDANCE_VIEW = "guidance-view";

/**
* Banner component types.
* https://docs.mapbox.com/api/navigation/#banner-instruction-object
Expand All @@ -83,7 +90,8 @@ public abstract class BannerComponents extends DirectionsJsonObject
DELIMITER,
EXIT_NUMBER,
EXIT,
LANE
LANE,
GUIDANCE_VIEW
})
public @interface BannerComponentsType {
}
Expand Down Expand Up @@ -171,6 +179,18 @@ public static Builder builder() {
@SerializedName("imageBaseURL")
public abstract String imageBaseUrl();

/**
* In some cases when the {@link StepManeuver} will be difficult to navigate, an image
* can describe how to proceed. The domain name for this image is a Junction View.
* Unlike the imageBaseUrl, this image url does not include image density encodings.
*
* @return the url which can be used to download the image.
* @since 5.0.0
*/
@Nullable
@SerializedName("imageURL")
public abstract String imageUrl();

/**
* A List of directions indicating which way you can go from a lane
* (left, right, or straight). If the value is ['left', 'straight'],
Expand Down Expand Up @@ -333,6 +353,17 @@ public abstract static class Builder {
*/
public abstract Builder imageBaseUrl(@Nullable String imageBaseUrl);

/**
* In some cases when the {@link StepManeuver} will be difficult to navigate, an image
* can describe how to proceed. The domain name for this image is a Junction View.
* Unlike the imageBaseUrl, this image url does not include image density encodings.
*
* @param imageUrl the url which can be used to download the image
* @return this builder for chaining options together
* @since 5.0.0
*/
public abstract Builder imageUrl(@Nullable String imageUrl);

/**
* A List of directions indicating which way you can go from a lane
* (left, right, or straight). If the value is ['left', 'straight'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,24 @@ public static Builder builder() {
* Can include information about the next maneuver (the one after the upcoming one),
* if the step is short - can be null, or can be lane information.
* If we have lane information, that trumps information about the next maneuver.
*
* @return {@link BannerText} representing the sub visual information
* @since 3.2.0
*/
@Nullable
public abstract BannerText sub();

/**
* Optional image to display for an upcoming maneuver. Used to provide a visual
* for complex junctions and maneuver. If the step is short the image should be displayed
* for the duration of the step, otherwise it is shown as you approach the maneuver.
*
* @return {@link BannerView} representing the secondary visual information
* @since 5.0.0
*/
@Nullable
public abstract BannerView view();

/**
* Convert the current {@link BannerInstructions} to its builder holding the currently assigned
* values. This allows you to modify a single property and then rebuild the object resulting in
Expand All @@ -92,7 +104,6 @@ public static TypeAdapter<BannerInstructions> typeAdapter(Gson gson) {
return new AutoValue_BannerInstructions.GsonTypeAdapter(gson);
}


/**
* Create a new instance of this class by passing in a formatted valid JSON String.
*
Expand Down Expand Up @@ -150,12 +161,24 @@ public abstract static class Builder {
* Can include information about the next maneuver (the one after the upcoming one),
* if the step is short - can be null, or can be lane information.
* If we have lane information, that trumps information about the next maneuver.
*
* @param sub {@link BannerText} representing the sub visual information
* @return {@link BannerText} representing the sub visual information
* @since 3.2.0
*/
public abstract Builder sub(@Nullable BannerText sub);

/**
* Optional image to display for an upcoming maneuver. Used to provide a visual
* for complex junctions and maneuver. If the step is short the image should be displayed
* for the duration of the step, otherwise it is shown as you approach the maneuver.
*
* @param view {@link BannerView} representing the sub visual information
* @return this builder for chaining options together
* @since 5.0.0
*/
public abstract Builder view(@Nullable BannerView view);

/**
* Build a new {@link BannerInstructions} object.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package com.mapbox.api.directions.v5.models;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.google.auto.value.AutoValue;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
import com.mapbox.api.directions.v5.MapboxDirections;

import java.util.List;

/**
* Includes both plain text information that can be visualized inside your navigation application
* along with the text string broken down into {@link BannerComponents} which may or may not
* include a image url. To receive this information, your request must have
* {@link MapboxDirections#bannerInstructions()} set to true.
*
* @since 5.0.0
*/
@AutoValue
public abstract class BannerView extends DirectionsJsonObject {

/**
* Create a new instance of this class by using the {@link Builder} class.
*
* @return this classes {@link Builder} for creating a new instance
* @since 5.0.0
*/
public static Builder builder() {
return new AutoValue_BannerView.Builder();
}

/**
* Plain text with all the {@link BannerComponents} text combined.
*
* @return plain text with all the {@link BannerComponents} text items combined
* @since 5.0.0
*/
@NonNull
public abstract String text();

/**
* A part or element of the {@link BannerInstructions}.
*
* @return a {@link BannerComponents} specific to a {@link LegStep}
* @since 5.0.0
*/
@Nullable
public abstract List<BannerComponents> components();

/**
* This indicates the type of maneuver.
*
* @return String with type of maneuver
* @see StepManeuver.StepManeuverType
* @since 5.0.0
*/
@Nullable
@StepManeuver.StepManeuverType
public abstract String type();

/**
* This indicates the mode of the maneuver. If type is of turn, the modifier indicates the
* change in direction accomplished through the turn. If the type is of depart/arrive, the
* modifier indicates the position of waypoint from the current direction of travel.
*
* @return String with modifier
* @since 5.0.0
*/
@Nullable
public abstract String modifier();

/**
* Convert the current {@link BannerView} to its builder holding the currently assigned
* values. This allows you to modify a single property and then rebuild the object resulting in
* an updated and modified {@link BannerView}.
*
* @return a {@link BannerView.Builder} with the same values set to match the ones defined
* in this {@link BannerView}
* @since 5.0.0
*/
public abstract BannerView.Builder toBuilder();

/**
* Gson type adapter for parsing Gson to this class.
*
* @param gson the built {@link Gson} object
* @return the type adapter for this class
* @since 5.0.0
*/
public static TypeAdapter<BannerView> typeAdapter(Gson gson) {
return new AutoValue_BannerView.GsonTypeAdapter(gson);
}

/**
* Create a new instance of this class by passing in a formatted valid JSON String.
*
* @param json a formatted valid JSON string defining a BannerText
* @return a new instance of this class defined by the values passed inside this static factory
* method
* @since 5.0.0
*/
public static BannerView fromJson(String json) {
GsonBuilder gson = new GsonBuilder();
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
return gson.create().fromJson(json, BannerView.class);
}

/**
* This builder can be used to set the values describing the {@link BannerView}.
*
* @since 5.0.0
*/
@AutoValue.Builder
public abstract static class Builder {

/**
* Plain text with all the {@link BannerComponents} text combined.
*
* @param text plain text with all the {@link BannerComponents} text items combined
* @return this builder for chaining options together
* @since 5.0.0
*/
public abstract Builder text(@NonNull String text);

/**
* A part or element of the {@link BannerInstructions}.
*
* @param components a {@link BannerComponents} specific to a {@link LegStep}
* @return this builder for chaining options together
* @since 5.0.0
*/
public abstract Builder components(List<BannerComponents> components);

/**
* This indicates the type of maneuver. See {@link BannerView#type()} for a full list of
* options.
*
* @param type String with type of maneuver
* @return this builder for chaining options together
* @see StepManeuver.StepManeuverType
* @since 5.0.0
*/
public abstract Builder type(@Nullable @StepManeuver.StepManeuverType String type);

/**
* This indicates the mode of the maneuver. If type is of turn, the modifier indicates the
* change in direction accomplished through the turn. If the type is of depart/arrive, the
* modifier indicates the position of waypoint from the current direction of travel.
*
* @param modifier String with modifier
* @return this builder for chaining options together
* @since 5.0.0
*/
public abstract Builder modifier(@Nullable String modifier);

/**
* Build a new {@link BannerView} object.
*
* @return a new {@link BannerView} using the provided values in this builder
* @since 5.0.0
*/
public abstract BannerView build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.mapbox.api.directions.v5.models;

import org.junit.Assert;
import org.junit.Test;

import static org.junit.Assert.assertNotNull;

public class JunctionViewResponseTest {

private static final String BANNER_INSTRUCTION_JSON = "{\"distanceAlongGeometry\":139.2,\"primary\":{\"text\":\"E23\",\"components\":[{\"text\":\"E23\",\"type\":\"icon\"}],\"type\":\"fork\",\"modifier\":\"right\"},\"secondary\":{\"text\":\"東名阪自動車道 / 亀山 / 四日市 / 東名阪自動車道\",\"components\":[{\"text\":\"東名阪自動車道\",\"type\":\"text\"},{\"text\":\"/\",\"type\":\"text\"},{\"text\":\"亀山\",\"type\":\"text\"},{\"text\":\"/\",\"type\":\"text\"},{\"text\":\"四日市\",\"type\":\"text\"},{\"text\":\"/\",\"type\":\"text\"},{\"text\":\"東名阪自動車道\",\"type\":\"text\"}],\"type\":\"fork\",\"modifier\":\"right\"},\"view\":{\"text\":\"CA01610_1_E\",\"components\":[{\"text\":\"CA01610_1_E\",\"type\":\"guidance-view\",\"imageURL\":\"https://api-turn-here-staging-451578336.us-east-1.elb.amazonaws.com/guidance-views/v1/z/jct/CA01610_1_E\"}],\"type\":\"fork\",\"modifier\":\"right\"}}";

@Test
public void shouldReadBannerInstruction() {
BannerInstructions response = BannerInstructions.fromJson(BANNER_INSTRUCTION_JSON);
assertNotNull(response);
}

@Test
public void fromtestToFromJson() {
BannerInstructions responseFromJson1 = BannerInstructions.fromJson(BANNER_INSTRUCTION_JSON);

String jsonString = responseFromJson1.toJson();
BannerInstructions responseFromJson2 = BannerInstructions.fromJson(jsonString);

Assert.assertEquals(responseFromJson1, responseFromJson2);
Assert.assertEquals(responseFromJson2, responseFromJson1);
}

@Test
public void testValuesFromJson() {
BannerInstructions responseFromJson = BannerInstructions.fromJson(BANNER_INSTRUCTION_JSON);

BannerView bannerView = responseFromJson.view();
Assert.assertEquals(bannerView.text(), "CA01610_1_E");
Assert.assertEquals(bannerView.type(), StepManeuver.FORK);
Assert.assertEquals(bannerView.modifier(), "right");

Assert.assertEquals(responseFromJson.view().components().size(), 1);
BannerComponents bannerComponent = responseFromJson.view().components().get(0);
Assert.assertEquals(bannerComponent.text(), "CA01610_1_E");
Assert.assertEquals(bannerComponent.type(), BannerComponents.GUIDANCE_VIEW);
Assert.assertEquals(bannerComponent.imageUrl(), "https://api-turn-here-staging-451578336.us-east-1.elb.amazonaws.com/guidance-views/v1/z/jct/CA01610_1_E");
}
}

0 comments on commit fbc9a1e

Please sign in to comment.