use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class ConfigureMapDialogs method showTextSizeDialog.
protected static void showTextSizeDialog(MapActivity activity, ContextMenuAdapter adapter, int themeRes, boolean nightMode, int pos, ArrayAdapter<ContextMenuItem> ad) {
OsmandApplication app = activity.getMyApplication();
OsmandSettings settings = app.getSettings();
int selectedProfileColor = settings.APPLICATION_MODE.get().getProfileColor(nightMode);
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes));
// test old descr as title
b.setTitle(R.string.text_size);
final Float[] txtValues = new Float[] { 0.33f, 0.5f, 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;
}
}
DialogListItemAdapter dialogAdapter = DialogListItemAdapter.createSingleChoiceAdapter(txtNames, nightMode, selected, app, selectedProfileColor, themeRes, new View.OnClickListener() {
@Override
public void onClick(View v) {
int which = (int) v.getTag();
view.getSettings().TEXT_SCALE.set(txtValues[which]);
activity.refreshMapComplete();
adapter.getItem(pos).setDescription(ConfigureMapUtils.getScale(activity));
ad.notifyDataSetInvalidated();
}
});
b.setAdapter(dialogAdapter, null);
b.setNegativeButton(R.string.shared_string_dismiss, null);
dialogAdapter.setDialog(b.show());
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class ConfigureMapDialogs method showMapLanguageDialog.
protected static void showMapLanguageDialog(MapActivity activity, ContextMenuAdapter adapter, int themeRes, boolean nightMode, int pos, ArrayAdapter<ContextMenuItem> ad) {
int[] selectedLanguageIndex = new int[1];
boolean[] transliterateNames = new boolean[1];
OsmandApplication app = activity.getMyApplication();
OsmandSettings settings = app.getSettings();
int selectedProfileColor = settings.APPLICATION_MODE.get().getProfileColor(nightMode);
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes));
b.setTitle(activity.getString(R.string.map_locale));
final String[] txtIds = ConfigureMapUtils.getSortedMapNamesIds(activity, ConfigureMapUtils.MAP_NAMES_IDS, ConfigureMapUtils.getMapNamesValues(activity, ConfigureMapUtils.MAP_NAMES_IDS));
final String[] txtValues = ConfigureMapUtils.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[0] = selected;
transliterateNames[0] = settings.MAP_TRANSLITERATE_NAMES.get();
final OnCheckedChangeListener translitChangdListener = (buttonView, isChecked) -> transliterateNames[0] = isChecked;
final ArrayAdapter<CharSequence> singleChoiceAdapter = new ArrayAdapter<CharSequence>(new ContextThemeWrapper(activity, themeRes), 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 = v.findViewById(R.id.text1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
UiUtilities.setupCompoundButtonDrawable(app, nightMode, selectedProfileColor, checkedTextView.getCheckMarkDrawable());
}
if (position == selectedLanguageIndex[0] && 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 = v.findViewById(R.id.switchText);
switchText.setText(activity.getString(R.string.translit_name_if_miss, txtValues[position]));
SwitchCompat check = v.findViewById(R.id.check);
check.setChecked(transliterateNames[0]);
check.setOnCheckedChangeListener(translitChangdListener);
UiUtilities.setupCompoundButton(nightMode, selectedProfileColor, check);
} else {
checkedTextView.setChecked(position == selectedLanguageIndex[0]);
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[0] = which;
transliterateNames[0] = settings.MAP_TRANSLITERATE_NAMES.isSet() ? transliterateNames[0] : txtIds[which].equals("en");
((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] > 0 && transliterateNames[0]);
AlertDialog dlg = (AlertDialog) dialog;
int index = dlg.getListView().getCheckedItemPosition();
view.getSettings().MAP_PREFERRED_LOCALE.set(txtIds[index]);
activity.refreshMapComplete();
String localeDescr = txtIds[index];
localeDescr = localeDescr == null || localeDescr.isEmpty() ? activity.getString(R.string.local_map_names) : localeDescr;
adapter.getItem(pos).setDescription(localeDescr);
ad.notifyDataSetInvalidated();
}
});
b.show();
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class ConfigureMapDialogs method showRenderingPropertyDialog.
protected static void showRenderingPropertyDialog(MapActivity activity, ContextMenuAdapter adapter, RenderingRuleProperty p, CommonPreference<String> pref, int pos, boolean nightMode) {
OsmandApplication app = activity.getMyApplication();
OsmandSettings settings = app.getSettings();
int currentProfileColor = settings.APPLICATION_MODE.get().getProfileColor(nightMode);
int themeRes = ConfigureMapMenu.getThemeRes(nightMode);
AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes));
String propertyDescr = AndroidUtils.getRenderingStringPropertyDescription(app, p.getAttrName(), p.getName());
// test old descr as title
b.setTitle(propertyDescr);
int i = Arrays.asList(p.getPossibleValues()).indexOf(pref.get());
if (i >= 0) {
i++;
} else if (Algorithms.isEmpty(pref.get())) {
i = 0;
}
String[] possibleValuesString = ConfigureMapUtils.getRenderingPropertyPossibleValues(app, p);
DialogListItemAdapter dialogAdapter = DialogListItemAdapter.createSingleChoiceAdapter(possibleValuesString, nightMode, i, app, currentProfileColor, themeRes, v -> {
int which = (int) v.getTag();
if (which == 0) {
pref.set("");
} else {
pref.set(p.getPossibleValues()[which - 1]);
}
activity.refreshMapComplete();
String description = AndroidUtils.getRenderingStringPropertyValue(activity, pref.get());
adapter.getItem(pos).setDescription(description);
});
b.setNegativeButton(R.string.shared_string_dismiss, null);
b.setAdapter(dialogAdapter, null);
dialogAdapter.setDialog(b.show());
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class SelectMapStyleBottomSheetDialogFragment method onRightBottomButtonClick.
@Override
protected void onRightBottomButtonClick() {
MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
return;
}
OsmandApplication app = getMyApplication();
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(selectedStyle);
if (loaded != null) {
OsmandMapTileView view = mapActivity.getMapView();
OsmandSettings settings = view.getSettings();
settings.RENDERER.set(selectedStyle);
final CommonPreference<Boolean> pisteRoutesPref = settings.getCustomRenderBooleanProperty(PISTE_ROUTES_ATTR);
if (pisteRoutesPref.get()) {
pisteRoutesPref.set(settings.RENDERER.get().equals(RendererRegistry.WINTER_SKI_RENDER));
}
app.getRendererRegistry().setCurrentSelectedRender(loaded);
mapActivity.refreshMapComplete();
mapActivity.getDashboard().refreshContent(true);
} else {
Toast.makeText(mapActivity, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
}
dismiss();
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class SendAnalyticsBottomSheetDialogFragment method onRightBottomButtonClick.
@Override
protected void onRightBottomButtonClick() {
OsmandApplication app = requiredMyApplication();
OsmandSettings settings = app.getSettings();
settings.SEND_ANONYMOUS_MAP_DOWNLOADS_DATA.set(sendAnonymousMapDownloadsData);
settings.SEND_ANONYMOUS_APP_USAGE_DATA.set(sendAnonymousAppUsageData);
settings.SEND_ANONYMOUS_DATA_REQUEST_PROCESSED.set(true);
informAnalyticsPrefsUpdate();
dismiss();
}
Aggregations