-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create groundwork for FasterRouteDetector
- Loading branch information
1 parent
bda98c8
commit 0f74331
Showing
9 changed files
with
217 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
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
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
8 changes: 8 additions & 0 deletions
8
...navigation/src/main/java/com/mapbox/services/android/navigation/v5/route/FasterRoute.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,8 @@ | ||
package com.mapbox.services.android.navigation.v5.route; | ||
|
||
import android.location.Location; | ||
|
||
public abstract class FasterRoute { | ||
|
||
public abstract boolean shouldCheckFasterRoute(Location location); | ||
} |
16 changes: 16 additions & 0 deletions
16
...on/src/main/java/com/mapbox/services/android/navigation/v5/route/FasterRouteDetector.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,16 @@ | ||
package com.mapbox.services.android.navigation.v5.route; | ||
|
||
import android.location.Location; | ||
|
||
public class FasterRouteDetector extends FasterRoute { | ||
|
||
private Location lastLocation; | ||
|
||
@Override | ||
public boolean shouldCheckFasterRoute(Location location) { | ||
if (lastLocation == null) { | ||
return false; | ||
} | ||
return false; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...navigation/src/main/java/com/mapbox/services/android/navigation/v5/route/RouteEngine.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,62 @@ | ||
package com.mapbox.services.android.navigation.v5.route; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import com.mapbox.api.directions.v5.models.DirectionsResponse; | ||
import com.mapbox.api.directions.v5.models.DirectionsRoute; | ||
import com.mapbox.api.directions.v5.models.RouteOptions; | ||
import com.mapbox.geojson.Point; | ||
import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.Callback; | ||
import retrofit2.Response; | ||
|
||
public class RouteEngine implements Callback<DirectionsResponse> { | ||
|
||
private Callback engineCallback; | ||
|
||
public RouteEngine(Callback engineCallback) { | ||
this.engineCallback = engineCallback; | ||
} | ||
|
||
public void fetchFasterRoute(Point origin, RouteOptions options) { | ||
if (options == null) { | ||
return; | ||
} | ||
|
||
NavigationRoute.builder() | ||
.origin(origin) | ||
.routeOptions(options) | ||
.build() | ||
.getRoute(this); | ||
} | ||
|
||
@Override | ||
public void onResponse(@NonNull Call<DirectionsResponse> call, @NonNull Response<DirectionsResponse> response) { | ||
// Check for successful response | ||
if (!response.isSuccessful()) { | ||
return; | ||
} | ||
|
||
if (isFasterRoute(response.body())) { | ||
engineCallback.onFasterRouteFound(response.body().routes().get(0)); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(@NonNull Call<DirectionsResponse> call, @NonNull Throwable throwable) { | ||
|
||
} | ||
|
||
public interface Callback { | ||
void onFasterRouteFound(DirectionsRoute route); | ||
} | ||
|
||
private boolean isFasterRoute(DirectionsResponse response) { | ||
|
||
// TODO determine is faster route | ||
|
||
return false; | ||
} | ||
} |