Skip to content

Commit

Permalink
Replace LocationLayerPlugin with LocationComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Oct 18, 2018
1 parent 2fa308a commit ef59dc9
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 205 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dependencies {
// Mapbox Navigation SDK
implementation project(':libandroid-navigation-ui')
implementation dependenciesList.mapboxMapSdk
implementation dependenciesList.locationLayerPlugin

// Support libraries
implementation dependenciesList.supportAppcompatV7
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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());
}

Expand All @@ -287,17 +289,17 @@ public void onPause() {
protected void onStart() {
super.onStart();
mapView.onStart();
if (locationLayerPlugin != null) {
locationLayerPlugin.onStart();
if (mapboxMap != null) {
mapboxMap.getLocationComponent().onStart();
}
}

@Override
protected void onStop() {
super.onStop();
mapView.onStop();
if (locationLayerPlugin != null) {
locationLayerPlugin.onStop();
if (mapboxMap != null) {
mapboxMap.getLocationComponent().onStop();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -125,8 +124,8 @@ protected void onStop() {

shutdownLocationEngine();

if (locationLayerPlugin != null) {
locationLayerPlugin.onStop();
if (mapboxMap != null) {
mapboxMap.getLocationComponent().onStop();
}

if (navigation != null) {
Expand Down Expand Up @@ -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);
Expand All @@ -177,7 +178,7 @@ public void onConnected() {
@Override
public void onLocationChanged(Location location) {
if (!tracking) {
locationLayerPlugin.forceLocationUpdate(location);
mapboxMap.getLocationComponent().forceLocationUpdate(location);
}
}

Expand Down Expand Up @@ -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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -164,8 +162,8 @@ public void onStart() {
super.onStart();
navigationView.onStart();
mapView.onStart();
if (locationLayer != null) {
locationLayer.onStart();
if (mapboxMap != null) {
mapboxMap.getLocationComponent().onStart();
}
}

Expand Down Expand Up @@ -224,8 +222,8 @@ public void onStop() {
super.onStop();
navigationView.onStop();
mapView.onStop();
if (locationLayer != null) {
locationLayer.onStop();
if (mapboxMap != null) {
mapboxMap.getLocationComponent().onStop();
}
}

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 0 additions & 2 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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}",
Expand Down
Loading

0 comments on commit ef59dc9

Please sign in to comment.