Merge remote-tracking branch 'origin/master'

This commit is contained in:
Korusn Oleksandr 2017-01-06 14:05:30 +02:00
commit a1ae6ab9f2
4 changed files with 57 additions and 39 deletions

View file

@ -2,7 +2,6 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:animateLayoutChanges="true"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">

View file

@ -2542,4 +2542,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

@ -42,8 +42,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.PoiCategory; import net.osmand.osm.PoiCategory;
@ -1851,7 +1853,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);
@ -2017,7 +2019,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);
@ -2088,7 +2090,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);
@ -2158,7 +2160,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);
@ -2199,6 +2202,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
@ -2230,39 +2263,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;
@ -2270,20 +2277,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);
} }