use of net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean in project Osmand by osmandapp.
the class SettingsHelper method getSettingsItems.
private Map<ExportSettingsType, List<?>> getSettingsItems(@Nullable List<ExportSettingsType> settingsTypes, boolean addEmptyItems) {
Map<ExportSettingsType, List<?>> settingsItems = new LinkedHashMap<>();
if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.PROFILE)) {
List<ApplicationModeBean> appModeBeans = new ArrayList<>();
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
appModeBeans.add(mode.toModeBean());
}
settingsItems.put(ExportSettingsType.PROFILE, appModeBeans);
}
List<GlobalSettingsItem> globalSettingsList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.GLOBAL) ? Collections.singletonList(new GlobalSettingsItem(app.getSettings())) : Collections.emptyList();
if (!globalSettingsList.isEmpty() || addEmptyItems) {
settingsItems.put(ExportSettingsType.GLOBAL, globalSettingsList);
}
QuickActionRegistry registry = app.getQuickActionRegistry();
List<QuickAction> actionsList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.QUICK_ACTIONS) ? registry.getQuickActions() : Collections.emptyList();
if (!actionsList.isEmpty() || addEmptyItems) {
settingsItems.put(ExportSettingsType.QUICK_ACTIONS, actionsList);
}
List<PoiUIFilter> poiList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.POI_TYPES) ? app.getPoiFilters().getUserDefinedPoiFilters(false) : Collections.emptyList();
if (!poiList.isEmpty() || addEmptyItems) {
settingsItems.put(ExportSettingsType.POI_TYPES, poiList);
}
Map<LatLon, AvoidRoadInfo> impassableRoads = settingsTypes == null || settingsTypes.contains(ExportSettingsType.AVOID_ROADS) ? app.getAvoidSpecificRoads().getImpassableRoads() : Collections.emptyMap();
if (!impassableRoads.isEmpty() || addEmptyItems) {
settingsItems.put(ExportSettingsType.AVOID_ROADS, new ArrayList<>(impassableRoads.values()));
}
return settingsItems;
}
use of net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean in project Osmand by osmandapp.
the class SettingsHelper method getBaseProfileSettingsItem.
@Nullable
private ProfileSettingsItem getBaseProfileSettingsItem(ApplicationModeBean modeBean, List<SettingsItem> settingsItems) {
for (SettingsItem settingsItem : settingsItems) {
if (settingsItem.getType() == SettingsItemType.PROFILE) {
ProfileSettingsItem profileItem = (ProfileSettingsItem) settingsItem;
ApplicationModeBean bean = profileItem.getModeBean();
if (Algorithms.objectEquals(bean.stringKey, modeBean.stringKey) && Algorithms.objectEquals(bean.userProfileName, modeBean.userProfileName)) {
return profileItem;
}
}
}
return null;
}
use of net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean in project Osmand by osmandapp.
the class ExportItemsBottomSheet method setupBottomSheetItem.
private void setupBottomSheetItem(BottomSheetItemWithCompoundButton item, Object object) {
if (object instanceof ApplicationModeBean) {
ApplicationModeBean modeBean = (ApplicationModeBean) object;
String profileName = modeBean.userProfileName;
if (Algorithms.isEmpty(profileName)) {
ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
if (appMode != null) {
profileName = appMode.toHumanString();
} else {
profileName = Algorithms.capitalizeFirstLetter(modeBean.stringKey);
}
}
item.setTitle(profileName);
String routingProfile = "";
String routingProfileValue = modeBean.routingProfile;
if (!routingProfileValue.isEmpty()) {
try {
routingProfile = getString(RoutingProfilesResources.valueOf(routingProfileValue.toUpperCase()).getStringRes());
routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfile);
} catch (IllegalArgumentException e) {
routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfileValue);
LOG.error("Error trying to get routing resource for " + routingProfileValue + "\n" + e);
}
}
if (!Algorithms.isEmpty(routingProfile)) {
item.setDescription(getString(R.string.ltr_or_rtl_combine_via_colon, getString(R.string.nav_type_hint), routingProfile));
} else {
item.setDescription(getString(R.string.profile_type_osmand_string));
}
int profileIconRes = AndroidUtils.getDrawableId(app, modeBean.iconName);
ProfileIconColors iconColor = modeBean.iconColor;
Integer customIconColor = modeBean.customIconColor;
int actualIconColor;
if (selectedItems.contains(object)) {
actualIconColor = customIconColor != null ? customIconColor : ContextCompat.getColor(app, iconColor.getColor(nightMode));
} else {
actualIconColor = ContextCompat.getColor(app, secondaryColorRes);
}
int iconRes = profileIconRes != 0 ? profileIconRes : R.drawable.ic_world_globe_dark;
item.setIcon(uiUtilities.getPaintedIcon(iconRes, actualIconColor));
} else if (object instanceof QuickAction) {
QuickAction quickAction = (QuickAction) object;
item.setTitle(quickAction.getName(app));
item.setIcon(uiUtilities.getIcon(quickAction.getIconRes(), getItemIconColor(object)));
} else if (object instanceof PoiUIFilter) {
PoiUIFilter poiUIFilter = (PoiUIFilter) object;
item.setTitle(poiUIFilter.getName());
int iconRes = RenderingIcons.getBigIconResourceId(poiUIFilter.getIconId());
item.setIcon(uiUtilities.getIcon(iconRes != 0 ? iconRes : R.drawable.ic_action_user, activeColorRes));
} else if (object instanceof TileSourceTemplate || object instanceof SQLiteTileSource) {
ITileSource tileSource = (ITileSource) object;
item.setTitle(tileSource.getName());
item.setIcon(uiUtilities.getIcon(R.drawable.ic_map, getItemIconColor(object)));
} else if (object instanceof File) {
setupBottomSheetItemForFile(item, (File) object);
} else if (object instanceof GpxSettingsItem) {
GpxSettingsItem settingsItem = (GpxSettingsItem) object;
setupBottomSheetItemForGpx(item, settingsItem.getFile(), settingsItem.getAppearanceInfo());
} else if (object instanceof FileSettingsItem) {
FileSettingsItem settingsItem = (FileSettingsItem) object;
setupBottomSheetItemForFile(item, settingsItem.getFile());
} else if (object instanceof AvoidRoadInfo) {
AvoidRoadInfo avoidRoadInfo = (AvoidRoadInfo) object;
item.setTitle(avoidRoadInfo.name);
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_alert, getItemIconColor(object)));
} else if (object instanceof OsmNotesPoint) {
OsmNotesPoint osmNotesPoint = (OsmNotesPoint) object;
item.setTitle(osmNotesPoint.getText());
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_osm_note_add, getItemIconColor(object)));
} else if (object instanceof OpenstreetmapPoint) {
OpenstreetmapPoint openstreetmapPoint = (OpenstreetmapPoint) object;
item.setTitle(OsmEditingPlugin.getTitle(openstreetmapPoint, app));
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_info_dark, getItemIconColor(object)));
} else if (object instanceof FavoriteGroup) {
FavoriteGroup group = (FavoriteGroup) object;
item.setTitle(group.getDisplayName(app));
int color;
if (selectedItems.contains(object)) {
color = group.getColor() == 0 ? ContextCompat.getColor(app, R.color.color_favorite) : group.getColor();
} else {
color = ContextCompat.getColor(app, secondaryColorRes);
}
item.setIcon(uiUtilities.getPaintedIcon(R.drawable.ic_action_folder, color));
int points = group.getPoints().size();
String itemsDescr = getString(R.string.shared_string_gpx_points);
item.setDescription(getString(R.string.ltr_or_rtl_combine_via_colon, itemsDescr, points));
} else if (object instanceof GlobalSettingsItem) {
GlobalSettingsItem globalSettingsItem = (GlobalSettingsItem) object;
item.setTitle(globalSettingsItem.getPublicName(app));
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_settings, getItemIconColor(object)));
} else if (object instanceof MapMarkersGroup) {
MapMarkersGroup markersGroup = (MapMarkersGroup) object;
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
item.setTitle(getString(R.string.map_markers));
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_flag, getItemIconColor(object)));
} else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
item.setTitle(getString(R.string.markers_history));
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_history, getItemIconColor(object)));
} else {
String groupName = markersGroup.getName();
if (Algorithms.isEmpty(groupName)) {
if (markersGroup.getType() == ItineraryType.FAVOURITES) {
groupName = app.getString(R.string.shared_string_favorites);
} else if (markersGroup.getType() == ItineraryType.MARKERS) {
groupName = app.getString(R.string.map_markers);
}
}
item.setTitle(groupName);
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_flag, getItemIconColor(object)));
}
int selectedMarkers = markersGroup.getMarkers().size();
String itemsDescr = getString(R.string.shared_string_items);
item.setDescription(getString(R.string.ltr_or_rtl_combine_via_colon, itemsDescr, selectedMarkers));
} else if (object instanceof HistoryEntry) {
HistoryEntry historyEntry = (HistoryEntry) object;
item.setTitle(historyEntry.getName().getName());
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_history, getItemIconColor(object)));
} else if (object instanceof OnlineRoutingEngine) {
OnlineRoutingEngine onlineRoutingEngine = (OnlineRoutingEngine) object;
item.setTitle(onlineRoutingEngine.getName(app));
item.setIcon(uiUtilities.getIcon(R.drawable.ic_world_globe_dark, getItemIconColor(object)));
}
}
use of net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean in project Osmand by osmandapp.
the class OsmandAidlApi method getProfiles.
public boolean getProfiles(List<AProfile> profiles) {
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
ApplicationModeBean bean = mode.toModeBean();
AProfile aProfile = new AProfile(bean.stringKey, bean.userProfileName, bean.parent, bean.iconName, bean.iconColor.name(), bean.routingProfile, bean.routeService.name(), bean.locIcon.name(), bean.navIcon.name(), bean.order);
aProfile.setVersion(bean.version);
profiles.add(aProfile);
}
return true;
}
use of net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean in project Osmand by osmandapp.
the class SettingsHelper method prepareSettingsItems.
public List<SettingsItem> prepareSettingsItems(List<?> data, List<SettingsItem> settingsItems, boolean export) {
List<SettingsItem> result = new ArrayList<>();
List<QuickAction> quickActions = new ArrayList<>();
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
List<ITileSource> tileSourceTemplates = new ArrayList<>();
List<AvoidRoadInfo> avoidRoads = new ArrayList<>();
List<ApplicationModeBean> appModeBeans = new ArrayList<>();
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
List<OsmNotesPoint> osmNotesPointList = new ArrayList<>();
List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
List<MapMarkersGroup> markersGroups = new ArrayList<>();
List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
List<HistoryEntry> historyEntries = new ArrayList<>();
List<OnlineRoutingEngine> onlineRoutingEngines = new ArrayList<>();
List<MapMarkersGroup> itineraryGroups = new ArrayList<>();
for (Object object : data) {
if (object instanceof QuickAction) {
quickActions.add((QuickAction) object);
} else if (object instanceof PoiUIFilter) {
poiUIFilters.add((PoiUIFilter) object);
} else if (object instanceof TileSourceTemplate || object instanceof SQLiteTileSource) {
tileSourceTemplates.add((ITileSource) object);
} else if (object instanceof File) {
try {
File file = (File) object;
if (file.getName().endsWith(IndexConstants.GPX_FILE_EXT)) {
result.add(new GpxSettingsItem(app, file));
} else {
result.add(new FileSettingsItem(app, file));
}
} catch (IllegalArgumentException e) {
LOG.warn("Trying to export unsuported file type", e);
}
} else if (object instanceof FileSettingsItem) {
result.add((FileSettingsItem) object);
} else if (object instanceof AvoidRoadInfo) {
avoidRoads.add((AvoidRoadInfo) object);
} else if (object instanceof ApplicationModeBean) {
appModeBeans.add((ApplicationModeBean) object);
} else if (object instanceof OsmNotesPoint) {
osmNotesPointList.add((OsmNotesPoint) object);
} else if (object instanceof OpenstreetmapPoint) {
osmEditsPointList.add((OpenstreetmapPoint) object);
} else if (object instanceof FavoriteGroup) {
favoriteGroups.add((FavoriteGroup) object);
} else if (object instanceof MapMarkersGroup) {
MapMarkersGroup markersGroup = (MapMarkersGroup) object;
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
markersGroups.add((MapMarkersGroup) object);
} else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
markersHistoryGroups.add((MapMarkersGroup) object);
} else {
itineraryGroups.add((MapMarkersGroup) object);
}
} else if (object instanceof HistoryEntry) {
historyEntries.add((HistoryEntry) object);
} else if (object instanceof GlobalSettingsItem) {
result.add((GlobalSettingsItem) object);
} else if (object instanceof OnlineRoutingEngine) {
onlineRoutingEngines.add((OnlineRoutingEngine) object);
}
}
if (!quickActions.isEmpty()) {
QuickActionsSettingsItem baseItem = getBaseItem(SettingsItemType.QUICK_ACTIONS, QuickActionsSettingsItem.class, settingsItems);
result.add(new QuickActionsSettingsItem(app, baseItem, quickActions));
}
if (!poiUIFilters.isEmpty()) {
PoiUiFiltersSettingsItem baseItem = getBaseItem(SettingsItemType.POI_UI_FILTERS, PoiUiFiltersSettingsItem.class, settingsItems);
result.add(new PoiUiFiltersSettingsItem(app, baseItem, poiUIFilters));
}
if (!tileSourceTemplates.isEmpty()) {
MapSourcesSettingsItem baseItem = getBaseItem(SettingsItemType.MAP_SOURCES, MapSourcesSettingsItem.class, settingsItems);
result.add(new MapSourcesSettingsItem(app, baseItem, tileSourceTemplates));
}
if (!avoidRoads.isEmpty()) {
AvoidRoadsSettingsItem baseItem = getBaseItem(SettingsItemType.AVOID_ROADS, AvoidRoadsSettingsItem.class, settingsItems);
result.add(new AvoidRoadsSettingsItem(app, baseItem, avoidRoads));
}
if (!appModeBeans.isEmpty()) {
for (ApplicationModeBean modeBean : appModeBeans) {
if (export) {
ApplicationMode mode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
if (mode != null) {
result.add(new ProfileSettingsItem(app, mode));
}
} else {
result.add(new ProfileSettingsItem(app, getBaseProfileSettingsItem(modeBean, settingsItems), modeBean));
}
}
}
if (!osmNotesPointList.isEmpty()) {
OsmNotesSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_NOTES, OsmNotesSettingsItem.class, settingsItems);
result.add(new OsmNotesSettingsItem(app, baseItem, osmNotesPointList));
}
if (!osmEditsPointList.isEmpty()) {
OsmEditsSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_EDITS, OsmEditsSettingsItem.class, settingsItems);
result.add(new OsmEditsSettingsItem(app, baseItem, osmEditsPointList));
}
if (!favoriteGroups.isEmpty()) {
FavoritesSettingsItem baseItem = getBaseItem(SettingsItemType.FAVOURITES, FavoritesSettingsItem.class, settingsItems);
result.add(new FavoritesSettingsItem(app, baseItem, favoriteGroups));
}
if (!markersGroups.isEmpty()) {
List<MapMarker> mapMarkers = new ArrayList<>();
for (MapMarkersGroup group : markersGroups) {
mapMarkers.addAll(group.getMarkers());
}
MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.ACTIVE_MARKERS, MarkersSettingsItem.class, settingsItems);
result.add(new MarkersSettingsItem(app, baseItem, mapMarkers));
}
if (!markersHistoryGroups.isEmpty()) {
List<MapMarker> mapMarkers = new ArrayList<>();
for (MapMarkersGroup group : markersHistoryGroups) {
mapMarkers.addAll(group.getMarkers());
}
HistoryMarkersSettingsItem baseItem = getBaseItem(SettingsItemType.HISTORY_MARKERS, HistoryMarkersSettingsItem.class, settingsItems);
result.add(new HistoryMarkersSettingsItem(app, baseItem, mapMarkers));
}
if (!historyEntries.isEmpty()) {
SearchHistorySettingsItem baseItem = getBaseItem(SettingsItemType.SEARCH_HISTORY, SearchHistorySettingsItem.class, settingsItems);
result.add(new SearchHistorySettingsItem(app, baseItem, historyEntries));
}
if (!onlineRoutingEngines.isEmpty()) {
OnlineRoutingSettingsItem baseItem = getBaseItem(SettingsItemType.ONLINE_ROUTING_ENGINES, OnlineRoutingSettingsItem.class, settingsItems);
result.add(new OnlineRoutingSettingsItem(app, baseItem, onlineRoutingEngines));
}
if (!itineraryGroups.isEmpty()) {
ItinerarySettingsItem baseItem = getBaseItem(SettingsItemType.ITINERARY_GROUPS, ItinerarySettingsItem.class, settingsItems);
result.add(new ItinerarySettingsItem(app, baseItem, itineraryGroups));
}
return result;
}
Aggregations