Navigation now car request location permission.

This commit is contained in:
GaidamakUA 2015-12-04 15:21:50 +02:00
parent d044d5f850
commit d199406c75
2 changed files with 84 additions and 63 deletions

View file

@ -1058,6 +1058,10 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents,
@Override @Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
OsmandPlugin.onRequestPermissionsResult(requestCode, permissions, grantResults, this); OsmandPlugin.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
MapControlsLayer mcl = mapView.getLayerByClass(MapControlsLayer.class);
if (mcl != null) {
mcl.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
} }

View file

@ -4,6 +4,7 @@ import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.ColorFilter; import android.graphics.ColorFilter;
@ -57,6 +58,7 @@ public class MapControlsLayer extends OsmandMapLayer {
private static final int TIMEOUT_TO_SHOW_BUTTONS = 7000; private static final int TIMEOUT_TO_SHOW_BUTTONS = 7000;
public static final int REQUEST_ADDRESS_SELECT = 2; public static final int REQUEST_ADDRESS_SELECT = 2;
private static final int REQUEST_LOCATION_FOR_NAVIGATION_PERMISSION = 200;
public MapHudButton createHudButton(View iv, int resId) { public MapHudButton createHudButton(View iv, int resId) {
MapHudButton mc = new MapHudButton(); MapHudButton mc = new MapHudButton();
@ -459,6 +461,18 @@ public class MapControlsLayer extends OsmandMapLayer {
routePlanButton.setOnClickListener(new View.OnClickListener() { routePlanButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
onNavigationClick();
} else {
ActivityCompat.requestPermissions(mapActivity,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
REQUEST_LOCATION_FOR_NAVIGATION_PERMISSION);
}
}
});
}
private void onNavigationClick() {
notifyClicked(); notifyClicked();
RoutingHelper routingHelper = mapActivity.getRoutingHelper(); RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) { if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
@ -467,8 +481,6 @@ public class MapControlsLayer extends OsmandMapLayer {
switchToRoutePlanningLayout(); switchToRoutePlanningLayout();
} }
} }
});
}
public void switchToRouteFollowingLayout() { public void switchToRouteFollowingLayout() {
@ -545,7 +557,6 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
private void stopCounter() { private void stopCounter() {
startCounter = 0; startCounter = 0;
@ -594,7 +605,6 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
private void updateControls(@NonNull RotatedTileBox tileBox, DrawSettings nightMode) { private void updateControls(@NonNull RotatedTileBox tileBox, DrawSettings nightMode) {
boolean isNight = nightMode != null && nightMode.isNightMode(); boolean isNight = nightMode != null && nightMode.isNightMode();
int shadw = isNight ? Color.TRANSPARENT : Color.WHITE; int shadw = isNight ? Color.TRANSPARENT : Color.WHITE;
@ -1030,4 +1040,11 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
} }
} }
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == REQUEST_LOCATION_FOR_NAVIGATION_PERMISSION
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
onNavigationClick();
}
}
} }