Skip to content

Commit

Permalink
Merge branch 'master' into route_legend
Browse files Browse the repository at this point in the history
# Conflicts:
#	OsmAnd/src/net/osmand/plus/configmap/ConfigureMapUtils.java
  • Loading branch information
Chumva committed Feb 7, 2025
2 parents 3283ef6 + f4cd579 commit 848b879
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 116 deletions.
12 changes: 9 additions & 3 deletions OsmAnd/res/layout/widget_route_information_medium.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,21 @@
android:background="?android:listDivider" />

<!-- Secondary block -->
<LinearLayout
<FrameLayout
android:id="@+id/secondary_block"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="16dp"
android:layout_marginVertical="6dp"
android:orientation="vertical">

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/primary_value_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginBottom="-1dp"
android:textColor="?android:textColorSecondary"
android:textSize="16sp"
tools:text="01:27" />
Expand All @@ -108,6 +111,7 @@
android:id="@+id/secondary_value_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?android:textColorSecondary"
android:textSize="16sp"
tools:text="9 h 23 m" />
Expand All @@ -116,10 +120,12 @@
android:id="@+id/tertiary_value_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="-1dp"
android:textColor="?android:textColorSecondary"
android:textSize="16sp"
tools:text="629 km" />

</LinearLayout>
</FrameLayout>

</LinearLayout>
31 changes: 21 additions & 10 deletions OsmAnd/res/layout/widget_route_information_small_duo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
android:orientation="horizontal">

<!-- Button with tappable area -->

<!-- Primary block -->
<FrameLayout
android:id="@+id/button_tappable_area"
android:layout_width="wrap_content"
android:layout_height="match_parent">

<FrameLayout
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="9dp">
Expand All @@ -25,11 +27,10 @@

</FrameLayout>

<!-- Primary block -->
<LinearLayout
<FrameLayout
android:id="@+id/primary_block"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="36dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
Expand All @@ -38,19 +39,22 @@
android:id="@+id/primary_value_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:textColor="?android:textColorPrimary"
android:textSize="16sp"
tools:text="20:33" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal">

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/secondary_value_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:textColor="?android:textColorSecondary"
android:textSize="14sp"
tools:text="13 h 27 m" />
Expand All @@ -59,6 +63,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="4dp"
android:gravity="bottom"
android:text=""
android:textColor="?android:textColorSecondary"
android:textSize="14sp"
Expand All @@ -68,49 +73,53 @@
android:id="@+id/tertiary_value_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:textColor="?android:textColorSecondary"
android:textSize="14sp"
tools:text="331 km" />

</LinearLayout>

</LinearLayout>
</FrameLayout>

<!-- Divider -->
<View
android:id="@+id/blocks_divider"
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_height="30dp"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="9dp"
android:background="?android:listDivider" />

<!-- Secondary block -->
<LinearLayout
<FrameLayout
android:id="@+id/secondary_block"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="36dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:layout_marginEnd="16dp"
android:orientation="vertical">

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/primary_value_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:textColor="?android:textColorPrimary"
android:textSize="16sp"
tools:text="01:27" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal">

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/secondary_value_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:textColor="?android:textColorSecondary"
android:textSize="14sp"
tools:text="9 h 23 m" />
Expand All @@ -119,6 +128,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="4dp"
android:gravity="bottom"
android:text=""
android:textColor="?android:textColorSecondary"
android:textSize="14sp"
Expand All @@ -128,13 +138,14 @@
android:id="@+id/tertiary_value_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:textColor="?android:textColorSecondary"
android:textSize="14sp"
tools:text="629 km" />

</LinearLayout>

</LinearLayout>
</FrameLayout>


</LinearLayout>
2 changes: 1 addition & 1 deletion OsmAnd/src/net/osmand/core/android/MapRendererContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ protected QStringStringHash getMapStyleSettings() {
if (property.isBoolean()) {
properties.put(attrName, String.valueOf(settings.getRenderBooleanPropertyValue(attrName)));
} else {
String value = settings.getRenderPropertyValue(attrName);
String value = settings.getRenderPropertyValue(property);
if (!Algorithms.isEmpty(value)) {
properties.put(attrName, value);
}
Expand Down
9 changes: 2 additions & 7 deletions OsmAnd/src/net/osmand/plus/configmap/ConfigureMapDialogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,7 @@ protected static void showRenderingPropertyDialog(
OsmandApplication app = activity.getMyApplication();
String title = AndroidUtils.getRenderingStringPropertyDescription(app, p.getAttrName(), p.getName());
String[] possibleValuesString = ConfigureMapUtils.getRenderingPropertyPossibleValues(app, p);
int selectedIndex = Arrays.asList(p.getPossibleValues()).indexOf(pref.get());
if (selectedIndex >= 0) {
selectedIndex++;
} else if (Algorithms.isEmpty(pref.get())) {
selectedIndex = 0;
}
int selectedIndex = AndroidUtils.getRenderPropertySelectedValueIndex(app, p);

AlertDialogData dialogData = new AlertDialogData(activity, nightMode)
.setTitle(title)
Expand All @@ -279,7 +274,7 @@ protected static void showRenderingPropertyDialog(
pref.set(p.getPossibleValues()[which - 1]);
}
activity.refreshMapComplete();
item.setDescription(AndroidUtils.getRenderingStringPropertyValue(activity, pref.get()));
item.setDescription(AndroidUtils.getRenderingStringPropertyValue(app, p));
String id = item.getId();
if (!Algorithms.isEmpty(id)) {
uiAdapter.onRefreshItem(id);
Expand Down
24 changes: 10 additions & 14 deletions OsmAnd/src/net/osmand/plus/configmap/ConfigureMapMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private void createRenderingAttributeItems(List<RenderingRuleProperty> customRul
})
.setItemDeleteAction(settings.MAP_DENSITY));

ContextMenuItem props = createRenderingProperty(customRules, adapter, activity,
ContextMenuItem props = createRenderingProperty(customRules, activity,
R.drawable.ic_action_intersection, ROAD_STYLE_ATTR, ROAD_STYLE_ID, nightMode);
if (props != null) {
adapter.addItem(props);
Expand Down Expand Up @@ -536,7 +536,7 @@ private void createCustomRenderingProperties(ContextMenuAdapter adapter, MapActi
boolean nightMode) {
for (RenderingRuleProperty p : customRules) {
if (isPropertyAccepted(p)) {
adapter.addItem(createRenderingProperty(adapter, activity, INVALID_ID, p, CUSTOM_RENDERING_ITEMS_ID_SCHEME + p.getName(), nightMode));
adapter.addItem(createRenderingProperty(activity, INVALID_ID, p, CUSTOM_RENDERING_ITEMS_ID_SCHEME + p.getName(), nightMode));
}
}
}
Expand All @@ -552,32 +552,28 @@ private int getCustomRenderingPropertiesSize(List<RenderingRuleProperty> customR
}

private ContextMenuItem createRenderingProperty(List<RenderingRuleProperty> customRules,
ContextMenuAdapter adapter, MapActivity activity,
MapActivity activity,
@DrawableRes int icon, String attrName, String id,
boolean nightMode) {
for (RenderingRuleProperty p : customRules) {
if (p.getAttrName().equals(attrName)) {
return createRenderingProperty(adapter, activity, icon, p, id, nightMode);
return createRenderingProperty(activity, icon, p, id, nightMode);
}
}
return null;
}

public static ContextMenuItem createRenderingProperty(ContextMenuAdapter adapter, MapActivity activity,
@DrawableRes int icon, RenderingRuleProperty p, String id,
public static ContextMenuItem createRenderingProperty(MapActivity activity, @DrawableRes int icon,
RenderingRuleProperty p, String id,
boolean nightMode) {
OsmandApplication app = activity.getMyApplication();
OsmandSettings settings = app.getSettings();
if (p.isBoolean()) {
String name = AndroidUtils.getRenderingStringPropertyName(activity, p.getAttrName(), p.getName());
return createBooleanRenderingProperty(activity, p.getAttrName(), name, id, p, icon, nightMode, null);
} else {
CommonPreference<String> pref = app.getSettings().getCustomRenderProperty(p.getAttrName());
String descr;
if (!Algorithms.isEmpty(pref.get())) {
descr = AndroidUtils.getRenderingStringPropertyValue(activity, pref.get());
} else {
descr = AndroidUtils.getRenderingStringPropertyValue(app, p.getDefaultValueDescription());
}
CommonPreference<String> pref = settings.getCustomRenderProperty(p.getAttrName());
String description = AndroidUtils.getRenderingStringPropertyValue(app, p);
String propertyName = AndroidUtils.getRenderingStringPropertyName(app, p.getAttrName(), p.getName());
ContextMenuItem item = new ContextMenuItem(id)
.setTitle(propertyName)
Expand All @@ -587,7 +583,7 @@ public static ContextMenuItem createRenderingProperty(ContextMenuAdapter adapter
}
return false;
})
.setDescription(descr)
.setDescription(description)
.setItemDeleteAction(pref)
.setLayout(R.layout.list_item_single_line_descrition_narrow);
if (icon != INVALID_ID) {
Expand Down
10 changes: 6 additions & 4 deletions OsmAnd/src/net/osmand/plus/configmap/ConfigureMapUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ public static List<RenderingRuleProperty> getCustomRules(@NonNull OsmandApplicat
return customRules;
}

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

for (int j = 0; j < p.getPossibleValues().length; j++) {
possibleValuesString[j + 1] = AndroidUtils.getRenderingStringPropertyValue(app, p.getPossibleValues()[j]);
for (int j = 0; j < possibleValues.length; j++) {
possibleValuesString[j + 1] = AndroidUtils.getRenderingStringPropertyValue(app, possibleValues[j]);
}
return possibleValuesString;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import net.osmand.render.RenderingRuleProperty;
import net.osmand.util.Algorithms;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class RouteLayersHelper {
Expand Down Expand Up @@ -237,8 +235,7 @@ public void updateHikingRoutesValue(@NonNull String value) {

public boolean isHikingRoutesEnabled() {
RenderingRuleProperty property = getHikingRenderingRuleProperty();
List<String> possibleValues = property != null ? Arrays.asList(property.getPossibleValues()) : null;
return possibleValues != null && possibleValues.contains(hikingRoutesPreference.get());
return property != null && property.containsValue(hikingRoutesPreference.get());
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,17 @@ private void setupPropertyPreferences(@NonNull View view) {

private View createPropertyView(@NonNull RenderingRuleProperty property, @NonNull LayoutInflater inflater, @Nullable ViewGroup container) {
String attrName = property.getAttrName();
View view = inflater.inflate(R.layout.configure_screen_list_item, container, false);
CommonPreference<String> pref = settings.getCustomRenderProperty(attrName);

View view = inflater.inflate(R.layout.configure_screen_list_item, container, false);
ImageView icon = view.findViewById(R.id.icon);
TextView title = view.findViewById(R.id.title);
TextView description = view.findViewById(R.id.description);
AndroidUiHelper.updateVisibility(description, true);

CommonPreference<String> pref = settings.getCustomRenderProperty(attrName);
String propertyValue = Algorithms.isEmpty(pref.get()) ? property.getDefaultValueDescription() : pref.get();

icon.setImageDrawable(getPropertyIcon(attrName));
title.setText(AndroidUtils.getRenderingStringPropertyName(app, attrName, property.getName()));
description.setText(AndroidUtils.getRenderingStringPropertyValue(app, propertyValue));
description.setText(AndroidUtils.getRenderingStringPropertyValue(app, property));

View button = view.findViewById(R.id.button_container);
button.setOnClickListener(v -> showPreferenceDialog(property, pref, description));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public boolean onContextMenuClick(@Nullable OnDataChangeUiAdapter uiAdapter, @Nu
if (RENDERING_CATEGORY_OSM_ASSISTANT.equals(property.getCategory())) {
iterator.remove();
String id = OPEN_STREET_MAP_ITEMS_ID_SCHEME + property.getAttrName();
adapter.addItem(ConfigureMapMenu.createRenderingProperty(adapter, mapActivity, INVALID_ID, property, id, nightMode));
adapter.addItem(ConfigureMapMenu.createRenderingProperty(mapActivity, INVALID_ID, property, id, nightMode));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import net.osmand.plus.OsmandApplication;
import net.osmand.plus.plugins.PluginsHelper;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.preferences.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
Expand Down Expand Up @@ -46,8 +47,8 @@ public void execute(@NonNull MapActivity mapActivity) {
OsmandApplication app = mapActivity.getMyApplication();
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
if (contourLinesProp != null) {
CommonPreference<String> pref = app.getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
if (!pref.get().equals(CONTOUR_LINES_DISABLED_VALUE)) {
OsmandSettings settings = app.getSettings();
if (!settings.getRenderPropertyValue(contourLinesProp).equals(CONTOUR_LINES_DISABLED_VALUE)) {
PluginsHelper.enablePluginIfNeeded(mapActivity, app, plugin, true);
}
mapActivity.refreshMapComplete();
Expand Down
Loading

0 comments on commit 848b879

Please sign in to comment.