diff --git a/OsmAnd/res/layout/map_hud_quick_actions.xml b/OsmAnd/res/layout/map_hud_quick_actions.xml index 925b6e921b..37b623525c 100644 --- a/OsmAnd/res/layout/map_hud_quick_actions.xml +++ b/OsmAnd/res/layout/map_hud_quick_actions.xml @@ -2,7 +2,6 @@ diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 4fed45d540..b51065d9e8 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2542,4 +2542,5 @@ If you need help with OsmAnd application, please contact our support team: suppo Map sources Tap on the action button will toggle the map source, from the list order. Add Source + Map source has been changed to the \"%s\". diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java index 43861875fd..0740a92f6a 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java @@ -42,8 +42,10 @@ import android.widget.Toast; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import net.osmand.ResultMatcher; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; +import net.osmand.map.TileSourceManager; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; @@ -1851,7 +1853,7 @@ public class QuickActionFactory { public static final int TYPE = 14; - private static String KEY_STYLES = "styles"; + private final static String KEY_STYLES = "styles"; protected MapStyleAction() { super(TYPE); @@ -2017,7 +2019,7 @@ public class QuickActionFactory { public static final int TYPE = 15; - private static String KEY_OVERLAYS = "overlays"; + private final static String KEY_OVERLAYS = "overlays"; protected MapOverlayAction() { super(TYPE); @@ -2088,7 +2090,7 @@ public class QuickActionFactory { public static final int TYPE = 16; - private static String KEY_UNDERLAYS = "underlays"; + private final static String KEY_UNDERLAYS = "underlays"; protected MapUnderlayAction() { super(TYPE); @@ -2158,7 +2160,8 @@ public class QuickActionFactory { public static final int TYPE = 17; - private static String KEY_SOURCE = "source"; + private final static String KEY_SOURCE = "source"; + private final String LAYER_OSM_VECTOR = "LAYER_OSM_VECTOR"; protected MapSourceAction() { super(TYPE); @@ -2199,6 +2202,36 @@ public class QuickActionFactory { @Override public void execute(MapActivity activity) { + if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null) { + + OsmandSettings settings = activity.getMyApplication().getSettings(); + List> sources = loadListFromParams(); + + Pair currentSource = settings.MAP_ONLINE_DATA.get() + ? new Pair<>(settings.MAP_TILE_SOURCES.get(), settings.MAP_TILE_SOURCES.get()) + : new Pair<>(LAYER_OSM_VECTOR, activity.getString(R.string.vector_data)); + + Pair nextSource = sources.get(0); + int index = sources.indexOf(currentSource); + + if (index >= 0 && index + 1 < sources.size()) { + nextSource = sources.get(index + 1); + } + + if (nextSource.first.equals(LAYER_OSM_VECTOR)) { + + settings.MAP_ONLINE_DATA.set(false); + activity.getMapLayers().updateMapSource(activity.getMapView(), null); + + } else { + + settings.MAP_TILE_SOURCES.set(nextSource.first); + settings.MAP_ONLINE_DATA.set(true); + activity.getMapLayers().updateMapSource(activity.getMapView(), settings.MAP_TILE_SOURCES); + } + + Toast.makeText(activity, activity.getString(R.string.quick_action_map_source_switch, nextSource.second), Toast.LENGTH_SHORT).show(); + } } @Override @@ -2230,39 +2263,13 @@ public class QuickActionFactory { final OsmandSettings settings = activity.getMyApplication().getSettings(); final LinkedHashMap entriesMap = new LinkedHashMap<>(); - final String layerOsmVector = "LAYER_OSM_VECTOR"; - - entriesMap.put(layerOsmVector, activity.getString(R.string.vector_data)); + entriesMap.put(LAYER_OSM_VECTOR, activity.getString(R.string.vector_data)); entriesMap.putAll(settings.getTileSourceEntries()); final List> entriesMapList = new ArrayList<>(entriesMap.entrySet()); AlertDialog.Builder builder = new AlertDialog.Builder(activity); - String selectedTileSourceKey = settings.MAP_TILE_SOURCES.get(); - - int selectedItem = -1; - - if (!settings.MAP_ONLINE_DATA.get()) { - - selectedItem = 0; - - } else { - - Entry selectedEntry = null; - for (Entry entry : entriesMap.entrySet()) { - if (entry.getKey().equals(selectedTileSourceKey)) { - selectedEntry = entry; - break; - } - } - if (selectedEntry != null) { - selectedItem = 0; - entriesMapList.remove(selectedEntry); - entriesMapList.add(0, selectedEntry); - } - } - final String[] items = new String[entriesMapList.size()]; int i = 0; @@ -2270,20 +2277,23 @@ public class QuickActionFactory { items[i++] = entry.getValue(); } - builder.setSingleChoiceItems(items, selectedItem, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { + final ArrayAdapter arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item); - Pair layer = new Pair( - entriesMapList.get(which).getKey(), - entriesMapList.get(which).getValue()); + arrayAdapter.addAll(items); + builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int i) { + + Pair layer = new Pair<>( + entriesMapList.get(i).getKey(), + entriesMapList.get(i).getValue()); adapter.addItem(layer, activity); dialog.dismiss(); } - }); + builder.setNegativeButton(R.string.shared_string_dismiss, null); builder.show(); } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java index 734d91c7c3..1d1f11604b 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java @@ -10,6 +10,7 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin; +import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import java.lang.reflect.Type; import java.util.ArrayList; @@ -99,6 +100,13 @@ public class QuickActionRegistry { } } + if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) { + + if (action.type == QuickActionFactory.MapSourceAction.TYPE) { + skip = true; + } + } + if (!skip) filteredActions.add(action); }