use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class DirectionIndicationDialogFragment method updateSelection.
private void updateSelection(boolean notifyListener) {
OsmandSettings settings = getSettings();
MapMarkersMode mode = settings.MAP_MARKERS_MODE.get();
boolean distIndEnabled = settings.MARKERS_DISTANCE_INDICATION_ENABLED.get();
int count = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get();
int topBarIconId = count == 1 ? R.drawable.ic_action_device_topbar : R.drawable.ic_action_device_topbar_two;
int widgetIconId = count == 1 ? R.drawable.ic_action_device_widget : R.drawable.ic_action_device_widget_two;
updateIcon(R.id.top_bar_icon, topBarIconId, mode.isToolbar() && distIndEnabled);
updateIcon(R.id.widget_icon, widgetIconId, mode.isWidgets() && distIndEnabled);
updateMarkerModeRow(R.id.top_bar_row, R.id.top_bar_radio_button, mode.isToolbar(), distIndEnabled);
updateMarkerModeRow(R.id.widget_row, R.id.widget_radio_button, mode.isWidgets(), distIndEnabled);
if (notifyListener) {
notifyListener();
}
updateHelpImage();
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class MapMarkersDbHelper method saveExistingMarkersToDb.
private void saveExistingMarkersToDb() {
OsmandSettings settings = context.getSettings();
List<LatLon> ips = settings.getMapMarkersPoints();
List<String> desc = settings.getMapMarkersPointDescriptions(ips.size());
List<Integer> colors = settings.getMapMarkersColors(ips.size());
int colorIndex = 0;
for (int i = 0; i < ips.size(); i++) {
if (colors.size() > i) {
colorIndex = colors.get(i);
}
MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, false, i);
marker.history = false;
addMarker(marker, true);
}
ips = settings.getMapMarkersHistoryPoints();
desc = settings.getMapMarkersHistoryPointDescriptions(ips.size());
colors = settings.getMapMarkersHistoryColors(ips.size());
for (int i = 0; i < ips.size(); i++) {
if (colors.size() > i) {
colorIndex = colors.get(i);
}
MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, false, i);
marker.history = true;
addMarker(marker, true);
}
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class MapillaryPlugin method registerLayerContextMenuActions.
@Override
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
if (itemId == R.string.mapillary) {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAPILLARY, AndroidUtils.getCenterViewCoordinates(view));
return false;
}
return true;
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
if (itemId == R.string.mapillary) {
OsmandMapTileView mapView = mapActivity.getMapView();
MapActivityLayers mapLayers = mapActivity.getMapLayers();
settings.SHOW_MAPILLARY.set(!settings.SHOW_MAPILLARY.get());
updateMapLayers(mapView, mapLayers, false);
ContextMenuItem item = adapter.getItem(pos);
if (item != null) {
item.setSelected(settings.SHOW_MAPILLARY.get());
item.setColorRes(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
}
return false;
}
};
if (rasterLayer.getMap() == null) {
settings.SHOW_MAPILLARY.set(false);
}
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.mapillary, mapActivity).setSelected(settings.SHOW_MAPILLARY.get()).setColor(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_mapillary).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(11).createItem());
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class CoordinateInputBottomSheetDialogFragment method createMenuItems.
@Override
public void createMenuItems(Bundle savedInstanceState) {
final Context context = getContext();
final OsmandSettings settings = getMyApplication().getSettings();
items.add(new TitleItem(getString(R.string.shared_string_options)));
boolean useOsmandKeyboard = settings.COORDS_INPUT_USE_OSMAND_KEYBOARD.get();
BaseBottomSheetItem useSystemKeyboardItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(!useOsmandKeyboard).setIcon(getContentIcon(R.drawable.ic_action_keyboard)).setTitle(getString(R.string.use_system_keyboard)).setLayoutId(R.layout.bottom_sheet_item_with_switch).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onKeyboardChanged();
}
dismiss();
}
}).create();
items.add(useSystemKeyboardItem);
boolean useTwoDigitsLogtitude = settings.COORDS_INPUT_TWO_DIGITS_LONGTITUDE.get();
BaseBottomSheetItem twoDigitsLongtitudeItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(useTwoDigitsLogtitude).setIcon(getContentIcon(R.drawable.ic_action_next_field_stroke)).setTitle(getString(R.string.use_two_digits_longitude)).setLayoutId(R.layout.bottom_sheet_item_with_switch).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
OsmandSettings.CommonPreference<Boolean> pref = settings.COORDS_INPUT_TWO_DIGITS_LONGTITUDE;
pref.set(!pref.get());
listener.onInputSettingsChanged();
}
dismiss();
}
}).create();
items.add(twoDigitsLongtitudeItem);
if (!AndroidUiHelper.isOrientationPortrait(getActivity())) {
boolean rightHand = settings.COORDS_INPUT_USE_RIGHT_SIDE.get();
BaseBottomSheetItem showNumberPadItem = new BottomSheetItemWithDescription.Builder().setDescription(getString(rightHand ? R.string.shared_string_right : R.string.shared_string_left)).setDescriptionColorId(getActiveColorId()).setIcon(getContentIcon(rightHand ? R.drawable.ic_action_show_keypad_right : R.drawable.ic_action_show_keypad_left)).setTitle(getString(R.string.show_number_pad)).setLayoutId(R.layout.bottom_sheet_item_with_right_descr).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
OsmandSettings.CommonPreference<Boolean> pref = settings.COORDS_INPUT_USE_RIGHT_SIDE;
pref.set(!pref.get());
listener.onHandChanged();
}
dismiss();
}
}).create();
items.add(showNumberPadItem);
}
items.add(new SubtitleDividerItem(context));
items.add(new SubtitleItem(getString(R.string.coordinates_format)));
int selectedFormat = settings.COORDS_INPUT_FORMAT.get();
Drawable formatIcon = getContentIcon(R.drawable.ic_action_coordinates_latitude);
View.OnClickListener formatsOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
int format = (int) v.getTag();
settings.COORDS_INPUT_FORMAT.set(format);
if (listener != null) {
listener.onInputSettingsChanged();
}
dismiss();
}
};
for (@CoordinateInputFormatDef int format : CoordinateInputFormats.VALUES) {
boolean selectedItem = format == selectedFormat;
BaseBottomSheetItem formatItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(selectedItem).setButtonTintList(selectedItem ? ColorStateList.valueOf(getResolvedColor(getActiveColorId())) : null).setIcon(selectedItem ? getActiveIcon(R.drawable.ic_action_coordinates_latitude) : formatIcon).setTitle(CoordinateInputFormats.formatToHumanString(context, format)).setTitleColorId(selectedItem ? getActiveColorId() : BaseBottomSheetItem.INVALID_ID).setLayoutId(R.layout.bottom_sheet_item_with_radio_btn).setOnClickListener(formatsOnClickListener).setTag(format).create();
items.add(formatItem);
}
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class MapillaryFiltersFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final MapActivity mapActivity = (MapActivity) getActivity();
final OsmandSettings settings = getSettings();
final MapillaryPlugin plugin = OsmandPlugin.getPlugin(MapillaryPlugin.class);
final boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final int backgroundColor = ContextCompat.getColor(getActivity(), nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
final DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
final View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_mapillary_filters, null);
view.findViewById(R.id.mapillary_filters_linear_layout).setBackgroundColor(backgroundColor);
final View toggleRow = view.findViewById(R.id.toggle_row);
final boolean selected = settings.SHOW_MAPILLARY.get();
final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
int toggleIconColorId;
int toggleIconId;
if (selected) {
toggleIconId = R.drawable.ic_action_view;
toggleIconColorId = nightMode ? R.color.color_dialog_buttons_dark : R.color.color_dialog_buttons_light;
} else {
toggleIconId = R.drawable.ic_action_hide;
toggleIconColorId = nightMode ? 0 : R.color.icon_color;
}
((AppCompatTextView) toggleRow.findViewById(R.id.toggle_row_title)).setText(toggleActionStringId);
final Drawable drawable = getIcon(toggleIconId, toggleIconColorId);
((AppCompatImageView) toggleRow.findViewById(R.id.toggle_row_icon)).setImageDrawable(drawable);
final CompoundButton toggle = (CompoundButton) toggleRow.findViewById(R.id.toggle_row_toggle);
toggle.setOnCheckedChangeListener(null);
toggle.setChecked(selected);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
settings.SHOW_MAPILLARY.set(!settings.SHOW_MAPILLARY.get());
plugin.updateLayers(mapActivity.getMapView(), mapActivity);
mapActivity.getDashboard().refreshContent(true);
}
});
toggleRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggle.setChecked(!toggle.isChecked());
}
});
final Button reloadTile = (Button) view.findViewById(R.id.button_reload_tile);
reloadTile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ResourceManager manager = getMyApplication().getResourceManager();
manager.clearCacheAndTiles(TileSourceManager.getMapillaryVectorSource());
manager.clearCacheAndTiles(TileSourceManager.getMapillaryRasterSource());
mapActivity.refreshMap();
}
});
final int colorRes = nightMode ? R.color.color_white : R.color.icon_color;
((AppCompatImageView) view.findViewById(R.id.mapillary_filters_user_icon)).setImageDrawable(getIcon(R.drawable.ic_action_user, colorRes));
((AppCompatImageView) view.findViewById(R.id.mapillary_filters_date_icon)).setImageDrawable(getIcon(R.drawable.ic_action_data, colorRes));
((AppCompatImageView) view.findViewById(R.id.mapillary_filters_tile_cache_icon)).setImageDrawable(getIcon(R.drawable.ic_layer_top_dark, colorRes));
final DelayAutoCompleteTextView textView = (DelayAutoCompleteTextView) view.findViewById(R.id.auto_complete_text_view);
textView.setAdapter(new MapillaryAutoCompleteAdapter(getContext(), R.layout.auto_complete_suggestion, getMyApplication()));
String selectedUsername = settings.MAPILLARY_FILTER_USERNAME.get();
if (!selectedUsername.equals("") && settings.USE_MAPILLARY_FILTER.get()) {
textView.setText(selectedUsername);
textView.setSelection(selectedUsername.length());
}
textView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
hideKeyboard();
mapActivity.getDashboard().refreshContent(true);
}
});
textView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
if (id == EditorInfo.IME_ACTION_DONE) {
hideKeyboard();
mapActivity.getDashboard().refreshContent(true);
return true;
}
return false;
}
});
textView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
view.findViewById(R.id.warning_linear_layout).setVisibility(View.GONE);
if (!settings.MAPILLARY_FILTER_USERNAME.get().equals("") || settings.MAPILLARY_FILTER_TO_DATE.get() != 0 || settings.MAPILLARY_FILTER_FROM_DATE.get() != 0) {
changeButtonState((Button) view.findViewById(R.id.button_apply), 1, true);
} else {
changeButtonState((Button) view.findViewById(R.id.button_apply), .5f, false);
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
ImageView imageView = (ImageView) view.findViewById(R.id.warning_image_view);
imageView.setImageDrawable(getPaintedContentIcon(R.drawable.ic_small_warning, getResources().getColor(R.color.color_warning)));
final EditText dateFromEt = (EditText) view.findViewById(R.id.date_from_edit_text);
final DatePickerDialog.OnDateSetListener dateFromDialog = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker v, int year, int monthOfYear, int dayOfMonth) {
Calendar from = Calendar.getInstance();
from.set(Calendar.YEAR, year);
from.set(Calendar.MONTH, monthOfYear);
from.set(Calendar.DAY_OF_MONTH, dayOfMonth);
dateFromEt.setText(dateFormat.format(from.getTime()));
settings.MAPILLARY_FILTER_FROM_DATE.set(from.getTimeInMillis());
changeButtonState((Button) view.findViewById(R.id.button_apply), 1, true);
mapActivity.getDashboard().refreshContent(true);
}
};
dateFromEt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar now = Calendar.getInstance();
new DatePickerDialog(mapActivity, dateFromDialog, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)).show();
}
});
dateFromEt.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null);
final EditText dateToEt = (EditText) view.findViewById(R.id.date_to_edit_text);
final DatePickerDialog.OnDateSetListener dateToDialog = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker v, int year, int monthOfYear, int dayOfMonth) {
Calendar to = Calendar.getInstance();
to.set(Calendar.YEAR, year);
to.set(Calendar.MONTH, monthOfYear);
to.set(Calendar.DAY_OF_MONTH, dayOfMonth);
dateToEt.setText(dateFormat.format(to.getTime()));
settings.MAPILLARY_FILTER_TO_DATE.set(to.getTimeInMillis());
changeButtonState((Button) view.findViewById(R.id.button_apply), 1, true);
mapActivity.getDashboard().refreshContent(true);
}
};
dateToEt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar now = Calendar.getInstance();
new DatePickerDialog(mapActivity, dateToDialog, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)).show();
}
});
dateToEt.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null);
if (settings.USE_MAPILLARY_FILTER.get()) {
long to = settings.MAPILLARY_FILTER_TO_DATE.get();
if (to != 0) {
dateToEt.setText(dateFormat.format(new Date(to)));
}
long from = settings.MAPILLARY_FILTER_FROM_DATE.get();
if (from != 0) {
dateFromEt.setText(dateFormat.format(new Date(from)));
}
}
final Button apply = (Button) view.findViewById(R.id.button_apply);
changeButtonState(apply, .5f, false);
apply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = textView.getText().toString();
String dateFrom = dateFromEt.getText().toString();
String dateTo = dateToEt.getText().toString();
if (!settings.MAPILLARY_FILTER_USERNAME.get().equals("") || !dateFrom.equals("") || !dateTo.equals("")) {
settings.USE_MAPILLARY_FILTER.set(true);
}
if (dateFrom.equals("")) {
settings.MAPILLARY_FILTER_FROM_DATE.set(0L);
}
if (dateTo.equals("")) {
settings.MAPILLARY_FILTER_TO_DATE.set(0L);
}
if (!username.equals("") && settings.MAPILLARY_FILTER_USERNAME.get().equals("")) {
view.findViewById(R.id.warning_linear_layout).setVisibility(View.VISIBLE);
} else {
mapActivity.getDashboard().hideDashboard();
}
changeButtonState(apply, .5f, false);
plugin.updateLayers(mapActivity.getMapView(), mapActivity);
hideKeyboard();
}
});
final Button clear = (Button) view.findViewById(R.id.button_clear);
clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textView.setText("");
dateFromEt.setText("");
dateToEt.setText("");
settings.USE_MAPILLARY_FILTER.set(false);
settings.MAPILLARY_FILTER_USER_KEY.set("");
settings.MAPILLARY_FILTER_USERNAME.set("");
settings.MAPILLARY_FILTER_FROM_DATE.set(0L);
settings.MAPILLARY_FILTER_TO_DATE.set(0L);
plugin.updateLayers(mapActivity.getMapView(), mapActivity);
hideKeyboard();
}
});
return view;
}
Aggregations