Skip to content

Commit 6b11620

Browse files
committed
add RouteLeg#notifications
1 parent d2848ac commit 6b11620

File tree

9 files changed

+727
-1
lines changed

9 files changed

+727
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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
Lines changed: 47 additions & 0 deletions
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

Lines changed: 69 additions & 0 deletions
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,49 @@ 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
504+
* {@link DirectionsCriteria#EXCLUDE_UNPAVED} is violated.
505+
*/
506+
public static final String NOTIFICATION_SUBTYPE_UNPAVED = "unpaved";
507+
508+
/**
509+
* Point exclusion notification subtype of type
510+
* {@link DirectionsCriteria#NOTIFICATION_TYPE_VIOLATION}.
511+
* {@link Notification#subtype()} will have this value
512+
* if {@link RouteOptions#exclude()} parameter with point value is violated.
513+
*/
514+
public static final String NOTIFICATION_SUBTYPE_POINT_EXCLUSION = "pointExclusion";
515+
471516
private DirectionsCriteria() {
472517
//not called
473518
}
@@ -685,4 +730,28 @@ private DirectionsCriteria() {
685730
})
686731
public @interface AmenityTypeCriteria {
687732
}
733+
734+
/**
735+
* Supported notification types. See {@link Notification#type()}.
736+
*/
737+
@Retention(RetentionPolicy.CLASS)
738+
@StringDef({
739+
NOTIFICATION_TYPE_VIOLATION,
740+
})
741+
public @interface NotificationsTypeCriteria {
742+
}
743+
744+
/**
745+
* Supported notification subtypes. See {@link Notification#subtype()}.
746+
*/
747+
@Retention(RetentionPolicy.CLASS)
748+
@StringDef({
749+
NOTIFICATION_SUBTYPE_MAX_HEIGHT,
750+
NOTIFICATION_SUBTYPE_MAX_WIDTH,
751+
NOTIFICATION_SUBTYPE_MAX_WEIGHT,
752+
NOTIFICATION_SUBTYPE_UNPAVED,
753+
NOTIFICATION_SUBTYPE_POINT_EXCLUSION,
754+
})
755+
public @interface NotificationsSubtypeCriteria {
756+
}
688757
}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
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()}
67+
* and {@link Notification#subtype()}.
68+
*
69+
* @return notification details
70+
*/
71+
@Nullable
72+
public abstract NotificationDetails details();
73+
74+
/**
75+
* Convert the current {@link Notification} to its builder holding the currently assigned
76+
* values. This allows you to modify a single property and then rebuild the object resulting in
77+
* an updated and modified {@link Notification}.
78+
*
79+
* @return a {@link Builder} with the same values set to match the ones defined
80+
* in this {@link Notification}
81+
*/
82+
public abstract Builder toBuilder();
83+
84+
/**
85+
* Gson type adapter for parsing Gson to this class.
86+
*
87+
* @param gson the built {@link Gson} object
88+
* @return the type adapter for this class
89+
*/
90+
public static TypeAdapter<Notification> typeAdapter(Gson gson) {
91+
return new AutoValue_Notification.GsonTypeAdapter(gson);
92+
}
93+
94+
/**
95+
* Create a new instance of this class by passing in a formatted valid JSON String.
96+
*
97+
* @param json a formatted valid JSON string defining a Notification
98+
* @return a new instance of this class defined by the values passed inside this static factory
99+
* method
100+
*/
101+
public static Notification fromJson(String json) {
102+
GsonBuilder gson = new GsonBuilder();
103+
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
104+
return gson.create().fromJson(json, Notification.class);
105+
}
106+
107+
/**
108+
* This builder can be used to set the values describing the {@link Notification}.
109+
*/
110+
@AutoValue.Builder
111+
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {
112+
113+
/**
114+
* Notification type. Can be one of {@link DirectionsCriteria.NotificationsTypeCriteria}.
115+
*
116+
* @param type notification type
117+
* @return this builder for chaining options together
118+
*/
119+
@NonNull
120+
public abstract Builder type(
121+
@NonNull @DirectionsCriteria.NotificationsTypeCriteria String type
122+
);
123+
124+
/**
125+
* Notification subtype. Can be one of {@link DirectionsCriteria.NotificationsSubtypeCriteria},
126+
* depending on {@link Notification.Builder#type()}.
127+
*
128+
* @param subtype notification subtype
129+
* @return this builder for chaining options together
130+
*/
131+
@NonNull
132+
public abstract Builder subtype(
133+
@Nullable @DirectionsCriteria.NotificationsSubtypeCriteria String subtype
134+
);
135+
136+
/**
137+
* Leg-wise start index of the area that violates the request parameter.
138+
*
139+
* @param geometryIndexStart start index
140+
* @return this builder for chaining options together
141+
*/
142+
@SerializedName("geometry_index_start")
143+
@NonNull
144+
public abstract Builder geometryIndexStart(@Nullable Integer geometryIndexStart);
145+
146+
/**
147+
* Leg-wise end index of the area that violates the request parameter.
148+
*
149+
* @param geometryIndexEnd end index
150+
* @return this builder for chaining options together
151+
*/
152+
@SerializedName("geometry_index_end")
153+
@NonNull
154+
public abstract Builder geometryIndexEnd(@Nullable Integer geometryIndexEnd);
155+
156+
/**
157+
* Notification details.
158+
*
159+
* @param details notification details
160+
* @return this builder for chaining options together
161+
*/
162+
@NonNull
163+
public abstract Builder details(@Nullable NotificationDetails details);
164+
165+
/**
166+
* Build a new {@link Notification} object.
167+
*
168+
* @return a new {@link Notification} using the provided values in this builder
169+
*/
170+
@NonNull
171+
public abstract Notification build();
172+
}
173+
}

0 commit comments

Comments
 (0)