Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add route legend card #21619

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/render/RenderingClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.osmand.render;

public class RenderingClass {

private final String name;
private final String title;
private final boolean enabledByDefault;

public RenderingClass(String name, String title, boolean enabledByDefault) {
this.name = name;
this.title = title;
this.enabledByDefault = enabledByDefault;
}

public String getName() {
return name;
}

public String getTitle() {
return title;
}

public boolean isEnabledByDefault() {
return enabledByDefault;
}

@Override
public String toString() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class RenderingRulesStorage {

protected Map<String, RenderingRule> renderingAttributes = new LinkedHashMap<String, RenderingRule>();
protected Map<String, RenderingRule> renderingAssociations = new LinkedHashMap<String, RenderingRule>();
protected Map<String, RenderingClass> renderingClasses = new LinkedHashMap<String, RenderingClass>();
protected Map<String, String> renderingConstants = new LinkedHashMap<String, String>();

protected String renderingName;
Expand Down Expand Up @@ -99,6 +100,7 @@ public RenderingRulesStorage copy() {
}
storage.renderingAttributes.putAll(renderingAttributes);
storage.renderingAssociations.putAll(renderingAssociations);
storage.renderingClasses.putAll(renderingClasses);
return storage;
}

Expand Down Expand Up @@ -431,6 +433,11 @@ public void startElement(Map<String, String> attrsMap, String name) throws XmlPu
}
} else if ("renderer".equals(name)) { //$NON-NLS-1$
throw new XmlPullParserException("Rendering style is deprecated and no longer supported.");
} else if ("renderingClass".equals(name)) {
String title = attrsMap.get("title");
String className = attrsMap.get("name");
boolean enable = Boolean.parseBoolean(attrsMap.get("enable"));
renderingClasses.put(className, new RenderingClass(className, title, enable));
} else {
log.warn("Unknown tag : " + name); //$NON-NLS-1$
}
Expand Down Expand Up @@ -458,7 +465,8 @@ private Map<String, String> parseAttributes(XmlPullParser parser, Map<String, St
String vl = parser.getAttributeValue(i);
if (vl != null && vl.startsWith("$")) {
String cv = vl.substring(1);
if (!renderingConstants.containsKey(cv) && !renderingAttributes.containsKey(cv) && !renderingAssociations.containsKey(cv)) {
if (!renderingConstants.containsKey(cv) && !renderingAttributes.containsKey(cv)
&& !renderingAssociations.containsKey(cv) && !renderingClasses.containsKey(cv)) {
throw new IllegalStateException("Rendering constant or attribute '" + cv + "' was not specified.");
}
if (renderingConstants.containsKey(cv)) {
Expand Down Expand Up @@ -559,6 +567,10 @@ public RenderingRule getRule(int state, int key) {
public RenderingRule getRenderingAttributeRule(String attribute) {
return renderingAttributes.get(attribute);
}

public RenderingClass getRenderingClass(String name) {
return renderingClasses.get(name);
}

public String[] getRenderingAttributeNames() {
return renderingAttributes.keySet().toArray(new String[0]);
Expand All @@ -575,6 +587,10 @@ public String[] getRenderingAssociationNames() {
return renderingAssociations.keySet().toArray(new String[0]);
}

public Map<String, RenderingClass> getRenderingClasses() {
return renderingClasses;
}

public RenderingRule[] getRules(int state){
if(state >= tagValueGlobalRules.length || tagValueGlobalRules[state] == null) {
return new RenderingRule[0];
Expand Down
28 changes: 28 additions & 0 deletions OsmAnd/res/layout/rendering_classes_card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rendering_classes_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:orientation="vertical">

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/header"
style="@style/TitleStyle.Medium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/content_padding"
android:layout_marginVertical="@dimen/content_padding_small"
android:textColor="?android:textColorPrimary"
tools:text="@string/mtb_scale" />

<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

</LinearLayout>

</LinearLayout>
14 changes: 12 additions & 2 deletions OsmAnd/src/net/osmand/core/android/MapRendererContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.preferences.CommonPreference;
import net.osmand.plus.utils.NativeUtilities;
import net.osmand.render.RenderingClass;
import net.osmand.render.RenderingRule;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRuleSearchRequest;
import net.osmand.render.RenderingRuleStorageProperties;
Expand Down Expand Up @@ -317,17 +320,24 @@ protected QStringStringHash getMapStyleSettings() {
for (RenderingRuleProperty property : storage.PROPS.getCustomRules()) {
String attrName = property.getAttrName();
if (property.isBoolean()) {
properties.put(attrName, settings.getRenderBooleanPropertyValue(attrName) + "");
properties.put(attrName, String.valueOf(settings.getRenderBooleanPropertyValue(attrName)));
} else {
String value = settings.getRenderPropertyValue(attrName);
if (!Algorithms.isEmpty(value)) {
properties.put(attrName, value);
}
}
}
for (Map.Entry<String, RenderingClass> entry : storage.getRenderingClasses().entrySet()) {
RenderingClass renderingClass = entry.getValue();

String name = renderingClass.getName();
boolean enabled = renderingClass.isEnabledByDefault();
CommonPreference<Boolean> preference = settings.getСustomBooleanRenderClassProperty(name, enabled);
properties.put(name, String.valueOf(preference.get()));
}
QStringStringHash styleSettings = new QStringStringHash();
for (Entry<String, String> setting : properties.entrySet()) {
for (Map.Entry<String, String> setting : properties.entrySet()) {
styleSettings.set(setting.getKey(), setting.getValue());
}
if (nightMode) {
Expand Down
8 changes: 5 additions & 3 deletions OsmAnd/src/net/osmand/plus/configmap/ConfigureMapMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import net.osmand.plus.widgets.ctxmenu.callback.OnDataChangeUiAdapter;
import net.osmand.plus.widgets.ctxmenu.callback.OnRowItemClick;
import net.osmand.plus.widgets.ctxmenu.data.ContextMenuItem;
import net.osmand.render.RenderingClass;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.util.Algorithms;
import net.osmand.util.SunriseSunset;
Expand All @@ -71,6 +72,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class ConfigureMapMenu {

Expand Down Expand Up @@ -104,10 +106,12 @@ public ContextMenuAdapter createListAdapter(@NonNull MapActivity mapActivity) {

List<RenderingRuleProperty> customRules = ConfigureMapUtils.getCustomRules(app,
UI_CATEGORY_HIDDEN, RENDERING_CATEGORY_TRANSPORT);

createLayersItems(customRules, adapter, mapActivity, nightMode);
PluginsHelper.registerConfigureMapCategory(adapter, mapActivity, customRules);
createRouteAttributeItems(customRules, adapter, mapActivity, nightMode);
createRenderingAttributeItems(customRules, adapter, mapActivity, nightMode);

return adapter;
}

Expand Down Expand Up @@ -210,9 +214,7 @@ private void createLayersItems(@NonNull List<RenderingRuleProperty> customRules,
}

private void createRouteAttributeItems(@NonNull List<RenderingRuleProperty> customRules,
@NonNull ContextMenuAdapter adapter,
@NonNull MapActivity activity,
boolean nightMode) {
@NonNull ContextMenuAdapter adapter, @NonNull MapActivity activity, boolean nightMode) {
adapter.addItem(new ContextMenuItem(ROUTES_CATEGORY_ID)
.setCategory(true)
.setTitleId(R.string.rendering_category_routes, activity)
Expand Down
49 changes: 41 additions & 8 deletions OsmAnd/src/net/osmand/plus/configmap/ConfigureMapUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static net.osmand.plus.dialogs.DetailsBottomSheet.STREET_LIGHTING_NIGHT;
import static net.osmand.plus.settings.backend.OsmandSettings.RENDERER_PREFERENCE_PREFIX;

import android.util.Pair;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -15,21 +17,19 @@
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.preferences.CommonPreference;
import net.osmand.plus.utils.AndroidUtils;
import net.osmand.render.RenderingClass;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.Algorithms;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.*;

public class ConfigureMapUtils {

public static final String[] MAP_LANGUAGES_IDS = {"", "en", "af", "als", "ar", "az", "be", "ber", "bg", "bn", "bpy", "br", "bs", "ca", "ceb", "ckb", "cs", "cy", "da", "de", "el", "eo", "es", "et", "eu", "fa", "fi", "fr", "fy", "ga", "gl", "he", "hi", "hsb", "hr", "ht", "hu", "hy", "id", "is", "it", "ja", "ka", "kab", "kk", "kn", "ko", "ku", "la", "lb", "lo", "lt", "lv", "mk", "ml", "mr", "ms", "nds", "new", "nl", "nn", "no", "nv", "oc", "os", "pl", "pms", "pt", "ro", "ru", "sat", "sc", "sh", "sk", "sl", "sq", "sr", "sr-latn", "sv", "sw", "ta", "te", "th", "tl", "tr", "uk", "vi", "vo", "zh", "zh-Hans", "zh-Hant"};

public static final String ROUTE_CLASS_PREFIX = ".route.";

@NonNull
public static Map<String, String> getSorterMapLanguages(@NonNull OsmandApplication app) {
Map<String, String> mapLanguages = new HashMap<>();
Expand Down Expand Up @@ -71,7 +71,8 @@ public static RenderingRuleProperty getPropertyForAttr(@NonNull OsmandApplicatio
}

@Nullable
public static RenderingRuleProperty getPropertyForAttr(@NonNull List<RenderingRuleProperty> customRules, @NonNull String attrName) {
public static RenderingRuleProperty getPropertyForAttr(
@NonNull List<RenderingRuleProperty> customRules, @NonNull String attrName) {
for (RenderingRuleProperty property : customRules) {
if (Algorithms.stringsEqual(property.getAttrName(), attrName)) {
return property;
Expand Down Expand Up @@ -103,7 +104,39 @@ public static List<RenderingRuleProperty> getCustomRules(@NonNull OsmandApplicat
return customRules;
}

protected static String[] getRenderingPropertyPossibleValues(OsmandApplication app, RenderingRuleProperty p) {
@NonNull
public static Map<String, RenderingClass> getRenderingClasses(@NonNull OsmandApplication app) {
RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
if (renderer == null) {
return new LinkedHashMap<>();
}
return renderer.getRenderingClasses();
}

@NonNull
public static Pair<RenderingClass, List<RenderingClass>> getRenderingClassesForKey(
@NonNull OsmandApplication app, @NonNull String attrName) {
RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
if (renderer == null) {
return null;
}
String key = ROUTE_CLASS_PREFIX + attrName.replace("show", "");
RenderingClass mainClass = renderer.getRenderingClass(key);
if (mainClass != null) {
List<RenderingClass> list = new ArrayList<>();
for (Map.Entry<String, RenderingClass> entry : renderer.getRenderingClasses().entrySet()) {
RenderingClass renderingClass = entry.getValue();
if (renderingClass.getName().startsWith(key + ".")) {
list.add(renderingClass);
}
}
return Pair.create(mainClass, list);
}
return null;
}

protected static String[] getRenderingPropertyPossibleValues(OsmandApplication app,
RenderingRuleProperty p) {
String[] possibleValuesString = new String[p.getPossibleValues().length + 1];
possibleValuesString[0] = AndroidUtils.getRenderingStringPropertyValue(app, p.getDefaultValueDescription());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.osmand.plus.configmap.routes;

import static net.osmand.osm.OsmRouteType.ALPINE;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
Expand All @@ -8,6 +10,7 @@

import net.osmand.plus.R;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.utils.AndroidUtils;

public class AlpineHikingScaleFragment extends MapRoutesFragment {
Expand All @@ -24,6 +27,12 @@ protected void toggleMainPreference(@NonNull View view) {
routeLayersHelper.toggleAlpineHikingRoutes();
}

@NonNull
@Override
protected String getSelectedAttrName() {
return ALPINE.getRenderingPropertyAttr();
}

protected void setupHeader(@NonNull View view) {
super.setupHeader(view);

Expand All @@ -34,21 +43,25 @@ protected void setupHeader(@NonNull View view) {
title.setText(R.string.rendering_attr_alpineHiking_name);

TextView description = container.findViewById(R.id.description);
description.setText(AlpineHikingCard.getDifficultyClassificationDescription(app));
description.setText(routeLayersHelper.getRoutesTypeDescription(getSelectedAttrName()));
AndroidUiHelper.updateVisibility(description, enabled);

int selectedColor = settings.getApplicationMode().getProfileColor(nightMode);
int disabledColor = AndroidUtils.getColorFromAttr(app, R.attr.default_icon_color);
ImageView icon = container.findViewById(R.id.icon);
icon.setImageDrawable(getPaintedContentIcon(R.drawable.ic_action_trekking_dark, enabled ? selectedColor : disabledColor));
icon.setImageDrawable(getPaintedContentIcon(RouteUtils.getIconIdForAttr(getSelectedAttrName()),
enabled ? selectedColor : disabledColor));
}

@Override
protected void setupCards(@NonNull View view) {
super.setupCards(view);
protected void createCards(@NonNull View view) {
super.createCards(view);

cardsContainer.addView(createDivider(cardsContainer, true, true));
addCard(new AlpineHikingCard(getMapActivity()));
cardsContainer.addView(createDivider(cardsContainer, false, true));

BaseCard card = createRenderingClassCard(getSelectedAttrName());
if (card != null) {
addCard(card);
}
}
}
Loading
Loading