Merge pull request #30 from fanatic84/UI_Fix_Layer
Change UI in select layer menu
This commit is contained in:
commit
c42ce307de
1 changed files with 52 additions and 19 deletions
|
@ -4,23 +4,25 @@ import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import net.osmand.Algoritms;
|
import net.osmand.Algoritms;
|
||||||
import net.osmand.CallbackWithObject;
|
import net.osmand.CallbackWithObject;
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities;
|
||||||
import net.osmand.OsmAndFormatter;
|
|
||||||
import net.osmand.GPXUtilities.GPXFileResult;
|
import net.osmand.GPXUtilities.GPXFileResult;
|
||||||
|
import net.osmand.OsmAndFormatter;
|
||||||
import net.osmand.data.AmenityType;
|
import net.osmand.data.AmenityType;
|
||||||
import net.osmand.map.ITileSource;
|
import net.osmand.map.ITileSource;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
|
import net.osmand.plus.OsmandSettings.CommonPreference;
|
||||||
import net.osmand.plus.PoiFilter;
|
import net.osmand.plus.PoiFilter;
|
||||||
import net.osmand.plus.PoiFiltersHelper;
|
import net.osmand.plus.PoiFiltersHelper;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.ResourceManager;
|
import net.osmand.plus.ResourceManager;
|
||||||
import net.osmand.plus.SQLiteTileSource;
|
import net.osmand.plus.SQLiteTileSource;
|
||||||
import net.osmand.plus.OsmandSettings.CommonPreference;
|
|
||||||
import net.osmand.plus.render.MapRenderRepositories;
|
import net.osmand.plus.render.MapRenderRepositories;
|
||||||
import net.osmand.plus.render.MapVectorLayer;
|
import net.osmand.plus.render.MapVectorLayer;
|
||||||
import net.osmand.plus.views.BaseMapLayer;
|
import net.osmand.plus.views.BaseMapLayer;
|
||||||
|
@ -40,8 +42,8 @@ import net.osmand.plus.views.RouteLayer;
|
||||||
import net.osmand.plus.views.TransportInfoLayer;
|
import net.osmand.plus.views.TransportInfoLayer;
|
||||||
import net.osmand.plus.views.TransportStopsLayer;
|
import net.osmand.plus.views.TransportStopsLayer;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.ProgressDialog;
|
|
||||||
import android.app.AlertDialog.Builder;
|
import android.app.AlertDialog.Builder;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
@ -73,7 +75,6 @@ public class MapActivityLayers {
|
||||||
private RouteInfoLayer routeInfoLayer;
|
private RouteInfoLayer routeInfoLayer;
|
||||||
private MapControlsLayer mapControlsLayer;
|
private MapControlsLayer mapControlsLayer;
|
||||||
|
|
||||||
|
|
||||||
public MapActivityLayers(MapActivity activity) {
|
public MapActivityLayers(MapActivity activity) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
|
@ -466,21 +467,52 @@ public class MapActivityLayers {
|
||||||
|
|
||||||
private void selectMapLayer(final OsmandMapTileView mapView){
|
private void selectMapLayer(final OsmandMapTileView mapView){
|
||||||
final OsmandSettings settings = getApplication().getSettings();
|
final OsmandSettings settings = getApplication().getSettings();
|
||||||
Map<String, String> entriesMap = settings.getTileSourceEntries();
|
|
||||||
|
final LinkedHashMap<String, String> entriesMap = new LinkedHashMap<String, String>();
|
||||||
|
|
||||||
|
final String layerOsmVector = "LAYER_OSM_VECTOR";
|
||||||
|
final String layerInstallMore = "LAYER_INSTALL_MORE";
|
||||||
|
|
||||||
|
entriesMap.put(layerOsmVector, getString(R.string.vector_data));
|
||||||
|
entriesMap.putAll(settings.getTileSourceEntries());
|
||||||
|
entriesMap.put(layerInstallMore, getString(R.string.install_more));
|
||||||
|
|
||||||
|
final List<Entry<String, String>> entriesMapList = new ArrayList<Entry<String, String>>(entriesMap.entrySet());
|
||||||
|
|
||||||
Builder builder = new AlertDialog.Builder(activity);
|
Builder builder = new AlertDialog.Builder(activity);
|
||||||
final ArrayList<String> keys = new ArrayList<String>(entriesMap.keySet());
|
|
||||||
final String[] items = new String[entriesMap.size() + 2];
|
String selectedTileSourceKey = settings.MAP_TILE_SOURCES.get();
|
||||||
items[0] = getString(R.string.vector_data);
|
|
||||||
int i = 1;
|
int selectedItem = -1;
|
||||||
for(String it : entriesMap.values()){
|
if (settings.MAP_VECTOR_DATA.get()) {
|
||||||
items[i++] = it;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
items[i] = getString(R.string.install_more);
|
final String[] items = new String[entriesMapList.size()];
|
||||||
builder.setItems(items, new DialogInterface.OnClickListener(){
|
int i = 0;
|
||||||
|
for (Entry<String, String> entry : entriesMapList) {
|
||||||
|
items[i++] = entry.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.setSingleChoiceItems(items, selectedItem, new DialogInterface.OnClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
if (which == 0) {
|
String layerKey = entriesMapList.get(which).getKey();
|
||||||
|
if (layerKey.equals(layerOsmVector)) {
|
||||||
MapRenderRepositories r = ((OsmandApplication) getApplication()).getResourceManager().getRenderer();
|
MapRenderRepositories r = ((OsmandApplication) getApplication()).getResourceManager().getRenderer();
|
||||||
if (r.isEmpty()) {
|
if (r.isEmpty()) {
|
||||||
Toast.makeText(activity, getString(R.string.no_vector_map_loaded), Toast.LENGTH_LONG).show();
|
Toast.makeText(activity, getString(R.string.no_vector_map_loaded), Toast.LENGTH_LONG).show();
|
||||||
|
@ -489,7 +521,7 @@ public class MapActivityLayers {
|
||||||
settings.MAP_VECTOR_DATA.set(true);
|
settings.MAP_VECTOR_DATA.set(true);
|
||||||
}
|
}
|
||||||
updateMapSource(mapView, null);
|
updateMapSource(mapView, null);
|
||||||
} else if (which == items.length - 1) {
|
} else if (layerKey.equals(layerInstallMore)) {
|
||||||
SettingsActivity.installMapLayers(activity, new DialogInterface.OnClickListener() {
|
SettingsActivity.installMapLayers(activity, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
@ -497,18 +529,18 @@ public class MapActivityLayers {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
settings.MAP_TILE_SOURCES.set(keys.get(which - 1));
|
settings.MAP_TILE_SOURCES.set(layerKey);
|
||||||
settings.MAP_VECTOR_DATA.set(false);
|
settings.MAP_VECTOR_DATA.set(false);
|
||||||
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
|
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void selectMapOverlayLayer(final OsmandMapTileView mapView,
|
private void selectMapOverlayLayer(final OsmandMapTileView mapView,
|
||||||
final CommonPreference<String> mapPref, final CommonPreference<Integer> transparencyPref,
|
final CommonPreference<String> mapPref, final CommonPreference<Integer> transparencyPref,
|
||||||
final BaseMapLayer... transparencyToChange){
|
final BaseMapLayer... transparencyToChange){
|
||||||
|
@ -523,7 +555,7 @@ public class MapActivityLayers {
|
||||||
}
|
}
|
||||||
|
|
||||||
items[i] = getString(R.string.install_more);
|
items[i] = getString(R.string.install_more);
|
||||||
builder.setItems(items, new DialogInterface.OnClickListener(){
|
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
if (which == items.length - 1){
|
if (which == items.length - 1){
|
||||||
|
@ -539,6 +571,7 @@ public class MapActivityLayers {
|
||||||
updateMapSource(mapView, mapPref);
|
updateMapSource(mapView, mapPref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue