Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;

import com.mapbox.android.core.location.LocationEngine;
import com.mapbox.android.core.location.LocationEnginePriority;
Expand Down Expand Up @@ -50,6 +48,7 @@ public void onMapReady(MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable();
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationEngine.setFastestInterval(1000);
locationEngine.activate();
locationPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine);
locationPlugin.setRenderMode(RenderMode.COMPASS);
Expand All @@ -64,9 +63,13 @@ public void onStyleFabClick() {
}

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

@Override
Expand Down Expand Up @@ -96,27 +99,6 @@ protected void onSaveInstanceState(Bundle outState) {
mapView.onSaveInstanceState(outState);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_location, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (locationPlugin == null) {
return super.onOptionsItemSelected(item);
}

if (item.getItemId() == R.id.action_style_change) {
customStyle = !customStyle;
locationPlugin.applyStyle(customStyle ? R.style.CustomLocationLayer : R.style.mapbox_LocationLayer);
return true;
}

return super.onOptionsItemSelected(item);
}

@Override
protected void onDestroy() {
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,24 @@ public void removeOnLocationStaleListener(@NonNull OnLocationStaleListener liste
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
@OnLifecycleEvent(Lifecycle.Event.ON_START)
public void onStart() {
onLocationLayerStart();
if (isEnabled) {
mapView.addOnMapChangedListener(onMapChangedListener);
}
}

/**
* Required to place inside your activities {@code onStop} method.
*
* @since 0.1.0
*/
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
public void onStop() {
onLocationLayerStop();
mapView.removeOnMapChangedListener(onMapChangedListener);
}

void onLocationLayerStart() {
if (isEnabled) {
if (locationEngine != null) {
locationEngine.addLocationEngineListener(locationEngineListener);
Expand All @@ -432,13 +450,7 @@ public void onStart() {
compassManager.onStart();
}

/**
* Required to place inside your activities {@code onStop} method.
*
* @since 0.1.0
*/
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
public void onStop() {
void onLocationLayerStop() {
staleStateManager.onStop();
compassManager.onStop();
locationLayerAnimator.cancelAllAnimations();
Expand All @@ -453,7 +465,6 @@ public void onStop() {
private void initialize() {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

mapView.addOnMapChangedListener(onMapChangedListener);
mapboxMap.addOnMapClickListener(onMapClickListener);
mapboxMap.addOnMapLongClickListener(onMapLongClickListener);

Expand All @@ -478,13 +489,13 @@ private void initialize() {
@SuppressLint("MissingPermission")
private void enableLocationLayerPlugin() {
isEnabled = true;
onStart();
onLocationLayerStart();
locationLayer.show();
}

private void disableLocationLayerPlugin() {
isEnabled = false;
onStop();
onLocationLayerStop();
locationLayer.hide();
}

Expand Down Expand Up @@ -601,13 +612,13 @@ public void onStaleStateChange(boolean isStale) {
@Override
public void onMapChanged(int change) {
if (change == MapView.WILL_START_LOADING_MAP) {
onStop();
onLocationLayerStop();
} else if (change == MapView.DID_FINISH_LOADING_STYLE) {
locationLayer.initializeComponents(options);
locationLayerCamera.initializeOptions(options);
setRenderMode(locationLayer.getRenderMode());
Copy link
Contributor

@LukasPaczos LukasPaczos May 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the plugin is disabled and we change the style this line will draw the puck in the last location even though the plugin is disabled. Could you address it in this PR as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, want to make this clear that this is a bug that is in master though, not something I introduced in this PR...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking into this, I'm not finding a solution to this fix. Will open a ticket and revisit in a separate PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setCameraMode(locationLayerCamera.getCameraMode());
onStart();
onLocationLayerStart();
}
}
};
Expand Down