use of android.widget.CompoundButton.OnCheckedChangeListener in project MGit by maks.
the class CommitAction method commit.
private void commit() {
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
LayoutInflater inflater = mActivity.getLayoutInflater();
View layout = inflater.inflate(R.layout.dialog_commit, null);
final EditText commitMsg = (EditText) layout.findViewById(R.id.commitMsg);
final AutoCompleteTextView commitAuthor = (AutoCompleteTextView) layout.findViewById(R.id.commitAuthor);
final CheckBox isAmend = (CheckBox) layout.findViewById(R.id.isAmend);
final CheckBox autoStage = (CheckBox) layout.findViewById(R.id.autoStage);
HashSet<Author> authors = new HashSet<Author>();
try {
Iterable<RevCommit> commits = mRepo.getGit().log().setMaxCount(500).call();
for (RevCommit commit : commits) {
authors.add(new Author(commit.getAuthorIdent()));
}
} catch (Exception e) {
}
String profileUsername = Profile.getUsername(mActivity.getApplicationContext());
String profileEmail = Profile.getEmail(mActivity.getApplicationContext());
if (profileUsername != null && !profileUsername.equals("") && profileEmail != null && !profileEmail.equals("")) {
authors.add(new Author(profileUsername, profileEmail));
}
ArrayList<Author> authorList = new ArrayList<Author>(authors);
Collections.sort(authorList);
AuthorsAdapter adapter = new AuthorsAdapter(mActivity, authorList);
commitAuthor.setAdapter(adapter);
isAmend.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
commitMsg.setText(mRepo.getLastCommitFullMsg());
} else {
commitMsg.setText("");
}
}
});
final AlertDialog d = builder.setTitle(R.string.dialog_commit_title).setView(layout).setPositiveButton(R.string.dialog_commit_positive_label, null).setNegativeButton(R.string.label_cancel, new DummyDialogListener()).create();
d.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button b = d.getButton(AlertDialog.BUTTON_POSITIVE);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String msg = commitMsg.getText().toString();
String author = commitAuthor.getText().toString().trim();
String authorName = null, authorEmail = null;
int ltidx;
if (msg.trim().equals("")) {
commitMsg.setError(mActivity.getString(R.string.error_no_commit_msg));
return;
}
if (!author.equals("")) {
ltidx = author.indexOf('<');
if (!author.endsWith(">") || ltidx == -1) {
commitAuthor.setError(mActivity.getString(R.string.error_invalid_author));
return;
}
authorName = author.substring(0, ltidx);
authorEmail = author.substring(ltidx + 1, author.length() - 1);
}
boolean amend = isAmend.isChecked();
boolean stage = autoStage.isChecked();
commit(msg, amend, stage, authorName, authorEmail);
d.dismiss();
}
});
}
});
d.show();
}
use of android.widget.CompoundButton.OnCheckedChangeListener in project Osmand by osmandapp.
the class OsmandMonitoringPlugin method createIntervalChooseLayout.
public static LinearLayout createIntervalChooseLayout(final Context uiCtx, final String patternMsg, final int[] seconds, final int[] minutes, final ValueHolder<Boolean> choice, final ValueHolder<Integer> v, final boolean showTrackSelection, DisplayMetrics dm) {
LinearLayout ll = new LinearLayout(uiCtx);
final int dp24 = AndroidUtils.dpToPx(uiCtx, 24f);
final int dp8 = AndroidUtils.dpToPx(uiCtx, 8f);
final TextView tv = new TextView(uiCtx);
tv.setPadding(dp24, dp8 * 2, dp24, dp8);
tv.setText(String.format(patternMsg, uiCtx.getString(R.string.int_continuosly)));
SeekBar sp = new SeekBar(uiCtx);
sp.setPadding(dp24 + dp8, dp8, dp24 + dp8, dp8);
final int secondsLength = seconds.length;
final int minutesLength = minutes.length;
sp.setMax(secondsLength + minutesLength - 1);
sp.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
String s;
if (progress == 0) {
s = uiCtx.getString(R.string.int_continuosly);
v.value = 0;
} else {
if (progress < secondsLength) {
s = seconds[progress] + " " + uiCtx.getString(R.string.int_seconds);
v.value = seconds[progress] * 1000;
} else {
s = minutes[progress - secondsLength] + " " + uiCtx.getString(R.string.int_min);
v.value = minutes[progress - secondsLength] * 60 * 1000;
}
}
tv.setText(String.format(patternMsg, s));
}
});
for (int i = 0; i < secondsLength + minutesLength - 1; i++) {
if (i < secondsLength) {
if (v.value <= seconds[i] * 1000) {
sp.setProgress(i);
break;
}
} else {
if (v.value <= minutes[i - secondsLength] * 1000 * 60) {
sp.setProgress(i);
break;
}
}
}
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(tv);
ll.addView(sp);
if (choice != null) {
final CheckBox cb = new CheckBox(uiCtx);
cb.setText(R.string.shared_string_remember_my_choice);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.setMargins(dp24, dp8, dp24, 0);
cb.setLayoutParams(lp);
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
choice.value = isChecked;
}
});
ll.addView(cb);
}
if (showTrackSelection) {
final OsmandApplication app = (OsmandApplication) uiCtx.getApplicationContext();
boolean light = app.getSettings().isLightContent();
View divider = new View(uiCtx);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, AndroidUtils.dpToPx(uiCtx, 1f));
lp.setMargins(0, dp8 * 2, 0, 0);
divider.setLayoutParams(lp);
divider.setBackgroundColor(uiCtx.getResources().getColor(light ? R.color.dashboard_divider_light : R.color.dashboard_divider_dark));
ll.addView(divider);
final CheckBox cb = new CheckBox(uiCtx);
cb.setText(R.string.shared_string_show_on_map);
lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.setMargins(dp24, dp8 * 2, dp24, 0);
cb.setLayoutParams(lp);
cb.setChecked(app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null);
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
app.getSelectedGpxHelper().selectGpxFile(app.getSavingTrackHelper().getCurrentGpx(), isChecked, false);
}
});
ll.addView(cb);
}
return ll;
}
use of android.widget.CompoundButton.OnCheckedChangeListener in project Osmand by osmandapp.
the class SelectWptCategoriesBottomSheetDialogFragment method createMenuItems.
@Override
public void createMenuItems(Bundle savedInstanceState) {
gpxFile = getGpxFile();
if (gpxFile == null) {
return;
}
items.add(new TitleItem(getGpxName(gpxFile)));
items.add(new DescriptionItem(getString(R.string.select_waypoints_category_description)));
final BottomSheetItemWithCompoundButton[] selectAllItem = new BottomSheetItemWithCompoundButton[1];
selectAllItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder().setChecked(true).setDescription(getString(R.string.shared_string_total) + ": " + gpxFile.getPoints().size()).setIcon(getContentIcon(R.drawable.ic_action_group_select_all)).setTitle(getString(R.string.shared_string_select_all)).setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean checked = !selectAllItem[0].isChecked();
selectAllItem[0].setChecked(checked);
for (BottomSheetItemWithCompoundButton item : categoryItems) {
item.setChecked(checked);
}
}
}).create();
items.add(selectAllItem[0]);
items.add(new DividerItem(getContext()));
Map<String, List<WptPt>> pointsByCategories = gpxFile.getPointsByCategories();
for (String category : pointsByCategories.keySet()) {
final BottomSheetItemWithCompoundButton[] categoryItem = new BottomSheetItemWithCompoundButton[1];
categoryItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder().setChecked(true).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
selectedCategories.add((String) categoryItem[0].getTag());
} else {
selectedCategories.remove((String) categoryItem[0].getTag());
}
}
}).setDescription(String.valueOf(pointsByCategories.get(category).size())).setIcon(getContentIcon(R.drawable.ic_action_folder)).setTitle(category.equals("") ? getString(R.string.waypoints) : category).setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp).setTag(category).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
categoryItem[0].setChecked(!categoryItem[0].isChecked());
selectAllItem[0].setChecked(isAllChecked());
}
}).create();
items.add(categoryItem[0]);
categoryItems.add(categoryItem[0]);
selectedCategories.add(category);
}
}
use of android.widget.CompoundButton.OnCheckedChangeListener in project Osmand by osmandapp.
the class ConfigureMapMenu method createLayersItems.
private void createLayersItems(List<RenderingRuleProperty> customRules, ContextMenuAdapter adapter, final MapActivity activity) {
final OsmandApplication app = activity.getMyApplication();
final OsmandSettings settings = app.getSettings();
LayerMenuListener l = new LayerMenuListener(activity, adapter);
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_show, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
// String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication()) +"] ";
boolean selected = settings.SHOW_FAVORITES.get();
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_favorites, activity).setSelected(settings.SHOW_FAVORITES.get()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_fav_dark).setListener(l).createItem());
selected = app.getPoiFilters().isShowingAnyPoi();
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_poi, activity).setSelected(selected).setDescription(app.getPoiFilters().getSelectedPoiFiltersName()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_info_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(l).createItem());
selected = settings.SHOW_POI_LABEL.get();
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_amenity_label, activity).setSelected(settings.SHOW_POI_LABEL.get()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_text_dark).setListener(l).createItem());
/*
ContextMenuItem item = createProperties(customRules, null, R.string.rendering_category_transport, R.drawable.ic_action_bus_dark,
"transport", settings.TRANSPORT_DEFAULT_SETTINGS, adapter, activity, false);
if (item != null) {
adapter.addItem(item);
}
*/
final List<RenderingRuleProperty> transportRules = new ArrayList<>();
final List<OsmandSettings.CommonPreference<Boolean>> transportPrefs = new ArrayList<>();
Iterator<RenderingRuleProperty> it = customRules.iterator();
while (it.hasNext()) {
RenderingRuleProperty p = it.next();
if ("transport".equals(p.getCategory()) && p.isBoolean()) {
transportRules.add(p);
final OsmandSettings.CommonPreference<Boolean> pref = activity.getMyApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName());
transportPrefs.add(pref);
it.remove();
}
}
selected = false;
for (OsmandSettings.CommonPreference<Boolean> p : transportPrefs) {
if (p.get()) {
selected = true;
break;
}
}
final boolean transportSelected = selected;
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.rendering_category_transport, activity).setIcon(R.drawable.ic_action_bus_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setSelected(transportSelected).setColor(transportSelected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setListener(new ContextMenuAdapter.OnRowItemClick() {
ArrayAdapter<CharSequence> adapter;
boolean transportSelectedInner = transportSelected;
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
if (transportSelectedInner) {
showTransportDialog(adapter, position);
return false;
} else {
CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked());
adapter.getItem(position).setColorRes(btn.isChecked() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
return false;
} else {
return onContextMenuClick(adapter, itemId, position, false, null);
}
}
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
if (transportSelectedInner) {
for (int i = 0; i < transportPrefs.size(); i++) {
transportPrefs.get(i).set(false);
}
transportSelectedInner = false;
ad.getItem(pos).setColorRes(ContextMenuItem.INVALID_ID);
refreshMapComplete(activity);
activity.getMapLayers().updateLayers(activity.getMapView());
} else {
ad.getItem(pos).setColorRes(R.color.osmand_orange);
showTransportDialog(ad, pos);
}
ad.notifyDataSetChanged();
return false;
}
private void showTransportDialog(final ArrayAdapter<ContextMenuItem> ad, final int pos) {
final AlertDialog.Builder b = new AlertDialog.Builder(activity);
b.setTitle(activity.getString(R.string.rendering_category_transport));
final int[] iconIds = new int[transportPrefs.size()];
final boolean[] checkedItems = new boolean[transportPrefs.size()];
for (int i = 0; i < transportPrefs.size(); i++) {
checkedItems[i] = transportPrefs.get(i).get();
}
final String[] vals = new String[transportRules.size()];
for (int i = 0; i < transportRules.size(); i++) {
RenderingRuleProperty p = transportRules.get(i);
String propertyName = SettingsActivity.getStringPropertyName(activity, p.getAttrName(), p.getName());
vals[i] = propertyName;
if ("transportStops".equals(p.getAttrName())) {
iconIds[i] = R.drawable.ic_action_transport_stop;
} else if ("publicTransportMode".equals(p.getAttrName())) {
iconIds[i] = R.drawable.ic_action_bus_dark;
} else if ("tramTrainRoutes".equals(p.getAttrName())) {
iconIds[i] = R.drawable.ic_action_transport_tram;
} else if ("subwayMode".equals(p.getAttrName())) {
iconIds[i] = R.drawable.ic_action_transport_subway;
} else {
iconIds[i] = R.drawable.ic_action_bus_dark;
}
}
adapter = new ArrayAdapter<CharSequence>(activity, R.layout.popup_list_item_icon24_and_menu, R.id.title, vals) {
@NonNull
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
final ImageView icon = (ImageView) v.findViewById(R.id.icon);
if (checkedItems[position]) {
icon.setImageDrawable(app.getIconsCache().getIcon(iconIds[position], R.color.osmand_orange));
} else {
icon.setImageDrawable(app.getIconsCache().getThemedIcon(iconIds[position]));
}
v.findViewById(R.id.divider).setVisibility(View.GONE);
v.findViewById(R.id.description).setVisibility(View.GONE);
v.findViewById(R.id.secondary_icon).setVisibility(View.GONE);
final SwitchCompat check = (SwitchCompat) v.findViewById(R.id.toggle_item);
check.setOnCheckedChangeListener(null);
check.setChecked(checkedItems[position]);
check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
checkedItems[position] = isChecked;
if (checkedItems[position]) {
icon.setImageDrawable(app.getIconsCache().getIcon(iconIds[position], R.color.osmand_orange));
} else {
icon.setImageDrawable(app.getIconsCache().getThemedIcon(iconIds[position]));
}
}
});
return v;
}
};
final ListView listView = new ListView(activity);
listView.setDivider(null);
listView.setClickable(true);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new ListView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
checkedItems[position] = !checkedItems[position];
adapter.notifyDataSetChanged();
}
});
b.setView(listView);
b.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
ContextMenuItem item = ad.getItem(pos);
if (item != null) {
item.setSelected(transportSelectedInner);
item.setColorRes(transportSelectedInner ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
ad.notifyDataSetChanged();
}
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
b.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
transportSelectedInner = false;
for (int i = 0; i < transportPrefs.size(); i++) {
transportPrefs.get(i).set(checkedItems[i]);
if (!transportSelectedInner && checkedItems[i]) {
transportSelectedInner = true;
}
}
refreshMapComplete(activity);
activity.getMapLayers().updateLayers(activity.getMapView());
}
});
b.show();
}
}).createItem());
selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_gpx_layer, activity).setSelected(app.getSelectedGpxHelper().isShowingAnyGpxFiles()).setDescription(app.getSelectedGpxHelper().getGpxDescription()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_polygom_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(l).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_map, activity).setIcon(R.drawable.ic_world_globe_dark).setDescription(settings.MAP_ONLINE_DATA.get() ? settings.MAP_TILE_SOURCES.get() : null).setListener(l).createItem());
OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity);
app.getAppCustomization().prepareLayerContextMenu(activity, adapter);
boolean srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
if (srtmDisabled) {
SRTMPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
if (srtmPlugin != null) {
srtmPlugin.registerLayerContextMenuActions(activity.getMapView(), adapter, activity);
}
}
}
use of android.widget.CompoundButton.OnCheckedChangeListener in project Osmand by osmandapp.
the class ConfigureMapMenu method createRenderingAttributeItems.
private void createRenderingAttributeItems(List<RenderingRuleProperty> customRules, final ContextMenuAdapter adapter, final MapActivity activity) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_map_rendering, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_renderer, activity).setDescription(getRenderDescr(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_map).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
bld.setTitle(R.string.renderers);
final OsmandApplication app = activity.getMyApplication();
final ArrayList<String> items = new ArrayList<>(app.getRendererRegistry().getRendererNames());
boolean nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
final List<String> visibleNamesList = new ArrayList<>();
int selected = -1;
final String selectedName = app.getRendererRegistry().getCurrentSelectedRenderer().getName();
int i = 0;
Iterator<String> iterator = items.iterator();
while (iterator.hasNext()) {
String item = iterator.next();
if (nauticalPluginDisabled && item.equals(RendererRegistry.NAUTICAL_RENDER)) {
iterator.remove();
} else {
if (item.equals(selectedName)) {
selected = i;
}
String translation = RendererRegistry.getTranslatedRendererName(activity, item);
visibleNamesList.add(translation != null ? translation : item.replace('_', ' ').replace('-', ' '));
i++;
}
}
bld.setSingleChoiceItems(visibleNamesList.toArray(new String[visibleNamesList.size()]), selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String renderer = items.get(which);
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
if (loaded != null) {
OsmandMapTileView view = activity.getMapView();
view.getSettings().RENDERER.set(renderer);
app.getRendererRegistry().setCurrentSelectedRender(loaded);
refreshMapComplete(activity);
} else {
Toast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
}
adapter.getItem(pos).setDescription(getRenderDescr(activity));
activity.getDashboard().refreshContent(true);
dialog.dismiss();
}
});
bld.setNegativeButton(R.string.shared_string_dismiss, null);
bld.show();
return false;
}
}).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_mode, activity).setDescription(getDayNightDescr(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(getDayNightIcon(activity)).setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
bld.setTitle(R.string.daynight);
final String[] items = new String[OsmandSettings.DayNightMode.values().length];
for (int i = 0; i < items.length; i++) {
items[i] = OsmandSettings.DayNightMode.values()[i].toHumanString(activity.getMyApplication());
}
int i = view.getSettings().DAYNIGHT_MODE.get().ordinal();
bld.setSingleChoiceItems(items, i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.values()[which]);
refreshMapComplete(activity);
dialog.dismiss();
activity.getDashboard().refreshContent(true);
// adapter.getItem(pos).setDescription(s, getDayNightDescr(activity));
// ad.notifyDataSetInvalidated();
}
});
bld.setNegativeButton(R.string.shared_string_dismiss, null);
bld.show();
return false;
}
}).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_magnifier, activity).setDescription(String.format(Locale.UK, "%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %").setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_magnifier).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandMapTileView view = activity.getMapView();
final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
int p = (int) (mapDensity.get() * 100);
final TIntArrayList tlist = new TIntArrayList(new int[] { 33, 50, 75, 100, 150, 200, 300, 400 });
final List<String> values = new ArrayList<>();
int i = -1;
for (int k = 0; k <= tlist.size(); k++) {
final boolean end = k == tlist.size();
if (i == -1) {
if ((end || p < tlist.get(k))) {
values.add(p + " %");
i = k;
} else if (p == tlist.get(k)) {
i = k;
}
}
if (k < tlist.size()) {
values.add(tlist.get(k) + " %");
}
}
if (values.size() != tlist.size()) {
tlist.insert(i, p);
}
bld.setTitle(R.string.map_magnifier);
bld.setSingleChoiceItems(values.toArray(new String[values.size()]), i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int p = tlist.get(which);
mapDensity.set(p / 100.0f);
view.setComplexZoom(view.getZoom(), view.getSettingsMapDensity());
MapRendererContext mapContext = NativeCoreContext.getMapRendererContext();
if (mapContext != null) {
mapContext.updateMapSettings();
}
adapter.getItem(pos).setDescription(String.format(Locale.UK, "%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %");
ad.notifyDataSetInvalidated();
dialog.dismiss();
}
});
bld.setNegativeButton(R.string.shared_string_dismiss, null);
bld.show();
return false;
}
}).createItem());
ContextMenuItem props;
props = createRenderingProperty(customRules, adapter, activity, R.drawable.ic_action_intersection, ROAD_STYLE_ATTR);
if (props != null) {
adapter.addItem(props);
}
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.text_size, activity).setDescription(getScale(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_text_size).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
// test old descr as title
b.setTitle(R.string.text_size);
final Float[] txtValues = new Float[] { 0.75f, 1f, 1.25f, 1.5f, 2f, 3f };
int selected = -1;
final String[] txtNames = new String[txtValues.length];
for (int i = 0; i < txtNames.length; i++) {
txtNames[i] = (int) (txtValues[i] * 100) + " %";
if (Math.abs(view.getSettings().TEXT_SCALE.get() - txtValues[i]) < 0.1f) {
selected = i;
}
}
b.setSingleChoiceItems(txtNames, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().TEXT_SCALE.set(txtValues[which]);
refreshMapComplete(activity);
adapter.getItem(pos).setDescription(getScale(activity));
ad.notifyDataSetInvalidated();
dialog.dismiss();
}
});
b.setNegativeButton(R.string.shared_string_dismiss, null);
b.show();
return false;
}
}).createItem());
String localeDescr = activity.getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get();
localeDescr = localeDescr == null || localeDescr.equals("") ? activity.getString(R.string.local_map_names) : localeDescr;
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_locale, activity).setDescription(localeDescr).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_language).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandMapTileView view = activity.getMapView();
final AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
b.setTitle(activity.getString(R.string.map_locale));
final String[] txtIds = getSortedMapNamesIds(activity, mapNamesIds, getMapNamesValues(activity, mapNamesIds));
final String[] txtValues = getMapNamesValues(activity, txtIds);
int selected = -1;
for (int i = 0; i < txtIds.length; i++) {
if (view.getSettings().MAP_PREFERRED_LOCALE.get().equals(txtIds[i])) {
selected = i;
break;
}
}
selectedLanguageIndex = selected;
transliterateNames = view.getSettings().MAP_TRANSLITERATE_NAMES.get();
final OnCheckedChangeListener translitChangdListener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
transliterateNames = isChecked;
}
};
final ArrayAdapter<CharSequence> singleChoiceAdapter = new ArrayAdapter<CharSequence>(activity, R.layout.single_choice_switch_item, R.id.text1, txtValues) {
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
AppCompatCheckedTextView checkedTextView = (AppCompatCheckedTextView) v.findViewById(R.id.text1);
if (position == selectedLanguageIndex && position > 0) {
checkedTextView.setChecked(true);
v.findViewById(R.id.topDivider).setVisibility(View.VISIBLE);
v.findViewById(R.id.bottomDivider).setVisibility(View.VISIBLE);
v.findViewById(R.id.switchLayout).setVisibility(View.VISIBLE);
TextView switchText = (TextView) v.findViewById(R.id.switchText);
switchText.setText(activity.getString(R.string.translit_name_if_miss, txtValues[position]));
SwitchCompat check = (SwitchCompat) v.findViewById(R.id.check);
check.setChecked(transliterateNames);
check.setOnCheckedChangeListener(translitChangdListener);
} else {
checkedTextView.setChecked(position == selectedLanguageIndex);
v.findViewById(R.id.topDivider).setVisibility(View.GONE);
v.findViewById(R.id.bottomDivider).setVisibility(View.GONE);
v.findViewById(R.id.switchLayout).setVisibility(View.GONE);
}
return v;
}
};
b.setAdapter(singleChoiceAdapter, null);
b.setSingleChoiceItems(txtValues, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
selectedLanguageIndex = which;
((AlertDialog) dialog).getListView().setSelection(which);
singleChoiceAdapter.notifyDataSetChanged();
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
b.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().MAP_TRANSLITERATE_NAMES.set(selectedLanguageIndex > 0 && transliterateNames);
AlertDialog dlg = (AlertDialog) dialog;
int index = dlg.getListView().getCheckedItemPosition();
view.getSettings().MAP_PREFERRED_LOCALE.set(txtIds[index]);
refreshMapComplete(activity);
String localeDescr = txtIds[index];
localeDescr = localeDescr == null || localeDescr.equals("") ? activity.getString(R.string.local_map_names) : localeDescr;
adapter.getItem(pos).setDescription(localeDescr);
ad.notifyDataSetInvalidated();
}
});
b.show();
return false;
}
}).createItem());
props = createProperties(customRules, null, R.string.rendering_category_transport, R.drawable.ic_action_bus_dark, "transport", null, adapter, activity, true);
if (props != null) {
adapter.addItem(props);
}
props = createProperties(customRules, null, R.string.rendering_category_details, R.drawable.ic_action_layers_dark, "details", null, adapter, activity, true);
if (props != null) {
adapter.addItem(props);
}
props = createProperties(customRules, null, R.string.rendering_category_hide, R.drawable.ic_action_hide, "hide", null, adapter, activity, true);
if (props != null) {
adapter.addItem(props);
}
List<RenderingRuleProperty> customRulesIncluded = new ArrayList<>();
for (RenderingRuleProperty p : customRules) {
if (p.getAttrName().equals(HIKING_ROUTES_OSMC_ATTR)) {
customRulesIncluded.add(p);
break;
}
}
props = createProperties(customRules, customRulesIncluded, R.string.rendering_category_routes, R.drawable.ic_action_map_routes, "routes", null, adapter, activity, true);
if (props != null) {
adapter.addItem(props);
}
if (getCustomRenderingPropertiesSize(customRules) > 0) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.rendering_category_others, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
createCustomRenderingProperties(adapter, activity, customRules);
}
}
Aggregations