From 4d9e23f3c764e414a728a815ff9ec88ada467767 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Mon, 10 Aug 2020 12:52:07 +0300 Subject: [PATCH] Fix #9408 --- .../plus/views/layers/MapControlsLayer.java | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java index 4300046334..e28f3e864c 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java @@ -405,20 +405,50 @@ public class MapControlsLayer extends OsmandMapLayer { backToLocation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) { - mapActivity.getMapViewTrackingUtilities().backToLocationImpl(); - } else { - ActivityCompat.requestPermissions(mapActivity, - new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, - OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); - } + onBackToLocationClick(false); } }); + + backToLocation.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + onBackToLocationClick(true); + return false; + } + }); + controls.add(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) { this.hasTargets = hasTargets; onNavigationClick();