Merge pull request #6041 from osmandapp/Fix_5797

Fix #5797
This commit is contained in:
Alexander Sytnyk 2018-09-14 16:38:48 +03:00 committed by GitHub
commit 60b62b6c7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 21 deletions

View file

@ -11,6 +11,7 @@
Thx - Hardy
-->
<string name="ask_for_location_permission">Please give OsmAnd permission for location to continue.</string>
<string name="thank_you_for_feedback">Thank you for feedback</string>
<string name="poi_cannot_be_found">Node or way cannot be found.</string>
<string name="search_no_results_feedback">No search results?\nGive us feedback</string>

View file

@ -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);
}
}
}

View file

@ -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;
@ -84,6 +86,8 @@ public class MapActivityActions implements DialogProvider {
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;
public static final int SEARCH_NEAR_ITEM_ORDER = 2000;
@ -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);

View file

@ -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);
}
}
}
}