From 25458783c03cc121b4563c3fece54679e672097a Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Thu, 25 Feb 2016 14:28:11 +0300 Subject: [PATCH] Fix https://github.com/osmandapp/Osmand/issues/2276#event-565269829. Fix marker widgets --- .../osmand/plus/activities/MapActivity.java | 4 +- .../net/osmand/plus/views/MapInfoLayer.java | 4 +- .../mapwidgets/MapMarkersWidgetsFactory.java | 144 ++++++------------ .../mapwidgets/RouteInfoWidgetsFactory.java | 17 ++- 4 files changed, 66 insertions(+), 103 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 4e91114006..31ae246b14 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -251,7 +251,9 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents, && !app.getRoutingHelper().isRouteBeingCalculated()) { FailSafeFuntions.restoreRoutingMode(this); } else if (app.getSettings().USE_MAP_MARKERS.get() - && !app.getRoutingHelper().isRoutePlanningMode() && app.getTargetPointsHelper().getAllPoints().size() > 0) { + && !app.getRoutingHelper().isRoutePlanningMode() + && !settings.FOLLOW_THE_ROUTE.get() + && app.getTargetPointsHelper().getAllPoints().size() > 0) { app.getRoutingHelper().clearCurrentRoute(null, new ArrayList()); app.getTargetPointsHelper().removeAllWayPoints(false); } diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index a5b95ccd1b..57457fd1c1 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -124,9 +124,9 @@ public class MapInfoLayer extends OsmandMapLayer { registerSideWidget(time, R.drawable.ic_action_time, R.string.map_widget_time, "time", false, 10); if (settings.USE_MAP_MARKERS.get()) { - TextInfoWidget marker = mwf.createMapMarkerControl(map); + TextInfoWidget marker = mwf.createMapMarkerControl(map, true); registerSideWidget(marker, R.drawable.ic_action_flag_dark, R.string.map_marker_1st, "map_marker_1st", false, 11); - TextInfoWidget marker2nd = mwf.createMapMarkerControl2nd(map); + TextInfoWidget marker2nd = mwf.createMapMarkerControl(map, false); registerSideWidget(marker2nd, R.drawable.ic_action_flag_dark, R.string.map_marker_2nd, "map_marker_2nd", false, 12); } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index a9b2e5761b..43408d94a2 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -12,8 +12,6 @@ import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndFormatter; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.OsmandSettings.MapMarkersMode; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashLocationFragment; @@ -22,6 +20,8 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.MapMarkerDialogHelper; import net.osmand.plus.views.DirectionDrawable; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; +import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory.DistanceToPointInfoControl; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -55,11 +55,7 @@ public class MapMarkersWidgetsFactory { private ImageButton moreButton2nd; private MapMarker marker; - private int markerColorIndex = -1; - private String markerDistText; private MapMarker marker2nd; - private int markerColorIndex2nd = -1; - private String markerDistText2nd; public MapMarkersWidgetsFactory(final MapActivity map) { this.map = map; @@ -281,112 +277,66 @@ public class MapMarkersWidgetsFactory { if (firstLine) { this.marker = marker; - markerColorIndex = marker.colorIndex; - if (txt != null) { - markerDistText = txt; - } } else { this.marker2nd = marker; - markerColorIndex2nd = marker.colorIndex; - if (txt != null) { - markerDistText2nd = txt; - } } } - public TextInfoWidget createMapMarkerControl(final MapActivity map) { - final TextInfoWidget mapMarkerControl = new TextInfoWidget(map) { + public TextInfoWidget createMapMarkerControl(final MapActivity map, final boolean firstMarker) { + DistanceToPointInfoControl ctrl = new DistanceToPointInfoControl(map, 0, 0) { private int cachedMarkerColorIndex = -1; - private String cachedMarkerDistText; @Override - public boolean updateInfo(DrawSettings d) { - if (markerColorIndex != -1 && markerDistText != null) { - boolean res = false; - if (markerColorIndex != cachedMarkerColorIndex) { + public LatLon getPointToNavigate() { + MapMarker marker = getMarker(); + if (marker != null) { + return marker.point; + } + return null; + } + + private MapMarker getMarker() { + List markers = helper.getSortedMapMarkers(); + if (firstMarker) { + if (markers.size() > 0) { + return markers.get(0); + } + } else { + if (markers.size() > 1) { + return markers.get(1); + } + } + return null; + } + + @Override + public boolean updateInfo(DrawSettings drawSettings) { + MapMarker marker = getMarker(); + if (marker == null) { + setText(null, null); + return false; + } + boolean res = super.updateInfo(drawSettings); + + if (marker.colorIndex != -1) { + if (marker.colorIndex != cachedMarkerColorIndex) { setImageDrawable(map.getMyApplication().getIconsCache() .getIcon(R.drawable.widget_marker_day, - MapMarkerDialogHelper.getMapMarkerColorId(markerColorIndex))); - cachedMarkerColorIndex = markerColorIndex; - res = true; + MapMarkerDialogHelper.getMapMarkerColorId(marker.colorIndex))); + cachedMarkerColorIndex = marker.colorIndex; } - if (!markerDistText.equals(cachedMarkerDistText)) { - int ls = markerDistText.lastIndexOf(' '); - if (ls == -1) { - setText(markerDistText, null); - } else { - setText(markerDistText.substring(0, ls), markerDistText.substring(ls + 1)); - } - cachedMarkerDistText = markerDistText; - res = true; - } - return res; - - } else if (cachedMarkerDistText != null) { - cachedMarkerColorIndex = -1; - cachedMarkerDistText = null; - setText(null, null); - return true; } - return false; + return res; + } + + @Override + protected void click(OsmandMapTileView view) { + showMarkerOnMap(firstMarker ? 0 : 1); } }; - mapMarkerControl.setText(null, null); - mapMarkerControl.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - showMarkerOnMap(0); - } - }); - return mapMarkerControl; - } - - public TextInfoWidget createMapMarkerControl2nd(final MapActivity map) { - final TextInfoWidget mapMarkerControl = new TextInfoWidget(map) { - private int cachedMarkerColorIndex = -1; - private String cachedMarkerDistText; - - @Override - public boolean updateInfo(DrawSettings d) { - if (markerColorIndex2nd != -1 && markerDistText2nd != null) { - boolean res = false; - if (markerColorIndex2nd != cachedMarkerColorIndex) { - setImageDrawable(map.getMyApplication().getIconsCache() - .getIcon(R.drawable.widget_marker_day, - MapMarkerDialogHelper.getMapMarkerColorId(markerColorIndex2nd))); - cachedMarkerColorIndex = markerColorIndex2nd; - res = true; - } - if (!markerDistText2nd.equals(cachedMarkerDistText)) { - int ls = markerDistText2nd.lastIndexOf(' '); - if (ls == -1) { - setText(markerDistText2nd, null); - } else { - setText(markerDistText2nd.substring(0, ls), markerDistText2nd.substring(ls + 1)); - } - cachedMarkerDistText = markerDistText2nd; - res = true; - } - return res; - - } else if (cachedMarkerDistText != null) { - cachedMarkerColorIndex = -1; - cachedMarkerDistText = null; - setText(null, null); - return true; - } - return false; - } - }; - mapMarkerControl.setText(null, null); - mapMarkerControl.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - showMarkerOnMap(1); - } - }); - return mapMarkerControl; + ctrl.setAutoHide(false); + return ctrl; } public boolean isLandscapeLayout() { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index b89b255e68..831a870c94 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -385,11 +385,14 @@ public class RouteInfoWidgetsFactory { private final OsmandMapTileView view; private float[] calculations = new float[1]; private int cachedMeters; + private boolean autoHide = true; public DistanceToPointInfoControl(MapActivity ma, int res, int resNight) { super(ma); this.view = ma.getMapView(); - setIcons(res, resNight); + if (res != 0 && resNight != 0) { + setIcons(res, resNight); + } setText(null, null); setOnClickListener(new View.OnClickListener() { @@ -399,7 +402,15 @@ public class RouteInfoWidgetsFactory { } }); } - + + public boolean isAutoHide() { + return autoHide; + } + + public void setAutoHide(boolean autoHide) { + this.autoHide = autoHide; + } + protected void click(final OsmandMapTileView view) { AnimateDraggingMapThread thread = view.getAnimatedDraggingThread(); LatLon pointToNavigate = getPointToNavigate(); @@ -414,7 +425,7 @@ public class RouteInfoWidgetsFactory { int d = getDistance(); if (distChanged(cachedMeters, d)) { cachedMeters = d; - if (cachedMeters <= 20) { + if (autoHide && cachedMeters <= 20) { cachedMeters = 0; setText(null, null); } else {