Merge branch 'sasha_pasha_branch' of ssh://github.com/osmandapp/Osmand into sasha_pasha_branch

This commit is contained in:
PavelRatushnyi 2017-09-20 21:53:55 +03:00
commit 67272ce744
7 changed files with 62 additions and 64 deletions

View file

@ -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<LatLon> points, List<PointDescription> 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);

View file

@ -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);

View file

@ -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();
}
});

View file

@ -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) {

View file

@ -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<MapMarker> 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) {

View file

@ -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<LatLon> fullObjectsLatLon;
protected List<LatLon> 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;
}

View file

@ -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;
}