-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into tvn-upgrade-androidx
- Loading branch information
Showing
4 changed files
with
268 additions
and
2 deletions.
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
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
168 changes: 168 additions & 0 deletions
168
services-directions/src/main/java/com/mapbox/api/directions/v5/models/BannerView.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,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(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...irections/src/test/java/com/mapbox/api/directions/v5/models/JunctionViewResponseTest.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,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"); | ||
} | ||
} |