Add title, cancel and ok for navigation settings dialog

This commit is contained in:
Zahnstocher 2014-08-23 23:19:37 +02:00
parent 7bb33be2e4
commit ed02508f39
2 changed files with 35 additions and 6 deletions

View file

@ -194,6 +194,16 @@ public abstract class SettingsBaseActivity extends SherlockPreferenceActivity im
return p; return p;
} }
public <T> ListPreference createListPreference(OsmandPreference<T> b, String[] names, T[] values, String title, String summary) {
ListPreference p = new ListPreference(this);
p.setTitle(title);
p.setKey(b.getId());
p.setDialogTitle(title);
p.setSummary(summary);
prepareListPreference(b, names, values, p);
return p;
}
public <T> ListPreference createListPreference(OsmandPreference<T> b, String[] names, T[] values) { public <T> ListPreference createListPreference(OsmandPreference<T> b, String[] names, T[] values) {
ListPreference p = new ListPreference(this); ListPreference p = new ListPreference(this);
p.setKey(b.getId()); p.setKey(b.getId());

View file

@ -168,7 +168,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
svlss[i++] = o.toString(); svlss[i++] = o.toString();
} }
basePref = createListPreference(settings.getCustomRoutingProperty(p.getId()), basePref = createListPreference(settings.getCustomRoutingProperty(p.getId()),
p.getPossibleValueDescriptions(), svlss); p.getPossibleValueDescriptions(), svlss, SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()), SettingsBaseActivity.getRoutingStringPropertyDescription(this, p.getId(), p.getDescription()));
} }
basePref.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName())); basePref.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()));
basePref.setSummary(SettingsBaseActivity.getRoutingStringPropertyDescription(this, p.getId(), p.getDescription())); basePref.setSummary(SettingsBaseActivity.getRoutingStringPropertyDescription(this, p.getId(), p.getDescription()));
@ -229,12 +229,12 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
vals[i] = SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()); vals[i] = SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName());
bls[i] = settings.getCustomRoutingBooleanProperty(p.getId()); bls[i] = settings.getCustomRoutingBooleanProperty(p.getId());
} }
showBooleanSettings(vals, bls); showBooleanSettings(vals, bls, preference.getTitle());
return true; return true;
} else if (preference == showAlarms) { } else if (preference == showAlarms) {
showBooleanSettings(new String[] { getString(R.string.show_traffic_warnings), getString(R.string.show_cameras), showBooleanSettings(new String[] { getString(R.string.show_traffic_warnings), getString(R.string.show_cameras),
getString(R.string.show_lanes) }, new OsmandPreference[] { settings.SHOW_TRAFFIC_WARNINGS, getString(R.string.show_lanes) }, new OsmandPreference[] { settings.SHOW_TRAFFIC_WARNINGS,
settings.SHOW_CAMERAS, settings.SHOW_LANES }); settings.SHOW_CAMERAS, settings.SHOW_LANES }, preference.getTitle());
return true; return true;
} else if (preference == speakAlarms) { } else if (preference == speakAlarms) {
showBooleanSettings(new String[] { getString(R.string.speak_street_names), getString(R.string.speak_traffic_warnings), getString(R.string.speak_cameras), showBooleanSettings(new String[] { getString(R.string.speak_street_names), getString(R.string.speak_traffic_warnings), getString(R.string.speak_cameras),
@ -244,25 +244,44 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
getString(R.string.announce_gpx_waypoints)}, getString(R.string.announce_gpx_waypoints)},
new OsmandPreference[] { settings.SPEAK_STREET_NAMES, settings.SPEAK_TRAFFIC_WARNINGS, new OsmandPreference[] { settings.SPEAK_STREET_NAMES, settings.SPEAK_TRAFFIC_WARNINGS,
settings.SPEAK_SPEED_CAMERA , settings.SPEAK_SPEED_LIMIT, settings.SPEAK_SPEED_CAMERA , settings.SPEAK_SPEED_LIMIT,
settings.ANNOUNCE_NEARBY_FAVORITES, settings.ANNOUNCE_NEARBY_POI, settings.ANNOUNCE_WPT}); settings.ANNOUNCE_NEARBY_FAVORITES, settings.ANNOUNCE_NEARBY_POI, settings.ANNOUNCE_WPT}, preference.getTitle());
return true; return true;
} }
return false; return false;
} }
public void showBooleanSettings(String[] vals, final OsmandPreference<Boolean>[] prefs) { public void showBooleanSettings(String[] vals, final OsmandPreference<Boolean>[] prefs, final CharSequence title) {
Builder bld = new AlertDialog.Builder(this); Builder bld = new AlertDialog.Builder(this);
boolean[] checkedItems = new boolean[prefs.length]; boolean[] checkedItems = new boolean[prefs.length];
for (int i = 0; i < prefs.length; i++) { for (int i = 0; i < prefs.length; i++) {
checkedItems[i] = prefs[i].get(); checkedItems[i] = prefs[i].get();
} }
final boolean[] tempPrefs = new boolean[prefs.length];
for (int i = 0; i < prefs.length; i++) {
tempPrefs[i] = prefs[i].get();
}
bld.setMultiChoiceItems(vals, checkedItems, new OnMultiChoiceClickListener() { bld.setMultiChoiceItems(vals, checkedItems, new OnMultiChoiceClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) { public void onClick(DialogInterface dialog, int which, boolean isChecked) {
prefs[which].set(isChecked); tempPrefs[which] = isChecked;
} }
}); });
bld.setTitle(title);
bld.setNegativeButton(R.string.default_buttons_cancel, null);
bld.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
for (int i = 0; i < prefs.length; i++) {
prefs[i].set(tempPrefs[i]);
}
}
});
bld.show(); bld.show();
} }