diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 48228e08c4..90dbbcb1fd 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + Please give OsmAnd permission for location to continue. Thank you for feedback Node or way cannot be found. No search results?\nGive us feedback diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 2e35e7dfa6..4672df1687 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1703,6 +1703,17 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } } }, 1); + } else if (requestCode == MapActivityActions.REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION + && grantResults.length > 0 && permissions.length > 0 + && Manifest.permission.ACCESS_FINE_LOCATION.equals(permissions[0])) { + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + LatLon latLon = getContextMenu().getLatLon(); + if (latLon != null) { + mapActions.enterDirectionsFromPoint(latLon.getLatitude(), latLon.getLongitude()); + } + } else { + app.showToastMessage(R.string.ask_for_location_permission); + } } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 0c808453b0..c61b5880e6 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -1,5 +1,6 @@ package net.osmand.plus.activities; +import android.Manifest; import android.app.Activity; import android.app.Dialog; import android.content.DialogInterface; @@ -7,6 +8,7 @@ import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.view.View; @@ -83,6 +85,8 @@ public class MapActivityActions implements DialogProvider { public static final String KEY_NAME = "name"; public static final String KEY_ZOOM = "zoom"; + + public static final int REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION = 203; // Constants for determining the order of items in the additional actions context menu public static final int DIRECTIONS_FROM_ITEM_ORDER = 1000; @@ -351,16 +355,12 @@ public class MapActivityActions implements DialogProvider { } else if (standardId == R.string.context_menu_item_search) { mapActivity.showQuickSearch(latitude, longitude); } else if (standardId == R.string.context_menu_item_directions_from) { - mapActivity.getContextMenu().hide(); - if (getMyApplication().getTargetPointsHelper().getPointToNavigate() == null) { - setFirstMapMarkerAsTarget(); - } - if (!mapActivity.getRoutingHelper().isFollowingMode() && !mapActivity.getRoutingHelper().isRoutePlanningMode()) { - enterRoutePlanningMode(new LatLon(latitude, longitude), - mapActivity.getContextMenu().getPointDescription()); + if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) { + enterDirectionsFromPoint(latitude, longitude); + } else if (!ActivityCompat.shouldShowRequestPermissionRationale(mapActivity, Manifest.permission.ACCESS_FINE_LOCATION)) { + mapActivity.getMyApplication().showToastMessage(R.string.ask_for_location_permission); } else { - getMyApplication().getTargetPointsHelper().setStartPoint(new LatLon(latitude, longitude), - true, mapActivity.getContextMenu().getPointDescription()); + ActivityCompat.requestPermissions(mapActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION); } } else if (standardId == R.string.measurement_tool) { mapActivity.getContextMenu().close(); @@ -371,6 +371,20 @@ public class MapActivityActions implements DialogProvider { actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), AdditionalActionsBottomSheetDialogFragment.TAG); } + public void enterDirectionsFromPoint(final double latitude, final double longitude) { + mapActivity.getContextMenu().hide(); + if (getMyApplication().getTargetPointsHelper().getPointToNavigate() == null) { + setFirstMapMarkerAsTarget(); + } + if (!mapActivity.getRoutingHelper().isFollowingMode() && !mapActivity.getRoutingHelper().isRoutePlanningMode()) { + enterRoutePlanningMode(new LatLon(latitude, longitude), + mapActivity.getContextMenu().getPointDescription()); + } else { + getMyApplication().getTargetPointsHelper().setStartPoint(new LatLon(latitude, longitude), + true, mapActivity.getContextMenu().getPointDescription()); + } + } + public void setGPXRouteParams(GPXFile result) { if (result == null) { mapActivity.getRoutingHelper().setGpxParams(null); diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 1650d6b059..167ab41942 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -442,6 +442,8 @@ public class MapControlsLayer extends OsmandMapLayer { this.hasTargets = hasTargets; if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) { onNavigationClick(); + } else if (!ActivityCompat.shouldShowRequestPermissionRationale(mapActivity, Manifest.permission.ACCESS_FINE_LOCATION)) { + app.showToastMessage(R.string.ask_for_location_permission); } else { ActivityCompat.requestPermissions(mapActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, @@ -1310,18 +1312,22 @@ public class MapControlsLayer extends OsmandMapLayer { } public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { - if (requestCode == REQUEST_LOCATION_FOR_NAVIGATION_PERMISSION - && grantResults.length > 0 - && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - onNavigationClick(); - } else if (requestCode == REQUEST_LOCATION_FOR_NAVIGATION_FAB_PERMISSION - && grantResults.length > 0 - && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - navigateButton(); - } else if (requestCode == REQUEST_LOCATION_FOR_ADD_DESTINATION_PERMISSION - && grantResults.length > 0 - && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - addDestination(requestedLatLon); + if (grantResults.length > 0) { + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + switch (requestCode) { + case REQUEST_LOCATION_FOR_NAVIGATION_PERMISSION: + onNavigationClick(); + break; + case REQUEST_LOCATION_FOR_NAVIGATION_FAB_PERMISSION: + navigateButton(); + break; + case REQUEST_LOCATION_FOR_ADD_DESTINATION_PERMISSION: + addDestination(requestedLatLon); + break; + } + } else if (grantResults[0] == PackageManager.PERMISSION_DENIED) { + app.showToastMessage(R.string.ask_for_location_permission); + } } } }