-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
727 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
samples/src/main/java/com/mapbox/samples/BasicRouteNotification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.mapbox.samples; | ||
|
||
import com.mapbox.api.directions.v5.DirectionsCriteria; | ||
import com.mapbox.api.directions.v5.MapboxDirections; | ||
import com.mapbox.api.directions.v5.models.DirectionsResponse; | ||
import com.mapbox.api.directions.v5.models.Notification; | ||
import com.mapbox.api.directions.v5.models.RouteOptions; | ||
import com.mapbox.sample.BuildConfig; | ||
import retrofit2.Response; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class BasicRouteNotification { | ||
|
||
public static void main(String[] args) throws IOException { | ||
simpleMapboxDirectionsRequest(); | ||
} | ||
|
||
private static void simpleMapboxDirectionsRequest() throws IOException { | ||
MapboxDirections.Builder builder = MapboxDirections.builder(); | ||
|
||
// 1. Pass in all the required information to get a simple directions route. | ||
RouteOptions routeOptions = RouteOptions.builder() | ||
.user("") // the user which has route notifications enabled | ||
.profile(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC) | ||
.coordinates("-115.5747924943478,49.58740426100405;-115.33330133850265,49.444367698479994") | ||
.steps(true) | ||
.overview(DirectionsCriteria.OVERVIEW_FULL) | ||
.geometries(DirectionsCriteria.GEOMETRY_POLYLINE6) | ||
.excludeList(Arrays.asList(DirectionsCriteria.EXCLUDE_UNPAVED)) | ||
.build(); | ||
builder.routeOptions(routeOptions); | ||
builder.accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN); | ||
|
||
// 2. That's it! Now execute the command and get the response. | ||
Response<DirectionsResponse> response = builder.build().executeCall(); | ||
|
||
// 3. Log information from the response | ||
System.out.println("Check that the GET response is successful " + response.isSuccessful()); | ||
if (response.isSuccessful()) { | ||
List<Notification> notifications = response.body().routes().get(0).legs().get(0).notifications(); | ||
System.out.println("Notifications: " + notifications); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
...ces-directions-models/src/main/java/com/mapbox/api/directions/v5/models/Notification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package com.mapbox.api.directions.v5.models; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.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.google.gson.annotations.SerializedName; | ||
import com.mapbox.api.directions.v5.DirectionsAdapterFactory; | ||
import com.mapbox.api.directions.v5.DirectionsCriteria; | ||
|
||
/** | ||
* Class containing information about route notification. See {@link RouteLeg#notifications()}. | ||
*/ | ||
@AutoValue | ||
public abstract class Notification 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 | ||
*/ | ||
public static Builder builder() { | ||
return new AutoValue_Notification.Builder(); | ||
} | ||
|
||
/** | ||
* Notification type. Can be one of {@link DirectionsCriteria.NotificationsTypeCriteria}. | ||
* | ||
* @return notification type | ||
*/ | ||
@NonNull | ||
@DirectionsCriteria.NotificationsTypeCriteria | ||
public abstract String type(); | ||
|
||
/** | ||
* Notification subtype. Can be one of {@link DirectionsCriteria.NotificationsSubtypeCriteria}, | ||
* depending on {@link Notification#type()}. | ||
* | ||
* @return notification subtype | ||
*/ | ||
@Nullable | ||
@DirectionsCriteria.NotificationsSubtypeCriteria | ||
public abstract String subtype(); | ||
|
||
/** | ||
* Leg-wise start index of the area that violates the request parameter. | ||
* | ||
* @return start index | ||
*/ | ||
@SerializedName("geometry_index_start") | ||
@Nullable | ||
public abstract Integer geometryIndexStart(); | ||
|
||
/** | ||
* Leg-wise end index of the area that violates the request parameter. | ||
* | ||
* @return end index | ||
*/ | ||
@SerializedName("geometry_index_end") | ||
@Nullable | ||
public abstract Integer geometryIndexEnd(); | ||
|
||
/** | ||
* Notification details specific to {@link Notification#type()} | ||
* and {@link Notification#subtype()}. | ||
* | ||
* @return notification details | ||
*/ | ||
@Nullable | ||
public abstract NotificationDetails details(); | ||
|
||
/** | ||
* Convert the current {@link Notification} 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 Notification}. | ||
* | ||
* @return a {@link Builder} with the same values set to match the ones defined | ||
* in this {@link Notification} | ||
*/ | ||
public abstract 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 | ||
*/ | ||
public static TypeAdapter<Notification> typeAdapter(Gson gson) { | ||
return new AutoValue_Notification.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 Notification | ||
* @return a new instance of this class defined by the values passed inside this static factory | ||
* method | ||
*/ | ||
public static Notification fromJson(String json) { | ||
GsonBuilder gson = new GsonBuilder(); | ||
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create()); | ||
return gson.create().fromJson(json, Notification.class); | ||
} | ||
|
||
/** | ||
* This builder can be used to set the values describing the {@link Notification}. | ||
*/ | ||
@AutoValue.Builder | ||
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> { | ||
|
||
/** | ||
* Notification type. Can be one of {@link DirectionsCriteria.NotificationsTypeCriteria}. | ||
* | ||
* @param type notification type | ||
* @return this builder for chaining options together | ||
*/ | ||
@NonNull | ||
public abstract Builder type( | ||
@NonNull @DirectionsCriteria.NotificationsTypeCriteria String type | ||
); | ||
|
||
/** | ||
* Notification subtype. Can be one of {@link DirectionsCriteria.NotificationsSubtypeCriteria}, | ||
* depending on {@link Notification.Builder#type()}. | ||
* | ||
* @param subtype notification subtype | ||
* @return this builder for chaining options together | ||
*/ | ||
@NonNull | ||
public abstract Builder subtype( | ||
@Nullable @DirectionsCriteria.NotificationsSubtypeCriteria String subtype | ||
); | ||
|
||
/** | ||
* Leg-wise start index of the area that violates the request parameter. | ||
* | ||
* @param geometryIndexStart start index | ||
* @return this builder for chaining options together | ||
*/ | ||
@SerializedName("geometry_index_start") | ||
@NonNull | ||
public abstract Builder geometryIndexStart(@Nullable Integer geometryIndexStart); | ||
|
||
/** | ||
* Leg-wise end index of the area that violates the request parameter. | ||
* | ||
* @param geometryIndexEnd end index | ||
* @return this builder for chaining options together | ||
*/ | ||
@SerializedName("geometry_index_end") | ||
@NonNull | ||
public abstract Builder geometryIndexEnd(@Nullable Integer geometryIndexEnd); | ||
|
||
/** | ||
* Notification details. | ||
* | ||
* @param details notification details | ||
* @return this builder for chaining options together | ||
*/ | ||
@NonNull | ||
public abstract Builder details(@Nullable NotificationDetails details); | ||
|
||
/** | ||
* Build a new {@link Notification} object. | ||
* | ||
* @return a new {@link Notification} using the provided values in this builder | ||
*/ | ||
@NonNull | ||
public abstract Notification build(); | ||
} | ||
} |
Oops, something went wrong.