From a3ed18c8df66b7939764ea382d88539aba2ff7a9 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Sun, 14 Feb 2016 12:01:55 +0300 Subject: [PATCH] Added switch on/off map markers to dev settings --- OsmAnd/res/layout-land/map_hud_top.xml | 3 +- OsmAnd/res/layout/map_hud_top.xml | 3 +- OsmAnd/res/values/strings.xml | 2 ++ .../src/net/osmand/plus/OsmandSettings.java | 2 ++ .../plus/activities/MapActivityActions.java | 36 ++++++++++++------- .../plus/activities/MapActivityLayers.java | 13 ++++--- .../SettingsDevelopmentActivity.java | 6 +++- .../plus/mapcontextmenu/MapContextMenu.java | 18 +++++++--- .../MapContextMenuFragment.java | 9 +++-- .../plus/views/PointNavigationLayer.java | 7 ++-- .../views/mapwidgets/MapMarkersWidget.java | 8 +++-- 11 files changed, 75 insertions(+), 32 deletions(-) diff --git a/OsmAnd/res/layout-land/map_hud_top.xml b/OsmAnd/res/layout-land/map_hud_top.xml index 2ab4c0b733..81615ed877 100644 --- a/OsmAnd/res/layout-land/map_hud_top.xml +++ b/OsmAnd/res/layout-land/map_hud_top.xml @@ -10,7 +10,8 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:clickable="true" - android:minHeight="@dimen/map_address_height"> + android:minHeight="@dimen/map_address_height" + android:visibility="gone"> + android:minHeight="@dimen/map_address_height" + android:visibility="gone"> + Map Markers + Activate Map Markers feature Do you want to delete all active markers? Do you want to clear markers history? Active markers diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 15b687c0b8..54d56184fb 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1101,6 +1101,8 @@ public class OsmandSettings { public final OsmandPreference SHOULD_SHOW_FREE_VERSION_BANNER = new BooleanPreference("should_show_free_version_banner", false).makeGlobal().cache(); + public final OsmandPreference USE_MAP_MARKERS = new BooleanPreference("use_map_markers", false).makeGlobal().cache(); + public ITileSource getMapTileSource(boolean warnWhenSelected) { String tileName = MAP_TILE_SOURCES.get(); if (tileName != null) { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index edf051dfa4..8ee3b868b1 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -98,14 +98,14 @@ public class MapActivityActions implements DialogProvider { openIntermediateEditPointsDialog(); } - + */ public void addAsTarget(double latitude, double longitude, PointDescription pd) { TargetPointsHelper targets = getMyApplication().getTargetPointsHelper(); targets.navigateToPoint(new LatLon(latitude, longitude), true, targets.getIntermediatePoints().size() + 1, pd); openIntermediatePointsDialog(); } - */ + public void addMapMarker(double latitude, double longitude, PointDescription pd) { MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper(); @@ -286,7 +286,7 @@ public class MapActivityActions implements DialogProvider { if (getMyApplication().getTargetPointsHelper().getPointToNavigate() != null && (mapActivity.getRoutingHelper().isFollowingMode() || mapActivity.getRoutingHelper().isRoutePlanningMode())) { adapter.item(R.string.context_menu_item_last_intermediate_point).iconColor( - R.drawable.ic_action_flage_dark).reg(); + R.drawable.ic_action_intermediate).reg(); } OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj); @@ -571,15 +571,27 @@ public class MapActivityActions implements DialogProvider { return true; } }).reg(); - optionsMenuHelper.item(R.string.map_markers).iconColor(R.drawable.ic_action_flag_dark) - .listen(new OnContextMenuClick() { - @Override - public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { - MapActivity.clearPrevActivityIntent(); - mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.MAP_MARKERS); - return false; - } - }).reg(); + if (settings.USE_MAP_MARKERS.get()) { + optionsMenuHelper.item(R.string.map_markers).iconColor(R.drawable.ic_action_flag_dark) + .listen(new OnContextMenuClick() { + @Override + public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { + MapActivity.clearPrevActivityIntent(); + mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.MAP_MARKERS); + return false; + } + }).reg(); + } else { + optionsMenuHelper.item(R.string.waypoints).iconColor(R.drawable.ic_action_intermediate) + .listen(new OnContextMenuClick() { + @Override + public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { + MapActivity.clearPrevActivityIntent(); + mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS); + return false; + } + }).reg(); + } optionsMenuHelper.item(R.string.get_directions).iconColor(R.drawable.ic_action_gdirections_dark) .listen(new OnContextMenuClick() { @Override diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index 868e0333b0..25fe948880 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -146,8 +146,10 @@ public class MapActivityLayers { navigationLayer = new PointNavigationLayer(activity); mapView.addLayer(navigationLayer, 7); // 7.3 map markers layer - mapMarkersLayer = new MapMarkersLayer(activity); - mapView.addLayer(mapMarkersLayer, 7.3f); + if (app.getSettings().USE_MAP_MARKERS.get()) { + mapMarkersLayer = new MapMarkersLayer(activity); + mapView.addLayer(mapMarkersLayer, 7.3f); + } // 7.5 Impassible roads impassableRoadsLayer = new ImpassableRoadsLayer(activity); mapView.addLayer(impassableRoadsLayer, 7.5f); @@ -463,8 +465,11 @@ public class MapActivityLayers { public MapControlsLayer getMapControlsLayer() { return mapControlsLayer; } - - + + public MapMarkersLayer getMapMarkersLayer() { + return mapMarkersLayer; + } + public MapTileLayer getMapTileLayer() { return mapTileLayer; } diff --git a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java index 4a0721a4c8..58a2a15ec3 100644 --- a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java @@ -63,7 +63,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity { firstRunPreference.setSummary(R.string.simulate_initial_startup_descr); firstRunPreference.setSelectable(true); firstRunPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override + @Override public boolean onPreferenceClick(Preference preference) { getMyApplication().getAppInitializer().resetFirstTimeRun(); getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.set(false); @@ -77,6 +77,10 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity { R.string.show_free_version_banner, R.string.show_free_version_banner_description)); + cat.addPreference(createCheckBoxPreference(settings.USE_MAP_MARKERS, + R.string.show_map_markers, + R.string.show_map_markers_description)); + Preference pref = new Preference(this); final Preference simulate = pref; final OsmAndLocationSimulation sim = getMyApplication().getLocationProvider().getLocationSimulation(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index ee6ce64fa1..e0433759ea 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -21,6 +21,7 @@ import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.MapActivity; @@ -48,6 +49,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL MapMarkerChangedListener { private MapActivity mapActivity; + private OsmandSettings settings; private MapMultiSelectionMenu mapMultiSelectionMenu; private FavoritePointEditor favoritePointEditor; @@ -81,6 +83,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL public void setMapActivity(MapActivity mapActivity) { this.mapActivity = mapActivity; + settings = mapActivity.getMyApplication().getSettings(); if (!appModeListenerAdded) { mapActivity.getMyApplication().getSettings().APPLICATION_MODE.addListener(this); appModeListenerAdded = true; @@ -500,12 +503,17 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL public void buttonWaypointPressed() { if (pointDescription.isDestination()) { mapActivity.getMapActions().editWaypoints(); - } else if (pointDescription.isMapMarker()) { - hide(); - MapActivity.clearPrevActivityIntent(); - mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAP_MARKERS); + } else if (settings.USE_MAP_MARKERS.get()) { + if (pointDescription.isMapMarker()) { + hide(); + MapActivity.clearPrevActivityIntent(); + mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAP_MARKERS); + } else { + mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(), + getPointDescriptionForTarget()); + } } else { - mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(), + mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(), getPointDescriptionForTarget()); } close(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index f3a6f60b1e..26b1b0a289 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -387,8 +387,13 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { }); final ImageButton buttonWaypoint = (ImageButton) view.findViewById(R.id.context_menu_route_button); - buttonWaypoint.setImageDrawable(iconsCache.getIcon(R.drawable.map_action_flag_dark, - !nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark)); + if (getMyApplication().getSettings().USE_MAP_MARKERS.get()) { + buttonWaypoint.setImageDrawable(iconsCache.getIcon(R.drawable.map_action_flag_dark, + !nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark)); + } else { + buttonWaypoint.setImageDrawable(iconsCache.getIcon(R.drawable.map_action_waypoint, + !nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark)); + } AndroidUtils.setDashButtonBackground(getMapActivity(), buttonWaypoint, nightMode); buttonWaypoint.setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java index 8705d6edcd..849348f046 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java @@ -8,6 +8,7 @@ import android.graphics.Paint; import android.graphics.Paint.Align; import android.graphics.Paint.Style; import android.graphics.PointF; + import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadPoint; @@ -16,7 +17,6 @@ import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; import java.util.Iterator; @@ -79,8 +79,7 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu @Override public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) { - RoutingHelper routingHelper = view.getApplication().getRoutingHelper(); - if (tb.getZoom() < 3 || (!routingHelper.isRoutePlanningMode() && !routingHelper.isFollowingMode())) { + if (tb.getZoom() < 3) { return; } @@ -128,7 +127,7 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu pointToNavigate = it.next(); } if (pointToNavigate != null && !isLocationVisible(tb, pointToNavigate)) { - boolean show = !routingHelper.isRouteCalculated(); + boolean show = !view.getApplication().getRoutingHelper().isRouteCalculated(); if(view.getSettings().SHOW_DESTINATION_ARROW.isSet()) { show = view.getSettings().SHOW_DESTINATION_ARROW.get(); } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidget.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidget.java index 580765c992..8d912cced0 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidget.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidget.java @@ -205,8 +205,12 @@ public class MapMarkersWidget { arrowImg.invalidate(); int dist = (int) mes[0]; - distText.setText(OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication())); - updateVisibility(okButton, dist < MIN_DIST_OK_VISIBLE); + if (loc != null) { + distText.setText(OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication())); + } else { + distText.setText("— " + map.getString(R.string.m)); + } + updateVisibility(okButton, loc != null && dist < MIN_DIST_OK_VISIBLE); String descr; PointDescription pd = marker.getPointDescription(map);