Navigation now car request location permission.
This commit is contained in:
parent
d044d5f850
commit
d199406c75
2 changed files with 84 additions and 63 deletions
|
@ -1058,6 +1058,10 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents,
|
|||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.Manifest;
|
|||
import android.annotation.SuppressLint;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
|
@ -57,6 +58,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
|
||||
private static final int TIMEOUT_TO_SHOW_BUTTONS = 7000;
|
||||
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) {
|
||||
MapHudButton mc = new MapHudButton();
|
||||
|
@ -233,7 +235,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
dashRouteButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(dash) {
|
||||
if (dash) {
|
||||
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD);
|
||||
} else {
|
||||
mapActivity.openDrawer();
|
||||
|
@ -284,7 +286,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
TextView routeGoButton = (TextView) mapActivity.findViewById(R.id.map_go_route_button);
|
||||
|
||||
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);
|
||||
controls.add(routeGoControl);
|
||||
routeGoButton.setText(mapActivity.getString(R.string.shared_string_go));
|
||||
|
@ -409,11 +411,11 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
backToLocation.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
|
||||
if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
|
||||
mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(mapActivity,
|
||||
new String[] {Manifest.permission.ACCESS_FINE_LOCATION},
|
||||
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
|
||||
OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION);
|
||||
}
|
||||
}
|
||||
|
@ -434,7 +436,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
// double lon = activity.getMapView().getLongitude();
|
||||
// MainMenuActivity.backToMainMenuDialog(activity, new LatLon(lat, lon));
|
||||
notifyClicked();
|
||||
if(dash) {
|
||||
if (dash) {
|
||||
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD);
|
||||
} else {
|
||||
mapActivity.openDrawer();
|
||||
|
@ -459,6 +461,18 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
routePlanButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
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();
|
||||
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
|
||||
if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
|
||||
|
@ -467,8 +481,6 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
switchToRoutePlanningLayout();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void switchToRouteFollowingLayout() {
|
||||
|
@ -545,7 +557,6 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
}
|
||||
|
||||
|
||||
|
||||
private void stopCounter() {
|
||||
startCounter = 0;
|
||||
|
||||
|
@ -594,7 +605,6 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
}
|
||||
|
||||
|
||||
|
||||
private void updateControls(@NonNull RotatedTileBox tileBox, DrawSettings nightMode) {
|
||||
boolean isNight = nightMode != null && nightMode.isNightMode();
|
||||
int shadw = isNight ? Color.TRANSPARENT : Color.WHITE;
|
||||
|
@ -622,7 +632,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
updateMyLocation(rh, dialogOpened);
|
||||
// routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_gabout_dark : R.drawable.map_directions );
|
||||
// routePlanningBtn.updateVisibility(showButtons && !routePlanningMode);
|
||||
routePlanningBtn.setIconResId(R.drawable.map_directions );
|
||||
routePlanningBtn.setIconResId(R.drawable.map_directions);
|
||||
routePlanningBtn.updateVisibility(!routeFollowingMode && !routePlanningMode);
|
||||
|
||||
menuControl.updateVisibility(showMenuButton && !dialogOpened);
|
||||
|
@ -631,7 +641,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
compassHud.updateVisibility(!dialogOpened);
|
||||
layersHud.updateVisibility(!dialogOpened);
|
||||
|
||||
if(routeFollowingMode || routePlanningMode) {
|
||||
if (routeFollowingMode || routePlanningMode) {
|
||||
mapAppModeShadow.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (mapView.isZooming()) {
|
||||
|
@ -639,7 +649,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
}
|
||||
mapAppModeShadow.setVisibility(View.VISIBLE);
|
||||
//if (!mapView.isZooming() || !OsmandPlugin.isDevelopment()) {
|
||||
if ((System.currentTimeMillis()-lastZoom > 1000) || !OsmandPlugin.isDevelopment()) {
|
||||
if ((System.currentTimeMillis() - lastZoom > 1000) || !OsmandPlugin.isDevelopment()) {
|
||||
zoomText.setVisibility(View.GONE);
|
||||
appModeIcon.setVisibility(View.VISIBLE);
|
||||
appModeIcon.setImageDrawable(
|
||||
|
@ -812,7 +822,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
|
||||
|
||||
public MapHudButton setBg(int dayBg, int nightBg) {
|
||||
if(bgDark == nightBg && dayBg == bgLight) {
|
||||
if (bgDark == nightBg && dayBg == bgLight) {
|
||||
return this;
|
||||
}
|
||||
bgDark = nightBg;
|
||||
|
@ -835,7 +845,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
}
|
||||
|
||||
public MapHudButton setBg(int bg) {
|
||||
if(bgDark == bg && bg == bgLight) {
|
||||
if (bgDark == bg && bg == bgLight) {
|
||||
return this;
|
||||
}
|
||||
bgDark = bg;
|
||||
|
@ -899,11 +909,11 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
}
|
||||
}
|
||||
Drawable d = null;
|
||||
if(resDarkId != 0 && nightMode) {
|
||||
if (resDarkId != 0 && nightMode) {
|
||||
d = ctx.getIconsCache().getIcon(resDarkId);
|
||||
} else if(resLightId != 0 && !nightMode) {
|
||||
} else if (resLightId != 0 && !nightMode) {
|
||||
d = ctx.getIconsCache().getIcon(resLightId);
|
||||
} else if(resId != 0){
|
||||
} else if (resId != 0) {
|
||||
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 AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
|
||||
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>();
|
||||
int i = -1;
|
||||
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) {
|
||||
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);
|
||||
boolean target = data.getBooleanExtra(MapRouteInfoControl.TARGET_SELECT, true);
|
||||
LatLon latLon = new LatLon(
|
||||
data.getDoubleExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_LAT, 0),
|
||||
data.getDoubleExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_LON, 0));
|
||||
if(name != null){
|
||||
if (name != null) {
|
||||
mapRouteInfoControlDialog.selectAddress(name, latLon, target);
|
||||
} else {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue