quick actions map source

This commit is contained in:
Rosty 2017-01-06 14:00:11 +02:00
parent b0e3306de7
commit 616cc14048
3 changed files with 57 additions and 38 deletions

View file

@ -2541,4 +2541,5 @@ If you need help with OsmAnd application, please contact our support team: suppo
<string name="quick_action_map_source_title">Map sources</string> <string name="quick_action_map_source_title">Map sources</string>
<string name="quick_action_map_source_dscr">Tap on the action button will toggle the map source, from the list order.</string> <string name="quick_action_map_source_dscr">Tap on the action button will toggle the map source, from the list order.</string>
<string name="quick_action_map_source_action">Add Source</string> <string name="quick_action_map_source_action">Add Source</string>
<string name="quick_action_map_source_switch">Map source has been changed to the \"%s\".</string>
</resources> </resources>

View file

@ -34,8 +34,10 @@ import android.widget.Toast;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import net.osmand.ResultMatcher;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.map.TileSourceManager;
import net.osmand.osm.AbstractPoiType; import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes; import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiType; import net.osmand.osm.PoiType;
@ -1662,7 +1664,7 @@ public class QuickActionFactory {
public static final int TYPE = 14; public static final int TYPE = 14;
private static String KEY_STYLES = "styles"; private final static String KEY_STYLES = "styles";
protected MapStyleAction() { protected MapStyleAction() {
super(TYPE); super(TYPE);
@ -1828,7 +1830,7 @@ public class QuickActionFactory {
public static final int TYPE = 15; public static final int TYPE = 15;
private static String KEY_OVERLAYS = "overlays"; private final static String KEY_OVERLAYS = "overlays";
protected MapOverlayAction() { protected MapOverlayAction() {
super(TYPE); super(TYPE);
@ -1899,7 +1901,7 @@ public class QuickActionFactory {
public static final int TYPE = 16; public static final int TYPE = 16;
private static String KEY_UNDERLAYS = "underlays"; private final static String KEY_UNDERLAYS = "underlays";
protected MapUnderlayAction() { protected MapUnderlayAction() {
super(TYPE); super(TYPE);
@ -1969,7 +1971,8 @@ public class QuickActionFactory {
public static final int TYPE = 17; 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() { protected MapSourceAction() {
super(TYPE); super(TYPE);
@ -2010,6 +2013,36 @@ public class QuickActionFactory {
@Override @Override
public void execute(MapActivity activity) { public void execute(MapActivity activity) {
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null) {
OsmandSettings settings = activity.getMyApplication().getSettings();
List<Pair<String, String>> sources = loadListFromParams();
Pair<String, String> 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<String, String> 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 @Override
@ -2041,39 +2074,13 @@ public class QuickActionFactory {
final OsmandSettings settings = activity.getMyApplication().getSettings(); final OsmandSettings settings = activity.getMyApplication().getSettings();
final LinkedHashMap<String, String> entriesMap = new LinkedHashMap<>(); final LinkedHashMap<String, String> entriesMap = new LinkedHashMap<>();
final String layerOsmVector = "LAYER_OSM_VECTOR"; entriesMap.put(LAYER_OSM_VECTOR, activity.getString(R.string.vector_data));
entriesMap.put(layerOsmVector, activity.getString(R.string.vector_data));
entriesMap.putAll(settings.getTileSourceEntries()); entriesMap.putAll(settings.getTileSourceEntries());
final List<Entry<String, String>> entriesMapList = new ArrayList<>(entriesMap.entrySet()); final List<Entry<String, String>> entriesMapList = new ArrayList<>(entriesMap.entrySet());
AlertDialog.Builder builder = new AlertDialog.Builder(activity); 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<String, String> selectedEntry = null;
for (Entry<String, String> 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()]; final String[] items = new String[entriesMapList.size()];
int i = 0; int i = 0;
@ -2081,20 +2088,23 @@ public class QuickActionFactory {
items[i++] = entry.getValue(); items[i++] = entry.getValue();
} }
builder.setSingleChoiceItems(items, selectedItem, new DialogInterface.OnClickListener() { final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
@Override
public void onClick(DialogInterface dialog, int which) {
Pair<String, String> layer = new Pair<String, String>( arrayAdapter.addAll(items);
entriesMapList.get(which).getKey(), builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
entriesMapList.get(which).getValue()); @Override
public void onClick(DialogInterface dialog, int i) {
Pair<String, String> layer = new Pair<>(
entriesMapList.get(i).getKey(),
entriesMapList.get(i).getValue());
adapter.addItem(layer, activity); adapter.addItem(layer, activity);
dialog.dismiss(); dialog.dismiss();
} }
}); });
builder.setNegativeButton(R.string.shared_string_dismiss, null); builder.setNegativeButton(R.string.shared_string_dismiss, null);
builder.show(); builder.show();
} }

View file

@ -10,6 +10,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; 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); if (!skip) filteredActions.add(action);
} }