diff --git a/app/build.gradle b/app/build.gradle index 0746c9aaba4..5b128ecaf4c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -42,7 +42,6 @@ dependencies { // Mapbox Navigation SDK implementation project(':libandroid-navigation-ui') implementation dependenciesList.mapboxMapSdk - implementation dependenciesList.locationLayerPlugin // Support libraries implementation dependenciesList.supportAppcompatV7 diff --git a/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/MockNavigationActivity.java b/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/MockNavigationActivity.java index 5ea76d22885..25539d33ede 100644 --- a/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/MockNavigationActivity.java +++ b/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/MockNavigationActivity.java @@ -1,5 +1,6 @@ package com.mapbox.services.android.navigation.testapp.activity; +import android.annotation.SuppressLint; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -22,11 +23,11 @@ import com.mapbox.mapboxsdk.annotations.MarkerOptions; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.location.LocationComponent; +import com.mapbox.mapboxsdk.location.modes.RenderMode; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin; -import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode; import com.mapbox.services.android.navigation.testapp.R; import com.mapbox.services.android.navigation.testapp.Utils; import com.mapbox.services.android.navigation.testapp.activity.notification.CustomNavigationNotification; @@ -81,7 +82,6 @@ public class MockNavigationActivity extends AppCompatActivity implements OnMapRe private MapboxNavigation navigation; private DirectionsRoute route; private NavigationMapRoute navigationMapRoute; - private LocationLayerPlugin locationLayerPlugin; private Point destination; private Point waypoint; @@ -144,7 +144,7 @@ public void onStartRouteClick() { ((ReplayRouteLocationEngine) locationEngine).assign(route); navigation.setLocationEngine(locationEngine); - locationLayerPlugin.setLocationLayerEnabled(true); + mapboxMap.getLocationComponent().setLocationComponentEnabled(true); navigation.startNavigation(route); mapboxMap.removeOnMapClickListener(this); } @@ -165,13 +165,15 @@ private void newOrigin() { } } + @SuppressLint("MissingPermission") @Override public void onMapReady(MapboxMap mapboxMap) { this.mapboxMap = mapboxMap; - locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap); - locationLayerPlugin.setRenderMode(RenderMode.GPS); - locationLayerPlugin.setLocationLayerEnabled(false); + LocationComponent locationComponent = mapboxMap.getLocationComponent(); + locationComponent.activateLocationComponent(this); + locationComponent.setRenderMode(RenderMode.GPS); + locationComponent.setLocationComponentEnabled(false); navigationMapRoute = new NavigationMapRoute(navigation, mapView, mapboxMap); mapboxMap.addOnMapClickListener(this); @@ -263,7 +265,7 @@ public void userOffRoute(Location location) { @Override public void onProgressChange(Location location, RouteProgress routeProgress) { - locationLayerPlugin.forceLocationUpdate(location); + mapboxMap.getLocationComponent().forceLocationUpdate(location); Timber.d("onProgressChange: fraction of route traveled: %f", routeProgress.fractionTraveled()); } @@ -287,8 +289,8 @@ public void onPause() { protected void onStart() { super.onStart(); mapView.onStart(); - if (locationLayerPlugin != null) { - locationLayerPlugin.onStart(); + if (mapboxMap != null) { + mapboxMap.getLocationComponent().onStart(); } } @@ -296,8 +298,8 @@ protected void onStart() { protected void onStop() { super.onStop(); mapView.onStop(); - if (locationLayerPlugin != null) { - locationLayerPlugin.onStop(); + if (mapboxMap != null) { + mapboxMap.getLocationComponent().onStop(); } } diff --git a/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/RerouteActivity.java b/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/RerouteActivity.java index 6c1e8c3b4bb..fe4d5250604 100644 --- a/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/RerouteActivity.java +++ b/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/RerouteActivity.java @@ -23,11 +23,11 @@ import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.location.LocationComponent; +import com.mapbox.mapboxsdk.location.modes.RenderMode; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin; -import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode; import com.mapbox.services.android.navigation.testapp.R; import com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView; import com.mapbox.services.android.navigation.v5.location.replay.ReplayRouteLocationEngine; @@ -67,7 +67,6 @@ public class RerouteActivity extends AppCompatActivity implements OnMapReadyCall private Point destination = Point.fromLngLat(-0.383524, 39.497825); private Polyline polyline; - private LocationLayerPlugin locationLayerPlugin; private ReplayRouteLocationEngine mockLocationEngine; private MapboxNavigation navigation; private MapboxMap mapboxMap; @@ -107,8 +106,8 @@ public void onResume() { protected void onStart() { super.onStart(); mapView.onStart(); - if (locationLayerPlugin != null) { - locationLayerPlugin.onStart(); + if (mapboxMap != null) { + mapboxMap.getLocationComponent().onStart(); } } @@ -125,8 +124,8 @@ protected void onStop() { shutdownLocationEngine(); - if (locationLayerPlugin != null) { - locationLayerPlugin.onStop(); + if (mapboxMap != null) { + mapboxMap.getLocationComponent().onStop(); } if (navigation != null) { @@ -159,8 +158,10 @@ public void onMapReady(MapboxMap mapboxMap) { this.mapboxMap = mapboxMap; mapboxMap.addOnMapClickListener(this); - locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap); - locationLayerPlugin.setRenderMode(RenderMode.GPS); + LocationComponent locationComponent = mapboxMap.getLocationComponent(); + locationComponent.activateLocationComponent(this); + locationComponent.setLocationComponentEnabled(true); + locationComponent.setRenderMode(RenderMode.GPS); mockLocationEngine = new ReplayRouteLocationEngine(); mockLocationEngine.addLocationEngineListener(this); @@ -177,7 +178,7 @@ public void onConnected() { @Override public void onLocationChanged(Location location) { if (!tracking) { - locationLayerPlugin.forceLocationUpdate(location); + mapboxMap.getLocationComponent().forceLocationUpdate(location); } } @@ -225,7 +226,7 @@ public void onProgressChange(Location location, RouteProgress routeProgress) { Snackbar.make(contentLayout, "Exit tunnel!", Snackbar.LENGTH_SHORT).show(); } if (tracking) { - locationLayerPlugin.forceLocationUpdate(location); + mapboxMap.getLocationComponent().forceLocationUpdate(location); CameraPosition cameraPosition = new CameraPosition.Builder() .zoom(15) .target(new LatLng(location.getLatitude(), location.getLongitude())) diff --git a/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/ComponentNavigationActivity.java b/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/ComponentNavigationActivity.java index fb5af6ed6d8..575a9f32899 100644 --- a/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/ComponentNavigationActivity.java +++ b/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/ComponentNavigationActivity.java @@ -34,6 +34,7 @@ import com.mapbox.services.android.navigation.testapp.R; import com.mapbox.services.android.navigation.testapp.activity.location.FusedLocationEngine; import com.mapbox.services.android.navigation.ui.v5.camera.DynamicCamera; +import com.mapbox.services.android.navigation.ui.v5.camera.NavigationCamera; import com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView; import com.mapbox.services.android.navigation.ui.v5.map.NavigationMapboxMap; import com.mapbox.services.android.navigation.ui.v5.voice.NavigationSpeechPlayer; @@ -136,7 +137,7 @@ public void onMapReady(MapboxMap mapboxMap) { // For navigation logic / processing initializeNavigation(mapboxMap); - navigationMap.updateCameraTrackingEnabled(false); + navigationMap.updateCameraTrackingMode(NavigationCamera.NAVIGATION_TRACKING_MODE_NONE); } @Override @@ -161,7 +162,7 @@ public void onMapLongClick(@NonNull LatLng point) { @OnClick(R.id.startNavigationFab) public void onStartNavigationClick(FloatingActionButton floatingActionButton) { - navigationMap.updateCameraTrackingEnabled(true); + navigationMap.updateCameraTrackingMode(NavigationCamera.NAVIGATION_TRACKING_MODE_GPS); // Transition to navigation state mapState = MapState.NAVIGATION; @@ -184,7 +185,7 @@ public void onStartNavigationClick(FloatingActionButton floatingActionButton) { @OnClick(R.id.cancelNavigationFab) public void onCancelNavigationClick(FloatingActionButton floatingActionButton) { - navigationMap.updateCameraTrackingEnabled(false); + navigationMap.updateCameraTrackingMode(NavigationCamera.NAVIGATION_TRACKING_MODE_NONE); // Transition to info state mapState = MapState.INFO; diff --git a/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/DualNavigationMapActivity.java b/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/DualNavigationMapActivity.java index 19714d5da09..be0e6ebafbe 100644 --- a/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/DualNavigationMapActivity.java +++ b/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/DualNavigationMapActivity.java @@ -22,11 +22,11 @@ import com.mapbox.mapboxsdk.annotations.MarkerViewOptions; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.location.LocationComponent; +import com.mapbox.mapboxsdk.location.modes.RenderMode; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin; -import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode; import com.mapbox.services.android.navigation.testapp.R; import com.mapbox.services.android.navigation.ui.v5.NavigationView; import com.mapbox.services.android.navigation.ui.v5.NavigationViewOptions; @@ -56,17 +56,15 @@ public class DualNavigationMapActivity extends AppCompatActivity implements OnNa private Point origin = Point.fromLngLat(-122.423579, 37.761689); private Point destination = Point.fromLngLat(-122.426183, 37.760872); private DirectionsRoute route; - private boolean isNavigationRunning; - private LocationLayerPlugin locationLayer; private LocationEngine locationEngine; private NavigationMapRoute mapRoute; private MapboxMap mapboxMap; private Marker currentMarker; + private boolean isNavigationRunning; private boolean locationFound; + private boolean[] constraintChanged; private ConstraintSet navigationMapConstraint; private ConstraintSet navigationMapExpandedConstraint; - private boolean[] constraintChanged; - @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -94,9 +92,9 @@ public void onNavigationReady(boolean isRunning) { @Override public void onMapReady(MapboxMap mapboxMap) { this.mapboxMap = mapboxMap; - this.mapboxMap.setOnMapLongClickListener(this); + this.mapboxMap.addOnMapLongClickListener(this); initLocationEngine(); - initLocationLayer(); + initializeLocationLayer(); initMapRoute(); fetchRoute(); } @@ -164,8 +162,8 @@ public void onStart() { super.onStart(); navigationView.onStart(); mapView.onStart(); - if (locationLayer != null) { - locationLayer.onStart(); + if (mapboxMap != null) { + mapboxMap.getLocationComponent().onStart(); } } @@ -224,8 +222,8 @@ public void onStop() { super.onStop(); navigationView.onStop(); mapView.onStop(); - if (locationLayer != null) { - locationLayer.onStop(); + if (mapboxMap != null) { + mapboxMap.getLocationComponent().onStop(); } } @@ -313,9 +311,11 @@ private void initLocationEngine() { } @SuppressWarnings( {"MissingPermission"}) - private void initLocationLayer() { - locationLayer = new LocationLayerPlugin(mapView, mapboxMap, locationEngine); - locationLayer.setRenderMode(RenderMode.COMPASS); + private void initializeLocationLayer() { + LocationComponent locationComponent = mapboxMap.getLocationComponent(); + locationComponent.activateLocationComponent(this, locationEngine); + locationComponent.setLocationComponentEnabled(true); + locationComponent.setRenderMode(RenderMode.COMPASS); } private void initMapRoute() { diff --git a/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/NavigationLauncherActivity.java b/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/NavigationLauncherActivity.java index 2b30c4d907d..f5a9202b20a 100644 --- a/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/NavigationLauncherActivity.java +++ b/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/NavigationLauncherActivity.java @@ -34,11 +34,11 @@ import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.location.LocationComponent; +import com.mapbox.mapboxsdk.location.modes.RenderMode; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin; -import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode; import com.mapbox.services.android.navigation.testapp.R; import com.mapbox.services.android.navigation.ui.v5.NavigationLauncher; import com.mapbox.services.android.navigation.ui.v5.NavigationLauncherOptions; @@ -66,10 +66,15 @@ public class NavigationLauncherActivity extends AppCompatActivity implements OnM private static final int DEFAULT_CAMERA_ZOOM = 16; private static final int CHANGE_SETTING_REQUEST_CODE = 1; - private LocationLayerPlugin locationLayer; private LocationEngine locationEngine; private NavigationMapRoute mapRoute; private MapboxMap mapboxMap; + private Marker currentMarker; + private Point currentLocation; + private Point destination; + private DirectionsRoute route; + private LocaleUtils localeUtils; + private boolean locationFound; @BindView(R.id.mapView) MapView mapView; @@ -80,14 +85,6 @@ public class NavigationLauncherActivity extends AppCompatActivity implements OnM @BindView(R.id.launch_btn_frame) FrameLayout launchBtnFrame; - private Marker currentMarker; - private Point currentLocation; - private Point destination; - private DirectionsRoute route; - private LocaleUtils localeUtils; - - private boolean locationFound; - @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -137,8 +134,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onStart() { super.onStart(); mapView.onStart(); - if (locationLayer != null) { - locationLayer.onStart(); + if (mapboxMap != null) { + mapboxMap.getLocationComponent().onStart(); } } @@ -174,8 +171,8 @@ public void onLowMemory() { protected void onStop() { super.onStop(); mapView.onStop(); - if (locationLayer != null) { - locationLayer.onStop(); + if (mapboxMap != null) { + mapboxMap.getLocationComponent().onStop(); } } @@ -203,9 +200,9 @@ public void onRouteLaunchClick() { @Override public void onMapReady(MapboxMap mapboxMap) { this.mapboxMap = mapboxMap; - this.mapboxMap.setOnMapLongClickListener(this); + this.mapboxMap.addOnMapLongClickListener(this); initLocationEngine(); - initLocationLayer(); + initializeLocationComponent(); initMapRoute(); } @@ -254,9 +251,11 @@ private void initLocationEngine() { } @SuppressWarnings( {"MissingPermission"}) - private void initLocationLayer() { - locationLayer = new LocationLayerPlugin(mapView, mapboxMap, locationEngine); - locationLayer.setRenderMode(RenderMode.COMPASS); + private void initializeLocationComponent() { + LocationComponent locationComponent = mapboxMap.getLocationComponent(); + locationComponent.activateLocationComponent(this, locationEngine); + locationComponent.setLocationComponentEnabled(true); + locationComponent.setRenderMode(RenderMode.COMPASS); } private void initMapRoute() { diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 2f8c1dc472c..39f231d92ce 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -12,7 +12,6 @@ ext { mapboxSdkServices : '4.0.0', mapboxEvents : '3.4.0', mapboxNavigator : '3.2.0', - locationLayerPlugin: '0.10.0', autoValue : '1.5.4', autoValueParcel : '0.2.5', junit : '4.12', @@ -53,7 +52,6 @@ ext { mapboxSdkTurf : "com.mapbox.mapboxsdk:mapbox-sdk-turf:${version.mapboxSdkServices}", mapboxEvents : "com.mapbox.mapboxsdk:mapbox-android-telemetry:${version.mapboxEvents}", mapboxNavigator : "com.mapbox.navigator:mapbox-navigation-native:${version.mapboxNavigator}", - locationLayerPlugin : "com.mapbox.mapboxsdk:mapbox-android-plugin-locationlayer:${version.locationLayerPlugin}", // AutoValue autoValue : "com.google.auto.value:auto-value:${version.autoValue}", diff --git a/libandroid-navigation-ui/build.gradle b/libandroid-navigation-ui/build.gradle index 4f2187ad877..55679991487 100644 --- a/libandroid-navigation-ui/build.gradle +++ b/libandroid-navigation-ui/build.gradle @@ -48,9 +48,6 @@ dependencies { implementation dependenciesList.lifecycleExtensions annotationProcessor dependenciesList.lifecycleCompiler - // Mapbox plugins - implementation dependenciesList.locationLayerPlugin - // AutoValues annotationProcessor dependenciesList.autoValue compileOnly dependenciesList.autoValue diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationContract.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationContract.java index 400d0c43675..ba822ef4e5e 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationContract.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationContract.java @@ -4,6 +4,7 @@ import com.mapbox.api.directions.v5.models.DirectionsRoute; import com.mapbox.geojson.Point; +import com.mapbox.services.android.navigation.ui.v5.camera.NavigationCamera; public interface NavigationContract { @@ -17,7 +18,7 @@ interface View { void updateWaynameVisibility(boolean isVisible); - void updateCameraTrackingEnabled(boolean isEnabled); + void updateCameraTrackingMode(@NavigationCamera.TrackingMode int trackingMode); void resetCameraPosition(); diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationOnCameraTrackingChangedListener.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationOnCameraTrackingChangedListener.java index c96e3313b66..e32ce0619a0 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationOnCameraTrackingChangedListener.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationOnCameraTrackingChangedListener.java @@ -2,7 +2,7 @@ import android.support.design.widget.BottomSheetBehavior; -import com.mapbox.mapboxsdk.plugins.locationlayer.OnCameraTrackingChangedListener; +import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener; /** * Listener used to detect user interaction with the map while driving. diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationPresenter.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationPresenter.java index 05f9a060ec3..ef338ec3f00 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationPresenter.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationPresenter.java @@ -5,6 +5,7 @@ import com.mapbox.api.directions.v5.models.DirectionsRoute; import com.mapbox.geojson.Point; +import com.mapbox.services.android.navigation.ui.v5.camera.NavigationCamera; class NavigationPresenter { @@ -31,7 +32,7 @@ void onCameraTrackingDismissed() { if (!view.isSummaryBottomSheetHidden()) { view.setSummaryBehaviorHideable(true); view.setSummaryBehaviorState(BottomSheetBehavior.STATE_HIDDEN); - view.updateCameraTrackingEnabled(false); + view.updateCameraTrackingMode(NavigationCamera.NAVIGATION_TRACKING_MODE_NONE); view.updateWaynameVisibility(false); } } diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationView.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationView.java index 332b90f3f27..0832b26bada 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationView.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationView.java @@ -24,6 +24,7 @@ import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.services.android.navigation.ui.v5.camera.NavigationCamera; import com.mapbox.services.android.navigation.ui.v5.instruction.ImageCoordinator; import com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView; import com.mapbox.services.android.navigation.ui.v5.map.NavigationMapboxMap; @@ -225,17 +226,18 @@ public boolean isSummaryBottomSheetHidden() { return summaryBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN; } + @Override - public void updateCameraTrackingEnabled(boolean isEnabled) { + public void updateCameraTrackingMode(int trackingMode) { if (navigationMap != null) { - navigationMap.updateCameraTrackingEnabled(isEnabled); + navigationMap.updateCameraTrackingMode(trackingMode); } } @Override public void resetCameraPosition() { if (navigationMap != null) { - navigationMap.resetCameraPosition(); + navigationMap.resetCameraPositionWith(NavigationCamera.NAVIGATION_TRACKING_MODE_GPS); } } diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/camera/NavigationCamera.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/camera/NavigationCamera.java index 1d19cd32bc4..3e00cbd594b 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/camera/NavigationCamera.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/camera/NavigationCamera.java @@ -15,9 +15,9 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.location.LocationComponent; +import com.mapbox.mapboxsdk.location.modes.CameraMode; import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin; -import com.mapbox.mapboxsdk.plugins.locationlayer.modes.CameraMode; import com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation; import com.mapbox.services.android.navigation.v5.navigation.camera.Camera; import com.mapbox.services.android.navigation.v5.navigation.camera.RouteInformation; @@ -49,16 +49,15 @@ public class NavigationCamera implements LifecycleObserver { private static final int ONE_POINT = 1; private MapboxMap mapboxMap; - private LocationLayerPlugin locationLayer; + private LocationComponent locationComponent; private MapboxNavigation navigation; private RouteInformation currentRouteInformation; private RouteProgress currentRouteProgress; - private boolean trackingEnabled; private ProgressChangeListener progressChangeListener = new ProgressChangeListener() { @Override public void onProgressChange(Location location, RouteProgress routeProgress) { currentRouteProgress = routeProgress; - if (trackingEnabled) { + if (isTrackingEnabled()) { currentRouteInformation = buildRouteInformationFromLocation(location, routeProgress); adjustCameraFromLocation(currentRouteInformation); } @@ -66,7 +65,10 @@ public void onProgressChange(Location location, RouteProgress routeProgress) { }; @Retention(RetentionPolicy.SOURCE) - @IntDef( {NAVIGATION_TRACKING_MODE_GPS, NAVIGATION_TRACKING_MODE_NORTH}) + @IntDef( {NAVIGATION_TRACKING_MODE_GPS, + NAVIGATION_TRACKING_MODE_NORTH, + NAVIGATION_TRACKING_MODE_NONE + }) public @interface TrackingMode { } @@ -84,23 +86,30 @@ public void onProgressChange(Location location, RouteProgress routeProgress) { */ public static final int NAVIGATION_TRACKING_MODE_NORTH = 1; + /** + * Camera does not tack the user location. + *
+ * Equivalent of the {@link CameraMode#NONE}. + */ + public static final int NAVIGATION_TRACKING_MODE_NONE = 2; + @TrackingMode private int trackingCameraMode = NAVIGATION_TRACKING_MODE_GPS; /** * Creates an instance of {@link NavigationCamera}. * - * @param mapboxMap for moving the camera - * @param navigation for listening to location updates - * @param locationLayer for managing camera mode + * @param mapboxMap for moving the camera + * @param navigation for listening to location updates + * @param locationComponent for managing camera mode * @since 0.6.0 */ public NavigationCamera(@NonNull MapboxMap mapboxMap, @NonNull MapboxNavigation navigation, - @NonNull LocationLayerPlugin locationLayer) { + @NonNull LocationComponent locationComponent) { this.mapboxMap = mapboxMap; this.navigation = navigation; - this.locationLayer = locationLayer; - initialize(); + this.locationComponent = locationComponent; + initializeWith(navigation); } /** @@ -108,23 +117,23 @@ public NavigationCamera(@NonNull MapboxMap mapboxMap, @NonNull MapboxNavigation *
* Camera will start tracking current user location by default.
*
- * @param mapboxMap for moving the camera
- * @param locationLayer for managing camera mode
+ * @param mapboxMap for moving the camera
+ * @param locationComponent for managing camera mode
* @since 0.15.0
*/
- public NavigationCamera(@NonNull MapboxMap mapboxMap, LocationLayerPlugin locationLayer) {
+ public NavigationCamera(@NonNull MapboxMap mapboxMap, LocationComponent locationComponent) {
this.mapboxMap = mapboxMap;
- this.locationLayer = locationLayer;
- setTrackingEnabled(true);
+ this.locationComponent = locationComponent;
+ updateCameraTrackingMode(trackingCameraMode);
}
/**
* Used for testing only.
*/
NavigationCamera(MapboxMap mapboxMap, MapboxNavigation navigation, ProgressChangeListener progressChangeListener,
- LocationLayerPlugin locationLayer) {
+ LocationComponent locationComponent) {
this.mapboxMap = mapboxMap;
- this.locationLayer = locationLayer;
+ this.locationComponent = locationComponent;
this.navigation = navigation;
this.progressChangeListener = progressChangeListener;
}
@@ -155,16 +164,6 @@ public void resume(Location location) {
navigation.addProgressChangeListener(progressChangeListener);
}
- /**
- * Setter for whether or not the camera should follow the location.
- *
- * @param trackingEnabled true if should track, false if should not
- * @since 0.6.0
- */
- public void updateCameraTrackingLocation(boolean trackingEnabled) {
- setTrackingEnabled(trackingEnabled);
- }
-
/**
* Updates the {@link TrackingMode} that's going to be used when camera tracking is enabled.
*
@@ -183,7 +182,7 @@ public void updateCameraTrackingMode(@TrackingMode int trackingMode) {
* @since 0.6.0
*/
public boolean isTrackingEnabled() {
- return trackingEnabled;
+ return trackingCameraMode != NAVIGATION_TRACKING_MODE_NONE;
}
/**
@@ -200,10 +199,12 @@ public int getCameraTrackingMode() {
/**
* Enables tracking and updates zoom/tilt based on the available route information.
*
+ * TODO javadoc updates
+ *
* @since 0.6.0
*/
- public void resetCameraPosition() {
- setTrackingEnabled(true);
+ public void resetCameraPositionWith(@TrackingMode int trackingCameraMode) {
+ updateCameraTrackingMode(trackingCameraMode);
if (currentRouteInformation != null) {
Camera camera = navigation.getCameraEngine();
if (camera instanceof DynamicCamera) {
@@ -214,7 +215,7 @@ public void resetCameraPosition() {
}
public void showRouteOverview(int[] padding) {
- setTrackingEnabled(false);
+ updateCameraTrackingMode(NAVIGATION_TRACKING_MODE_NONE);
RouteInformation routeInformation = buildRouteInformationFromProgress(currentRouteProgress);
animateCameraForRouteOverview(routeInformation, padding);
}
@@ -251,9 +252,9 @@ public void addProgressChangeListener(MapboxNavigation navigation) {
navigation.addProgressChangeListener(progressChangeListener);
}
- private void initialize() {
+ private void initializeWith(MapboxNavigation navigation) {
navigation.setCameraEngine(new DynamicCamera(mapboxMap));
- setTrackingEnabled(true);
+ updateCameraTrackingMode(trackingCameraMode);
}
/**
@@ -292,11 +293,6 @@ private RouteInformation buildRouteInformationFromProgress(RouteProgress routePr
return RouteInformation.create(routeProgress.directionsRoute(), null, null);
}
- private void setTrackingEnabled(boolean trackingEnabled) {
- this.trackingEnabled = trackingEnabled;
- setCameraMode();
- }
-
private void animateCameraForRouteOverview(RouteInformation routeInformation, int[] padding) {
Camera cameraEngine = navigation.getCameraEngine();
List
* Tracking is also re-enabled.
*/
- public void resetCameraPosition() {
- mapCamera.resetCameraPosition();
+ public void resetCameraPositionWith(@NavigationCamera.TrackingMode int trackingCameraMode) {
+ mapCamera.resetCameraPositionWith(trackingCameraMode);
resetMapPadding();
}
@@ -393,7 +380,7 @@ public void updateWaynameQueryMap(boolean isEnabled) {
* accounting for the lifecycle.
*/
public void onStart() {
- locationLayer.onStart();
+ locationComponent.onStart();
mapCamera.onStart();
mapRoute.onStart();
}
@@ -403,7 +390,7 @@ public void onStart() {
* accounting for the lifecycle.
*/
public void onStop() {
- locationLayer.onStop();
+ locationComponent.onStop();
mapCamera.onStop();
mapRoute.onStop();
mapWayname.onStop();
@@ -414,8 +401,8 @@ public void onStop() {
*
* @param isVisible true to show, false to hide
*/
- public void updateLocationLayerVisibilityTo(boolean isVisible) {
- locationLayer.setLocationLayerEnabled(isVisible);
+ public void updateLocationVisibilityTo(boolean isVisible) {
+ locationComponent.setLocationComponentEnabled(isVisible);
}
/**
@@ -468,7 +455,7 @@ public boolean isTrafficVisible() {
}
/**
- * Add a {@link OnCameraTrackingChangedListener} to the {@link LocationLayerPlugin} that is
+ * Add a {@link OnCameraTrackingChangedListener} to the {@link LocationComponent} that is
* wrapped within this class.
*
* This listener will fire any time camera tracking is dismissed or the camera mode is updated.
@@ -476,34 +463,36 @@ public boolean isTrafficVisible() {
* @param listener to be added
*/
public void addOnCameraTrackingChangedListener(OnCameraTrackingChangedListener listener) {
- locationLayer.addOnCameraTrackingChangedListener(listener);
+ locationComponent.addOnCameraTrackingChangedListener(listener);
}
/**
- * Remove a {@link OnCameraTrackingChangedListener} from the {@link LocationLayerPlugin} that is
+ * Remove a {@link OnCameraTrackingChangedListener} from the {@link LocationComponent} that is
* wrapped within this class.
*
* @param listener to be removed
*/
public void removeOnCameraTrackingChangedListener(OnCameraTrackingChangedListener listener) {
- locationLayer.removeOnCameraTrackingChangedListener(listener);
+ locationComponent.removeOnCameraTrackingChangedListener(listener);
}
public void takeScreenshot(NavigationSnapshotReadyCallback navigationSnapshotReadyCallback) {
mapboxMap.snapshot(navigationSnapshotReadyCallback);
}
- private void initializeLocationLayer(MapView mapView, MapboxMap map) {
+ private void initializeLocationComponent(MapView mapView, MapboxMap map) {
Context context = mapView.getContext();
int locationLayerStyleRes = ThemeSwitcher.retrieveNavigationViewStyle(context,
R.attr.navigationViewLocationLayerStyle);
- LocationLayerOptions locationLayerOptions =
- LocationLayerOptions.createFromAttributes(context, locationLayerStyleRes);
- locationLayerOptions = locationLayerOptions.toBuilder().minZoom(NAVIGATION_MINIMUM_MAP_ZOOM).build();
+ LocationComponentOptions locationComponentOptions =
+ LocationComponentOptions.createFromAttributes(context, locationLayerStyleRes);
+ locationComponentOptions = locationComponentOptions.toBuilder().minZoom(NAVIGATION_MINIMUM_MAP_ZOOM).build();
- locationLayer = new LocationLayerPlugin(mapView, map, null, locationLayerOptions);
- locationLayer.setRenderMode(RenderMode.GPS);
+ locationComponent = map.getLocationComponent();
+ locationComponent.activateLocationComponent(context, null, locationComponentOptions);
+ locationComponent.setLocationComponentEnabled(true);
+ locationComponent.setRenderMode(RenderMode.GPS);
}
private void initializeMapPaddingAdjustor(MapView mapView, MapboxMap mapboxMap) {
@@ -511,7 +500,7 @@ private void initializeMapPaddingAdjustor(MapView mapView, MapboxMap mapboxMap)
}
private void initializeCamera(MapboxMap map) {
- mapCamera = new NavigationCamera(map, locationLayer);
+ mapCamera = new NavigationCamera(map, locationComponent);
}
private void initializeWayname(MapView mapView, MapboxMap mapboxMap, MapLayerInteractor layerInteractor,
diff --git a/libandroid-navigation-ui/src/main/res/values/styles.xml b/libandroid-navigation-ui/src/main/res/values/styles.xml
index d13fe672e07..66ffea65348 100644
--- a/libandroid-navigation-ui/src/main/res/values/styles.xml
+++ b/libandroid-navigation-ui/src/main/res/values/styles.xml
@@ -74,7 +74,7 @@