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();
@ -233,7 +235,7 @@ public class MapControlsLayer extends OsmandMapLayer {
dashRouteButton.setOnClickListener(new View.OnClickListener() { dashRouteButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if(dash) { if (dash) {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD); mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD);
} else { } else {
mapActivity.openDrawer(); mapActivity.openDrawer();
@ -284,7 +286,7 @@ public class MapControlsLayer extends OsmandMapLayer {
TextView routeGoButton = (TextView) mapActivity.findViewById(R.id.map_go_route_button); TextView routeGoButton = (TextView) mapActivity.findViewById(R.id.map_go_route_button);
routeGoControl = createHudButton(routeGoButton, routeGoControl = createHudButton(routeGoButton,
R.drawable.map_start_navigation).setIconColorId(R.color.color_myloc_distance) .setBg( R.drawable.map_start_navigation).setIconColorId(R.color.color_myloc_distance).setBg(
R.drawable.btn_flat, R.drawable.btn_flat_night); R.drawable.btn_flat, R.drawable.btn_flat_night);
controls.add(routeGoControl); controls.add(routeGoControl);
routeGoButton.setText(mapActivity.getString(R.string.shared_string_go)); routeGoButton.setText(mapActivity.getString(R.string.shared_string_go));
@ -409,11 +411,11 @@ public class MapControlsLayer extends OsmandMapLayer {
backToLocation.setOnClickListener(new View.OnClickListener() { backToLocation.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if(OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) { if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
mapActivity.getMapViewTrackingUtilities().backToLocationImpl(); mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
} else { } else {
ActivityCompat.requestPermissions(mapActivity, ActivityCompat.requestPermissions(mapActivity,
new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION);
} }
} }
@ -434,7 +436,7 @@ public class MapControlsLayer extends OsmandMapLayer {
// double lon = activity.getMapView().getLongitude(); // double lon = activity.getMapView().getLongitude();
// MainMenuActivity.backToMainMenuDialog(activity, new LatLon(lat, lon)); // MainMenuActivity.backToMainMenuDialog(activity, new LatLon(lat, lon));
notifyClicked(); notifyClicked();
if(dash) { if (dash) {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD); mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD);
} else { } else {
mapActivity.openDrawer(); mapActivity.openDrawer();
@ -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;
@ -622,7 +632,7 @@ public class MapControlsLayer extends OsmandMapLayer {
updateMyLocation(rh, dialogOpened); updateMyLocation(rh, dialogOpened);
// routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_gabout_dark : R.drawable.map_directions ); // routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_gabout_dark : R.drawable.map_directions );
// routePlanningBtn.updateVisibility(showButtons && !routePlanningMode); // routePlanningBtn.updateVisibility(showButtons && !routePlanningMode);
routePlanningBtn.setIconResId(R.drawable.map_directions ); routePlanningBtn.setIconResId(R.drawable.map_directions);
routePlanningBtn.updateVisibility(!routeFollowingMode && !routePlanningMode); routePlanningBtn.updateVisibility(!routeFollowingMode && !routePlanningMode);
menuControl.updateVisibility(showMenuButton && !dialogOpened); menuControl.updateVisibility(showMenuButton && !dialogOpened);
@ -631,7 +641,7 @@ public class MapControlsLayer extends OsmandMapLayer {
compassHud.updateVisibility(!dialogOpened); compassHud.updateVisibility(!dialogOpened);
layersHud.updateVisibility(!dialogOpened); layersHud.updateVisibility(!dialogOpened);
if(routeFollowingMode || routePlanningMode) { if (routeFollowingMode || routePlanningMode) {
mapAppModeShadow.setVisibility(View.GONE); mapAppModeShadow.setVisibility(View.GONE);
} else { } else {
if (mapView.isZooming()) { if (mapView.isZooming()) {
@ -639,7 +649,7 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
mapAppModeShadow.setVisibility(View.VISIBLE); mapAppModeShadow.setVisibility(View.VISIBLE);
//if (!mapView.isZooming() || !OsmandPlugin.isDevelopment()) { //if (!mapView.isZooming() || !OsmandPlugin.isDevelopment()) {
if ((System.currentTimeMillis()-lastZoom > 1000) || !OsmandPlugin.isDevelopment()) { if ((System.currentTimeMillis() - lastZoom > 1000) || !OsmandPlugin.isDevelopment()) {
zoomText.setVisibility(View.GONE); zoomText.setVisibility(View.GONE);
appModeIcon.setVisibility(View.VISIBLE); appModeIcon.setVisibility(View.VISIBLE);
appModeIcon.setImageDrawable( appModeIcon.setImageDrawable(
@ -812,7 +822,7 @@ public class MapControlsLayer extends OsmandMapLayer {
public MapHudButton setBg(int dayBg, int nightBg) { public MapHudButton setBg(int dayBg, int nightBg) {
if(bgDark == nightBg && dayBg == bgLight) { if (bgDark == nightBg && dayBg == bgLight) {
return this; return this;
} }
bgDark = nightBg; bgDark = nightBg;
@ -835,7 +845,7 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
public MapHudButton setBg(int bg) { public MapHudButton setBg(int bg) {
if(bgDark == bg && bg == bgLight) { if (bgDark == bg && bg == bgLight) {
return this; return this;
} }
bgDark = bg; bgDark = bg;
@ -899,11 +909,11 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
} }
Drawable d = null; Drawable d = null;
if(resDarkId != 0 && nightMode) { if (resDarkId != 0 && nightMode) {
d = ctx.getIconsCache().getIcon(resDarkId); d = ctx.getIconsCache().getIcon(resDarkId);
} else if(resLightId != 0 && !nightMode) { } else if (resLightId != 0 && !nightMode) {
d = ctx.getIconsCache().getIcon(resLightId); d = ctx.getIconsCache().getIcon(resLightId);
} else if(resId != 0){ } else if (resId != 0) {
d = ctx.getIconsCache().getIcon(resId, nightMode ? resClrDark : resClrLight); d = ctx.getIconsCache().getIcon(resId, nightMode ? resClrDark : resClrLight);
} }
@ -972,7 +982,7 @@ public class MapControlsLayer extends OsmandMapLayer {
final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY; final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext()); final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
int p = (int) (mapDensity.get() * 100); int p = (int) (mapDensity.get() * 100);
final TIntArrayList tlist = new TIntArrayList(new int[] { 20, 25, 33, 50, 75, 100, 150, 200, 300, 400 }); final TIntArrayList tlist = new TIntArrayList(new int[]{20, 25, 33, 50, 75, 100, 150, 200, 300, 400});
final List<String> values = new ArrayList<String>(); final List<String> values = new ArrayList<String>();
int i = -1; int i = -1;
for (int k = 0; k <= tlist.size(); k++) { for (int k = 0; k <= tlist.size(); k++) {
@ -1017,17 +1027,24 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == REQUEST_ADDRESS_SELECT && resultCode == SearchAddressFragment.SELECT_ADDRESS_POINT_RESULT_OK){ if (requestCode == REQUEST_ADDRESS_SELECT && resultCode == SearchAddressFragment.SELECT_ADDRESS_POINT_RESULT_OK) {
String name = data.getStringExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_INTENT_KEY); String name = data.getStringExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_INTENT_KEY);
boolean target = data.getBooleanExtra(MapRouteInfoControl.TARGET_SELECT, true); boolean target = data.getBooleanExtra(MapRouteInfoControl.TARGET_SELECT, true);
LatLon latLon = new LatLon( LatLon latLon = new LatLon(
data.getDoubleExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_LAT, 0), data.getDoubleExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_LAT, 0),
data.getDoubleExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_LON, 0)); data.getDoubleExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_LON, 0));
if(name != null){ if (name != null) {
mapRouteInfoControlDialog.selectAddress(name, latLon, target); mapRouteInfoControlDialog.selectAddress(name, latLon, target);
} else { } else {
mapRouteInfoControlDialog.selectAddress("", latLon, target); mapRouteInfoControlDialog.selectAddress("", latLon, target);
} }
} }
} }
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == REQUEST_LOCATION_FOR_NAVIGATION_PERMISSION
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
onNavigationClick();
}
}
} }