use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.
the class FavoritesTreeFragment method onChildClick.
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if (selectionMode) {
CheckBox ch = v.findViewById(R.id.toggle_item);
FavouritePoint model = favouritesAdapter.getChild(groupPosition, childPosition);
FavoriteGroup group = favouritesAdapter.getGroup(groupPosition);
ch.setChecked(!ch.isChecked());
if (ch.isChecked()) {
Set<FavouritePoint> set = favoritesSelected.get(group.getName());
if (set != null) {
set.add(model);
} else {
set = new LinkedHashSet<>();
set.add(model);
favoritesSelected.put(group.getName(), set);
}
} else {
Set<FavouritePoint> set = favoritesSelected.get(group.getName());
if (set != null) {
set.remove(model);
}
}
updateSelectionMode(actionMode);
} else {
final FavouritePoint point = favouritesAdapter.getChild(groupPosition, childPosition);
showOnMap(point, groupPosition, childPosition);
}
return true;
}
use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.
the class DuplicatesSettingsAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
Object currentItem = items.get(position);
if (holder instanceof HeaderViewHolder) {
HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
headerHolder.title.setText((String) currentItem);
headerHolder.subTitle.setText(String.format(app.getString(R.string.listed_exist), currentItem));
headerHolder.divider.setVisibility(View.VISIBLE);
} else if (holder instanceof ItemViewHolder) {
ItemViewHolder itemHolder = (ItemViewHolder) holder;
itemHolder.subTitle.setVisibility(View.GONE);
if (currentItem instanceof ApplicationModeBean) {
ApplicationModeBean modeBean = (ApplicationModeBean) currentItem;
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);
}
}
itemHolder.title.setText(profileName);
String routingProfile = "";
String routingProfileValue = modeBean.routingProfile;
if (!routingProfileValue.isEmpty()) {
try {
routingProfile = app.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)) {
itemHolder.subTitle.setVisibility(View.GONE);
} else {
itemHolder.subTitle.setText(String.format(app.getString(R.string.ltr_or_rtl_combine_via_colon), app.getString(R.string.nav_type_hint), routingProfile));
itemHolder.subTitle.setVisibility(View.VISIBLE);
}
int profileIconRes = AndroidUtils.getDrawableId(app, modeBean.iconName);
ProfileIconColors iconColor = modeBean.iconColor;
Integer customIconColor = modeBean.customIconColor;
int actualIconColor = customIconColor != null ? customIconColor : ContextCompat.getColor(app, iconColor.getColor(nightMode));
itemHolder.icon.setImageDrawable(uiUtilities.getPaintedIcon(profileIconRes, actualIconColor));
} else if (currentItem instanceof QuickAction) {
QuickAction action = (QuickAction) currentItem;
itemHolder.title.setText(action.getName(app));
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(action.getIconRes(), activeColorRes));
} else if (currentItem instanceof PoiUIFilter) {
PoiUIFilter filter = (PoiUIFilter) currentItem;
itemHolder.title.setText(filter.getName());
int iconRes = RenderingIcons.getBigIconResourceId(filter.getIconId());
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(iconRes != 0 ? iconRes : R.drawable.ic_action_user, activeColorRes));
} else if (currentItem instanceof ITileSource) {
itemHolder.title.setText(((ITileSource) currentItem).getName());
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_map, activeColorRes));
} else if (currentItem instanceof File) {
File file = (File) currentItem;
FileSubtype fileSubtype = FileSubtype.getSubtypeByPath(app, file.getPath());
itemHolder.title.setText(file.getName());
if (file.getAbsolutePath().contains(IndexConstants.RENDERERS_DIR)) {
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_map_style, activeColorRes));
} else if (file.getAbsolutePath().contains(IndexConstants.ROUTING_PROFILES_DIR)) {
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_route_distance, activeColorRes));
} else if (file.getAbsolutePath().contains(IndexConstants.GPX_INDEX_DIR)) {
itemHolder.title.setText(GpxUiHelper.getGpxTitle(file.getName()));
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_route_distance, activeColorRes));
} else if (file.getAbsolutePath().contains(IndexConstants.AV_INDEX_DIR)) {
int iconId = AudioVideoNotesPlugin.getIconIdForRecordingFile(file);
if (iconId == -1) {
iconId = R.drawable.ic_action_photo_dark;
}
itemHolder.title.setText(new Recording(file).getName(app, true));
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(iconId, activeColorRes));
} else if (fileSubtype.isMap() || fileSubtype == FileSubtype.TTS_VOICE || fileSubtype == FileSubtype.VOICE) {
itemHolder.title.setText(FileNameTranslationHelper.getFileNameWithRegion(app, file.getName()));
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(fileSubtype.getIconId(), activeColorRes));
}
} else if (currentItem instanceof AvoidRoadInfo) {
itemHolder.title.setText(((AvoidRoadInfo) currentItem).name);
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_alert, activeColorRes));
} else if (currentItem instanceof FavoriteGroup) {
itemHolder.title.setText(((FavoriteGroup) currentItem).getDisplayName(app));
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_favorite, activeColorRes));
} else if (currentItem instanceof MapMarker) {
MapMarker mapMarker = (MapMarker) currentItem;
itemHolder.title.setText(mapMarker.getName(app));
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_flag, activeColorRes));
} else if (currentItem instanceof HistoryEntry) {
itemHolder.title.setText(((HistoryEntry) currentItem).getName().getName());
} else if (currentItem instanceof OnlineRoutingEngine) {
itemHolder.title.setText(((OnlineRoutingEngine) currentItem).getName(app));
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_world_globe_dark, activeColorRes));
} else if (currentItem instanceof MapMarkersGroup) {
MapMarkersGroup markersGroup = (MapMarkersGroup) currentItem;
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);
}
}
itemHolder.title.setText(groupName);
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_flag, activeColorRes));
}
itemHolder.divider.setVisibility(shouldShowDivider(position) ? View.VISIBLE : View.GONE);
}
}
use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.
the class MapMarkersHelper method syncFavouriteGroup.
private void syncFavouriteGroup(@NonNull MapMarkersGroup group, @NonNull List<MapMarker> existingMarkers) {
FavoriteGroup favGroup = ctx.getFavoritesHelper().getGroup(group.getId());
if (favGroup == null) {
removeFromGroupsList(group);
return;
}
group.setVisible(favGroup.isVisible());
if (!group.isVisible() || group.isDisabled()) {
removeGroupActiveMarkers(group, true);
return;
}
int colorIndex = -1;
List<FavouritePoint> points = new ArrayList<>(favGroup.getPoints());
for (FavouritePoint point : points) {
if (colorIndex == -1) {
colorIndex = mapMarkers.isEmpty() ? 0 : (mapMarkers.get(0).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
} else {
colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
}
MapMarker mapMarker = ItineraryDataHelper.fromFavourite(ctx, point, group);
mapMarker.colorIndex = colorIndex;
existingMarkers.add(mapMarker);
}
}
use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.
the class QuickSearchListItem method getIcon.
@Nullable
public static Drawable getIcon(OsmandApplication app, SearchResult searchResult) {
if (searchResult == null || searchResult.objectType == null) {
return null;
}
int iconId = -1;
switch(searchResult.objectType) {
case CITY:
return getIcon(app, R.drawable.ic_action_building2);
case VILLAGE:
return getIcon(app, R.drawable.ic_action_village);
case POSTCODE:
case STREET:
return getIcon(app, R.drawable.ic_action_street_name);
case HOUSE:
return getIcon(app, R.drawable.ic_action_building);
case STREET_INTERSECTION:
return getIcon(app, R.drawable.ic_action_intersection);
case POI_TYPE:
if (searchResult.object instanceof AbstractPoiType) {
String iconName = PoiUIFilter.getPoiTypeIconName((AbstractPoiType) searchResult.object);
if (!Algorithms.isEmpty(iconName)) {
iconId = RenderingIcons.getBigIconResourceId(iconName);
}
} else if (searchResult.object instanceof CustomSearchPoiFilter) {
CustomSearchPoiFilter searchPoiFilter = (CustomSearchPoiFilter) searchResult.object;
PoiUIFilter filter = app.getPoiFilters().getFilterById(searchPoiFilter.getFilterId());
if (filter != null) {
iconId = getCustomFilterIconRes(filter);
}
}
if (iconId > 0) {
return getIcon(app, iconId);
} else {
return getIcon(app, R.drawable.ic_action_search_dark);
}
case POI:
Amenity amenity = (Amenity) searchResult.object;
String id = getAmenityIconName(amenity);
Drawable icon = null;
if (id != null) {
iconId = RenderingIcons.getBigIconResourceId(id);
if (iconId > 0) {
icon = getIcon(app, iconId);
}
}
if (icon == null) {
return getIcon(app, R.drawable.ic_action_search_dark);
} else {
return icon;
}
case GPX_TRACK:
return getIcon(app, R.drawable.ic_action_polygom_dark);
case LOCATION:
return getIcon(app, R.drawable.ic_action_world_globe);
case FAVORITE:
FavouritePoint fav = (FavouritePoint) searchResult.object;
int color = app.getFavoritesHelper().getColorWithCategory(fav, ContextCompat.getColor(app, R.color.color_favorite));
return PointImageDrawable.getFromFavorite(app, color, false, fav);
case FAVORITE_GROUP:
FavoriteGroup group = (FavoriteGroup) searchResult.object;
color = group.getColor() == 0 ? ContextCompat.getColor(app, R.color.color_favorite) : group.getColor();
return app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_favorite, color | 0xff000000);
case REGION:
return getIcon(app, R.drawable.ic_world_globe_dark);
case RECENT_OBJ:
HistoryEntry entry = (HistoryEntry) searchResult.object;
iconId = getHistoryIconId(app, entry);
try {
return getIcon(app, iconId);
} catch (Exception e) {
return getIcon(app, SearchHistoryFragment.getItemIcon(entry.getName()));
}
case WPT:
WptPt wpt = (WptPt) searchResult.object;
return PointImageDrawable.getFromWpt(app, wpt.getColor(), false, wpt);
case MAP_MARKER:
MapMarker marker = (MapMarker) searchResult.object;
if (!marker.history) {
return MapMarkerDialogHelper.getMapMarkerIcon(app, marker.colorIndex);
} else {
return getIcon(app, R.drawable.ic_action_flag);
}
case ROUTE:
return getIcon(app, R.drawable.ic_action_previous_route);
case UNKNOWN_NAME_FILTER:
break;
}
return null;
}
Aggregations