diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index b03c4b7773..d607a3676d 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -8,6 +8,9 @@
If you are making/correcting english translations make sure :
1. All your modified/created strings are in the top of the file (to make easier find what's translated).
-->
+ Enable online maps plugin to select different map sources
+ Online maps
+ Use online maps (download and save them on sdcard)
Online Map
Configure online or cached tile map sources
- Map Settings
@@ -442,8 +445,6 @@
None
Overlay map
Choose overlay map
- Offline vector maps
- Use downloaded vector maps
Map is already installed, settings will be updated
Select (tile) maps to install or update
Internet connection required for operation is not available
diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java
index f589f7d20f..e5f1354f89 100644
--- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java
+++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java
@@ -1,15 +1,17 @@
package net.osmand.plus;
+import gnu.trove.list.array.TIntArrayList;
+
import java.util.ArrayList;
-import gnu.trove.list.array.TIntArrayList;
import android.content.Context;
+import android.content.DialogInterface;
public class ContextMenuAdapter {
public interface OnContextMenuClick {
- public void onContextMenuClick(int itemId, int pos, boolean isChecked);
+ public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog);
}
private final Context ctx;
diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java
index 0cdbfb84ad..91de332b0c 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java
@@ -58,22 +58,6 @@ public abstract class OsmandPlugin {
installedPlugins.add(new OsmandDevelopmentPlugin(app));
Set enabledPlugins = settings.getEnabledPlugins();
- // update special plugin state
- if (!enabledPlugins.contains(rasterMapsPlugin.getId())) {
- if (settings.MAP_VECTOR_DATA.get()) {
- if(settings.MAP_OVERLAY.get() != null) {
- settings.MAP_OVERLAY.set(null);
- }
- if(settings.MAP_UNDERLAY.get() != null) {
- settings.MAP_UNDERLAY.set(null);
- }
- } else {
- settings.enablePlugin(rasterMapsPlugin.getId(), true);
- enabledPlugins = settings.getEnabledPlugins();
- }
- }
-
-
for (OsmandPlugin plugin : installedPlugins) {
if (enabledPlugins.contains(plugin.getId())) {
try {
@@ -101,10 +85,7 @@ public abstract class OsmandPlugin {
return true;
}
- /**
- * ????
- */
- public void updateLayers(OsmandMapTileView mapView) {};
+ public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {};
public abstract void registerLayers(MapActivity activity);
@@ -122,13 +103,13 @@ public abstract class OsmandPlugin {
public void settingsActivityUpdate(final SettingsActivity activity){}
- public void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter) {}
+ public void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter, MapActivity mapActivity) {}
public void registerMapContextMenuActions(MapActivity mapActivity, double latitude, double longitude, ContextMenuAdapter adapter, Object selectedObj) {}
- public static void refreshLayers(OsmandMapTileView mapView) {
+ public static void refreshLayers(OsmandMapTileView mapView, MapActivity activity) {
for (OsmandPlugin plugin : activePlugins) {
- plugin.updateLayers(mapView);
+ plugin.updateLayers(mapView, activity);
}
}
@@ -206,9 +187,9 @@ public abstract class OsmandPlugin {
}
}
- public static void registerLayerContextMenu(OsmandMapTileView mapView, ContextMenuAdapter adapter) {
+ public static void registerLayerContextMenu(OsmandMapTileView mapView, ContextMenuAdapter adapter, MapActivity mapActivity) {
for (OsmandPlugin plugin : activePlugins) {
- plugin.registerLayerContextMenuActions(mapView, adapter);
+ plugin.registerLayerContextMenuActions(mapView, adapter, mapActivity);
}
}
diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java
index 71aad41898..86db3c3ac7 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java
@@ -684,24 +684,24 @@ public class OsmandSettings {
}
// this value string is synchronized with settings_pref.xml preference name
- public final CommonPreference MAP_VECTOR_DATA = new BooleanPreference("map_vector_data",
- true, false);
+ public final CommonPreference MAP_ONLINE_DATA = new BooleanPreference("map_online_data",
+ false, true);
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference MAP_OVERLAY = new StringPreference("map_overlay",
- null, false);
+ null, true);
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference MAP_UNDERLAY = new StringPreference("map_underlay",
- null, false);
+ null, true);
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference MAP_OVERLAY_TRANSPARENCY = new IntPreference("overlay_transparency",
- 200, false);
+ 200, true);
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference MAP_TRANSPARENCY = new IntPreference("map_transparency",
- 255, false);
+ 255, true);
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference MAP_TILE_SOURCES = new StringPreference("map_tile_sources",
diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java
index 9842cc144d..9d1c7764dd 100644
--- a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java
@@ -620,11 +620,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
if (vectorMapsToReindex) {
ResourceManager manager = getMyApplication().getResourceManager();
List warnings = manager.indexingMaps(progress);
- if (warnings.isEmpty() && !settings.MAP_VECTOR_DATA.get()) {
- warnings.add(getString(R.string.binary_map_download_success));
- // Is it proper way to switch every tome to vector data?
- settings.MAP_VECTOR_DATA.set(true);
- }
if (!warnings.isEmpty()) {
return warnings.get(0);
}
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
index e3703f7899..c3e180ce90 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
@@ -164,16 +164,6 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
startProgressDialog = new ProgressDialog(this);
startProgressDialog.setCancelable(true);
((OsmandApplication) getApplication()).checkApplicationIsBeingInitialized(this, startProgressDialog);
- // Do some action on close
- startProgressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- OsmandApplication app = ((OsmandApplication) getApplication());
- if (settings.MAP_VECTOR_DATA.get() && app.getResourceManager().getRenderer().isEmpty()) {
- AccessibleToast.makeText(MapActivity.this, getString(R.string.no_vector_map_loaded), Toast.LENGTH_LONG).show();
- }
- }
- });
parseLaunchIntentLocation();
mapView = (OsmandMapTileView) findViewById(R.id.MapView);
@@ -183,7 +173,14 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
showAndHideMapPosition();
return MapActivity.this.onTrackballEvent(e);
}
-
+ });
+
+ // Do some action on close
+ startProgressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ mapView.refreshMap();
+ }
});
getMyApplication().getResourceManager().getMapTileDownloader().addDownloaderCallback(new IMapDownloaderCallback(){
@@ -260,7 +257,6 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
- mapLayers.updateMapSource(mapView, null);
updateApplicationModeSettings();
mapLayers.getPoiMapLayer().setFilter(settings.getPoiFilterForMap((OsmandApplication) getApplication()));
@@ -1001,7 +997,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
registerUnregisterSensor(getLastKnownLocation());
mapLayers.getMapInfoLayer().applyTheme();
mapLayers.updateLayers(mapView);
- mapLayers.updateMapSource(mapView, settings.MAP_TILE_SOURCES);
+
getMyApplication().getDaynightHelper().setDayNightMode(settings.DAYNIGHT_MODE.get());
}
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
index 67377c6c15..68e0688652 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
@@ -200,7 +200,7 @@ public class MapActivityActions implements DialogProvider {
return b.create();
}
- protected void addWaypoint(final double latitude, final double longitude){
+ public void addWaypoint(final double latitude, final double longitude){
String name = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName();
enhance(dialogBundle,latitude,longitude, name);
mapActivity.showDialog(DIALOG_ADD_WAYPOINT);
@@ -234,58 +234,13 @@ public class MapActivityActions implements DialogProvider {
return builder.create();
}
- protected void reloadTile(final int zoom, final double latitude, final double longitude){
+ public void reloadTile(final int zoom, final double latitude, final double longitude){
enhance(dialogBundle,latitude,longitude,zoom);
mapActivity.showDialog(DIALOG_RELOAD_TITLE);
}
- private Dialog createReloadTitleDialog(final Bundle args) {
- Builder builder = new AccessibleAlertBuilder(mapActivity);
- builder.setMessage(R.string.context_menu_item_update_map_confirm);
- builder.setNegativeButton(R.string.default_buttons_cancel, null);
- final OsmandMapTileView mapView = mapActivity.getMapView();
- builder.setPositiveButton(R.string.context_menu_item_update_map, new DialogInterface.OnClickListener(){
- @Override
- public void onClick(DialogInterface dialog, int which) {
- int zoom = args.getInt(KEY_ZOOM);
- BaseMapLayer mainLayer = mapView.getMainLayer();
- if(!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()){
- AccessibleToast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
- return;
- }
- final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
- if(mapSource == null || !mapSource.couldBeDownloadedFromInternet()){
- AccessibleToast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
- return;
- }
- Rect pixRect = new Rect(0, 0, mapView.getWidth(), mapView.getHeight());
- RectF tilesRect = new RectF();
- mapView.calculateTileRectangle(pixRect, mapView.getCenterPointX(), mapView.getCenterPointY(),
- mapView.getXTile(), mapView.getYTile(), tilesRect);
- int left = (int) FloatMath.floor(tilesRect.left);
- int top = (int) FloatMath.floor(tilesRect.top);
- int width = (int) (FloatMath.ceil(tilesRect.right) - left);
- int height = (int) (FloatMath.ceil(tilesRect.bottom) - top);
- for (int i = 0; i preference, float layerOrder, boolean warnWhenSelected) {
- ITileSource overlay = settings.getTileSourceByName(preference.get(), warnWhenSelected);
- if(!Algoritms.objectEquals(overlay, layer.getMap())){
- if(overlay == null){
- mapView.removeLayer(layer);
- } else {
- mapView.addLayer(layer, layerOrder);
- }
- layer.setMap(overlay);
- mapView.refreshMap();
- }
- }
public void openLayerSelectionDialog(final OsmandMapTileView mapView){
final OsmandSettings settings = getApplication().getSettings();
final ContextMenuAdapter adapter = new ContextMenuAdapter(activity);
- adapter.registerSelectedItem(R.string.layer_map, -1, R.drawable.list_activities_map_src);
adapter.registerSelectedItem(R.string.layer_poi, settings.SHOW_POI_OVER_MAP.get() ? 1 : 0,
R.drawable.list_activities_poi);
adapter.registerSelectedItem(R.string.layer_poi_label, settings.SHOW_POI_LABEL.get() ? 1 : 0,
@@ -270,12 +240,7 @@ public class MapActivityLayers {
}
- adapter.registerSelectedItem(R.string.layer_overlay, overlayLayer.getMap() != null ? 1 : 0,
- R.drawable.list_activities_overlay_map);
- adapter.registerSelectedItem(R.string.layer_underlay, underlayLayer.getMap() != null ? 1 : 0,
- R.drawable.list_activities_underlay_map);
-
- OsmandPlugin.registerLayerContextMenu(mapView, adapter);
+ OsmandPlugin.registerLayerContextMenu(mapView, adapter, activity);
final OnMultiChoiceClickListener listener = new DialogInterface.OnMultiChoiceClickListener() {
@@ -284,10 +249,7 @@ public class MapActivityLayers {
int itemId = adapter.getItemId(item);
OnContextMenuClick clck = adapter.getClickAdapter(item);
if(clck != null) {
- clck.onContextMenuClick(itemId, item, isChecked);
- } else if (itemId == R.string.layer_map) {
- dialog.dismiss();
- selectMapLayer(mapView);
+ clck.onContextMenuClick(itemId, item, isChecked, dialog);
} else if(itemId == R.string.layer_poi){
if(isChecked){
selectPOIFilterLayer(mapView);
@@ -311,24 +273,6 @@ public class MapActivityLayers {
transportInfoLayer.setVisible(isChecked);
} else if(itemId == R.string.layer_transport){
settings.SHOW_TRANSPORT_OVER_MAP.set(isChecked);
- } else if(itemId == R.string.layer_overlay){
- if(overlayLayer.getMap() != null){
- settings.MAP_OVERLAY.set(null);
- updateMapSource(mapView, null);
- } else {
- dialog.dismiss();
- selectMapOverlayLayer(mapView, settings.MAP_OVERLAY, settings.MAP_OVERLAY_TRANSPARENCY,
- overlayLayer);
- }
- } else if(itemId == R.string.layer_underlay){
- if(underlayLayer.getMap() != null){
- settings.MAP_UNDERLAY.set(null);
- updateMapSource(mapView, null);
- } else {
- dialog.dismiss();
- selectMapOverlayLayer(mapView, settings.MAP_UNDERLAY,settings.MAP_TRANSPARENCY,
- mapTileLayer, mapVectorLayer);
- }
}
updateLayers(mapView);
mapView.refreshMap();
@@ -561,10 +505,15 @@ public class MapActivityLayers {
}
public void selectMapLayer(final OsmandMapTileView mapView){
+ if(OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) {
+ AccessibleToast.makeText(activity, R.string.map_online_plugin_is_not_installed, Toast.LENGTH_LONG).show();
+ return;
+ }
final OsmandSettings settings = getApplication().getSettings();
final LinkedHashMap entriesMap = new LinkedHashMap();
+
final String layerOsmVector = "LAYER_OSM_VECTOR";
final String layerInstallMore = "LAYER_INSTALL_MORE";
@@ -579,7 +528,7 @@ public class MapActivityLayers {
String selectedTileSourceKey = settings.MAP_TILE_SOURCES.get();
int selectedItem = -1;
- if (settings.MAP_VECTOR_DATA.get()) {
+ if (!settings.MAP_ONLINE_DATA.get()) {
selectedItem = 0;
} else {
@@ -608,13 +557,7 @@ public class MapActivityLayers {
public void onClick(DialogInterface dialog, int which) {
String layerKey = entriesMapList.get(which).getKey();
if (layerKey.equals(layerOsmVector)) {
- MapRenderRepositories r = ((OsmandApplication) getApplication()).getResourceManager().getRenderer();
- if (r.isEmpty()) {
- AccessibleToast.makeText(activity, getString(R.string.no_vector_map_loaded), Toast.LENGTH_LONG).show();
- return;
- } else {
- settings.MAP_VECTOR_DATA.set(true);
- }
+ settings.MAP_ONLINE_DATA.set(false);
updateMapSource(mapView, null);
} else if (layerKey.equals(layerInstallMore)) {
SettingsActivity.installMapLayers(activity, new ResultMatcher() {
@@ -625,7 +568,7 @@ public class MapActivityLayers {
if(object == null){
if(count == 1){
settings.MAP_TILE_SOURCES.set(template.getName());
- settings.MAP_VECTOR_DATA.set(false);
+ settings.MAP_ONLINE_DATA.set(true);
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
} else {
selectMapLayer(mapView);
@@ -644,7 +587,7 @@ public class MapActivityLayers {
});
} else {
settings.MAP_TILE_SOURCES.set(layerKey);
- settings.MAP_VECTOR_DATA.set(false);
+ settings.MAP_ONLINE_DATA.set(true);
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
}
@@ -655,62 +598,6 @@ public class MapActivityLayers {
builder.show();
}
- private void selectMapOverlayLayer(final OsmandMapTileView mapView,
- final CommonPreference mapPref, final CommonPreference transparencyPref,
- final BaseMapLayer... transparencyToChange){
- final OsmandSettings settings = getApplication().getSettings();
- Map entriesMap = settings.getTileSourceEntries();
- final ArrayList keys = new ArrayList(entriesMap.keySet());
- Builder builder = new AlertDialog.Builder(activity);
- final String[] items = new String[entriesMap.size() + 1];
- int i = 0;
- for(String it : entriesMap.values()){
- items[i++] = it;
- }
-
- items[i] = getString(R.string.install_more);
- builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener(){
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (which == items.length - 1){
- SettingsActivity.installMapLayers(activity, new ResultMatcher() {
- TileSourceTemplate template = null;
- int count = 0;
- @Override
- public boolean publish(TileSourceTemplate object) {
- if(object == null){
- if(count == 1){
- mapPref.set(template.getName());
- mapControlsLayer.showAndHideTransparencyBar(transparencyPref, transparencyToChange);
- updateMapSource(mapView, mapPref);
- } else {
- selectMapOverlayLayer(mapView, mapPref, transparencyPref, transparencyToChange);
- }
- } else {
- count ++;
- template = object;
- }
- return false;
- }
-
- @Override
- public boolean isCancelled() {
- return false;
- }
- });
- } else {
- mapPref.set(keys.get(which));
- mapControlsLayer.showAndHideTransparencyBar(transparencyPref, transparencyToChange);
- updateMapSource(mapView, mapPref);
- }
-
- dialog.dismiss();
- }
-
- });
- builder.show();
- }
-
private String getString(int resId) {
return activity.getString(resId);
@@ -739,6 +626,18 @@ public class MapActivityLayers {
return mapInfoLayer;
}
+ public MapControlsLayer getMapControlsLayer() {
+ return mapControlsLayer;
+ }
+
+ public MapTileLayer getMapTileLayer() {
+ return mapTileLayer;
+ }
+
+ public MapVectorLayer getMapVectorLayer() {
+ return mapVectorLayer;
+ }
+
public POIMapLayer getPoiMapLayer() {
return poiMapLayer;
}
diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java
index 64a67eace1..36603ca11a 100644
--- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java
@@ -1,15 +1,18 @@
package net.osmand.plus.monitoring;
+import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R;
+import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.activities.ApplicationMode;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsActivity;
import android.app.ProgressDialog;
+import android.content.DialogInterface;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
@@ -49,6 +52,20 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
public void registerLayers(MapActivity activity) {
}
+ @Override
+ public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter,
+ Object selectedObj) {
+ OnContextMenuClick listener = new OnContextMenuClick() {
+ @Override
+ public void onContextMenuClick(int resId, int pos, boolean isChecked, DialogInterface dialog) {
+ if (resId == R.string.context_menu_item_add_waypoint) {
+ mapActivity.getMapActions().addWaypoint(latitude, longitude);
+ }
+ }
+ };
+ adapter.registerItem(R.string.context_menu_item_add_waypoint, 0, listener, -1);
+ }
+
@Override
public void settingsActivityCreate(final SettingsActivity activity, PreferenceScreen screen) {
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java
index 704f1c61a7..f8532f51fd 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java
@@ -457,7 +457,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
OnContextMenuClick listener = new OnContextMenuClick() {
@Override
- public void onContextMenuClick(int itemId, int pos, boolean isChecked) {
+ public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
if (itemId == R.string.osb_comment_menu_item) {
commentBug(bug);
} else if (itemId == R.string.osb_close_menu_item) {
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java
index b4b7b7e9c7..a70dc714d0 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java
@@ -1,5 +1,6 @@
package net.osmand.plus.osmedit;
+import android.content.DialogInterface;
import android.content.Intent;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
@@ -43,7 +44,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
private EditingPOIActivity poiActions;
@Override
- public void updateLayers(OsmandMapTileView mapView){
+ public void updateLayers(OsmandMapTileView mapView, MapActivity activity){
if(mapView.getLayers().contains(osmBugsLayer) != settings.SHOW_OSM_BUGS.get()){
if(settings.SHOW_OSM_BUGS.get()){
mapView.addLayer(osmBugsLayer, 2);
@@ -108,7 +109,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
OnContextMenuClick alist = new OnContextMenuClick() {
@Override
- public void onContextMenuClick(int resId, int pos, boolean isChecked) {
+ public void onContextMenuClick(int resId, int pos, boolean isChecked, DialogInterface dialog) {
if (resId == R.string.poi_context_menu_delete) {
getPoiActions().showDeleteDialog(a);
} else if (resId == R.string.poi_context_menu_modify) {
@@ -122,7 +123,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
OnContextMenuClick listener = new OnContextMenuClick() {
@Override
- public void onContextMenuClick(int resId, int pos, boolean isChecked) {
+ public void onContextMenuClick(int resId, int pos, boolean isChecked, DialogInterface dialog) {
if (resId == R.string.context_menu_item_create_poi) {
poiActions.showCreateDialog(latitude, longitude);
} else if (resId == R.string.context_menu_item_open_bug) {
@@ -135,12 +136,12 @@ public class OsmEditingPlugin extends OsmandPlugin {
}
@Override
- public void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter) {
+ public void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter, MapActivity mapActivity) {
adapter.registerSelectedItem(R.string.layer_osm_bugs, settings.SHOW_OSM_BUGS.get() ? 1 : 0, R.drawable.list_activities_osm_bugs,
new OnContextMenuClick() {
@Override
- public void onContextMenuClick(int itemId, int pos, boolean isChecked) {
+ public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
if (itemId == R.string.layer_osm_bugs) {
settings.SHOW_OSM_BUGS.set(isChecked);
}
diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java
index c4cc5bf965..98e952d531 100644
--- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java
@@ -1,16 +1,30 @@
package net.osmand.plus.rastermaps;
+import java.util.ArrayList;
import java.util.Map;
+import net.osmand.Algoritms;
import net.osmand.ResultMatcher;
+import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager.TileSourceTemplate;
+import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
+import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
+import net.osmand.plus.OsmandSettings.CommonPreference;
+import net.osmand.plus.activities.DownloadTilesDialog;
import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.activities.SettingsActivity;
+import net.osmand.plus.views.BaseMapLayer;
+import net.osmand.plus.views.MapTileLayer;
+import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.SeekBarPreference;
+import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
+import android.content.DialogInterface;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
@@ -27,6 +41,9 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
private ListPreference overlayPreference;
private ListPreference underlayPreference;
+ private MapTileLayer overlayLayer;
+ private MapTileLayer underlayLayer;
+
public OsmandRasterMapsPlugin(OsmandApplication app) {
this.app = app;
}
@@ -51,6 +68,154 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
}
@Override
public void registerLayers(MapActivity activity) {
+ underlayLayer = new MapTileLayer(false);
+ // mapView.addLayer(underlayLayer, -0.5f);
+ overlayLayer = new MapTileLayer(false);
+ // mapView.addLayer(overlayLayer, 0.7f);
+ }
+
+ @Override
+ public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
+ updateMapLayers(mapView, null, activity.getMapLayers());
+ }
+
+
+ public void updateMapLayers(OsmandMapTileView mapView, CommonPreference settingsToWarnAboutMap,
+ final MapActivityLayers layers) {
+ overlayLayer.setAlpha(settings.MAP_OVERLAY_TRANSPARENCY.get());
+ updateLayer(mapView, settings, overlayLayer, settings.MAP_OVERLAY, 0.7f, settings.MAP_OVERLAY == settingsToWarnAboutMap);
+ updateLayer(mapView, settings, underlayLayer, settings.MAP_UNDERLAY, -0.5f, settings.MAP_UNDERLAY == settingsToWarnAboutMap);
+ layers.updateMapSource(mapView, settingsToWarnAboutMap);
+ }
+
+ public void updateLayer(OsmandMapTileView mapView, OsmandSettings settings,
+ MapTileLayer layer, CommonPreference preference, float layerOrder, boolean warnWhenSelected) {
+ ITileSource overlay = settings.getTileSourceByName(preference.get(), warnWhenSelected);
+ if(!Algoritms.objectEquals(overlay, layer.getMap())){
+ if(overlay == null){
+ mapView.removeLayer(layer);
+ } else {
+ mapView.addLayer(layer, layerOrder);
+ }
+ layer.setMap(overlay);
+ mapView.refreshMap();
+ }
+ }
+
+ public void selectMapOverlayLayer(final OsmandMapTileView mapView,
+ final CommonPreference mapPref, final CommonPreference transparencyPref,
+ final MapActivity activity,
+ final BaseMapLayer... transparencyToChange){
+ final OsmandSettings settings = app.getSettings();
+ final MapActivityLayers layers = activity.getMapLayers();
+ Map entriesMap = settings.getTileSourceEntries();
+ final ArrayList keys = new ArrayList(entriesMap.keySet());
+ Builder builder = new AlertDialog.Builder(activity);
+ final String[] items = new String[entriesMap.size() + 1];
+ int i = 0;
+ for(String it : entriesMap.values()){
+ items[i++] = it;
+ }
+
+ items[i] = app.getString(R.string.install_more);
+ builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener(){
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (which == items.length - 1){
+ SettingsActivity.installMapLayers(activity, new ResultMatcher() {
+ TileSourceTemplate template = null;
+ int count = 0;
+ @Override
+ public boolean publish(TileSourceTemplate object) {
+ if(object == null){
+ if(count == 1){
+ mapPref.set(template.getName());
+ layers.getMapControlsLayer().showAndHideTransparencyBar(transparencyPref, transparencyToChange);
+ updateMapLayers(mapView, mapPref, layers);
+ } else {
+ selectMapOverlayLayer(mapView, mapPref, transparencyPref, activity, transparencyToChange);
+ }
+ } else {
+ count ++;
+ template = object;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return false;
+ }
+ });
+ } else {
+ mapPref.set(keys.get(which));
+ layers.getMapControlsLayer().showAndHideTransparencyBar(transparencyPref, transparencyToChange);
+ updateMapLayers(mapView, mapPref, layers);
+ }
+ dialog.dismiss();
+ }
+
+ });
+ builder.show();
+ }
+
+ @Override
+ public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
+ final MapActivityLayers layers = mapActivity.getMapLayers();
+ OnContextMenuClick listener = new OnContextMenuClick() {
+ @Override
+ public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
+ if (itemId == R.string.layer_map) {
+ dialog.dismiss();
+ layers.selectMapLayer(mapView);
+ } else if(itemId == R.string.layer_overlay){
+ if(overlayLayer.getMap() != null){
+ settings.MAP_OVERLAY.set(null);
+ updateMapLayers(mapView, null, layers);
+ } else {
+ dialog.dismiss();
+ selectMapOverlayLayer(mapView, settings.MAP_OVERLAY, settings.MAP_OVERLAY_TRANSPARENCY, mapActivity,
+ overlayLayer);
+ }
+ } else if(itemId == R.string.layer_underlay){
+ if(underlayLayer.getMap() != null){
+ settings.MAP_UNDERLAY.set(null);
+ updateMapLayers(mapView, null, layers);
+ } else {
+ dialog.dismiss();
+ selectMapOverlayLayer(mapView, settings.MAP_UNDERLAY,settings.MAP_TRANSPARENCY,
+ mapActivity, layers.getMapTileLayer(), layers.getMapVectorLayer());
+ }
+ }
+ }
+ };
+ adapter.registerSelectedItem(R.string.layer_map, -1, R.drawable.list_activities_map_src, listener, 0);
+ adapter.registerSelectedItem(R.string.layer_overlay, overlayLayer.getMap() != null ? 1 : 0,
+ R.drawable.list_activities_overlay_map, listener, -1);
+ adapter.registerSelectedItem(R.string.layer_underlay, underlayLayer.getMap() != null ? 1 : 0,
+ R.drawable.list_activities_underlay_map, listener, -1);
+ }
+
+
+ @Override
+ public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter,
+ Object selectedObj) {
+ final OsmandMapTileView mapView = mapActivity.getMapView();
+ if (mapView.getMainLayer() instanceof MapTileLayer) {
+ OnContextMenuClick listener = new OnContextMenuClick() {
+ @Override
+ public void onContextMenuClick(int resId, int pos, boolean isChecked, DialogInterface dialog) {
+ if (resId == R.string.context_menu_item_update_map) {
+ mapActivity.getMapActions().reloadTile(mapView.getZoom(), latitude, longitude);
+ } else if (resId == R.string.context_menu_item_download_map) {
+ DownloadTilesDialog dlg = new DownloadTilesDialog(mapActivity, (OsmandApplication) mapActivity.getApplication(), mapView);
+ dlg.openDialog();
+ }
+ }
+ };
+ adapter.registerItem(R.string.context_menu_item_update_map, 0, listener, -1);
+ adapter.registerItem(R.string.context_menu_item_download_map, 0, listener, -1);
+ }
}
@Override
@@ -76,7 +241,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
cat.setTitle(R.string.pref_raster_map);
grp.addPreference(cat);
- CheckBoxPreference mapVectorData = activity.createCheckBoxPreference(settings.MAP_VECTOR_DATA,
+ CheckBoxPreference mapVectorData = activity.createCheckBoxPreference(settings.MAP_ONLINE_DATA,
R.string.map_vector_data, R.string.map_vector_data_descr);
// final OnPreferenceChangeListener parent = mapVectorData.getOnPreferenceChangeListener();
// MapRenderRepositories r = app.getResourceManager().getRenderer();
diff --git a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java
index ead6fd1b7b..65b1c10040 100644
--- a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java
+++ b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java
@@ -110,7 +110,8 @@ public class MapVectorLayer extends BaseMapLayer {
}
- private void drawRenderedMap(Canvas canvas, Bitmap bmp, RotatedTileBox bmpLoc) {
+ private boolean drawRenderedMap(Canvas canvas, Bitmap bmp, RotatedTileBox bmpLoc) {
+ boolean shown = false;
if (bmp != null && bmpLoc != null) {
float rot = bmpLoc.getRotate();
float mult = (float) MapUtils.getPowZoom(view.getZoom() - bmpLoc.getZoom());
@@ -131,9 +132,11 @@ public class MapVectorLayer extends BaseMapLayer {
* view.getTileSize());
if(!bmp.isRecycled()){
canvas.drawBitmap(bmp, null, destImage, paintImg);
+ shown = true;
}
canvas.rotate(rot, view.getCenterPointX(), view.getCenterPointY());
}
+ return shown;
}
diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java
index 6625112840..5fb6878f53 100644
--- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java
+++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java
@@ -21,6 +21,7 @@ import net.osmand.plus.render.RenderingIcons;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@@ -302,7 +303,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
final Amenity a = (Amenity) o;
OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
@Override
- public void onContextMenuClick(int itemId, int pos, boolean isChecked) {
+ public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
if (itemId == R.string.poi_context_menu_call) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);