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 24, 2018
1 parent 596dd6e commit c9bd57a
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 228 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,18 +289,12 @@ public void onPause() {
protected void onStart() {
super.onStart();
mapView.onStart();
if (locationLayerPlugin != null) {
locationLayerPlugin.onStart();
}
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,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 @@ -66,7 +66,6 @@ public class RerouteActivity extends HistoryActivity implements OnMapReadyCallba
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 @@ -102,14 +101,10 @@ public void onResume() {
mapView.onResume();
}

@SuppressLint("MissingPermission")
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
if (locationLayerPlugin != null) {
locationLayerPlugin.onStart();
}
}

@Override
Expand All @@ -125,10 +120,6 @@ protected void onStop() {

shutdownLocationEngine();

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

if (navigation != null) {
navigation.stopNavigation();
}
Expand Down Expand Up @@ -159,8 +150,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 +170,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 +218,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.activity.HistoryActivity;
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 @@ -131,7 +132,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 @@ -156,7 +157,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 @@ -177,7 +178,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,9 +162,6 @@ public void onStart() {
super.onStart();
navigationView.onStart();
mapView.onStart();
if (locationLayer != null) {
locationLayer.onStart();
}
}

@Override
Expand Down Expand Up @@ -224,9 +219,6 @@ public void onStop() {
super.onStop();
navigationView.onStop();
mapView.onStop();
if (locationLayer != null) {
locationLayer.onStop();
}
}

@Override
Expand Down Expand Up @@ -313,9 +305,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 @@ -132,14 +129,10 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

@SuppressWarnings( {"MissingPermission"})
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
if (locationLayer != null) {
locationLayer.onStart();
}
}

@SuppressWarnings( {"MissingPermission"})
Expand Down Expand Up @@ -174,9 +167,6 @@ public void onLowMemory() {
protected void onStop() {
super.onStop();
mapView.onStop();
if (locationLayer != null) {
locationLayer.onStop();
}
}

@Override
Expand All @@ -203,9 +193,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 +244,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
Loading

0 comments on commit c9bd57a

Please sign in to comment.