Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-02-05 22:33:58 +01:00
commit ae0ce181ba
6 changed files with 70 additions and 51 deletions

View file

@ -118,6 +118,15 @@ public class OsmAndFormatter {
return fixed2.format(((float) meters) / mainUnitInMeters) + " " + ctx.getString(mainUnitStr);
}
}
public static String getFormattedAlarmInfoDistance(OsmandApplication app, float meters) {
boolean kmAndMeters = app.getSettings().METRIC_SYSTEM.get() == MetricsConstants.KILOMETERS_AND_METERS;
int mainUnitStr = kmAndMeters ? R.string.km : R.string.mile;
float mainUnitInMeters = kmAndMeters ? METERS_IN_KILOMETER : METERS_IN_ONE_MILE;
DecimalFormat df = new DecimalFormat("#.#");
return df.format(meters / mainUnitInMeters) + " " + app.getString(mainUnitStr);
}
public static String getFormattedDistance(float meters, OsmandApplication ctx) {
return getFormattedDistance(meters, ctx, true);

View file

@ -42,15 +42,12 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.activities.PluginActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.views.GPXLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.RouteLayer;
import net.osmand.plus.views.corenative.NativeCoreContext;
import net.osmand.render.RenderingRule;
import net.osmand.render.RenderingRuleProperty;
@ -62,7 +59,6 @@ import org.apache.commons.logging.Log;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@ -503,29 +499,33 @@ public class ConfigureMapMenu {
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
bld.setTitle(R.string.renderers);
final OsmandApplication app = activity.getMyApplication();
Collection<String> rendererNames = app.getRendererRegistry().getRendererNames();
final String[] items = rendererNames.toArray(new String[rendererNames.size()]);
final ArrayList<String> items = new ArrayList<>(app.getRendererRegistry().getRendererNames());
boolean nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
final List<String> visibleNamesList = new ArrayList<>();
int selected = -1;
final String selectedName = app.getRendererRegistry().getCurrentSelectedRenderer().getName();
int i = 0;
for (String item : items) {
Iterator<String> iterator = items.iterator();
while (iterator.hasNext()) {
String item = iterator.next();
if (nauticalPluginDisabled && item.equals(RendererRegistry.NAUTICAL_RENDER)) {
continue;
iterator.remove();
} else {
if (item.equals(selectedName)) {
selected = i;
}
String translation = RendererRegistry.getTranslatedRendererName(activity, item);
visibleNamesList.add(translation != null ? translation
: item.replace('_', ' ').replace('-', ' '));
i++;
}
if (item.equals(selectedName)) {
selected = i;
}
visibleNamesList.add(item);
i++;
}
bld.setSingleChoiceItems(visibleNamesList.toArray(new String[visibleNamesList.size()]), selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String renderer = visibleNamesList.get(which);
String renderer = items.get(which);
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
if (loaded != null) {
OsmandMapTileView view = activity.getMapView();
@ -1135,7 +1135,8 @@ public class ConfigureMapMenu {
if (storage == null) {
return "";
}
return storage.getName();
String translation = RendererRegistry.getTranslatedRendererName(activity, storage.getName());
return translation == null ? storage.getName() : translation;
}
protected String getDayNightDescr(final MapActivity activity) {

View file

@ -208,7 +208,7 @@ public class WaypointHelper {
AlarmInfo inf = new AlarmInfo(AlarmInfoType.TUNNEL, 0);
int d = route.getDistanceToPoint(segments.get(0).getStartPointIndex());
float time = speed > 0 ? d / speed : Integer.MAX_VALUE;
inf.setFloatValue(calculateDistance(segments, mc));
inf.setFloatValue(calculateDistance(segments));
int vl = inf.updateDistanceAndGetPriority(time, d);
if (vl < value && (showCameras || inf.getType() != AlarmInfoType.SPEED_CAMERA)) {
mostImportant = inf;
@ -217,16 +217,12 @@ public class WaypointHelper {
return mostImportant;
}
private float calculateDistance(List<RouteSegmentResult> segments, MetricsConstants mc) {
private float calculateDistance(List<RouteSegmentResult> segments) {
float sum = 0f;
for (RouteSegmentResult r : segments) {
sum += r.getDistance();
}
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
return sum / 1000f;
} else {
return sum * 0.00062137f;
}
return sum;
}
public void enableWaypointType(int type, boolean enable) {

View file

@ -20,8 +20,8 @@ import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.render.RenderingRulesStorage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class MapStyleAction extends SwitchableAction<String> {
@ -120,17 +120,19 @@ public class MapStyleAction extends SwitchableAction<String> {
final OsmandApplication app = activity.getMyApplication();
final List<String> visibleNamesList = new ArrayList<>();
final Collection<String> rendererNames = app.getRendererRegistry().getRendererNames();
final String[] items = rendererNames.toArray(new String[rendererNames.size()]);
final ArrayList<String> items = new ArrayList<>(app.getRendererRegistry().getRendererNames());
final boolean nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
for (String item : items) {
Iterator<String> iterator = items.iterator();
while (iterator.hasNext()) {
String item = iterator.next();
if (nauticalPluginDisabled && item.equals(RendererRegistry.NAUTICAL_RENDER)) {
continue;
iterator.remove();
} else {
String translation = RendererRegistry.getTranslatedRendererName(activity, item);
visibleNamesList.add(translation != null ? translation
: item.replace('_', ' ').replace('-', ' '));
}
visibleNamesList.add(item.replace('_', ' ').replace('-', ' '));
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
@ -140,7 +142,7 @@ public class MapStyleAction extends SwitchableAction<String> {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String renderer = visibleNamesList.get(i);
String renderer = items.get(i);
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
if (loaded != null) {

View file

@ -1,15 +1,8 @@
package net.osmand.plus.render;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
@ -25,6 +18,17 @@ import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
public class RendererRegistry {
@ -32,12 +36,11 @@ public class RendererRegistry {
public final static String DEFAULT_RENDER = "OsmAnd"; //$NON-NLS-1$
public final static String DEFAULT_RENDER_FILE_PATH = "default.render.xml";
public final static String TOURING_VIEW = "Touring view (contrast and details)"; //$NON-NLS-1$
public final static String WINTER_SKI_RENDER = "Winter and ski"; //$NON-NLS-1$
public final static String NAUTICAL_RENDER = "Nautical"; //$NON-NLS-1$
public final static String TOPO_RENDER = "Topo"; //$NON-NLS-1$
public final static String MAPNIK_RENDER = "Mapnik"; //$NON-NLS-1$
// Translatable renders
public static String TOURING_VIEW;
public static String WINTER_SKI_RENDER;
public static String NAUTICAL_RENDER;
private RenderingRulesStorage defaultRender = null;
private RenderingRulesStorage currentSelectedRender = null;
@ -57,9 +60,6 @@ public class RendererRegistry {
public RendererRegistry(OsmandApplication app){
this.app = app;
WINTER_SKI_RENDER = app.getResources().getString(R.string.winter_and_ski_renderer);
TOURING_VIEW = app.getResources().getString(R.string.touring_view_renderer);
NAUTICAL_RENDER = app.getResources().getString(R.string.nautical_renderer);
internalRenderers.put(DEFAULT_RENDER, DEFAULT_RENDER_FILE_PATH);
internalRenderers.put(TOURING_VIEW, "Touring-view_(more-contrast-and-details)" +".render.xml");
internalRenderers.put(TOPO_RENDER, "topo" + ".render.xml");
@ -247,6 +247,19 @@ public class RendererRegistry {
return names;
}
@Nullable
public static String getTranslatedRendererName(@NonNull Context ctx, @NonNull String key) {
switch (key) {
case TOURING_VIEW:
return ctx.getString(R.string.touring_view_renderer);
case WINTER_SKI_RENDER:
return ctx.getString(R.string.winter_and_ski_renderer);
case NAUTICAL_RENDER:
return ctx.getString(R.string.nautical_renderer);
}
return null;
}
public RenderingRulesStorage getCurrentSelectedRenderer() {
if(currentSelectedRender == null){
return defaultRender();

View file

@ -1274,14 +1274,12 @@ public class RouteInfoWidgetsFactory {
locimgId = R.drawable.warnings_pedestrian;
}
} else if(alarm.getType() == AlarmInfoType.TUNNEL) {
DecimalFormat df = new DecimalFormat("#.#");
if(settings.DRIVING_REGION.get().americanSigns){
locimgId = R.drawable.warnings_tunnel_us;
text = df.format(alarm.getFloatValue()) +" mi";
} else {
locimgId = R.drawable.warnings_tunnel;
text = df.format(alarm.getFloatValue()) +" km";
}
text = OsmAndFormatter.getFormattedAlarmInfoDistance(settings.getContext(), alarm.getFloatValue());
} else {
text = null;
}