Fix #4977
This commit is contained in:
parent
953cfec17b
commit
f027adf0eb
3 changed files with 43 additions and 20 deletions
|
@ -59,7 +59,6 @@ import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -500,29 +499,33 @@ public class ConfigureMapMenu {
|
||||||
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
|
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
|
||||||
bld.setTitle(R.string.renderers);
|
bld.setTitle(R.string.renderers);
|
||||||
final OsmandApplication app = activity.getMyApplication();
|
final OsmandApplication app = activity.getMyApplication();
|
||||||
Collection<String> rendererNames = app.getRendererRegistry().getRendererNames();
|
final ArrayList<String> items = new ArrayList<>(app.getRendererRegistry().getRendererNames());
|
||||||
final String[] items = rendererNames.toArray(new String[rendererNames.size()]);
|
|
||||||
boolean nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
|
boolean nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
|
||||||
final List<String> visibleNamesList = new ArrayList<>();
|
final List<String> visibleNamesList = new ArrayList<>();
|
||||||
int selected = -1;
|
int selected = -1;
|
||||||
final String selectedName = app.getRendererRegistry().getCurrentSelectedRenderer().getName();
|
final String selectedName = app.getRendererRegistry().getCurrentSelectedRenderer().getName();
|
||||||
int i = 0;
|
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)) {
|
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.replace('_', ' ').replace('-', ' '));
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bld.setSingleChoiceItems(visibleNamesList.toArray(new String[visibleNamesList.size()]), selected, new DialogInterface.OnClickListener() {
|
bld.setSingleChoiceItems(visibleNamesList.toArray(new String[visibleNamesList.size()]), selected, new DialogInterface.OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
String renderer = visibleNamesList.get(which);
|
String renderer = items.get(which);
|
||||||
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
|
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
|
||||||
if (loaded != null) {
|
if (loaded != null) {
|
||||||
OsmandMapTileView view = activity.getMapView();
|
OsmandMapTileView view = activity.getMapView();
|
||||||
|
|
|
@ -20,8 +20,8 @@ import net.osmand.plus.views.OsmandMapTileView;
|
||||||
import net.osmand.render.RenderingRulesStorage;
|
import net.osmand.render.RenderingRulesStorage;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MapStyleAction extends SwitchableAction<String> {
|
public class MapStyleAction extends SwitchableAction<String> {
|
||||||
|
@ -120,17 +120,19 @@ public class MapStyleAction extends SwitchableAction<String> {
|
||||||
|
|
||||||
final OsmandApplication app = activity.getMyApplication();
|
final OsmandApplication app = activity.getMyApplication();
|
||||||
final List<String> visibleNamesList = new ArrayList<>();
|
final List<String> visibleNamesList = new ArrayList<>();
|
||||||
final Collection<String> rendererNames = app.getRendererRegistry().getRendererNames();
|
final ArrayList<String> items = new ArrayList<>(app.getRendererRegistry().getRendererNames());
|
||||||
final String[] items = rendererNames.toArray(new String[rendererNames.size()]);
|
|
||||||
final boolean nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
|
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)) {
|
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);
|
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
|
||||||
|
@ -140,7 +142,7 @@ public class MapStyleAction extends SwitchableAction<String> {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
|
||||||
String renderer = visibleNamesList.get(i);
|
String renderer = items.get(i);
|
||||||
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
|
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
|
||||||
|
|
||||||
if (loaded != null) {
|
if (loaded != null) {
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package net.osmand.plus.render;
|
package net.osmand.plus.render;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import net.osmand.IProgress;
|
import net.osmand.IProgress;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
import net.osmand.render.RenderingRuleProperty;
|
import net.osmand.render.RenderingRuleProperty;
|
||||||
import net.osmand.render.RenderingRulesStorage;
|
import net.osmand.render.RenderingRulesStorage;
|
||||||
import net.osmand.render.RenderingRulesStorage.RenderingRulesStorageResolver;
|
import net.osmand.render.RenderingRulesStorage.RenderingRulesStorageResolver;
|
||||||
|
@ -242,6 +247,19 @@ public class RendererRegistry {
|
||||||
return names;
|
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() {
|
public RenderingRulesStorage getCurrentSelectedRenderer() {
|
||||||
if(currentSelectedRender == null){
|
if(currentSelectedRender == null){
|
||||||
return defaultRender();
|
return defaultRender();
|
||||||
|
|
Loading…
Reference in a new issue