-
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.
Add option to load offline maps database for NavigationView (#1895)
* Add option to load offline maps database for NavigationView * Wire up geometry and route geometry with buffer * add download offline map tiles support into offline region download activity to help testing * [WIP] add offline map database path option to navigation launcher * [WIP] fix route geometry comparison, extract callbacks into classes, hardcode offline tile pyramid region definition values to match offline region definition provider ones and release a snapshot to test / debug upstream in gl-native * extract offline region observer into a separate class, bump nn to route_buffer-SNAPSHOT-7 version, retrieve a geometry from nn instead of a feature collection and test downloading a geometry using offline geometry region definition via offline region download activity * fix maps connected state that was preventing the route buffer downloading to finish * [WIP] add tests - create offline region callback and map offline manager tests (for now) * Add NavigationUiOption for offline map style URL * [WIP] add offline map style url option to mapbox navigation activity * reset map connectivity state when navigation is stopped * Add tests for OfflineRegion provider, observer, and region download callback * add missing merge offline regions callback, navigation offline database callback, navigation view model progress change listener and offline metadata provider tests * Add MapOfflineOptions to make sure offline path and style URL are provided together * convert mapbox navigator retrieve route geometry and retrieve route geometry with buffer checks into guard clauses * fix offline map callbacks issue * bump mapboxNavigator to 6.2.0 version and cleanup * add pr changelog entry * Cleanup remaining SDK TODOs and add javadoc
- Loading branch information
1 parent
61a7a6e
commit 29a7217
Showing
39 changed files
with
1,158 additions
and
33 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
24 changes: 24 additions & 0 deletions
24
...c/main/java/com/mapbox/services/android/navigation/ui/v5/CreateOfflineRegionCallback.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,24 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import com.mapbox.mapboxsdk.offline.OfflineManager; | ||
import com.mapbox.mapboxsdk.offline.OfflineRegion; | ||
|
||
class CreateOfflineRegionCallback implements OfflineManager.CreateOfflineRegionCallback { | ||
|
||
private final OfflineRegionDownloadCallback callback; | ||
|
||
CreateOfflineRegionCallback(OfflineRegionDownloadCallback callback) { | ||
this.callback = callback; | ||
} | ||
|
||
@Override | ||
public void onCreate(OfflineRegion offlineRegion) { | ||
offlineRegion.setDownloadState(OfflineRegion.STATE_ACTIVE); | ||
offlineRegion.setObserver(new OfflineRegionObserver(callback)); | ||
} | ||
|
||
@Override | ||
public void onError(String error) { | ||
callback.onError(error); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...src/main/java/com/mapbox/services/android/navigation/ui/v5/MapConnectivityController.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,10 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import com.mapbox.mapboxsdk.Mapbox; | ||
|
||
class MapConnectivityController { | ||
|
||
void assign(Boolean state) { | ||
Mapbox.setConnected(state); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...tion-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/MapOfflineManager.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,73 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import android.location.Location; | ||
import android.support.annotation.NonNull; | ||
|
||
import com.mapbox.geojson.Geometry; | ||
import com.mapbox.mapboxsdk.offline.OfflineGeometryRegionDefinition; | ||
import com.mapbox.mapboxsdk.offline.OfflineManager; | ||
import com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener; | ||
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; | ||
|
||
class MapOfflineManager implements ProgressChangeListener { | ||
|
||
private final OfflineManager offlineManager; | ||
private final OfflineRegionDefinitionProvider definitionProvider; | ||
private final OfflineMetadataProvider metadataProvider; | ||
private final MapConnectivityController connectivityController; | ||
private final RegionDownloadCallback regionDownloadCallback; | ||
private Geometry previousRouteGeometry; | ||
private MergeOfflineRegionsCallback mergeOfflineRegionsCallback; | ||
|
||
MapOfflineManager(OfflineManager offlineManager, OfflineRegionDefinitionProvider definitionProvider, | ||
OfflineMetadataProvider metadataProvider, MapConnectivityController connectivityController, | ||
RegionDownloadCallback regionDownloadCallback) { | ||
this.offlineManager = offlineManager; | ||
this.definitionProvider = definitionProvider; | ||
this.metadataProvider = metadataProvider; | ||
this.connectivityController = connectivityController; | ||
this.regionDownloadCallback = regionDownloadCallback; | ||
} | ||
|
||
// Package private (no modifier) for testing purposes | ||
MapOfflineManager(OfflineManager offlineManager, OfflineRegionDefinitionProvider definitionProvider, | ||
OfflineMetadataProvider metadataProvider, MapConnectivityController connectivityController, | ||
RegionDownloadCallback regionDownloadCallback, | ||
MergeOfflineRegionsCallback mergeOfflineRegionsCallback) { | ||
this.offlineManager = offlineManager; | ||
this.definitionProvider = definitionProvider; | ||
this.metadataProvider = metadataProvider; | ||
this.connectivityController = connectivityController; | ||
this.regionDownloadCallback = regionDownloadCallback; | ||
this.mergeOfflineRegionsCallback = mergeOfflineRegionsCallback; | ||
} | ||
|
||
@Override | ||
public void onProgressChange(Location location, RouteProgress routeProgress) { | ||
Geometry currentRouteGeometry = routeProgress.routeGeometryWithBuffer(); | ||
if (previousRouteGeometry == null || !previousRouteGeometry.equals(currentRouteGeometry)) { | ||
previousRouteGeometry = currentRouteGeometry; | ||
String routeSummary = routeProgress.directionsRoute().routeOptions().requestUuid(); | ||
download(routeSummary, previousRouteGeometry, regionDownloadCallback); | ||
} | ||
} | ||
|
||
void loadDatabase(@NonNull String offlineDatabasePath, OfflineDatabaseLoadedCallback callback) { | ||
mergeOfflineRegionsCallback = new MergeOfflineRegionsCallback(callback); | ||
offlineManager.mergeOfflineRegions(offlineDatabasePath, mergeOfflineRegionsCallback); | ||
} | ||
|
||
void onDestroy() { | ||
if (mergeOfflineRegionsCallback != null) { | ||
mergeOfflineRegionsCallback.onDestroy(); | ||
} | ||
} | ||
|
||
private void download(@NonNull String routeSummary, @NonNull Geometry routeGeometry, | ||
final OfflineRegionDownloadCallback callback) { | ||
OfflineGeometryRegionDefinition definition = definitionProvider.buildRegionFor(routeGeometry); | ||
byte[] metadata = metadataProvider.buildMetadataFor(routeSummary); | ||
connectivityController.assign(null); | ||
offlineManager.createOfflineRegion(definition, metadata, new CreateOfflineRegionCallback(callback)); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...tion-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/MapOfflineOptions.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,40 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
public class MapOfflineOptions { | ||
|
||
private final String databasePath; | ||
private final String styleUrl; | ||
|
||
/** | ||
* Add an offline path and style URL for loading an offline map database. | ||
* | ||
* @param databaseFilePath to the offline database on the device | ||
* @param styleUrl for the offline database data | ||
*/ | ||
public MapOfflineOptions(@NonNull String databaseFilePath, @NonNull String styleUrl) { | ||
this.databasePath = databaseFilePath; | ||
this.styleUrl = styleUrl; | ||
} | ||
|
||
/** | ||
* The offline path to the offline map database. | ||
* | ||
* @return the database path | ||
*/ | ||
@NonNull | ||
public String getDatabasePath() { | ||
return databasePath; | ||
} | ||
|
||
/** | ||
* The map style URL for the offline map database. | ||
* | ||
* @return the style URL | ||
*/ | ||
@NonNull | ||
public String getStyleUrl() { | ||
return styleUrl; | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
...c/main/java/com/mapbox/services/android/navigation/ui/v5/MergeOfflineRegionsCallback.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,32 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import com.mapbox.mapboxsdk.offline.OfflineManager; | ||
import com.mapbox.mapboxsdk.offline.OfflineRegion; | ||
|
||
class MergeOfflineRegionsCallback implements OfflineManager.MergeOfflineRegionsCallback { | ||
|
||
private OfflineDatabaseLoadedCallback callback; | ||
|
||
MergeOfflineRegionsCallback(OfflineDatabaseLoadedCallback callback) { | ||
this.callback = callback; | ||
} | ||
|
||
@Override | ||
public void onMerge(OfflineRegion[] offlineRegions) { | ||
if (callback != null) { | ||
callback.onComplete(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onError(String error) { | ||
if (callback != null) { | ||
callback.onError(error); | ||
} | ||
} | ||
|
||
OfflineDatabaseLoadedCallback onDestroy() { | ||
callback = null; | ||
return callback; | ||
} | ||
} |
Oops, something went wrong.