use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.
the class OnlineRoutingSettingsItem method renameItem.
@NonNull
@Override
public OnlineRoutingEngine renameItem(@NonNull OnlineRoutingEngine item) {
OnlineRoutingEngine renamedItem = (OnlineRoutingEngine) item.clone();
OnlineRoutingUtils.generateUniqueName(app, renamedItem, otherEngines);
renamedItem.remove(EngineParameter.KEY);
otherEngines.add(renamedItem);
return renamedItem;
}
use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.
the class OnlineRoutingHelper method getEnginesExceptMentionedKeys.
@NonNull
public List<OnlineRoutingEngine> getEnginesExceptMentionedKeys(@Nullable String... excludeKeys) {
List<OnlineRoutingEngine> engines = getEngines();
if (excludeKeys != null) {
for (String key : excludeKeys) {
OnlineRoutingEngine engine = getEngineByKey(key);
engines.remove(engine);
}
}
return engines;
}
use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.
the class OnlineRoutingUtils method readFromJson.
public static void readFromJson(@NonNull JSONObject json, @NonNull List<OnlineRoutingEngine> engines) throws JSONException {
if (!json.has("items")) {
return;
}
Gson gson = new Gson();
Type typeToken = new TypeToken<HashMap<String, String>>() {
}.getType();
JSONArray itemsJson = json.getJSONArray(ITEMS);
for (int i = 0; i < itemsJson.length(); i++) {
JSONObject object = itemsJson.getJSONObject(i);
if (object.has(TYPE) && object.has(PARAMS)) {
OnlineRoutingEngine type = EngineType.getTypeByName(object.getString(TYPE));
String paramsString = object.getString(PARAMS);
HashMap<String, String> params = gson.fromJson(paramsString, typeToken);
OnlineRoutingEngine engine = type.newInstance(params);
if (!Algorithms.isEmpty(engine.getStringKey())) {
engines.add(engine);
}
}
}
}
use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.
the class SelectNavProfileBottomSheet method savePredefinedEngine.
private void savePredefinedEngine(RoutingDataObject profile) {
String stringKey = profile.getStringKey();
OnlineRoutingHelper helper = app.getOnlineRoutingHelper();
ProfilesGroup profilesGroup = findGroupOfProfile(profile);
if (profilesGroup != null) {
PredefinedProfilesGroup group = (PredefinedProfilesGroup) profilesGroup;
String type = group.getType().toUpperCase();
OnlineRoutingEngine engine = EngineType.getTypeByName(type).newInstance(null);
engine.put(EngineParameter.KEY, stringKey);
engine.put(EngineParameter.VEHICLE_KEY, NONE_VEHICLE.getKey());
engine.put(EngineParameter.CUSTOM_URL, profile.getDescription());
String namePattern = getString(R.string.ltr_or_rtl_combine_via_dash);
String name = String.format(namePattern, group.getTitle(), profile.getName());
engine.put(EngineParameter.CUSTOM_NAME, name);
helper.saveEngine(engine);
}
}
use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.
the class RoutingDataUtils method getOnlineRoutingProfiles.
private List<ProfileDataObject> getOnlineRoutingProfiles(boolean onlyCustom) {
OnlineRoutingHelper helper = app.getOnlineRoutingHelper();
List<ProfileDataObject> objects = new ArrayList<>();
List<OnlineRoutingEngine> engines = onlyCustom ? helper.getOnlyCustomEngines() : helper.getEngines();
for (int i = 0; i < engines.size(); i++) {
OnlineRoutingDataObject profile = convertOnlineEngineToDataObject(engines.get(i));
profile.setOrder(i);
objects.add(profile);
}
return objects;
}
Aggregations