Search in sources :

Example 6 with VehicleType

use of net.osmand.plus.onlinerouting.VehicleType in project Osmand by osmandapp.

the class OnlineRoutingEngineFragment method setupVehicleTypes.

private void setupVehicleTypes() {
    List<ChipItem> vehicleItems = new ArrayList<>();
    for (VehicleType vehicle : engine.getAllowedVehicles()) {
        String title = vehicle.getTitle(app);
        ChipItem item = new ChipItem(title);
        item.title = title;
        item.tag = vehicle;
        vehicleItems.add(item);
    }
    vehicleCard.setSelectionMenu(vehicleItems, engine.getSelectedVehicleType().getTitle(app), result -> {
        VehicleType vehicle = (VehicleType) result.tag;
        if (!Algorithms.objectEquals(engine.getSelectedVehicleType(), vehicle)) {
            String vehicleKey = vehicle.equals(CUSTOM_VEHICLE) ? customVehicleKey : vehicle.getKey();
            engine.put(EngineParameter.VEHICLE_KEY, vehicleKey);
            generateUniqueNameIfNeeded();
            updateCardViews(nameCard, vehicleCard, exampleCard);
            return true;
        }
        return false;
    });
}
Also used : VehicleType(net.osmand.plus.onlinerouting.VehicleType) ArrayList(java.util.ArrayList) ChipItem(net.osmand.plus.widgets.chips.ChipItem)

Example 7 with VehicleType

use of net.osmand.plus.onlinerouting.VehicleType in project Osmand by osmandapp.

the class OnlineRoutingEngine method getSelectedVehicleName.

@Nullable
private String getSelectedVehicleName(@NonNull Context ctx) {
    String key = get(EngineParameter.VEHICLE_KEY);
    VehicleType vt = getVehicleTypeByKey(key);
    if (!vt.equals(CUSTOM_VEHICLE)) {
        return vt.getTitle(ctx);
    }
    return key != null ? Algorithms.capitalizeFirstLetter(key) : null;
}
Also used : VehicleType(net.osmand.plus.onlinerouting.VehicleType) Nullable(androidx.annotation.Nullable)

Aggregations

VehicleType (net.osmand.plus.onlinerouting.VehicleType)7 Nullable (androidx.annotation.Nullable)1 ArrayList (java.util.ArrayList)1 OnlineRoutingEngine (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)1 BaseCard (net.osmand.plus.routepreparationmenu.cards.BaseCard)1 ChipItem (net.osmand.plus.widgets.chips.ChipItem)1