This commit is contained in:
Nazar-Kutz 2020-08-10 12:52:07 +03:00
parent b9a4d2843a
commit 4d9e23f3c7

View file

@ -405,20 +405,50 @@ public class MapControlsLayer extends OsmandMapLayer {
backToLocation.setOnClickListener(new View.OnClickListener() { backToLocation.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) { onBackToLocationClick(false);
mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
} else {
ActivityCompat.requestPermissions(mapActivity,
new String[] {Manifest.permission.ACCESS_FINE_LOCATION},
OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION);
}
} }
}); });
backToLocation.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
onBackToLocationClick(true);
return false;
}
});
controls.add(backToLocationButton); controls.add(backToLocationButton);
return backToLocationButton; return backToLocationButton;
} }
private void onBackToLocationClick(boolean longClick) {
if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
if (longClick) {
showContextMenuForMyLocation();
} else {
mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
}
} else {
ActivityCompat.requestPermissions(mapActivity,
new String[] {Manifest.permission.ACCESS_FINE_LOCATION},
OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION);
}
}
private void showContextMenuForMyLocation() {
OsmAndLocationProvider lp = app.getLocationProvider();
net.osmand.Location lastKnownLocation = lp.getLastKnownLocation();
net.osmand.Location lastStaleKnownLocation = lp.getLastStaleKnownLocation();
net.osmand.Location location = lastKnownLocation != null ? lastKnownLocation : lastStaleKnownLocation;
if (location != null) {
ContextMenuLayer cml = mapActivity.getMapView().getLayerByClass(ContextMenuLayer.class);
if (cml != null) {
cml.showContextMenu(location.getLatitude(), location.getLongitude(), true);
}
}
}
public void doRoute(boolean hasTargets) { public void doRoute(boolean hasTargets) {
this.hasTargets = hasTargets; this.hasTargets = hasTargets;
onNavigationClick(); onNavigationClick();