From f85fa4118d20af3160d6533225e5e1b5451135b8 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 29 May 2011 23:12:24 +0200 Subject: [PATCH] Change preference screen --- .../src/net/osmand/ToDoConstants.java | 21 +--- OsmAnd/res/values-ru/strings.xml | 4 +- OsmAnd/res/values/strings.xml | 2 + OsmAnd/res/xml/settings_pref.xml | 2 + .../src/net/osmand/plus/OsmandSettings.java | 15 +-- .../plus/activities/DownloadTilesDialog.java | 2 +- .../osmand/plus/activities/MapActivity.java | 2 +- .../plus/activities/MapActivityLayers.java | 64 ++-------- .../plus/activities/SettingsActivity.java | 113 ++++++++++++++---- config/site/tile_sources.xml | 24 ++-- 10 files changed, 138 insertions(+), 111 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/ToDoConstants.java b/DataExtractionOSM/src/net/osmand/ToDoConstants.java index 1898903efa..7904494453 100644 --- a/DataExtractionOSM/src/net/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/net/osmand/ToDoConstants.java @@ -11,22 +11,17 @@ public class ToDoConstants { // == Osmand application (TODO 127) == // Map Refactoring -// || 124 || Animated transition using only raster images (?) - skip animations (!) - don not render vectoring for animations (Issue 238) || -// Fix issue with min/max zoom -// Empty screen replace (?) // Remove notification from OsmAndMapTileView (?) -// Refactoring ResourceManager with cached images (tiles density) -// YandexLayer goes to MapTileLayer // Add transparency filter to bitmap layers -// Download layers from internet / Yandex Traffic (not download on osmand?) - // Review all constructors of TileSourceTemplate -/// allow to add own tile sources from application (?) -// Manage tile sources and allow to compact them into sqlite db +// Allow to create over/under map layers +// Allow to config transparency filter +// Yandex Traffic make downloadable +// allow to add own tile sources from OsmAnd (?) +// allow to create sqlite sources from OsmAnd (?) // === Refactoring issues === // !|| 125 || Introduce service layer rather than singletons and put all related into new package (services). Review architecture. Split some big classes. || - // === Common issues === // || 104 || Add activity to show current loaded indexes and information about them (Issue 366) || @@ -49,9 +44,6 @@ public class ToDoConstants { // === Unscheduled (complex) === // || 65 || Intermediate points - for better control routing, to avoid traffic jams ...(?) || - // _19. colors for road trunk and motorway - - /////////////////////////// DONE ////////////////////////////// // DONE ANDROID : // || 112 || Investigate exiting/minimizing app (Issue 214) || @@ -59,9 +51,8 @@ public class ToDoConstants { // || 120 || Show icons over poi circle (issue 414) || // || 119 || Dialog on main screen tips and tricks (Issue 415) || // || 118 || Config switching between maps on different zoom levels <14 (using raster), > 14 vector (Issue 419) || +// || 124 || Animated transition using only raster images (?) - skip animations (!) - don not render vectoring for animations (Issue 238) || // DONE SWING - - } diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index fd974599dd..3fb6f5408a 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -1,5 +1,7 @@ + Векторные карты + Использовать загруженные векторные карты Карта уже установлена, настройки будут обновлены Выберите карты для установки или обновления Интернет соединение не доступно @@ -437,7 +439,7 @@ Показывать слой POI POI Загружать недостающие части карты из : - Источник данных + Растровые карты Источник карты Интернет Показать место diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 63539922b3..11c34018d3 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,7 @@ + Vector maps + Use downloaded vector maps Map is already installed, settings will be updated Select maps to install or update Internet connection required for operation is not available diff --git a/OsmAnd/res/xml/settings_pref.xml b/OsmAnd/res/xml/settings_pref.xml index 19c42ac0b2..bd29e2f9fd 100644 --- a/OsmAnd/res/xml/settings_pref.xml +++ b/OsmAnd/res/xml/settings_pref.xml @@ -4,6 +4,8 @@ + diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index bec6f56cc1..ba4b905372 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -508,20 +508,15 @@ public class OsmandSettings { USE_STEP_BY_STEP_RENDERING.setModeDefaultValue(ApplicationMode.BICYCLE, false); USE_STEP_BY_STEP_RENDERING.setModeDefaultValue(ApplicationMode.PEDESTRIAN, false); } - + + // this value string is synchronized with settings_pref.xml preference name + public final CommonPreference MAP_VECTOR_DATA = new BooleanPreference("map_vector_data", + false, true); + // this value string is synchronized with settings_pref.xml preference name - public static final String MAP_VECTOR_DATA = "map_vector_data"; //$NON-NLS-1$ public static final String MAP_TILE_SOURCES = "map_tile_sources"; //$NON-NLS-1$ - public boolean isUsingMapVectorData(){ - return globalPreferences.getBoolean(MAP_VECTOR_DATA, false); - } - - public boolean setUsingMapVectorData(boolean val){ - return globalPreferences.edit().putBoolean(MAP_VECTOR_DATA, val).commit(); - } - public boolean setMapTileSource(String tileSource){ return globalPreferences.edit().putString(MAP_TILE_SOURCES, tileSource).commit(); } diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadTilesDialog.java b/OsmAnd/src/net/osmand/plus/activities/DownloadTilesDialog.java index be187d56e9..2d28027044 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadTilesDialog.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadTilesDialog.java @@ -47,7 +47,7 @@ public class DownloadTilesDialog { public void openDialog(){ BaseMapLayer mainLayer = mapView.getMainLayer(); - if(!(mainLayer instanceof MapTileLayer) || ((MapTileLayer) mainLayer).isVisible()){ + if(!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()){ Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show(); } final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap(); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index e6201ff69c..5c6b67a69f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -158,7 +158,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso @Override public void onDismiss(DialogInterface dialog) { OsmandApplication app = ((OsmandApplication)getApplication()); - if(settings.isUsingMapVectorData() && app.getResourceManager().getRenderer().isEmpty()){ + if(settings.MAP_VECTOR_DATA.get() && app.getResourceManager().getRenderer().isEmpty()){ Toast.makeText(MapActivity.this, getString(R.string.no_vector_map_loaded), Toast.LENGTH_LONG).show(); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index c894049645..9534cb0837 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -181,13 +181,13 @@ public class MapActivityLayers { public void updateMapSource(OsmandMapTileView mapView){ OsmandSettings settings = getApplication().getSettings(); - boolean showTiles = !settings.isUsingMapVectorData(); + boolean showTiles = !settings.MAP_VECTOR_DATA.get(); ITileSource source = showTiles ? settings.getMapTileSource() : null; if (showTiles == mapTileLayer.isVisible() && Algoritms.objectEquals(mapTileLayer.getMap(), source)) { return; } - boolean vectorData = settings.isUsingMapVectorData(); + boolean vectorData = settings.MAP_VECTOR_DATA.get(); OsmandApplication app = ((OsmandApplication)getApplication()); ResourceManager rm = app.getResourceManager(); if(vectorData && !app.isApplicationInitializing()){ @@ -440,14 +440,19 @@ public class MapActivityLayers { Toast.makeText(activity, getString(R.string.no_vector_map_loaded), Toast.LENGTH_LONG).show(); return; } else { - settings.setUsingMapVectorData(true); + settings.MAP_VECTOR_DATA.set(true); } updateMapSource(mapView); } else if (which == items.length - 1){ - installMapLayers(mapView); + SettingsActivity.installMapLayers(activity, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + openLayerSelectionDialog(mapView); + } + }); } else { settings.setMapTileSource(keys.get(which - 1)); - settings.setUsingMapVectorData(false); + settings.MAP_VECTOR_DATA.set(false); updateMapSource(mapView); } @@ -457,54 +462,7 @@ public class MapActivityLayers { builder.show(); } - private void installMapLayers(final OsmandMapTileView mapView){ - final OsmandSettings settings = getApplication().getSettings(); - final Map entriesMap = settings.getTileSourceEntries(); - if(!settings.isInternetConnectionAvailable(true)){ - Toast.makeText(activity, R.string.internet_not_available, Toast.LENGTH_LONG).show(); - return; - } - final List downloaded = TileSourceManager.downloadTileSourceTemplates(); - if(downloaded == null || downloaded.isEmpty()){ - Toast.makeText(activity, R.string.error_io_error, Toast.LENGTH_SHORT).show(); - return; - } - Builder builder = new AlertDialog.Builder(activity); - String[] names = new String[downloaded.size()]; - for(int i=0; i toInstall = new ArrayList(); - for(int i=0; i entriesMap = osmandSettings.getTileSourceEntries(); - String[] entries = new String[entriesMap.size() + 1]; - String[] values = new String[entriesMap.size() + 1]; - values[0] = VECTOR_MAP; - entries[0] = getString(R.string.vector_data); - int ki = 1; - for(Map.Entry es : entriesMap.entrySet()){ - entries[ki] = es.getValue(); - values[ki] = es.getKey(); - ki++; - } - String value = osmandSettings.isUsingMapVectorData()? VECTOR_MAP : osmandSettings.getMapTileSourceName(); - fill(tileSourcePreference, entries, values, value); - + updateTileSourceSummary(); updateApplicationDirTextAndSummary(); } private void updateTileSourceSummary() { - String mapName = " " + (osmandSettings.isUsingMapVectorData() ? getString(R.string.vector_data) : //$NON-NLS-1$ - osmandSettings.getMapTileSourceName()); + Map entriesMap = osmandSettings.getTileSourceEntries(); + String[] entries = new String[entriesMap.size() + 1]; + String[] values = new String[entriesMap.size() + 1]; + int ki = 0; + for(Map.Entry es : entriesMap.entrySet()){ + entries[ki] = es.getValue(); + values[ki] = es.getKey(); + ki++; + } + entries[ki] = getString(R.string.more_external_layer); + values[ki] = MORE_VALUE; + String value = osmandSettings.getMapTileSourceName(); + fill(tileSourcePreference, entries, values, value); + + String mapName = " " + osmandSettings.getMapTileSourceName(); //$NON-NLS-1$ String summary = tileSourcePreference.getSummary().toString(); if (summary.lastIndexOf(':') != -1) { summary = summary.substring(0, summary.lastIndexOf(':') + 1); @@ -364,6 +369,13 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference OsmandPreference editPref = editTextPreferences.get(preference.getKey()); if(boolPref != null){ boolPref.set((Boolean)newValue); + if (boolPref.getId().equals(osmandSettings.MAP_VECTOR_DATA.getId())) { + MapRenderRepositories r = ((OsmandApplication)getApplication()).getResourceManager().getRenderer(); + if(r.isEmpty()){ + Toast.makeText(this, getString(R.string.no_vector_map_loaded), Toast.LENGTH_LONG).show(); + return false; + } + } } else if (editPref != null) { editPref.set((String) newValue); } else if (listPref != null) { @@ -410,16 +422,22 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } } } else if (preference == tileSourcePreference) { - if(VECTOR_MAP.equals((String) newValue)){ - osmandSettings.setUsingMapVectorData(true); + if(MORE_VALUE.equals(newValue)){ + SettingsActivity.installMapLayers(this, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + updateTileSourceSummary(); + } + }); } else { - osmandSettings.setUsingMapVectorData(false); osmandSettings.setMapTileSource((String) newValue); + updateTileSourceSummary(); } - updateTileSourceSummary(); } return true; } + + private void warnAboutChangingStorage(final String newValue) { final String newDir = newValue != null ? newValue.trim(): newValue; @@ -545,4 +563,55 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } return false; } + + public static void installMapLayers(final Activity activity, final DialogInterface.OnClickListener onClickListener){ + final OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings(); + final Map entriesMap = settings.getTileSourceEntries(); + if(!settings.isInternetConnectionAvailable(true)){ + Toast.makeText(activity, R.string.internet_not_available, Toast.LENGTH_LONG).show(); + return; + } + final List downloaded = TileSourceManager.downloadTileSourceTemplates(); + if(downloaded == null || downloaded.isEmpty()){ + Toast.makeText(activity, R.string.error_io_error, Toast.LENGTH_SHORT).show(); + return; + } + Builder builder = new AlertDialog.Builder(activity); + String[] names = new String[downloaded.size()]; + for(int i=0; i toInstall = new ArrayList(); + for(int i=0; i - + + + + + + + - - - - + + @@ -24,9 +28,13 @@ - - - + + + + + + +