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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
59 changes: 59 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,59 @@
package net.osmand.render;

import java.util.List;
import java.util.ArrayList;

public class RenderingClass {
private final String name;
private final String title;
private final boolean enable;
private String path;
private final List<RenderingClass> children = new ArrayList<>();

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

public String getName() {
return name;
}

public String getTitle() {
return title;
}

public boolean isEnable() {
return enable;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

public List<RenderingClass> getChildren() {
return children;
}

public void addChild(RenderingClass child) {
children.add(child);
}

public RenderingClass findByPath(String path) {
if (this.path.equals(path)) {
return this;
}
for (RenderingClass child : children) {
RenderingClass result = child.findByPath(path);
if (result != null) {
return result;
}
}
return null;
}
}
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 @@ -271,6 +272,7 @@ private class RenderingRulesHandler {
private final XmlPullParser parser;
private int state;
Stack<RenderingRule> stack = new Stack<RenderingRule>();
private final Stack<RenderingClass> renderingClassStack = new Stack<>();
private final RenderingRulesStorageResolver resolver;
private final boolean addon;
private RenderingRulesStorage dependsStorage;
Expand Down Expand Up @@ -431,6 +433,23 @@ 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 className = parser.getAttributeValue(null, "name");
String title = parser.getAttributeValue(null, "title");
boolean enable = Boolean.parseBoolean(parser.getAttributeValue(null, "enable"));

RenderingClass newClass = new RenderingClass(className, title, enable);

if (!renderingClassStack.isEmpty()) {
RenderingClass parent = renderingClassStack.peek();
parent.addChild(newClass);
newClass.setPath(parent.getPath() + className);
} else {
newClass.setPath(className);
}

renderingClasses.put(newClass.getPath(), newClass);
renderingClassStack.push(newClass);
} else {
log.warn("Unknown tag : " + name); //$NON-NLS-1$
}
Expand Down Expand Up @@ -483,6 +502,8 @@ public void endElement(String name) throws XmlPullParserException {
stack.pop();
} else if ("renderingAssociation".equals(name)) { //$NON-NLS-1$
stack.pop();
} else if ("renderingClass".equals(name)) {
renderingClassStack.pop();
}
}
}
Expand Down Expand Up @@ -559,6 +580,10 @@ public RenderingRule getRule(int state, int key) {
public RenderingRule getRenderingAttributeRule(String attribute) {
return renderingAttributes.get(attribute);
}

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

public String[] getRenderingAttributeNames() {
return renderingAttributes.keySet().toArray(new String[0]);
Expand Down
4 changes: 0 additions & 4 deletions OsmAnd/res/layout/fragment_mtb_routes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@

</LinearLayout>

<include
android:id="@+id/bottom_divider"
layout="@layout/card_bottom_divider" />

<View
android:id="@+id/bottom_empty_space"
android:layout_width="match_parent"
Expand Down
22 changes: 22 additions & 0 deletions OsmAnd/res/layout/map_route_types_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@
android:id="@+id/card_bottom_divider"
layout="@layout/card_bottom_divider" />

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

<include layout="@layout/list_item_divider" />

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

</LinearLayout>

<include
android:id="@+id/bottom_divider"
layout="@layout/card_bottom_divider" />

</LinearLayout>

<View
android:id="@+id/bottom_empty_space"
android:layout_width="match_parent"
Expand Down
45 changes: 45 additions & 0 deletions OsmAnd/res/layout/route_legend_card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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/route_legend_card"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:id="@+id/properties_container"
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/card_title"
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="Legend" />

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

</LinearLayout>

</LinearLayout>

<LinearLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:orientation="vertical">

</LinearLayout>

</LinearLayout>
80 changes: 80 additions & 0 deletions OsmAnd/res/layout/route_legend_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?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/main_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"
android:gravity="center"
android:orientation="horizontal">

<ImageView
android:id="@+id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/favorites_icon_right_margin"
android:layout_gravity="center_vertical"
tools:src="@drawable/ic_action_track_line_bold_color"
tools:tint="?attr/default_icon_color" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/setting_profile_item_height"
android:orientation="horizontal">

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">

<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="Title" />

<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
tools:text="Description" />

</LinearLayout>

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/compound_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|end"
android:background="@null"
android:focusableInTouchMode="true"
android:padding="@dimen/content_padding" />

</LinearLayout>

<View
android:id="@+id/divider_bottom"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/list_divider" />

</LinearLayout>

</LinearLayout>
27 changes: 27 additions & 0 deletions OsmAnd/src/net/osmand/plus/configmap/HikingRoutesFragment.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.osmand.plus.configmap;

import static net.osmand.osm.OsmRouteType.HIKING;
import static net.osmand.plus.configmap.routes.RClassUtils.RClassType.HIKING_OSMC_NODES;
import static net.osmand.plus.configmap.routes.RClassUtils.getDataClasses;

import android.os.Bundle;
import android.view.LayoutInflater;
Expand All @@ -18,6 +20,7 @@
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.configmap.RouteLegendCard.DataClass;
import net.osmand.plus.configmap.routes.RouteLayersHelper;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.utils.AndroidUtils;
Expand All @@ -33,6 +36,7 @@
public class HikingRoutesFragment extends BaseOsmAndFragment {

public static final String TAG = HikingRoutesFragment.class.getSimpleName();
public static final String NODE_NETWORKS_VALUE = "walkingRoutesOSMCNodes";

private RouteLayersHelper routeLayersHelper;
@Nullable
Expand Down Expand Up @@ -61,6 +65,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,

showHideTopShadow(view);
setupHeader(view);
setupLegendCard(view);
setupTypesCard(view);

return view;
Expand Down Expand Up @@ -144,13 +149,35 @@ private TextRadioItem createRadioButton(@NonNull String value) {
if (view != null) {
setupHeader(view);
setupTypesCard(view);
setupLegendCard(view);
}
refreshMap();
return true;
});
return item;
}

private void setupLegendCard(View view) {
ViewGroup container = view.findViewById(R.id.legend_container);
ViewGroup contentGroup = view.findViewById(R.id.legend_content);
contentGroup.removeAllViews();
String propertyValue = routeLayersHelper.getSelectedHikingRoutesValue();

if (NODE_NETWORKS_VALUE.equals(propertyValue)) {
List<DataClass> dataClasses = getDataClasses(app, HIKING_OSMC_NODES);
if (!Algorithms.isEmpty(dataClasses)) {
RouteLegendCard card = new RouteLegendCard(requireActivity(), dataClasses, app.getString(R.string.shared_string_legend));
View cardView = card.build();
contentGroup.addView(cardView);
AndroidUiHelper.updateVisibility(container, true);
} else {
AndroidUiHelper.updateVisibility(container, false);
}
} else {
AndroidUiHelper.updateVisibility(container, false);
}
}

private void refreshMap() {
MapActivity mapActivity = (MapActivity) getMyActivity();
if (mapActivity != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,4 @@ public static void showInstance(@NonNull FragmentManager manager) {
.commitAllowingStateLoss();
}
}

}
Loading
Loading