Skip to content

Commit ffcb424

Browse files
committed
add RouteLeg#notifications
1 parent d2848ac commit ffcb424

File tree

9 files changed

+720
-1
lines changed

9 files changed

+720
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Mapbox welcomes participation and contributions from everyone.
44

55
### main
6+
- Added `RouteLeg#notifications`.
67

78
### v6.11.0 - March 03, 2023
89
- No additional changes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.mapbox.samples;
2+
3+
import com.mapbox.api.directions.v5.DirectionsCriteria;
4+
import com.mapbox.api.directions.v5.MapboxDirections;
5+
import com.mapbox.api.directions.v5.models.DirectionsResponse;
6+
import com.mapbox.api.directions.v5.models.Notification;
7+
import com.mapbox.api.directions.v5.models.RouteOptions;
8+
import com.mapbox.sample.BuildConfig;
9+
import retrofit2.Response;
10+
11+
import java.io.IOException;
12+
import java.util.Arrays;
13+
import java.util.List;
14+
15+
public class BasicRouteNotification {
16+
17+
public static void main(String[] args) throws IOException {
18+
simpleMapboxDirectionsRequest();
19+
}
20+
21+
private static void simpleMapboxDirectionsRequest() throws IOException {
22+
MapboxDirections.Builder builder = MapboxDirections.builder();
23+
24+
// 1. Pass in all the required information to get a simple directions route.
25+
RouteOptions routeOptions = RouteOptions.builder()
26+
.user("") // the user which has route notifications enabled
27+
.profile(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC)
28+
.coordinates("-115.5747924943478,49.58740426100405;-115.33330133850265,49.444367698479994")
29+
.steps(true)
30+
.overview(DirectionsCriteria.OVERVIEW_FULL)
31+
.geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
32+
.excludeList(Arrays.asList(DirectionsCriteria.EXCLUDE_UNPAVED))
33+
.build();
34+
builder.routeOptions(routeOptions);
35+
builder.accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN);
36+
37+
// 2. That's it! Now execute the command and get the response.
38+
Response<DirectionsResponse> response = builder.build().executeCall();
39+
40+
// 3. Log information from the response
41+
System.out.println("Check that the GET response is successful " + response.isSuccessful());
42+
if (response.isSuccessful()) {
43+
List<Notification> notifications = response.body().routes().get(0).legs().get(0).notifications();
44+
System.out.println("Notifications: " + notifications);
45+
}
46+
}
47+
}

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

+67
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import androidx.annotation.IntDef;
44
import androidx.annotation.StringDef;
55
import com.mapbox.api.directions.v5.models.Amenity;
6+
import com.mapbox.api.directions.v5.models.Notification;
7+
import com.mapbox.api.directions.v5.models.RouteOptions;
68

79
import java.lang.annotation.Retention;
810
import java.lang.annotation.RetentionPolicy;
@@ -468,6 +470,47 @@ public final class DirectionsCriteria {
468470
*/
469471
public static final String AMENITY_TYPE_FAX = "FAX";
470472

473+
/**
474+
* Violation notification type. {@link Notification#type()} will have this value
475+
* if some request parameters were violated.
476+
*/
477+
public static final String NOTIFICATION_TYPE_VIOLATION = "violation";
478+
479+
/**
480+
* Max height notification subtype of type {@link DirectionsCriteria#NOTIFICATION_TYPE_VIOLATION}.
481+
* {@link Notification#subtype()} will have this value
482+
* if {@link RouteOptions#maxHeight()} parameter is violated.
483+
*/
484+
public static final String NOTIFICATION_SUBTYPE_MAX_HEIGHT = "maxHeight";
485+
486+
/**
487+
* Max width notification subtype of type {@link DirectionsCriteria#NOTIFICATION_TYPE_VIOLATION}.
488+
* {@link Notification#subtype()} will have this value
489+
* if {@link RouteOptions#maxWidth()} parameter is violated.
490+
*/
491+
public static final String NOTIFICATION_SUBTYPE_MAX_WIDTH = "maxWidth";
492+
493+
/**
494+
* Max weight notification subtype of type {@link DirectionsCriteria#NOTIFICATION_TYPE_VIOLATION}.
495+
* {@link Notification#subtype()} will have this value
496+
* if {@link RouteOptions#maxWeight()} parameter is violated.
497+
*/
498+
public static final String NOTIFICATION_SUBTYPE_MAX_WEIGHT = "maxWeight";
499+
500+
/**
501+
* Unpaved notification subtype of type {@link DirectionsCriteria#NOTIFICATION_TYPE_VIOLATION}.
502+
* {@link Notification#subtype()} will have this value
503+
* if {@link RouteOptions#exclude()} parameter with value {@link DirectionsCriteria#EXCLUDE_UNPAVED} is violated.
504+
*/
505+
public static final String NOTIFICATION_SUBTYPE_UNPAVED = "unpaved";
506+
507+
/**
508+
* Point exclusion notification subtype of type {@link DirectionsCriteria#NOTIFICATION_TYPE_VIOLATION}.
509+
* {@link Notification#subtype()} will have this value
510+
* if {@link RouteOptions#exclude()} parameter with point value is violated.
511+
*/
512+
public static final String NOTIFICATION_SUBTYPE_POINT_EXCLUSION = "pointExclusion";
513+
471514
private DirectionsCriteria() {
472515
//not called
473516
}
@@ -685,4 +728,28 @@ private DirectionsCriteria() {
685728
})
686729
public @interface AmenityTypeCriteria {
687730
}
731+
732+
/**
733+
* Supported notification types. See {@link Notification#type()}.
734+
*/
735+
@Retention(RetentionPolicy.CLASS)
736+
@StringDef({
737+
NOTIFICATION_TYPE_VIOLATION,
738+
})
739+
public @interface NotificationsTypeCriteria {
740+
}
741+
742+
/**
743+
* Supported notification subtypes. See {@link Notification#subtype()}.
744+
*/
745+
@Retention(RetentionPolicy.CLASS)
746+
@StringDef({
747+
NOTIFICATION_SUBTYPE_MAX_HEIGHT,
748+
NOTIFICATION_SUBTYPE_MAX_WIDTH,
749+
NOTIFICATION_SUBTYPE_MAX_WEIGHT,
750+
NOTIFICATION_SUBTYPE_UNPAVED,
751+
NOTIFICATION_SUBTYPE_POINT_EXCLUSION,
752+
})
753+
public @interface NotificationsSubtypeCriteria {
754+
}
688755
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
package com.mapbox.api.directions.v5.models;
2+
3+
import androidx.annotation.NonNull;
4+
import androidx.annotation.Nullable;
5+
import com.google.auto.value.AutoValue;
6+
import com.google.gson.Gson;
7+
import com.google.gson.GsonBuilder;
8+
import com.google.gson.TypeAdapter;
9+
import com.google.gson.annotations.SerializedName;
10+
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
11+
import com.mapbox.api.directions.v5.DirectionsCriteria;
12+
13+
/**
14+
* Class containing information about route notification. See {@link RouteLeg#notifications()}.
15+
*/
16+
@AutoValue
17+
public abstract class Notification extends DirectionsJsonObject {
18+
19+
/**
20+
* Create a new instance of this class by using the {@link Builder} class.
21+
*
22+
* @return this classes {@link Builder} for creating a new instance
23+
*/
24+
public static Builder builder() {
25+
return new AutoValue_Notification.Builder();
26+
}
27+
28+
/**
29+
* Notification type. Can be one of {@link DirectionsCriteria.NotificationsTypeCriteria}.
30+
*
31+
* @return notification type
32+
*/
33+
@NonNull
34+
@DirectionsCriteria.NotificationsTypeCriteria
35+
public abstract String type();
36+
37+
/**
38+
* Notification subtype. Can be one of {@link DirectionsCriteria.NotificationsSubtypeCriteria},
39+
* depending on {@link Notification#type()}.
40+
*
41+
* @return notification subtype
42+
*/
43+
@Nullable
44+
@DirectionsCriteria.NotificationsSubtypeCriteria
45+
public abstract String subtype();
46+
47+
/**
48+
* Leg-wise start index of the area that violates the request parameter.
49+
*
50+
* @return start index
51+
*/
52+
@SerializedName("geometry_index_start")
53+
@Nullable
54+
public abstract Integer geometryIndexStart();
55+
56+
/**
57+
* Leg-wise end index of the area that violates the request parameter.
58+
*
59+
* @return end index
60+
*/
61+
@SerializedName("geometry_index_end")
62+
@Nullable
63+
public abstract Integer geometryIndexEnd();
64+
65+
/**
66+
* Notification details specific to {@link Notification#type()} and {@link Notification#subtype()}.
67+
*
68+
* @return notification details
69+
*/
70+
@Nullable
71+
public abstract NotificationDetails details();
72+
73+
/**
74+
* Convert the current {@link Notification} to its builder holding the currently assigned
75+
* values. This allows you to modify a single property and then rebuild the object resulting in
76+
* an updated and modified {@link Notification}.
77+
*
78+
* @return a {@link Builder} with the same values set to match the ones defined
79+
* in this {@link Notification}
80+
*/
81+
public abstract Builder toBuilder();
82+
83+
/**
84+
* Gson type adapter for parsing Gson to this class.
85+
*
86+
* @param gson the built {@link Gson} object
87+
* @return the type adapter for this class
88+
*/
89+
public static TypeAdapter<Notification> typeAdapter(Gson gson) {
90+
return new AutoValue_Notification.GsonTypeAdapter(gson);
91+
}
92+
93+
/**
94+
* Create a new instance of this class by passing in a formatted valid JSON String.
95+
*
96+
* @param json a formatted valid JSON string defining a Notification
97+
* @return a new instance of this class defined by the values passed inside this static factory
98+
* method
99+
*/
100+
public static Notification fromJson(String json) {
101+
GsonBuilder gson = new GsonBuilder();
102+
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
103+
return gson.create().fromJson(json, Notification.class);
104+
}
105+
106+
/**
107+
* This builder can be used to set the values describing the {@link Notification}.
108+
*/
109+
@AutoValue.Builder
110+
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {
111+
112+
/**
113+
* Notification type. Can be one of {@link DirectionsCriteria.NotificationsTypeCriteria}.
114+
*
115+
* @param type notification type
116+
* @return this builder for chaining options together
117+
*/
118+
@NonNull
119+
public abstract Builder type(@NonNull @DirectionsCriteria.NotificationsTypeCriteria String type);
120+
121+
/**
122+
* Notification subtype. Can be one of {@link DirectionsCriteria.NotificationsSubtypeCriteria},
123+
* depending on {@link Notification.Builder#type()}.
124+
*
125+
* @param subtype notification subtype
126+
* @return this builder for chaining options together
127+
*/
128+
@NonNull
129+
public abstract Builder subtype(@Nullable @DirectionsCriteria.NotificationsSubtypeCriteria String subtype);
130+
131+
/**
132+
* Leg-wise start index of the area that violates the request parameter.
133+
*
134+
* @param geometryIndexStart start index
135+
* @return this builder for chaining options together
136+
*/
137+
@SerializedName("geometry_index_start")
138+
@NonNull
139+
public abstract Builder geometryIndexStart(@Nullable Integer geometryIndexStart);
140+
141+
/**
142+
* Leg-wise end index of the area that violates the request parameter.
143+
*
144+
* @param geometryIndexEnd end index
145+
* @return this builder for chaining options together
146+
*/
147+
@SerializedName("geometry_index_end")
148+
@NonNull
149+
public abstract Builder geometryIndexEnd(@Nullable Integer geometryIndexEnd);
150+
151+
/**
152+
* Notification details.
153+
*
154+
* @param details notification details
155+
* @return this builder for chaining options together
156+
*/
157+
@NonNull
158+
public abstract Builder details(@Nullable NotificationDetails details);
159+
160+
/**
161+
* Build a new {@link Notification} object.
162+
*
163+
* @return a new {@link Notification} using the provided values in this builder
164+
*/
165+
@NonNull
166+
public abstract Notification build();
167+
}
168+
}

0 commit comments

Comments
 (0)