This commit is contained in:
Chumva 2018-09-14 16:34:02 +03:00
parent d4a75fb88a
commit 603577ff05
4 changed files with 53 additions and 21 deletions

View file

@ -11,6 +11,7 @@
Thx - Hardy 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="thank_you_for_feedback">Thank you for feedback</string>
<string name="poi_cannot_be_found">Node or way cannot be found.</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> <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); }, 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; package net.osmand.plus.activities;
import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -7,6 +8,7 @@ import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.View; import android.view.View;
@ -84,6 +86,8 @@ public class MapActivityActions implements DialogProvider {
public static final String KEY_ZOOM = "zoom"; 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 // 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 DIRECTIONS_FROM_ITEM_ORDER = 1000;
public static final int SEARCH_NEAR_ITEM_ORDER = 2000; public static final int SEARCH_NEAR_ITEM_ORDER = 2000;
@ -351,6 +355,23 @@ public class MapActivityActions implements DialogProvider {
} else if (standardId == R.string.context_menu_item_search) { } else if (standardId == R.string.context_menu_item_search) {
mapActivity.showQuickSearch(latitude, longitude); mapActivity.showQuickSearch(latitude, longitude);
} else if (standardId == R.string.context_menu_item_directions_from) { } else if (standardId == R.string.context_menu_item_directions_from) {
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 {
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();
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), new LatLon(latitude, longitude));
}
}
});
actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), AdditionalActionsBottomSheetDialogFragment.TAG);
}
public void enterDirectionsFromPoint(final double latitude, final double longitude) {
mapActivity.getContextMenu().hide(); mapActivity.getContextMenu().hide();
if (getMyApplication().getTargetPointsHelper().getPointToNavigate() == null) { if (getMyApplication().getTargetPointsHelper().getPointToNavigate() == null) {
setFirstMapMarkerAsTarget(); setFirstMapMarkerAsTarget();
@ -362,13 +383,6 @@ public class MapActivityActions implements DialogProvider {
getMyApplication().getTargetPointsHelper().setStartPoint(new LatLon(latitude, longitude), getMyApplication().getTargetPointsHelper().setStartPoint(new LatLon(latitude, longitude),
true, mapActivity.getContextMenu().getPointDescription()); true, mapActivity.getContextMenu().getPointDescription());
} }
} else if (standardId == R.string.measurement_tool) {
mapActivity.getContextMenu().close();
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), new LatLon(latitude, longitude));
}
}
});
actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), AdditionalActionsBottomSheetDialogFragment.TAG);
} }
public void setGPXRouteParams(GPXFile result) { public void setGPXRouteParams(GPXFile result) {

View file

@ -442,6 +442,8 @@ public class MapControlsLayer extends OsmandMapLayer {
this.hasTargets = hasTargets; this.hasTargets = hasTargets;
if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) { if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
onNavigationClick(); onNavigationClick();
} else if (!ActivityCompat.shouldShowRequestPermissionRationale(mapActivity, Manifest.permission.ACCESS_FINE_LOCATION)) {
app.showToastMessage(R.string.ask_for_location_permission);
} else { } else {
ActivityCompat.requestPermissions(mapActivity, ActivityCompat.requestPermissions(mapActivity,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 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) { public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == REQUEST_LOCATION_FOR_NAVIGATION_PERMISSION if (grantResults.length > 0) {
&& grantResults.length > 0 if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { switch (requestCode) {
case REQUEST_LOCATION_FOR_NAVIGATION_PERMISSION:
onNavigationClick(); onNavigationClick();
} else if (requestCode == REQUEST_LOCATION_FOR_NAVIGATION_FAB_PERMISSION break;
&& grantResults.length > 0 case REQUEST_LOCATION_FOR_NAVIGATION_FAB_PERMISSION:
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
navigateButton(); navigateButton();
} else if (requestCode == REQUEST_LOCATION_FOR_ADD_DESTINATION_PERMISSION break;
&& grantResults.length > 0 case REQUEST_LOCATION_FOR_ADD_DESTINATION_PERMISSION:
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
addDestination(requestedLatLon); addDestination(requestedLatLon);
break;
}
} else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
app.showToastMessage(R.string.ask_for_location_permission);
}
} }
} }
} }