Search in sources :

Example 1 with VehicleSizeAssets

use of net.osmand.plus.settings.bottomsheets.VehicleSizeAssets in project Osmand by osmandapp.

the class VehicleParametersFragment method setupCustomRoutingPropertyPref.

private void setupCustomRoutingPropertyPref(@Nullable RoutingParameter parameter, GeneralRouterProfile routerProfile) {
    if (parameter == null) {
        return;
    }
    String parameterId = parameter.getId();
    String title = AndroidUtils.getRoutingStringPropertyName(app, parameterId, parameter.getName());
    String description = AndroidUtils.getRoutingStringPropertyDescription(app, parameterId, parameter.getDescription());
    String defValue = parameter.getType() == RoutingParameterType.NUMERIC ? ROUTING_PARAMETER_NUMERIC_DEFAULT : ROUTING_PARAMETER_SYMBOLIC_DEFAULT;
    StringPreference pref = (StringPreference) app.getSettings().getCustomRoutingProperty(parameterId, defValue);
    VehicleSizeAssets assets = VehicleSizeAssets.getAssets(parameterId, routerProfile);
    Object[] values = parameter.getPossibleValues();
    String[] valuesStr = new String[values.length];
    for (int i = 0; i < values.length; i++) {
        valuesStr[i] = values[i].toString();
    }
    String[] entriesStr = parameter.getPossibleValueDescriptions().clone();
    entriesStr[0] = app.getString(R.string.shared_string_none);
    for (int i = 1; i < entriesStr.length; i++) {
        int firstCharIndex = Algorithms.findFirstNumberEndIndex(entriesStr[i]);
        entriesStr[i] = String.format(app.getString(R.string.ltr_or_rtl_combine_via_space), entriesStr[i].substring(0, firstCharIndex), getString(assets.getMetricShortRes()));
    }
    Context ctx = getContext();
    if (ctx == null) {
        return;
    }
    SizePreference vehicleSizePref = new SizePreference(ctx);
    vehicleSizePref.setKey(pref.getId());
    vehicleSizePref.setAssets(assets);
    vehicleSizePref.setDefaultValue(defValue);
    vehicleSizePref.setTitle(title);
    vehicleSizePref.setEntries(entriesStr);
    vehicleSizePref.setEntryValues(valuesStr);
    vehicleSizePref.setSummary(description);
    vehicleSizePref.setIcon(getPreferenceIcon(parameterId));
    vehicleSizePref.setLayoutResource(R.layout.preference_with_descr);
    getPreferenceScreen().addPreference(vehicleSizePref);
}
Also used : Context(android.content.Context) VehicleSizeAssets(net.osmand.plus.settings.bottomsheets.VehicleSizeAssets) SizePreference(net.osmand.plus.settings.preferences.SizePreference) StringPreference(net.osmand.plus.settings.backend.preferences.StringPreference)

Aggregations

Context (android.content.Context)1 StringPreference (net.osmand.plus.settings.backend.preferences.StringPreference)1 VehicleSizeAssets (net.osmand.plus.settings.bottomsheets.VehicleSizeAssets)1 SizePreference (net.osmand.plus.settings.preferences.SizePreference)1