Skip to content

Commit 532e7b9

Browse files
committed
add support for mapbox shield
1 parent 518e883 commit 532e7b9

5 files changed

Lines changed: 215 additions & 1 deletion

File tree

gradle/dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ext {
1111
mockito : '2.28.2',
1212
hamcrestJunit : '2.0.0.0',
1313
googleTruth : '1.0.1',
14-
errorprone : '2.3.1',
14+
errorprone : '2.3.3',
1515
]
1616

1717
pluginVersion = [

services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/BannerComponents.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ public static Builder builder() {
215215
@SerializedName("imageBaseURL")
216216
public abstract String imageBaseUrl();
217217

218+
/**
219+
* In some cases when the {@link LegStep} is a highway or major roadway, there might be a shield
220+
* icon that's included to better identify to your user to roadway. Note that this doesn't
221+
* return the image itself but rather a complex object that can used to formulate the url which
222+
* in turn would be used to make a network request and download a file.
223+
*
224+
* @return a complex object which can be used to download the shield icon if one is available
225+
* @since 3.0.0
226+
*/
227+
@Nullable
228+
@SerializedName("mapbox_shield")
229+
public abstract MapboxShield mapboxShield();
230+
218231
/**
219232
* In some cases when the {@link StepManeuver} will be difficult to navigate, an image
220233
* can describe how to proceed. The domain name for this image is a Junction View.
@@ -422,6 +435,17 @@ public abstract static class Builder {
422435
*/
423436
public abstract Builder imageBaseUrl(@Nullable String imageBaseUrl);
424437

438+
/**
439+
* In some cases when the {@link LegStep} is a highway or major roadway, there might be a shield
440+
* icon that's included to better identify to your user to roadway. Note that this doesn't
441+
* return the image itself but rather a complex object that can used to formulate the url which
442+
* in turn would be used to make a network request and download a file.
443+
*
444+
* @param mapboxShield an object which can be used to download the shield icon if available
445+
* @return this builder for chaining options together
446+
*/
447+
public abstract Builder mapboxShield(@Nullable MapboxShield mapboxShield);
448+
425449
/**
426450
* In some cases when the {@link StepManeuver} will be difficult to navigate, an image
427451
* can describe how to proceed. The domain name for this image is a Junction View.
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package com.mapbox.api.directions.v5.models;
2+
3+
import com.google.auto.value.AutoValue;
4+
import com.google.gson.Gson;
5+
import com.google.gson.GsonBuilder;
6+
import com.google.gson.TypeAdapter;
7+
import com.google.gson.annotations.SerializedName;
8+
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
9+
10+
/**
11+
* A part of the {@link BannerComponents} which includes a snippet of the route shield associated
12+
* with the instruction. In cases where data is available, a base url will be provided to help in
13+
* constructing an actual URL that can then be used to fetch a shield in the form of SVG.
14+
* To receive this information, your request must have
15+
* <tt>MapboxDirections.Builder#bannerInstructions()</tt> set to true.
16+
*/
17+
@AutoValue
18+
public abstract class MapboxShield extends DirectionsJsonObject {
19+
/**
20+
* Create a new instance of this class by using the {@link Builder} class.
21+
*
22+
* @return {@link Builder} for creating a new instance
23+
*/
24+
public static Builder builder() {
25+
return new AutoValue_MapboxShield.Builder();
26+
}
27+
28+
/**
29+
* Base url to query the styles endpoint.
30+
*
31+
* @return base url to query the styles endpoint
32+
*/
33+
@SerializedName("base_url")
34+
public abstract String baseUrl();
35+
36+
/**
37+
* String indicating the name of the route shield.
38+
*
39+
* @return name of the route shield
40+
*/
41+
public abstract String name();
42+
43+
/**
44+
* String indicating the color of the text to be rendered on the route shield.
45+
*
46+
* @return String color of the text to be rendered on the route shield
47+
*/
48+
@SerializedName("text_color")
49+
public abstract String textColor();
50+
51+
/**
52+
* String indicating the display ref.
53+
*
54+
* @return String display ref
55+
*/
56+
@SerializedName("display_ref")
57+
public abstract String displayRef();
58+
59+
/**
60+
* Convert the current {@link MapboxShield} to its builder holding the currently assigned
61+
* values. This allows you to modify a single property and then rebuild the object resulting in
62+
* an updated and modified {@link MapboxShield}.
63+
*
64+
* @return a {@link Builder} with the same values set to match the ones defined
65+
* in this {@link MapboxShield}
66+
* @since 3.1.0
67+
*/
68+
69+
public abstract Builder toBuilder();
70+
71+
/**
72+
* Gson type adapter for parsing Gson to this class.
73+
*
74+
* @param gson the built {@link Gson} object
75+
* @return the type adapter for this class
76+
* @since 3.0.0
77+
*/
78+
public static TypeAdapter<MapboxShield> typeAdapter(Gson gson) {
79+
return new AutoValue_MapboxShield.GsonTypeAdapter(gson);
80+
}
81+
82+
/**
83+
* Create a new instance of this class by passing in a formatted valid JSON String.
84+
*
85+
* @param json a formatted valid JSON string defining a MapboxShield
86+
* @return a new instance of this class defined by the values passed inside this static factory
87+
* method
88+
*/
89+
public static MapboxShield fromJson(String json) {
90+
GsonBuilder gson = new GsonBuilder();
91+
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
92+
return gson.create().fromJson(json, MapboxShield.class);
93+
}
94+
95+
/**
96+
* This builder can be used to set the values describing the {@link MapboxShield}.
97+
*
98+
* @since 3.0.0
99+
*/
100+
@AutoValue.Builder
101+
public abstract static class Builder {
102+
103+
/**
104+
* Base url to query the styles endpoint.
105+
*
106+
* @param baseUrl base url to query the styles endpoint
107+
* @return a {@link Builder} object
108+
*/
109+
public abstract Builder baseUrl(String baseUrl);
110+
111+
/**
112+
* String indicating the name of the route shield.
113+
*
114+
* @param name name of the shield
115+
* @return a {@link Builder} object
116+
*/
117+
public abstract Builder name(String name);
118+
119+
/**
120+
* String indicating the color of the text to be rendered on the route shield.
121+
*
122+
* @param textColor color of the text to be rendered on the route shield
123+
* @return a {@link Builder} object
124+
*/
125+
public abstract Builder textColor(String textColor);
126+
127+
/**
128+
* String indicating the display ref.
129+
*
130+
* @param displayRef display ref for the shield
131+
* @return a {@link Builder} object
132+
*/
133+
public abstract Builder displayRef(String displayRef);
134+
135+
/**
136+
* Build a new {@link MapboxShield} object.
137+
*
138+
* @return a new {@link MapboxShield} using the provided values in this builder
139+
* @since 3.0.0
140+
*/
141+
public abstract MapboxShield build();
142+
}
143+
}

services-directions-models/src/test/java/com/mapbox/api/directions/v5/models/BannerComponentTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,29 @@ public void testToFromJsonActiveDirection() {
162162
assertEquals(bannerComponents, bannerComponentsFromJson);
163163
}
164164

165+
@Test
166+
public void testToFromJsonRouteShield() {
167+
168+
BannerComponents bannerComponents = BannerComponents.builder()
169+
.mapboxShield(
170+
MapboxShield
171+
.builder()
172+
.baseUrl("https://api.mapbox.com/styles/v1/")
173+
.displayRef("242")
174+
.name("us-interstate")
175+
.textColor("black")
176+
.build()
177+
)
178+
.text("I 95")
179+
.type("icon")
180+
.build();
181+
182+
String jsonString = bannerComponents.toJson();
183+
BannerComponents bannerComponentsFromJson = BannerComponents.fromJson(jsonString);
184+
185+
assertEquals(bannerComponents, bannerComponentsFromJson);
186+
}
187+
165188
@Test
166189
public void testToFromJsonLaneIcon() {
167190

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.mapbox.api.directions.v5.models;
2+
3+
import com.mapbox.core.TestUtils;
4+
import org.junit.Test;
5+
6+
import static org.junit.Assert.assertEquals;
7+
8+
public class MapboxShieldTest extends TestUtils {
9+
10+
@Test
11+
public void testToFromJsonRouteShield() {
12+
MapboxShield shield = MapboxShield
13+
.builder()
14+
.baseUrl("https://api.mapbox.com/styles/v1/")
15+
.displayRef("242")
16+
.name("us-interstate")
17+
.textColor("black")
18+
.build();
19+
String jsonString = shield.toJson();
20+
MapboxShield mapboxShieldFromJson = MapboxShield.fromJson(jsonString);
21+
22+
assertEquals(shield, mapboxShieldFromJson);
23+
}
24+
}

0 commit comments

Comments
 (0)