use of net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.InterruptMusicRoutingParameter in project Osmand by osmandapp.
the class RoutePreferencesMenu method getItemClickListener.
public OnItemClickListener getItemClickListener(final ArrayAdapter<?> listAdapter) {
return new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int item, long l) {
Object obj = listAdapter.getItem(item);
if (obj instanceof LocalRoutingParameterGroup) {
final LocalRoutingParameterGroup group = (LocalRoutingParameterGroup) obj;
final ContextMenuAdapter adapter = new ContextMenuAdapter(app);
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().onSettingsChanged(true);
updateParameters();
}
}
}).setNegativeButton(R.string.shared_string_cancel, null);
builder.create().show();
} else if (obj instanceof MuteSoundRoutingParameter) {
final CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
btn.performClick();
} else if (obj instanceof VoiceGuidanceRoutingParameter) {
doSelectVoiceGuidance();
} else if (obj instanceof InterruptMusicRoutingParameter) {
final CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
btn.performClick();
} else if (obj instanceof AvoidRoadsRoutingParameter) {
routingOptionsHelper.selectRestrictedRoads(mapActivity);
} else if (obj instanceof GpxLocalRoutingParameter) {
showOptionsMenu((TextView) view.findViewById(R.id.description));
} else {
CheckBox ch = (CheckBox) view.findViewById(R.id.toggle_item);
if (ch != null) {
ch.setChecked(!ch.isChecked());
}
}
}
};
}
Aggregations