use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class RouteProvider method findVectorMapsRoute.
protected RouteCalculationResult findVectorMapsRoute(final RouteCalculationParams params, boolean calcGPXRoute) throws IOException {
BinaryMapIndexReader[] files = params.ctx.getResourceManager().getRoutingMapFiles();
RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(false);
OsmandSettings settings = params.ctx.getSettings();
router.setUseFastRecalculation(settings.USE_FAST_RECALCULATION.get());
RoutingConfiguration.Builder config = params.ctx.getDefaultRoutingConfig();
GeneralRouter generalRouter = SettingsNavigationActivity.getRouter(config, params.mode);
if (generalRouter == null) {
return applicationModeNotSupported(params);
}
RoutingConfiguration cf = initOsmAndRoutingConfig(config, params, settings, generalRouter);
if (cf == null) {
return applicationModeNotSupported(params);
}
PrecalculatedRouteDirection precalculated = null;
if (calcGPXRoute) {
ArrayList<Location> sublist = findStartAndEndLocationsFromRoute(params.gpxRoute.points, params.start, params.end, null, null);
LatLon[] latLon = new LatLon[sublist.size()];
for (int k = 0; k < latLon.length; k++) {
latLon[k] = new LatLon(sublist.get(k).getLatitude(), sublist.get(k).getLongitude());
}
precalculated = PrecalculatedRouteDirection.build(latLon, generalRouter.getMaxDefaultSpeed());
precalculated.setFollowNext(true);
// cf.planRoadDirection = 1;
}
// BUILD context
NativeOsmandLibrary lib = settings.SAFE_MODE.get() ? null : NativeOsmandLibrary.getLoadedLibrary();
// check loaded files
int leftX = MapUtils.get31TileNumberX(params.start.getLongitude());
int rightX = leftX;
int bottomY = MapUtils.get31TileNumberY(params.start.getLatitude());
int topY = bottomY;
if (params.intermediates != null) {
for (LatLon l : params.intermediates) {
leftX = Math.min(MapUtils.get31TileNumberX(l.getLongitude()), leftX);
rightX = Math.max(MapUtils.get31TileNumberX(l.getLongitude()), rightX);
bottomY = Math.max(MapUtils.get31TileNumberY(l.getLatitude()), bottomY);
topY = Math.min(MapUtils.get31TileNumberY(l.getLatitude()), topY);
}
}
LatLon l = params.end;
leftX = Math.min(MapUtils.get31TileNumberX(l.getLongitude()), leftX);
rightX = Math.max(MapUtils.get31TileNumberX(l.getLongitude()), rightX);
bottomY = Math.max(MapUtils.get31TileNumberY(l.getLatitude()), bottomY);
topY = Math.min(MapUtils.get31TileNumberY(l.getLatitude()), topY);
params.ctx.getResourceManager().getRenderer().checkInitialized(15, lib, leftX, rightX, bottomY, topY);
RoutingContext ctx = router.buildRoutingContext(cf, lib, files, RouteCalculationMode.NORMAL);
RoutingContext complexCtx = null;
boolean complex = params.mode.isDerivedRoutingFrom(ApplicationMode.CAR) && !settings.DISABLE_COMPLEX_ROUTING.get() && precalculated == null;
ctx.leftSideNavigation = params.leftSide;
ctx.calculationProgress = params.calculationProgress;
if (params.previousToRecalculate != null && params.onlyStartPointChanged) {
int currentRoute = params.previousToRecalculate.getCurrentRoute();
List<RouteSegmentResult> originalRoute = params.previousToRecalculate.getOriginalRoute();
if (originalRoute != null && currentRoute < originalRoute.size()) {
ctx.previouslyCalculatedRoute = originalRoute.subList(currentRoute, originalRoute.size());
}
}
if (complex && router.getRecalculationEnd(ctx) != null) {
complex = false;
}
if (complex) {
complexCtx = router.buildRoutingContext(cf, lib, files, RouteCalculationMode.COMPLEX);
complexCtx.calculationProgress = params.calculationProgress;
complexCtx.leftSideNavigation = params.leftSide;
complexCtx.previouslyCalculatedRoute = ctx.previouslyCalculatedRoute;
}
LatLon st = new LatLon(params.start.getLatitude(), params.start.getLongitude());
LatLon en = new LatLon(params.end.getLatitude(), params.end.getLongitude());
List<LatLon> inters = new ArrayList<LatLon>();
if (params.intermediates != null) {
inters = new ArrayList<LatLon>(params.intermediates);
}
return calcOfflineRouteImpl(params, router, ctx, complexCtx, st, en, inters, precalculated);
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class MapSourceAction method getOnAddBtnClickListener.
@Override
protected View.OnClickListener getOnAddBtnClickListener(final MapActivity activity, final Adapter adapter) {
return new View.OnClickListener() {
@Override
public void onClick(View view) {
final OsmandSettings settings = activity.getMyApplication().getSettings();
final LinkedHashMap<String, String> entriesMap = new LinkedHashMap<>();
entriesMap.put(LAYER_OSM_VECTOR, activity.getString(R.string.vector_data));
entriesMap.putAll(settings.getTileSourceEntries());
final List<Map.Entry<String, String>> entriesMapList = new ArrayList<>(entriesMap.entrySet());
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final String[] items = new String[entriesMapList.size()];
int i = 0;
for (Map.Entry<String, String> entry : entriesMapList) {
items[i++] = entry.getValue();
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
arrayAdapter.addAll(items);
builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
Pair<String, String> layer = new Pair<>(entriesMapList.get(i).getKey(), entriesMapList.get(i).getValue());
adapter.addItem(layer, activity);
dialog.dismiss();
}
});
builder.setNegativeButton(R.string.shared_string_dismiss, null);
builder.show();
}
};
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class MapUnderlayAction method execute.
@Override
public void execute(MapActivity activity) {
OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
if (plugin != null) {
OsmandSettings settings = activity.getMyApplication().getSettings();
List<Pair<String, String>> sources = loadListFromParams();
Pair<String, String> currentSource = new Pair<>(settings.MAP_UNDERLAY.get(), settings.MAP_UNDERLAY.get());
Pair<String, String> nextSource = sources.get(0);
int index = sources.indexOf(currentSource);
if (index >= 0 && index + 1 < sources.size()) {
nextSource = sources.get(index + 1);
}
boolean hasUnderlay = !nextSource.first.equals(KEY_NO_UNDERLAY);
if (hasUnderlay) {
settings.MAP_UNDERLAY.set(nextSource.first);
settings.MAP_UNDERLAY_PREVIOUS.set(nextSource.first);
} else {
settings.MAP_UNDERLAY.set(null);
settings.MAP_UNDERLAY_PREVIOUS.set(null);
}
final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = activity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
hidePolygonsPref.set(hasUnderlay);
plugin.updateMapLayers(activity.getMapView(), settings.MAP_UNDERLAY, activity.getMapLayers());
Toast.makeText(activity, activity.getString(R.string.quick_action_map_underlay_switch, nextSource.second), Toast.LENGTH_SHORT).show();
}
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class MapUnderlayAction method getOnAddBtnClickListener.
@Override
protected View.OnClickListener getOnAddBtnClickListener(final MapActivity activity, final Adapter adapter) {
return new View.OnClickListener() {
@Override
public void onClick(View view) {
final OsmandSettings settings = activity.getMyApplication().getSettings();
Map<String, String> entriesMap = settings.getTileSourceEntries();
entriesMap.put(KEY_NO_UNDERLAY, activity.getString(R.string.no_underlay));
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final ArrayList<String> keys = new ArrayList<>(entriesMap.keySet());
final String[] items = new String[entriesMap.size()];
int i = 0;
for (String it : entriesMap.values()) {
items[i++] = it;
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
arrayAdapter.addAll(items);
builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
Pair<String, String> layer = new Pair<>(keys.get(i), items[i]);
adapter.addItem(layer, activity);
dialog.dismiss();
}
}).setNegativeButton(R.string.shared_string_cancel, null);
builder.show();
}
};
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class NavAutoZoomMapAction method execute.
@Override
public void execute(MapActivity activity) {
OsmandSettings settings = activity.getMyApplication().getSettings();
settings.AUTO_ZOOM_MAP.set(!settings.AUTO_ZOOM_MAP.get());
Toast.makeText(activity, activity.getString(!settings.AUTO_ZOOM_MAP.get() ? R.string.quick_action_auto_zoom_off : R.string.quick_action_auto_zoom_on), Toast.LENGTH_SHORT).show();
}
Aggregations