use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.
the class OnlineRoutingEngineFragment method showExitDialog.
public void showExitDialog() {
View focus = view.findFocus();
AndroidUtils.hideSoftKeyboard(mapActivity, focus);
if (hasNameDuplicate(initEngine)) {
List<OnlineRoutingEngine> cachedEngines = helper.getEnginesExceptMentionedKeys(editedEngineKey);
OnlineRoutingUtils.generateUniqueName(app, initEngine, cachedEngines);
}
if (!engine.equals(initEngine)) {
AlertDialog.Builder dismissDialog = createWarningDialog(mapActivity, R.string.shared_string_dismiss, R.string.exit_without_saving, R.string.shared_string_cancel);
dismissDialog.setPositiveButton(R.string.shared_string_exit, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
});
dismissDialog.show();
} else {
dismiss();
}
}
use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.
the class OnlineRoutingEngineFragment method changeEngineType.
private void changeEngineType(OnlineRoutingEngine type) {
OnlineRoutingEngine tmp = (OnlineRoutingEngine) engine.clone();
engine = type.newInstance(tmp.getParams());
// after changing the type, select the vehicle
// with the same name that was selected before
VehicleType previous = tmp.getSelectedVehicleType();
VehicleType next = null;
for (VehicleType vt : engine.getAllowedVehicles()) {
if (Algorithms.objectEquals(previous.getTitle(app), vt.getTitle(app))) {
next = vt;
break;
}
}
String vehicleKey;
if (next != null) {
vehicleKey = next.equals(CUSTOM_VEHICLE) ? customVehicleKey : next.getKey();
} else {
vehicleKey = engine.getAllowedVehicles().get(0).getKey();
}
engine.put(EngineParameter.VEHICLE_KEY, vehicleKey);
setupVehicleTypes();
generateUniqueNameIfNeeded();
updateCardViews(nameCard, typeCard, vehicleCard, exampleCard);
}
use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.
the class OnlineRoutingEngineFragment method testEngineWork.
private void testEngineWork() {
final OnlineRoutingEngine requestedEngine = (OnlineRoutingEngine) engine.clone();
final ExampleLocation location = selectedLocation;
new Thread(new Runnable() {
@Override
public void run() {
StringBuilder errorMessage = new StringBuilder();
boolean resultOk = false;
try {
String method = engine.getHTTPMethod();
List<LatLon> path = Arrays.asList(location.getCityAirportLatLon(), location.getCityCenterLatLon());
String body = engine.getRequestBody(path, null);
Map<String, String> headers = engine.getRequestHeaders();
String response = helper.makeRequest(exampleCard.getEditedText(), method, body, headers);
resultOk = requestedEngine.isResultOk(errorMessage, response);
} catch (IOException | JSONException e) {
errorMessage.append(e.toString());
}
showTestResults(resultOk, errorMessage.toString(), location);
}
}).start();
}
use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.
the class OnlineRoutingEngineFragment method setupTypeCard.
private void setupTypeCard() {
typeCard = new OnlineRoutingCard(mapActivity, isNightMode(), appMode);
typeCard.build(mapActivity);
typeCard.setHeaderTitle(getString(R.string.shared_string_type));
List<net.osmand.plus.widgets.chips.ChipItem> typeItems = new ArrayList<>();
for (OnlineRoutingEngine type : EngineType.values()) {
String title = type.getTitle();
ChipItem item = new ChipItem(title);
item.title = title;
item.tag = type;
typeItems.add(item);
}
typeCard.setSelectionMenu(typeItems, engine.getType().getTitle(), result -> {
OnlineRoutingEngine type = (OnlineRoutingEngine) result.tag;
if (engine.getType() != type) {
changeEngineType(type);
return true;
}
return false;
});
typeCard.setOnTextChangedListener(new OnTextChangedListener() {
@Override
public void onTextChanged(boolean editedByUser, @NonNull String text) {
if (editedByUser) {
engine.put(EngineParameter.CUSTOM_URL, text);
updateCardViews(exampleCard);
}
}
});
typeCard.setFieldBoxLabelText(getString(R.string.shared_string_server_url));
typeCard.showDivider();
segmentsContainer.addView(typeCard.getView());
}
use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.
the class OnlineRoutingHelper method readFromSettings.
@NonNull
private List<OnlineRoutingEngine> readFromSettings() {
List<OnlineRoutingEngine> engines = new ArrayList<>();
String jsonString = settings.ONLINE_ROUTING_ENGINES.get();
if (!isEmpty(jsonString)) {
try {
JSONObject json = new JSONObject(jsonString);
OnlineRoutingUtils.readFromJson(json, engines);
} catch (JSONException | IllegalArgumentException e) {
LOG.debug("Error when reading engines from JSON ", e);
}
}
return engines;
}
Aggregations