use of net.osmand.plus.OsmandSettings.AutoZoomMap in project Osmand by osmandapp.
the class SettingsNavigationActivity method onPreferenceClick.
@SuppressWarnings("unchecked")
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference == avoidRouting || preference == preferRouting) {
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);
vals[i] = SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName());
bls[i] = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
}
showBooleanSettings(vals, bls, preference.getTitle());
return true;
} else if (preference == autoZoom) {
final ApplicationMode am = settings.getApplicationMode();
final ContextMenuAdapter adapter = new ContextMenuAdapter();
int i = 0;
int selectedIndex = -1;
adapter.addItem(ContextMenuItem.createBuilder(getString(R.string.auto_zoom_none)).setSelected(false).createItem());
if (!settings.AUTO_ZOOM_MAP.get()) {
selectedIndex = 0;
}
i++;
for (AutoZoomMap autoZoomMap : AutoZoomMap.values()) {
adapter.addItem(ContextMenuItem.createBuilder(getString(autoZoomMap.name)).setSelected(false).createItem());
if (selectedIndex == -1 && settings.AUTO_ZOOM_MAP_SCALE.get() == autoZoomMap) {
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(R.string.auto_zoom_map).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int position = selectedPosition[0];
if (position == 0) {
settings.AUTO_ZOOM_MAP.set(false);
} else {
settings.AUTO_ZOOM_MAP.set(true);
settings.AUTO_ZOOM_MAP_SCALE.set(AutoZoomMap.values()[position - 1]);
}
}
}).setNegativeButton(R.string.shared_string_cancel, null);
builder.create().show();
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), getString(R.string.show_tunnels) }, new OsmandPreference[] { settings.SHOW_TRAFFIC_WARNINGS, settings.SHOW_PEDESTRIAN, settings.SHOW_CAMERAS, settings.SHOW_LANES, settings.SHOW_TUNNELS }, preference.getTitle());
return true;
} else if (preference == speakAlarms) {
AlertDialog dlg = showBooleanSettings(new String[] { getString(R.string.speak_street_names), getString(R.string.speak_traffic_warnings), getString(R.string.speak_pedestrian), getString(R.string.speak_speed_limit), getString(R.string.speak_cameras), getString(R.string.announce_gpx_waypoints), getString(R.string.speak_favorites), getString(R.string.speak_poi) }, new OsmandPreference[] { settings.SPEAK_STREET_NAMES, settings.SPEAK_TRAFFIC_WARNINGS, settings.SPEAK_PEDESTRIAN, settings.SPEAK_SPEED_LIMIT, settings.SPEAK_SPEED_CAMERA, settings.ANNOUNCE_WPT, settings.ANNOUNCE_NEARBY_FAVORITES, settings.ANNOUNCE_NEARBY_POI }, preference.getTitle());
final boolean initialSpeedCam = settings.SPEAK_SPEED_CAMERA.get();
final boolean initialFavorites = settings.ANNOUNCE_NEARBY_FAVORITES.get();
final boolean initialPOI = settings.ANNOUNCE_NEARBY_POI.get();
// final boolean initialWpt = settings.ANNOUNCE_WPT.get();
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (settings.ANNOUNCE_NEARBY_POI.get() != initialPOI) {
settings.SHOW_NEARBY_POI.set(settings.ANNOUNCE_NEARBY_POI.get());
}
if (settings.ANNOUNCE_NEARBY_FAVORITES.get() != initialFavorites) {
settings.SHOW_NEARBY_FAVORITES.set(settings.ANNOUNCE_NEARBY_FAVORITES.get());
}
if (settings.ANNOUNCE_WPT.get()) {
settings.SHOW_WPT.set(settings.ANNOUNCE_WPT.get());
}
if (!initialSpeedCam) {
if (settings.SPEAK_SPEED_CAMERA.get()) {
settings.SPEAK_SPEED_CAMERA.set(false);
confirmSpeedCamerasDlg();
}
}
}
});
return true;
}
return false;
}
Aggregations