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);
}
Aggregations