Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
68c059b5ab
8 changed files with 362 additions and 59 deletions
|
@ -164,12 +164,14 @@ public class GeneralRouter implements VehicleRouter {
|
|||
}
|
||||
|
||||
|
||||
public void registerBooleanParameter(String id, String name, String description) {
|
||||
public void registerBooleanParameter(String id, String group, String name, String description, boolean defaultValue) {
|
||||
RoutingParameter rp = new RoutingParameter();
|
||||
rp.group = group;
|
||||
rp.name = name;
|
||||
rp.description = description;
|
||||
rp.id = id;
|
||||
rp.type = RoutingParameterType.BOOLEAN;
|
||||
rp.defaultBoolean = defaultValue;
|
||||
parameters.put(rp.id, rp);
|
||||
|
||||
}
|
||||
|
@ -435,16 +437,21 @@ public class GeneralRouter implements VehicleRouter {
|
|||
|
||||
public static class RoutingParameter {
|
||||
private String id;
|
||||
private String group;
|
||||
private String name;
|
||||
private String description;
|
||||
private RoutingParameterType type;
|
||||
private Object[] possibleValues;
|
||||
private String[] possibleValueDescriptions;
|
||||
private boolean defaultBoolean;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -457,10 +464,12 @@ public class GeneralRouter implements VehicleRouter {
|
|||
public String[] getPossibleValueDescriptions() {
|
||||
return possibleValueDescriptions;
|
||||
}
|
||||
|
||||
public Object[] getPossibleValues() {
|
||||
return possibleValues;
|
||||
}
|
||||
public boolean getDefaultBoolean() {
|
||||
return defaultBoolean;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -215,11 +215,13 @@ public class RoutingConfiguration {
|
|||
|
||||
private static void parseRoutingParameter(XmlPullParser parser, GeneralRouter currentRouter) {
|
||||
String description = parser.getAttributeValue("", "description");
|
||||
String group = parser.getAttributeValue("", "group");
|
||||
String name = parser.getAttributeValue("", "name");
|
||||
String id = parser.getAttributeValue("", "id");
|
||||
String type = parser.getAttributeValue("", "type");
|
||||
if(type.equalsIgnoreCase("boolean")) {
|
||||
currentRouter.registerBooleanParameter(id, name, description);
|
||||
boolean defaultValue = Boolean.parseBoolean(parser.getAttributeValue("", "default"));
|
||||
if (type.equalsIgnoreCase("boolean")) {
|
||||
currentRouter.registerBooleanParameter(id, Algorithms.isEmpty(group) ? null : group, name, description, defaultValue);
|
||||
} else if(type.equalsIgnoreCase("numeric")) {
|
||||
String values = parser.getAttributeValue("", "values");
|
||||
String valueDescriptions = parser.getAttributeValue("", "valueDescriptions");
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:descendantFocusability="blocksDescendants"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="@dimen/list_content_padding"
|
||||
android:paddingRight="@dimen/list_content_padding" >
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="@dimen/list_item_height"
|
||||
android:descendantFocusability="blocksDescendants"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="@dimen/list_content_padding"
|
||||
android:paddingRight="@dimen/list_content_padding" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
|
@ -15,18 +16,33 @@
|
|||
android:visibility="gone"
|
||||
android:layout_marginRight="@dimen/list_content_padding"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:src="@drawable/ic_action_settings" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="6dp"
|
||||
android:text="@string/layer_poi"
|
||||
android:textSize="@dimen/default_list_text_size" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="6dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/toggle_item"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="relief_smoothness_factor_descr">More plains, balance, more hills</string>
|
||||
<string name="shared_string_slope">Slope</string>
|
||||
<string name="add_new_folder">Add new folder</string>
|
||||
<string name="points_delete_multiple_succesful">Point(s) deleted successfully.</string>
|
||||
|
|
|
@ -2724,9 +2724,9 @@ public class OsmandSettings {
|
|||
|
||||
Map<String, CommonPreference<Boolean>> customBooleanRoutingProps = new LinkedHashMap<String, OsmandSettings.CommonPreference<Boolean>>();
|
||||
|
||||
public CommonPreference<Boolean> getCustomRoutingBooleanProperty(String attrName) {
|
||||
public CommonPreference<Boolean> getCustomRoutingBooleanProperty(String attrName, boolean defaulfValue) {
|
||||
if (!customBooleanRoutingProps.containsKey(attrName)) {
|
||||
customBooleanRoutingProps.put(attrName, new BooleanPreference("prouting_" + attrName, false).makeProfile());
|
||||
customBooleanRoutingProps.put(attrName, new BooleanPreference("prouting_" + attrName, defaulfValue).makeProfile());
|
||||
}
|
||||
return customBooleanRoutingProps.get(attrName);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.activities;
|
|||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnMultiChoiceClickListener;
|
||||
import android.content.Intent;
|
||||
|
@ -12,8 +13,17 @@ import android.preference.ListPreference;
|
|||
import android.preference.Preference;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.DeviceAdminRecv;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -26,6 +36,7 @@ import net.osmand.plus.routing.RouteProvider.RouteService;
|
|||
import net.osmand.router.GeneralRouter;
|
||||
import net.osmand.router.GeneralRouter.RoutingParameter;
|
||||
import net.osmand.router.GeneralRouter.RoutingParameterType;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -35,6 +46,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
|
||||
private Preference avoidRouting;
|
||||
private Preference preferRouting;
|
||||
private Preference reliefFactorRouting;
|
||||
private Preference showAlarms;
|
||||
private Preference speakAlarms;
|
||||
private ListPreference routerServicePreference;
|
||||
|
@ -46,6 +58,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
|
||||
private List<RoutingParameter> avoidParameters = new ArrayList<RoutingParameter>();
|
||||
private List<RoutingParameter> preferParameters = new ArrayList<RoutingParameter>();
|
||||
private List<RoutingParameter> reliefFactorParameters = new ArrayList<RoutingParameter>();
|
||||
public static final String INTENT_SKIP_DIALOG = "INTENT_SKIP_DIALOG";
|
||||
|
||||
public SettingsNavigationActivity() {
|
||||
|
@ -238,12 +251,15 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
List<RoutingParameter> others = new ArrayList<GeneralRouter.RoutingParameter>();
|
||||
for(Map.Entry<String, RoutingParameter> e : parameters.entrySet()) {
|
||||
String param = e.getKey();
|
||||
if(param.startsWith("avoid_")) {
|
||||
avoidParameters.add(e.getValue());
|
||||
} else if(param.startsWith("prefer_")) {
|
||||
preferParameters.add(e.getValue());
|
||||
} else if(!param.equals("short_way")) {
|
||||
others.add(e.getValue());
|
||||
RoutingParameter routingParameter = e.getValue();
|
||||
if (param.startsWith("avoid_")) {
|
||||
avoidParameters.add(routingParameter);
|
||||
} else if (param.startsWith("prefer_")) {
|
||||
preferParameters.add(routingParameter);
|
||||
} else if ("relief_smoothness_factor".equals(routingParameter.getGroup())) {
|
||||
reliefFactorParameters.add(routingParameter);
|
||||
} else if (!param.equals("short_way") && !"driving_style".equals(routingParameter.getGroup())) {
|
||||
others.add(routingParameter);
|
||||
}
|
||||
}
|
||||
if (avoidParameters.size() > 0) {
|
||||
|
@ -260,10 +276,18 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
preferRouting.setOnPreferenceClickListener(this);
|
||||
cat.addPreference(preferRouting);
|
||||
}
|
||||
if (reliefFactorParameters.size() > 0) {
|
||||
reliefFactorRouting = new Preference(this);
|
||||
reliefFactorRouting.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, reliefFactorParameters.get(0).getGroup(),
|
||||
Algorithms.capitalizeFirstLetterAndLowercase(reliefFactorParameters.get(0).getGroup().replace('_', ' '))));
|
||||
reliefFactorRouting.setSummary(R.string.relief_smoothness_factor_descr);
|
||||
reliefFactorRouting.setOnPreferenceClickListener(this);
|
||||
cat.addPreference(reliefFactorRouting);
|
||||
}
|
||||
for(RoutingParameter p : others) {
|
||||
Preference basePref;
|
||||
if(p.getType() == RoutingParameterType.BOOLEAN) {
|
||||
basePref = createCheckBoxPreference(settings.getCustomRoutingBooleanProperty(p.getId()));
|
||||
basePref = createCheckBoxPreference(settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean()));
|
||||
} else {
|
||||
Object[] vls = p.getPossibleValues();
|
||||
String[] svlss = new String[vls.length];
|
||||
|
@ -293,6 +317,31 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
}
|
||||
}
|
||||
|
||||
public String getRoutinParameterTitle(Context context, RoutingParameter routingParameter) {
|
||||
return SettingsBaseActivity.getRoutingStringPropertyName(context, routingParameter.getId(),
|
||||
routingParameter.getName());
|
||||
}
|
||||
|
||||
public boolean isRoutingParameterSelected(OsmandSettings settings, ApplicationMode am, RoutingParameter routingParameter) {
|
||||
final OsmandSettings.CommonPreference<Boolean> property =
|
||||
settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean());
|
||||
if(am != null) {
|
||||
return property.getModeValue(am);
|
||||
} else {
|
||||
return property.get();
|
||||
}
|
||||
}
|
||||
|
||||
public void setRoutingParameterSelected(OsmandSettings settings, ApplicationMode am, RoutingParameter routingParameter, boolean isChecked) {
|
||||
final OsmandSettings.CommonPreference<Boolean> property =
|
||||
settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean());
|
||||
if(am != null) {
|
||||
property.setModeValue(am, isChecked);
|
||||
} else {
|
||||
property.set(isChecked);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void clearParameters() {
|
||||
preferParameters.clear();
|
||||
|
@ -349,13 +398,80 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
List<RoutingParameter> prms = preference == avoidRouting ? avoidParameters : preferParameters;
|
||||
String[] vals = new String[prms.size()];
|
||||
OsmandPreference[] bls = new OsmandPreference[prms.size()];
|
||||
for(int i = 0; i < prms.size(); i++) {
|
||||
RoutingParameter p = prms.get(i);
|
||||
for (int i = 0; i < prms.size(); i++) {
|
||||
RoutingParameter p = prms.get(i);
|
||||
vals[i] = SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName());
|
||||
bls[i] = settings.getCustomRoutingBooleanProperty(p.getId());
|
||||
bls[i] = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
|
||||
}
|
||||
showBooleanSettings(vals, bls, preference.getTitle());
|
||||
return true;
|
||||
} else if (preference == reliefFactorRouting) {
|
||||
final ApplicationMode am = settings.getApplicationMode();
|
||||
final ContextMenuAdapter adapter = new ContextMenuAdapter();
|
||||
int i = 0;
|
||||
int selectedIndex = -1;
|
||||
for (RoutingParameter p : reliefFactorParameters) {
|
||||
adapter.addItem(ContextMenuItem.createBuilder(getRoutinParameterTitle(this, p))
|
||||
.setSelected(false).createItem());
|
||||
if (isRoutingParameterSelected(settings, am, p)) {
|
||||
selectedIndex = i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (selectedIndex == -1) {
|
||||
selectedIndex = 0;
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
final int layout = R.layout.list_menu_item_native_singlechoice;
|
||||
|
||||
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, layout, R.id.text1,
|
||||
adapter.getItemNames()) {
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
// User super class to create the View
|
||||
View v = convertView;
|
||||
if (v == null) {
|
||||
v = SettingsNavigationActivity.this.getLayoutInflater().inflate(layout, null);
|
||||
}
|
||||
final ContextMenuItem item = adapter.getItem(position);
|
||||
TextView tv = (TextView) v.findViewById(R.id.text1);
|
||||
tv.setText(item.getTitle());
|
||||
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f);
|
||||
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
final int[] selectedPosition = {selectedIndex};
|
||||
builder.setSingleChoiceItems(listAdapter, selectedIndex, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int position) {
|
||||
selectedPosition[0] = position;
|
||||
}
|
||||
});
|
||||
builder.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, reliefFactorParameters.get(0).getGroup(),
|
||||
Algorithms.capitalizeFirstLetterAndLowercase(reliefFactorParameters.get(0).getGroup().replace('_', ' '))))
|
||||
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
int position = selectedPosition[0];
|
||||
if (position >= 0 && position < reliefFactorParameters.size()) {
|
||||
for (int i = 0; i < reliefFactorParameters.size(); i++) {
|
||||
setRoutingParameterSelected(settings, am, reliefFactorParameters.get(i), i == position);
|
||||
}
|
||||
//mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
|
||||
//updateParameters();
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
|
||||
builder.create().show();
|
||||
return true;
|
||||
} else if (preference == showAlarms) {
|
||||
showBooleanSettings(new String[] { getString(R.string.show_traffic_warnings), getString(R.string.show_pedestrian_warnings),
|
||||
getString(R.string.show_cameras), getString(R.string.show_lanes) }, new OsmandPreference[] { settings.SHOW_TRAFFIC_WARNINGS,
|
||||
|
|
|
@ -3,8 +3,10 @@ package net.osmand.plus.mapcontextmenu.other;
|
|||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.util.TypedValue;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -41,6 +43,8 @@ import net.osmand.plus.routing.RouteProvider;
|
|||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.views.MapControlsLayer;
|
||||
import net.osmand.router.GeneralRouter;
|
||||
import net.osmand.router.GeneralRouter.RoutingParameter;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -70,7 +74,7 @@ public class RoutePreferencesMenu {
|
|||
|
||||
public static class LocalRoutingParameter {
|
||||
|
||||
public GeneralRouter.RoutingParameter routingParameter;
|
||||
public RoutingParameter routingParameter;
|
||||
private ApplicationMode am;
|
||||
|
||||
public LocalRoutingParameter(ApplicationMode am) {
|
||||
|
@ -83,8 +87,8 @@ public class RoutePreferencesMenu {
|
|||
}
|
||||
|
||||
public boolean isSelected(OsmandSettings settings) {
|
||||
final OsmandSettings.CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter
|
||||
.getId());
|
||||
final OsmandSettings.CommonPreference<Boolean> property =
|
||||
settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean());
|
||||
if(am != null) {
|
||||
return property.getModeValue(am);
|
||||
} else {
|
||||
|
@ -93,8 +97,8 @@ public class RoutePreferencesMenu {
|
|||
}
|
||||
|
||||
public void setSelected(OsmandSettings settings, boolean isChecked) {
|
||||
final OsmandSettings.CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter
|
||||
.getId());
|
||||
final OsmandSettings.CommonPreference<Boolean> property =
|
||||
settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean());
|
||||
if(am != null) {
|
||||
property.setModeValue(am, isChecked);
|
||||
} else {
|
||||
|
@ -102,6 +106,58 @@ public class RoutePreferencesMenu {
|
|||
}
|
||||
}
|
||||
|
||||
public ApplicationMode getApplicationMode() {
|
||||
return am;
|
||||
}
|
||||
}
|
||||
|
||||
private static class LocalRoutingParameterGroup extends LocalRoutingParameter {
|
||||
|
||||
private String groupName;
|
||||
private List<LocalRoutingParameter> routingParameters = new ArrayList<>();
|
||||
|
||||
public LocalRoutingParameterGroup(ApplicationMode am, String groupName) {
|
||||
super(am);
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
public void addRoutingParameter(RoutingParameter routingParameter) {
|
||||
LocalRoutingParameter p = new LocalRoutingParameter(getApplicationMode());
|
||||
p.routingParameter = routingParameter;
|
||||
routingParameters.add(p);
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
public List<LocalRoutingParameter> getRoutingParameters() {
|
||||
return routingParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(MapActivity mapActivity) {
|
||||
return SettingsBaseActivity.getRoutingStringPropertyName(mapActivity, groupName,
|
||||
Algorithms.capitalizeFirstLetterAndLowercase(groupName.replace('_', ' ')));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(OsmandSettings settings) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(OsmandSettings settings, boolean isChecked) {
|
||||
}
|
||||
|
||||
public LocalRoutingParameter getSelected(OsmandSettings settings) {
|
||||
for (LocalRoutingParameter p : routingParameters) {
|
||||
if (p.isSelected(settings)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class MuteSoundRoutingParameter extends LocalRoutingParameter {
|
||||
|
@ -291,7 +347,73 @@ public class RoutePreferencesMenu {
|
|||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int item, long l) {
|
||||
Object obj = listAdapter.getItem(item);
|
||||
if (obj instanceof OtherSettingsRoutingParameter) {
|
||||
if (obj instanceof LocalRoutingParameterGroup) {
|
||||
final LocalRoutingParameterGroup group = (LocalRoutingParameterGroup) obj;
|
||||
final ContextMenuAdapter adapter = new ContextMenuAdapter();
|
||||
int i = 0;
|
||||
int selectedIndex = -1;
|
||||
for (LocalRoutingParameter p : group.getRoutingParameters()) {
|
||||
adapter.addItem(ContextMenuItem.createBuilder(p.getText(mapActivity))
|
||||
.setSelected(false).createItem());
|
||||
if (p.isSelected(settings)) {
|
||||
selectedIndex = i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (selectedIndex == -1) {
|
||||
selectedIndex = 0;
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
|
||||
final int layout = R.layout.list_menu_item_native_singlechoice;
|
||||
|
||||
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(mapActivity, layout, R.id.text1,
|
||||
adapter.getItemNames()) {
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
// User super class to create the View
|
||||
View v = convertView;
|
||||
if (v == null) {
|
||||
v = mapActivity.getLayoutInflater().inflate(layout, null);
|
||||
}
|
||||
final ContextMenuItem item = adapter.getItem(position);
|
||||
TextView tv = (TextView) v.findViewById(R.id.text1);
|
||||
tv.setText(item.getTitle());
|
||||
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f);
|
||||
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
final int[] selectedPosition = {selectedIndex};
|
||||
builder.setSingleChoiceItems(listAdapter, selectedIndex, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int position) {
|
||||
selectedPosition[0] = position;
|
||||
}
|
||||
});
|
||||
builder.setTitle(group.getText(mapActivity))
|
||||
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
int position = selectedPosition[0];
|
||||
if (position >= 0 && position < group.getRoutingParameters().size()) {
|
||||
for (int i = 0; i < group.getRoutingParameters().size(); i++) {
|
||||
LocalRoutingParameter rp = group.getRoutingParameters().get(i);
|
||||
rp.setSelected(settings, i == position);
|
||||
}
|
||||
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
|
||||
updateParameters();
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
|
||||
builder.create().show();
|
||||
} else if (obj instanceof OtherSettingsRoutingParameter) {
|
||||
final Intent settings = new Intent(mapActivity, SettingsNavigationActivity.class);
|
||||
settings.putExtra(SettingsNavigationActivity.INTENT_SKIP_DIALOG, true);
|
||||
settings.putExtra(SettingsBaseActivity.INTENT_APP_MODE, routingHelper.getAppMode().getStringKey());
|
||||
|
@ -460,33 +582,36 @@ public class RoutePreferencesMenu {
|
|||
View v = mapActivity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null);
|
||||
AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
|
||||
final TextView tv = (TextView) v.findViewById(R.id.title);
|
||||
final TextView desc = (TextView) v.findViewById(R.id.description);
|
||||
final CheckBox ch = ((CheckBox) v.findViewById(R.id.toggle_item));
|
||||
final LocalRoutingParameter rp = getItem(position);
|
||||
AndroidUtils.setTextPrimaryColor(mapActivity, tv, nightMode);
|
||||
tv.setText(rp.getText(mapActivity));
|
||||
ch.setOnCheckedChangeListener(null);
|
||||
if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) {
|
||||
// if short route settings - it should be inverse of fast_route_mode
|
||||
ch.setChecked(!settings.FAST_ROUTE_MODE.getModeValue(routingHelper.getAppMode()));
|
||||
} else {
|
||||
ch.setChecked(rp.isSelected(settings));
|
||||
}
|
||||
ch.setVisibility(View.VISIBLE);
|
||||
ch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
// if short way that it should set valut to fast mode opposite of current
|
||||
if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) {
|
||||
settings.FAST_ROUTE_MODE.setModeValue(routingHelper.getAppMode(), !isChecked);
|
||||
}
|
||||
rp.setSelected(settings, isChecked);
|
||||
|
||||
if (rp instanceof OtherLocalRoutingParameter) {
|
||||
updateGpxRoutingParameter((OtherLocalRoutingParameter) rp);
|
||||
}
|
||||
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
|
||||
if (rp instanceof LocalRoutingParameterGroup) {
|
||||
LocalRoutingParameterGroup group = (LocalRoutingParameterGroup) rp;
|
||||
AndroidUtils.setTextPrimaryColor(mapActivity, desc, nightMode);
|
||||
LocalRoutingParameter selected = group.getSelected(settings);
|
||||
if (selected != null) {
|
||||
desc.setText(selected.getText(mapActivity));
|
||||
desc.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
ch.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) {
|
||||
// if short route settings - it should be inverse of fast_route_mode
|
||||
ch.setChecked(!settings.FAST_ROUTE_MODE.getModeValue(routingHelper.getAppMode()));
|
||||
} else {
|
||||
ch.setChecked(rp.isSelected(settings));
|
||||
}
|
||||
ch.setVisibility(View.VISIBLE);
|
||||
ch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
applyRoutingParameter(rp, isChecked);
|
||||
}
|
||||
});
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
@ -494,6 +619,19 @@ public class RoutePreferencesMenu {
|
|||
return listAdapter;
|
||||
}
|
||||
|
||||
private void applyRoutingParameter(LocalRoutingParameter rp, boolean isChecked) {
|
||||
// if short way that it should set valut to fast mode opposite of current
|
||||
if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) {
|
||||
settings.FAST_ROUTE_MODE.setModeValue(routingHelper.getAppMode(), !isChecked);
|
||||
}
|
||||
rp.setSelected(settings, isChecked);
|
||||
|
||||
if (rp instanceof OtherLocalRoutingParameter) {
|
||||
updateGpxRoutingParameter((OtherLocalRoutingParameter) rp);
|
||||
}
|
||||
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
|
||||
}
|
||||
|
||||
private void updateGpxRoutingParameter(OtherLocalRoutingParameter gpxParam) {
|
||||
RouteProvider.GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
|
||||
boolean selected = gpxParam.isSelected(settings);
|
||||
|
@ -590,17 +728,38 @@ public class RoutePreferencesMenu {
|
|||
if (rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute()) && !rparams.getFile().hasRtePt()) {
|
||||
return list;
|
||||
}
|
||||
for (GeneralRouter.RoutingParameter r : rm.getParameters().values()) {
|
||||
for (RoutingParameter r : rm.getParameters().values()) {
|
||||
if (r.getType() == GeneralRouter.RoutingParameterType.BOOLEAN) {
|
||||
LocalRoutingParameter rp = new LocalRoutingParameter(am);
|
||||
rp.routingParameter = r;
|
||||
list.add(rp);
|
||||
if ("relief_smoothness_factor".equals(r.getGroup())) {
|
||||
continue;
|
||||
}
|
||||
if (!Algorithms.isEmpty(r.getGroup())) {
|
||||
LocalRoutingParameterGroup rpg = getLocalRoutingParameterGroup(list, r.getGroup());
|
||||
if (rpg == null) {
|
||||
rpg = new LocalRoutingParameterGroup(am, r.getGroup());
|
||||
list.add(rpg);
|
||||
}
|
||||
rpg.addRoutingParameter(r);
|
||||
} else {
|
||||
LocalRoutingParameter rp = new LocalRoutingParameter(am);
|
||||
rp.routingParameter = r;
|
||||
list.add(rp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private LocalRoutingParameterGroup getLocalRoutingParameterGroup(List<LocalRoutingParameter> list, String groupName) {
|
||||
for (LocalRoutingParameter p : list) {
|
||||
if (p instanceof LocalRoutingParameterGroup && groupName.equals(((LocalRoutingParameterGroup) p).getGroupName())) {
|
||||
return (LocalRoutingParameterGroup) p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateParameters() {
|
||||
//ApplicationMode am = settings.APPLICATION_MODE.get();
|
||||
ApplicationMode am = routingHelper.getAppMode();
|
||||
|
|
|
@ -743,7 +743,7 @@ public class RouteProvider {
|
|||
Boolean bool = !settings.FAST_ROUTE_MODE.getModeValue(params.mode);
|
||||
vl = bool ? "true" : null;
|
||||
} else if(pr.getType() == RoutingParameterType.BOOLEAN) {
|
||||
CommonPreference<Boolean> pref = settings.getCustomRoutingBooleanProperty(key);
|
||||
CommonPreference<Boolean> pref = settings.getCustomRoutingBooleanProperty(key, pr.getDefaultBoolean());
|
||||
Boolean bool = pref.getModeValue(params.mode);
|
||||
vl = bool ? "true" : null;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue