use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.
the class FavoritesTreeFragment method selectMapMarkersImpl.
private void selectMapMarkersImpl() {
if (getSelectedFavoritesCount() > 0) {
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
List<LatLon> points = new ArrayList<>();
List<PointDescription> names = new ArrayList<>();
for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
FavoriteGroup group = helper.getGroup(entry.getKey());
if (group != null && entry.getValue().size() == group.getPoints().size()) {
markersHelper.addOrEnableGroup(group);
} else {
for (FavouritePoint fp : entry.getValue()) {
points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
}
markersHelper.addMapMarkers(points, names, null);
points.clear();
names.clear();
}
}
MapActivity.launchMapActivityMoveToTop(getActivity());
}
}
use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.
the class FavoriteAction method drawUI.
@Override
public void drawUI(@NonNull final ViewGroup parent, @NonNull final MapActivity mapActivity) {
FavouritesHelper helper = mapActivity.getMyApplication().getFavoritesHelper();
final View root = LayoutInflater.from(parent.getContext()).inflate(R.layout.quick_action_add_favorite, parent, false);
parent.addView(root);
AutoCompleteTextViewEx categoryEdit = (AutoCompleteTextViewEx) root.findViewById(R.id.category_edit);
SwitchCompat showDialog = (SwitchCompat) root.findViewById(R.id.saveButton);
ImageView categoryImage = (ImageView) root.findViewById(R.id.category_image);
EditText name = (EditText) root.findViewById(R.id.name_edit);
if (!getParams().isEmpty()) {
showDialog.setChecked(Boolean.valueOf(getParams().get(KEY_DIALOG)));
categoryImage.setColorFilter(Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)));
name.setText(getParams().get(KEY_NAME));
categoryEdit.setText(getParams().get(KEY_CATEGORY_NAME));
if (getParams().get(KEY_NAME).isEmpty() && Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)) == 0) {
categoryEdit.setText(mapActivity.getString(R.string.shared_string_favorites));
categoryImage.setColorFilter(mapActivity.getResources().getColor(R.color.color_favorite));
}
} else if (helper.getFavoriteGroups().size() > 0) {
FavoriteGroup group = helper.getFavoriteGroups().get(0);
int color = group.getColor() == 0 ? mapActivity.getResources().getColor(R.color.color_favorite) : group.getColor();
categoryEdit.setText(group.getDisplayName(mapActivity));
categoryImage.setColorFilter(color);
getParams().put(KEY_CATEGORY_NAME, group.getName());
getParams().put(KEY_CATEGORY_COLOR, String.valueOf(group.getColor()));
} else {
categoryEdit.setText(mapActivity.getString(R.string.shared_string_favorites));
categoryImage.setColorFilter(mapActivity.getResources().getColor(R.color.color_favorite));
getParams().put(KEY_CATEGORY_NAME, "");
getParams().put(KEY_CATEGORY_COLOR, "0");
}
categoryEdit.setOnClickListener(view -> {
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
CategorySelectionListener listener = (category, color) -> fillGroupParams(root, category, color);
SelectPointsCategoryBottomSheet.showSelectFavoriteCategoryFragment(fragmentManager, listener, "");
});
SelectPointsCategoryBottomSheet dialogFragment = (SelectPointsCategoryBottomSheet) mapActivity.getSupportFragmentManager().findFragmentByTag(SelectPointsCategoryBottomSheet.TAG);
if (dialogFragment != null) {
dialogFragment.setSelectionListener((category, color) -> fillGroupParams(root, category, color));
}
}
use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.
the class SettingsHelper method getMyPlacesItems.
private Map<ExportSettingsType, List<?>> getMyPlacesItems(@Nullable List<ExportSettingsType> settingsTypes, boolean addEmptyItems) {
Map<ExportSettingsType, List<?>> myPlacesItems = new LinkedHashMap<>();
List<FavoriteGroup> favoriteGroups = settingsTypes == null || settingsTypes.contains(ExportSettingsType.FAVORITES) ? app.getFavoritesHelper().getFavoriteGroups() : Collections.emptyList();
if (!favoriteGroups.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.FAVORITES, favoriteGroups);
}
List<GpxDataItem> gpxItems = settingsTypes == null || settingsTypes.contains(ExportSettingsType.TRACKS) ? app.getGpxDbHelper().getItems() : Collections.emptyList();
if (!gpxItems.isEmpty() || addEmptyItems) {
List<File> files = new ArrayList<>();
for (GpxDataItem gpxItem : gpxItems) {
File file = gpxItem.getFile();
if (file.exists() && !file.isDirectory()) {
files.add(file);
}
}
if (!files.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.TRACKS, files);
}
}
OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getActivePlugin(OsmEditingPlugin.class);
if (osmEditingPlugin != null) {
List<OsmNotesPoint> notesPointList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.OSM_NOTES) ? osmEditingPlugin.getDBBug().getOsmbugsPoints() : Collections.emptyList();
if (!notesPointList.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.OSM_NOTES, notesPointList);
}
List<OpenstreetmapPoint> editsPointList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.OSM_EDITS) ? osmEditingPlugin.getDBPOI().getOpenstreetmapPoints() : Collections.emptyList();
if (!editsPointList.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.OSM_EDITS, editsPointList);
}
}
AudioVideoNotesPlugin avNotesPlugin = OsmandPlugin.getActivePlugin(AudioVideoNotesPlugin.class);
if (avNotesPlugin != null) {
List<File> files = new ArrayList<>();
if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.MULTIMEDIA_NOTES)) {
for (Recording rec : avNotesPlugin.getAllRecordings()) {
File file = rec.getFile();
if (file != null && file.exists()) {
files.add(file);
}
}
}
if (!files.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.MULTIMEDIA_NOTES, files);
}
}
List<MapMarker> mapMarkers = settingsTypes == null || settingsTypes.contains(ExportSettingsType.ACTIVE_MARKERS) ? app.getMapMarkersHelper().getMapMarkers() : Collections.emptyList();
if (!mapMarkers.isEmpty() || addEmptyItems) {
String name = app.getString(R.string.map_markers);
String groupId = ExportSettingsType.ACTIVE_MARKERS.name();
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
markersGroup.setMarkers(mapMarkers);
myPlacesItems.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup));
}
List<MapMarker> markersHistory = settingsTypes == null || settingsTypes.contains(ExportSettingsType.HISTORY_MARKERS) ? app.getMapMarkersHelper().getMapMarkersHistory() : Collections.emptyList();
if (!markersHistory.isEmpty() || addEmptyItems) {
String name = app.getString(R.string.shared_string_history);
String groupId = ExportSettingsType.HISTORY_MARKERS.name();
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
markersGroup.setMarkers(markersHistory);
myPlacesItems.put(ExportSettingsType.HISTORY_MARKERS, Collections.singletonList(markersGroup));
}
List<HistoryEntry> historyEntries = settingsTypes == null || settingsTypes.contains(ExportSettingsType.SEARCH_HISTORY) ? SearchHistoryHelper.getInstance(app).getHistoryEntries(false) : Collections.emptyList();
if (!historyEntries.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.SEARCH_HISTORY, historyEntries);
}
List<MapMarkersGroup> markersGroups = settingsTypes == null || settingsTypes.contains(ExportSettingsType.ITINERARY_GROUPS) ? app.getMapMarkersHelper().getVisibleMapMarkersGroups() : Collections.emptyList();
if (!markersGroups.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.ITINERARY_GROUPS, markersGroups);
}
return myPlacesItems;
}
use of net.osmand.plus.myplaces.FavoriteGroup 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.myplaces.FavoriteGroup in project Osmand by osmandapp.
the class FavouritesLayer method onPrepareBufferImage.
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
cache.clear();
if (this.settings.SHOW_FAVORITES.get() && favouritesHelper.isFavoritesLoaded()) {
if (tileBox.getZoom() >= START_ZOOM) {
float textScale = getTextScale();
float iconSize = getIconSize(view.getApplication());
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
// request to load
final QuadRect latLonBounds = tileBox.getLatLonBounds();
List<LatLon> fullObjectsLatLon = new ArrayList<>();
List<LatLon> smallObjectsLatLon = new ArrayList<>();
for (FavoriteGroup group : favouritesHelper.getFavoriteGroups()) {
List<Pair<FavouritePoint, MapMarker>> fullObjects = new ArrayList<>();
boolean synced = isSynced(group);
for (FavouritePoint favoritePoint : group.getPoints()) {
double lat = favoritePoint.getLatitude();
double lon = favoritePoint.getLongitude();
if (favoritePoint.isVisible() && favoritePoint != contextMenuLayer.getMoveableObject() && lat >= latLonBounds.bottom && lat <= latLonBounds.top && lon >= latLonBounds.left && lon <= latLonBounds.right) {
MapMarker marker = null;
if (synced) {
marker = mapMarkersHelper.getMapMarker(favoritePoint);
if (marker == null || marker.history && !view.getSettings().KEEP_PASSED_MARKERS_ON_MAP.get()) {
continue;
}
}
cache.add(favoritePoint);
float x = tileBox.getPixXFromLatLon(lat, lon);
float y = tileBox.getPixYFromLatLon(lat, lon);
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
@ColorInt int color;
if (marker != null && marker.history) {
color = grayColor;
} else {
color = favouritesHelper.getColorWithCategory(favoritePoint, defaultColor);
}
PointImageDrawable pointImageDrawable = PointImageDrawable.getFromFavorite(view.getContext(), color, true, favoritePoint);
pointImageDrawable.drawSmallPoint(canvas, x, y, textScale);
smallObjectsLatLon.add(new LatLon(lat, lon));
} else {
fullObjects.add(new Pair<>(favoritePoint, marker));
fullObjectsLatLon.add(new LatLon(lat, lon));
}
}
}
for (Pair<FavouritePoint, MapMarker> pair : fullObjects) {
FavouritePoint favoritePoint = pair.first;
float x = tileBox.getPixXFromLatLon(favoritePoint.getLatitude(), favoritePoint.getLongitude());
float y = tileBox.getPixYFromLatLon(favoritePoint.getLatitude(), favoritePoint.getLongitude());
drawBigPoint(canvas, favoritePoint, x, y, pair.second, textScale);
}
}
this.fullObjectsLatLon = fullObjectsLatLon;
this.smallObjectsLatLon = smallObjectsLatLon;
}
}
if (isTextVisible()) {
textLayer.putData(this, cache);
}
}
Aggregations