diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 2a38b8c96d..93f0103367 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -15,7 +15,6 @@ import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; -import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -415,13 +414,10 @@ public class MapMarkersHelper { for (MapMarker marker : markers) { if (marker.id.equals(group.getId() + name)) { exists = true; - int colorIndex = MapMarker.getColorIndex(ctx, ColorDialogs.getNearestColor(group.getColor(), MapMarker.getColors(ctx))); - boolean updateColor = group.getColor() != -1 && marker.colorIndex != colorIndex; - if (!marker.history && (!marker.point.equals(latLon) || updateColor)) { + if (!marker.history && (!marker.point.equals(latLon))) { for (MapMarker m : mapMarkers) { if (m.id.equals(marker.id)) { m.point = latLon; - m.colorIndex = colorIndex; updateMapMarker(m, true); break; } @@ -641,8 +637,7 @@ public class MapMarkersHelper { private void addMarkers(List points, List historyNames, @Nullable MarkersSyncGroup group) { if (points.size() > 0) { - boolean randomColor = group == null || group.getColor() == -1; - int colorIndex = randomColor ? -1 : MapMarker.getColorIndex(ctx, ColorDialogs.getNearestColor(group.getColor(), MapMarker.getColors(ctx))); + int colorIndex = -1; for (int i = 0; i < points.size(); i++) { LatLon point = points.get(i); PointDescription historyName = historyNames.get(i); @@ -655,16 +650,14 @@ public class MapMarkersHelper { if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) { pointDescription.setName(PointDescription.getSearchAddressStr(ctx)); } - if (randomColor) { - if (colorIndex == -1) { - if (mapMarkers.size() > 0) { - colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; - } else { - colorIndex = 0; - } + if (colorIndex == -1) { + if (mapMarkers.size() > 0) { + colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; } else { - colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; + colorIndex = 0; } + } else { + colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; } MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0); diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index d07a2b40d4..ad96b84af6 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -38,6 +38,7 @@ import android.location.LocationManager; import android.os.Build; import android.os.Bundle; import android.provider.Settings; +import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AlertDialog; import android.util.Log; @@ -69,11 +70,14 @@ public class OsmAndLocationProvider implements SensorEventListener { private static final int GPS_DIST_REQUEST = 0; private static final int NOT_SWITCH_TO_NETWORK_WHEN_GPS_LOST_MS = 12000; - private static final long STALE_LOCATION_TIMEOUT = 1000 * 60 * 60; // 60 minutes - public static final long STALE_LOCATION_TIMEOUT_FOR_ICON = 1000 * 60 * 5; // 5 minutes + private static final long STALE_LOCATION_TIMEOUT = 1000 * 60 * 5; // 5 minutes + private static final long STALE_LOCATION_TIMEOUT_FOR_UI = 1000 * 60 * 15; // 15 minutes private static final int UPDATES_BEFORE_CHECK_LOCATION = 100; private int updatesCounter; + private int updatesCounterUi; + + private net.osmand.Location cachedLocation; private long lastTimeGPSLocationFixed = 0; private boolean gpsSignalLost; @@ -877,6 +881,26 @@ public class OsmAndLocationProvider implements SensorEventListener { return location; } + @Nullable + public net.osmand.Location getLastStaleKnownLocation() { + if (updatesCounterUi == 0) { + net.osmand.Location newLoc = getLastKnownLocation(); + if (newLoc == null) { + if (cachedLocation != null && System.currentTimeMillis() - cachedLocation.getTime() > STALE_LOCATION_TIMEOUT_FOR_UI) { + cachedLocation = null; + } + } else { + cachedLocation = newLoc; + } + } + if (updatesCounterUi == UPDATES_BEFORE_CHECK_LOCATION) { + updatesCounterUi = 0; + } else { + updatesCounterUi++; + } + return cachedLocation; + } + public void showNavigationInfo(TargetPoint pointToNavigate, Context uiActivity) { getNavigationInfo().show(pointToNavigate, getHeading(), uiActivity); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java index 7c84e30f85..a7d10456db 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -90,29 +90,31 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra ((TextView) mainView.findViewById(R.id.show_direction_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); } - CompoundButton showArrowsToggle = (CompoundButton) mainView.findViewById(R.id.show_arrows_switch); + final CompoundButton showArrowsToggle = (CompoundButton) mainView.findViewById(R.id.show_arrows_switch); showArrowsToggle.setChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()); mainView.findViewById(R.id.show_arrows_row).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - settings.SHOW_ARROWS_TO_FIRST_MARKERS.set(!settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()); + boolean newState = !settings.SHOW_ARROWS_TO_FIRST_MARKERS.get(); + settings.SHOW_ARROWS_TO_FIRST_MARKERS.set(newState); + showArrowsToggle.setChecked(newState); if (getMapActivity() != null) { getMapActivity().refreshMap(); } - dismiss(); } }); - CompoundButton showLinesToggle = (CompoundButton) mainView.findViewById(R.id.show_guide_line_switch); + final CompoundButton showLinesToggle = (CompoundButton) mainView.findViewById(R.id.show_guide_line_switch); showLinesToggle.setChecked(settings.SHOW_LINES_TO_FIRST_MARKERS.get()); mainView.findViewById(R.id.show_guide_line_row).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - settings.SHOW_LINES_TO_FIRST_MARKERS.set(!settings.SHOW_LINES_TO_FIRST_MARKERS.get()); + boolean newState = !settings.SHOW_LINES_TO_FIRST_MARKERS.get(); + settings.SHOW_LINES_TO_FIRST_MARKERS.set(newState); + showLinesToggle.setChecked(newState); if (getMapActivity() != null) { getMapActivity().refreshMap(); } - dismiss(); } }); diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 50bb769fca..88dd4bf182 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -797,7 +797,7 @@ public class MapControlsLayer extends OsmandMapLayer { private void updateMyLocation(RoutingHelper rh, boolean dialogOpened) { Location lastKnownLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); - boolean enabled = lastKnownLocation != null && !isLocationOutdated(lastKnownLocation); + boolean enabled = lastKnownLocation != null; boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation(); if (!enabled) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index ec93c52755..556e90c20f 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -35,6 +35,7 @@ import gnu.trove.list.array.TIntArrayList; public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider, IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider { + protected static final int DIST_TO_SHOW = 80; private final MapActivity map; @@ -189,7 +190,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi @Override public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { - Location myLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation(); + Location myLoc = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation(); widgetsFactory.updateInfo(myLoc == null ? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()), tileBox.getZoom()); OsmandSettings settings = map.getMyApplication().getSettings(); @@ -227,27 +228,26 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi List activeMapMarkers = markersHelper.getMapMarkers(); if (settings.SHOW_LINES_TO_FIRST_MARKERS.get() && myLoc != null) { - linePath.reset(); - tx.clear(); - ty.clear(); int locX = tileBox.getPixXFromLonNoRot(myLoc.getLongitude()); int locY = tileBox.getPixYFromLatNoRot(myLoc.getLatitude()); + int[] colors = MapMarker.getColors(map); for (int i = 0; i < activeMapMarkers.size() && i < 2; i++) { - int markerX = tileBox.getPixXFromLonNoRot(activeMapMarkers.get(i).getLongitude()); - int markerY = tileBox.getPixYFromLatNoRot(activeMapMarkers.get(i).getLatitude()); + MapMarker marker = activeMapMarkers.get(i); + int markerX = tileBox.getPixXFromLonNoRot(marker.getLongitude()); + int markerY = tileBox.getPixYFromLatNoRot(marker.getLatitude()); + linePath.reset(); + tx.clear(); + ty.clear(); + linePath.moveTo(locX, locY); + linePath.lineTo(markerX, markerY); + tx.add(locX); + ty.add(locY); tx.add(markerX); ty.add(markerY); - if (i == 0) { - linePath.moveTo(markerX, markerY); - linePath.lineTo(locX, locY); - tx.add(locX); - ty.add(locY); - } else { - linePath.lineTo(markerX, markerY); - } + calculatePath(tileBox, tx, ty, linePath); + lineAttrs.paint.setColor(colors[marker.colorIndex]); + canvas.drawPath(linePath, lineAttrs.paint); } - calculatePath(tileBox, tx, ty, linePath); - canvas.drawPath(linePath, lineAttrs.paint); } for (MapMarker marker : activeMapMarkers) { diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index dc09eca433..0c2592cd07 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -16,13 +16,11 @@ import android.os.Build; import android.support.annotation.NonNull; import android.view.MotionEvent; -import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.data.QuadTree; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; -import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.render.OsmandRenderer; @@ -40,8 +38,6 @@ import gnu.trove.list.array.TIntArrayList; public abstract class OsmandMapLayer { - protected static final int UPDATES_BEFORE_CHECK_LOCATION = 40; - protected List fullObjectsLatLon; protected List smallObjectsLatLon; @@ -51,22 +47,6 @@ public abstract class OsmandMapLayer { TWO_POINTERS_ZOOM_OUT } - private int updatesCounter; - private boolean locationOutdated; - - boolean isLocationOutdated(Location location) { - if (location != null && updatesCounter == 0) { - locationOutdated = System.currentTimeMillis() - location.getTime() > - OsmAndLocationProvider.STALE_LOCATION_TIMEOUT_FOR_ICON; - } - if (updatesCounter == UPDATES_BEFORE_CHECK_LOCATION) { - updatesCounter = 0; - } else { - updatesCounter++; - } - return locationOutdated; - } - public boolean isMapGestureAllowed(MapGestureType type) { return true; } diff --git a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java index f66c05713f..860b0cc58f 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java @@ -64,8 +64,7 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay aroundArea.setAntiAlias(true); locationProvider = view.getApplication().getLocationProvider(); - updateIcons(view.getSettings().getApplicationMode(), false, - isLocationOutdated(locationProvider.getLastKnownLocation())); + updateIcons(view.getSettings().getApplicationMode(), false, locationProvider.getLastKnownLocation() == null); } @Override @@ -86,9 +85,9 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay } // draw boolean nm = nightMode != null && nightMode.isNightMode(); - Location lastKnownLocation = locationProvider.getLastKnownLocation(); + Location lastKnownLocation = locationProvider.getLastStaleKnownLocation(); updateIcons(view.getSettings().getApplicationMode(), nm, - isLocationOutdated(lastKnownLocation)); + view.getApplication().getLocationProvider().getLastKnownLocation() == null); if(lastKnownLocation == null || view == null){ return; }