use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class ConfigureMapMenu method createBooleanRenderingProperty.
public static ContextMenuItem createBooleanRenderingProperty(@NonNull MapActivity activity, @NonNull String attrName, @NonNull String name, @NonNull String id, @Nullable RenderingRuleProperty property, @DrawableRes int icon, boolean nightMode, @Nullable CallbackWithObject<Boolean> callback) {
OsmandApplication app = activity.getMyApplication();
OsmandSettings settings = app.getSettings();
CommonPreference<Boolean> pref = settings.getCustomRenderBooleanProperty(attrName);
return ContextMenuItem.createBuilder(name).setId(id).setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
if (property != null) {
pref.set(isChecked);
activity.refreshMap();
activity.updateLayers();
} else {
isChecked = pref.get();
}
if (callback != null) {
callback.processResult(isChecked);
}
ContextMenuItem item = adapter.getItem(pos);
if (item != null) {
item.setSelected(pref.get());
item.setColor(activity, isChecked ? R.color.osmand_orange : INVALID_ID);
item.setDescription(app.getString(isChecked ? R.string.shared_string_enabled : R.string.shared_string_disabled));
adapter.notifyDataSetChanged();
}
return false;
}
}).setSelected(pref.get()).setColor(pref.get() ? settings.getApplicationMode().getProfileColor(nightMode) : null).setDescription(app.getString(pref.get() ? R.string.shared_string_enabled : R.string.shared_string_disabled)).setIcon(icon).createItem();
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class ConfigureMapMenu method createCycleRoutesItem.
private ContextMenuItem createCycleRoutesItem(@NonNull MapActivity activity, @NonNull String attrName, @Nullable RenderingRuleProperty property, boolean nightMode) {
OsmandApplication app = activity.getMyApplication();
OsmandSettings settings = app.getSettings();
CommonPreference<Boolean> pref = settings.getCustomRenderBooleanProperty(attrName);
return new ContextMenuItem.ItemBuilder().setId(ROUTES_ID + attrName).setTitle(AndroidUtils.getRenderingStringPropertyName(app, attrName, property != null ? property.getName() : attrName)).setIcon(getIconIdForAttr(attrName)).setSecondaryIcon(R.drawable.ic_action_additional_option).setSelected(pref.get()).setColor(pref.get() ? settings.getApplicationMode().getProfileColor(nightMode) : null).setDescription(app.getString(pref.get() ? R.string.shared_string_enabled : R.string.shared_string_disabled)).setListener(new OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
if (property != null) {
activity.getDashboard().setDashboardVisibility(true, DashboardType.CYCLE_ROUTES, AndroidUtils.getCenterViewCoordinates(view));
} else {
showRendererSnackbarForAttr(activity, attrName, nightMode, null);
}
return false;
}
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
pref.set(isChecked);
ContextMenuItem item = adapter.getItem(position);
if (item != null) {
item.setColor(activity, isChecked ? R.color.osmand_orange : INVALID_ID);
item.setDescription(app.getString(isChecked ? R.string.shared_string_enabled : R.string.shared_string_disabled));
adapter.notifyDataSetChanged();
}
if (property != null) {
activity.refreshMap();
activity.updateLayers();
} else {
showRendererSnackbarForAttr(activity, attrName, nightMode, null);
}
return false;
}
}).createItem();
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class DashboardOnMap method removeFragment.
private void removeFragment(String tag) {
FragmentManager manager = mapActivity.getSupportFragmentManager();
Fragment fragment = manager.findFragmentByTag(tag);
if (fragment != null) {
OsmandSettings settings = getMyApplication().getSettings();
TransactionBuilder builder = new TransactionBuilder(manager, settings, mapActivity);
builder.getFragmentTransaction().remove(fragment).commitAllowingStateLoss();
}
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class DashDashboardOrDrawerFragment method initView.
@Override
public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_dashboard_or_drawer_fragment, container, false);
view.findViewById(R.id.useDashboardButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final OsmandSettings settings = getMyApplication().getSettings();
settings.SHOW_DASHBOARD_ON_START.set(true);
settings.SHOW_DASHBOARD_ON_MAP_SCREEN.set(true);
settings.SHOW_CARD_TO_CHOOSE_DRAWER.set(false);
dashboard.hideFragmentByTag(TAG);
}
});
view.findViewById(R.id.useDrawerButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final OsmandSettings settings = getMyApplication().getSettings();
settings.SHOW_DASHBOARD_ON_START.set(false);
settings.SHOW_DASHBOARD_ON_MAP_SCREEN.set(false);
settings.SHOW_CARD_TO_CHOOSE_DRAWER.set(false);
dashboard.hideDashboard();
}
});
return view;
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class AvailableGPXFragment method showGpxOnMap.
private void showGpxOnMap(GpxInfo info) {
info.setGpx(GPXUtilities.loadGPXFile(info.file));
boolean e = true;
if (info.gpx != null) {
WptPt loc = info.gpx.findPointToShow();
OsmandApplication app = requireMyApplication();
OsmandSettings settings = app.getSettings();
if (loc != null) {
settings.setMapLocationToShow(loc.lat, loc.lon, settings.getLastKnownMapZoom());
e = false;
app.getSelectedGpxHelper().setGpxFileToDisplay(info.gpx);
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState());
}
}
if (e) {
app.showToastMessage(app.getString(R.string.gpx_file_is_empty));
}
}
Aggregations