Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions mapbox/build.gradle
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
mavenCentral()
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}
repositories {
jcenter()
mavenCentral()
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://plugins.gradle.org/m2/" }
}

dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.2'
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
mavenCentral()
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}
repositories {
jcenter()
mavenCentral()
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}

group = GROUP
version = VERSION_NAME
group = GROUP
version = VERSION_NAME
}

task clean(type: Delete) {
delete rootProject.buildDir
delete rootProject.buildDir
}

apply from: rootProject.file('dependencies.gradle')
apply from: rootProject.file('dependencies.gradle')
6 changes: 5 additions & 1 deletion mapbox/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ext {
mapbox : 'com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.2@aar',

// gson
gson : 'com.google.code.gson:gson:2.8.0',
gson : 'com.google.code.gson:gson:2.8.1',

// timber
timber : 'com.jakewharton.timber:timber:4.5.1',
Expand All @@ -30,6 +30,10 @@ ext {
retrofit2Gson : 'com.squareup.retrofit2:converter-gson:2.2.0',
retrofit2Rx : 'com.squareup.retrofit2:adapter-rxjava2:2.2.0',

// auto value
autoValues : 'com.google.auto.value:auto-value:1.4.1',
autoValuesGson : 'com.ryanharter.auto.value:auto-value-gson:0.4.6',

// okhttp
okhttp3 : 'com.squareup.okhttp3:okhttp:3.6.0',
okhttp3Logging : 'com.squareup.okhttp3:logging-interceptor:3.6.0',
Expand Down
28 changes: 18 additions & 10 deletions mapbox/libjava-services/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
plugins { id "net.ltgt.apt" version "0.10" }
apply plugin: 'java'
apply plugin: 'idea'

sourceCompatibility = "1.7"
targetCompatibility = "1.7"

dependencies {
// Mapbox Java Services requires GeoJSON support
compile project(':libjava-geojson')
// Mapbox Java Services requires GeoJSON support
compile project(':libjava-geojson')

// Retrofit
compile rootProject.ext.dep.retrofit2Main
compile rootProject.ext.dep.retrofit2Gson
compile rootProject.ext.dep.okhttp3Logging
// Retrofit
compile rootProject.ext.dep.retrofit2Main
compile rootProject.ext.dep.retrofit2Gson
compile rootProject.ext.dep.okhttp3Logging

// Testing
testCompile rootProject.ext.dep.okhttp3Mockwebserver
testCompile rootProject.ext.dep.junit
testCompile rootProject.ext.dep.hamcrestJunit
// AutoValues
compileOnly rootProject.ext.dep.autoValuesGson
apt rootProject.ext.dep.autoValuesGson
// compileOnly rootProject.ext.dep.autoValues
// apt rootProject.ext.dep.autoValues

// Testing
testCompile rootProject.ext.dep.okhttp3Mockwebserver
testCompile rootProject.ext.dep.junit
testCompile rootProject.ext.dep.hamcrestJunit
}

apply from: 'gradle-javadoc.gradle'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.mapbox.services.api.directions;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.mapbox.services.api.directions.v5.models.DirectionsResponse;
import com.ryanharter.auto.value.gson.GsonTypeAdapterFactory;

@GsonTypeAdapterFactory
public abstract class DirectionsTypeAdapterFactory implements TypeAdapterFactory {

public static DirectionsTypeAdapterFactory create() {
return new AutoValueGson_DirectionsTypeAdapterFactory();
}

@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
Class<? super T> rawType = type.getRawType();
if (rawType.equals(DirectionsResponse.class)) {
return (TypeAdapter<T>) DirectionsResponse.typeAdapter(gson);
}
return null;
}
}

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.mapbox.services.api.directions.v5;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mapbox.services.api.MapboxBuilder;
import com.mapbox.services.api.MapboxService;
import com.mapbox.services.api.ServicesException;
import com.mapbox.services.api.directions.DirectionsTypeAdapterFactory;
import com.mapbox.services.api.directions.v5.models.DirectionsResponse;
import com.mapbox.services.commons.models.Position;
import com.mapbox.services.commons.utils.TextUtils;
Expand Down Expand Up @@ -30,11 +33,22 @@ public class MapboxDirections extends MapboxService<DirectionsResponse> {
protected Builder builder = null;
private DirectionsService service = null;
private Call<DirectionsResponse> call = null;
private Gson gson;

protected MapboxDirections(Builder builder) {
this.builder = builder;
}

protected Gson getGson() {
// Gson instance with type adapters
if (gson == null) {
gson = new GsonBuilder()
.registerTypeAdapterFactory(DirectionsTypeAdapterFactory.create())
.create();
}
return gson;
}

private DirectionsService getService() {
// No need to recreate it
if (service != null) {
Expand All @@ -44,7 +58,7 @@ private DirectionsService getService() {
// Retrofit instance
Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
.baseUrl(builder.getBaseUrl())
.addConverterFactory(GsonConverterFactory.create());
.addConverterFactory(GsonConverterFactory.create(getGson()));
if (getCallFactory() != null) {
retrofitBuilder.callFactory(getCallFactory());
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,82 +1,45 @@
package com.mapbox.services.api.directions.v5.models;

import com.google.auto.value.AutoValue;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;

import java.util.List;

/**
* The response to a directions request.
*
* @since 1.0.0
*/
public class DirectionsResponse {

private String code;
private List<DirectionsRoute> routes;
private List<DirectionsWaypoint> waypoints;

/**
* Empty constructor
*
* @since 2.1.0
*/
public DirectionsResponse() {
}
@AutoValue
public abstract class DirectionsResponse {

/**
* Constructor taking in both a list of {@link DirectionsRoute} and a list of {@link DirectionsWaypoint}s.
*
* @param routes list of routes you can pass in while building this object.
* @param code {@code String} that indicates the status of the response
* @param routes list of routes you can pass in while building this object
* @param waypoints list of waypoints you can pass in while building this object. Ideally these should match what was
* used to crate the route.
* used to crate the route
* @since 2.0.0
*/
public DirectionsResponse(List<DirectionsRoute> routes, List<DirectionsWaypoint> waypoints) {
this.routes = routes;
this.waypoints = waypoints;
public static DirectionsResponse create(String code, List<DirectionsRoute> routes,
List<DirectionsWaypoint> waypoints) {
return new AutoValue_DirectionsResponse(code, routes, waypoints);
}

/**
* String indicating the state of the response. This is a separate code than the HTTP
* status code.
*
* @return "Ok", "NoRoute", "ProfileNotFound", or "InvalidInput".
* @since 1.0.0
*/
public String getCode() {
return code;
public static TypeAdapter<DirectionsResponse> typeAdapter(Gson gson) {
return new AutoValue_DirectionsResponse.GsonTypeAdapter(gson);
}

/**
* String indicating the state of the response. This is a separate code than the HTTP
* status code.
*
* @param code "Ok", "NoRoute", "ProfileNotFound", or "InvalidInput".
* @since 2.1.0
*/
public void setCode(String code) {
this.code = code;
}

/**
* List with Waypoints of locations snapped to the road and path network and appear in the List
* in the order of the input coordinates.
*
* @return List of {@link DirectionsWaypoint} objects.
* @return "Ok", "NoRoute", "ProfileNotFound", or "InvalidInput".
* @since 1.0.0
*/
public List<DirectionsWaypoint> getWaypoints() {
return waypoints;
}

/**
* List with Waypoints of locations snapped to the road and path network and should appear in the List
* in the order of the input coordinates.
*
* @param waypoints List of {@link DirectionsWaypoint} objects.
* @since 2.1.0
*/
public void setWaypoints(List<DirectionsWaypoint> waypoints) {
this.waypoints = waypoints;
}
public abstract String getCode();

/**
* List containing all the different route options. It's ordered by descending recommendation
Expand All @@ -87,20 +50,14 @@ public void setWaypoints(List<DirectionsWaypoint> waypoints) {
* @return List of {@link DirectionsRoute} objects.
* @since 1.0.0
*/
public List<DirectionsRoute> getRoutes() {
return routes;
}
public abstract List<DirectionsRoute> getRoutes();

/**
* List containing all the different route options. It should be ordered by descending recommendation
* rank. In other words, object 0 in the List is the highest recommended route. if you don't
* setAlternatives to true (default is false) in your builder this should always be a List of
* size 1.
* List with waypoints of locations snapped to the road and path network and appear in the List
* in the order of the input coordinates.
*
* @param routes List of {@link DirectionsRoute} objects.
* @since 2.1.0
* @return List of {@link DirectionsWaypoint} objects.
* @since 1.0.0
*/
public void setRoutes(List<DirectionsRoute> routes) {
this.routes = routes;
}
public abstract List<DirectionsWaypoint> getWaypoints();
}
Loading