From 616cc1404866c15cf899bc1b1a57c3cb4b19bdb6 Mon Sep 17 00:00:00 2001 From: Rosty Date: Fri, 6 Jan 2017 14:00:11 +0200 Subject: [PATCH] quick actions map source --- OsmAnd/res/values/strings.xml | 1 + .../plus/quickaction/QuickActionFactory.java | 86 +++++++++++-------- .../plus/quickaction/QuickActionRegistry.java | 8 ++ 3 files changed, 57 insertions(+), 38 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index e11db20856..6352b9f942 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2541,4 +2541,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 45cd15d38a..5ed1acb1fb 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java @@ -34,8 +34,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.PoiType; @@ -1662,7 +1664,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); @@ -1828,7 +1830,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); @@ -1899,7 +1901,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); @@ -1969,7 +1971,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); @@ -2010,6 +2013,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 @@ -2041,39 +2074,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; @@ -2081,20 +2088,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); }