refactoring and fixes
This commit is contained in:
parent
42a7a5d88d
commit
576c4330b4
9 changed files with 68 additions and 58 deletions
|
@ -691,31 +691,21 @@ public class OsmandRegions {
|
|||
}
|
||||
}
|
||||
|
||||
public List<WorldRegion> getWoldRegionsAt(LatLon latLon) throws IOException {
|
||||
List<WorldRegion> result = new ArrayList<>();
|
||||
List<BinaryMapDataObject> mapDataObjects = getBinaryMapDataObjectsAt(latLon);
|
||||
for (BinaryMapDataObject obj : mapDataObjects) {
|
||||
String fullName = getFullName(obj);
|
||||
if (fullName != null) {
|
||||
WorldRegion reg = getRegionData(fullName);
|
||||
if (reg != null) {
|
||||
result.add(reg);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
public List<WorldRegion> getWorldRegionsAt(LatLon latLon) throws IOException {
|
||||
Map<WorldRegion, BinaryMapDataObject> mapDataObjects = getBinaryMapDataObjectsWithRegionsAt(latLon);
|
||||
return new ArrayList<>(mapDataObjects.keySet());
|
||||
}
|
||||
|
||||
public BinaryMapDataObject getSmallestBinaryMapDataObjectAt(LatLon latLon) throws IOException {
|
||||
List<BinaryMapDataObject> mapDataObjects = getBinaryMapDataObjectsAt(latLon);
|
||||
return getSmallestBinaryMapDataObjectAt(mapDataObjects);
|
||||
public Map.Entry<WorldRegion, BinaryMapDataObject> getSmallestBinaryMapDataObjectAt(LatLon latLon) throws IOException {
|
||||
Map<WorldRegion, BinaryMapDataObject> mapDataObjectsWithRegions = getBinaryMapDataObjectsWithRegionsAt(latLon);
|
||||
return getSmallestBinaryMapDataObjectAt(mapDataObjectsWithRegions);
|
||||
}
|
||||
|
||||
public BinaryMapDataObject getSmallestBinaryMapDataObjectAt(List<BinaryMapDataObject> mapDataObjects) {
|
||||
BinaryMapDataObject res = null;
|
||||
public Map.Entry<WorldRegion, BinaryMapDataObject> getSmallestBinaryMapDataObjectAt(Map<WorldRegion, BinaryMapDataObject> mapDataObjectsWithRegions) {
|
||||
Map.Entry<WorldRegion, BinaryMapDataObject> res = null;
|
||||
double smallestArea = -1;
|
||||
for (BinaryMapDataObject o : mapDataObjects) {
|
||||
double area = OsmandRegions.getArea(o);
|
||||
for (Map.Entry<WorldRegion, BinaryMapDataObject> o : mapDataObjectsWithRegions.entrySet()) {
|
||||
double area = OsmandRegions.getArea(o.getValue());
|
||||
if (smallestArea == -1) {
|
||||
smallestArea = area;
|
||||
res = o;
|
||||
|
@ -727,10 +717,10 @@ public class OsmandRegions {
|
|||
return res;
|
||||
}
|
||||
|
||||
private List<BinaryMapDataObject> getBinaryMapDataObjectsAt(LatLon latLon) throws IOException {
|
||||
private Map<WorldRegion, BinaryMapDataObject> getBinaryMapDataObjectsWithRegionsAt(LatLon latLon) throws IOException {
|
||||
int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
|
||||
int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
|
||||
|
||||
Map<WorldRegion, BinaryMapDataObject> foundObjects = new LinkedHashMap<>();
|
||||
List<BinaryMapDataObject> mapDataObjects;
|
||||
try {
|
||||
mapDataObjects = queryBboxNoInit(point31x, point31x, point31y, point31y, true);
|
||||
|
@ -748,11 +738,13 @@ public class OsmandRegions {
|
|||
|| !downloadRegion.isRegionMapDownload()
|
||||
|| !contain(o, point31x, point31y)) {
|
||||
it.remove();
|
||||
} else {
|
||||
foundObjects.put(downloadRegion, o);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return mapDataObjects;
|
||||
return foundObjects;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1342,6 +1342,29 @@ public class OsmandSettings {
|
|||
public final OsmandPreference<AngularConstants> ANGULAR_UNITS = new EnumIntPreference<AngularConstants>(
|
||||
"angular_measurement", AngularConstants.DEGREES, AngularConstants.values()).makeProfile();
|
||||
|
||||
public static final String LAST_START_LAT = "last_searched_lat"; //$NON-NLS-1$
|
||||
public static final String LAST_START_LON = "last_searched_lon"; //$NON-NLS-1$
|
||||
|
||||
public LatLon getLastStartPoint() {
|
||||
if (settingsAPI.contains(globalPreferences, LAST_START_LAT) && settingsAPI.contains(globalPreferences, LAST_START_LON)) {
|
||||
return new LatLon(settingsAPI.getFloat(globalPreferences, LAST_START_LAT, 0),
|
||||
settingsAPI.getFloat(globalPreferences, LAST_START_LON, 0));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean setLastStartPoint(LatLon l) {
|
||||
if (l == null) {
|
||||
return settingsAPI.edit(globalPreferences).remove(LAST_START_LAT).remove(LAST_START_LON).commit();
|
||||
} else {
|
||||
return setLastStartPoint(l.getLatitude(), l.getLongitude());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setLastStartPoint(double lat, double lon) {
|
||||
return settingsAPI.edit(globalPreferences).putFloat(LAST_START_LAT, (float) lat).
|
||||
putFloat(LAST_START_LON, (float) lon).commit();
|
||||
}
|
||||
|
||||
public final OsmandPreference<SpeedConstants> SPEED_SYSTEM = new EnumIntPreference<SpeedConstants>(
|
||||
"default_speed_system", SpeedConstants.KILOMETERS_PER_HOUR, SpeedConstants.values()) {
|
||||
|
|
|
@ -445,6 +445,7 @@ public class TargetPointsHelper {
|
|||
Location lastKnownLocation = ctx.getLocationProvider().getLastKnownLocation();
|
||||
LatLon latLon = lastKnownLocation != null ?
|
||||
new LatLon(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude()) : null;
|
||||
routingHelper.checkAndUpdateStartLocation(latLon);
|
||||
setMyLocationPoint(latLon, false, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import android.view.WindowManager;
|
|||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.StateChangedListener;
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.map.IMapLocationListener;
|
||||
|
@ -28,6 +27,7 @@ import net.osmand.plus.views.AnimateDraggingMapThread;
|
|||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
|
@ -167,7 +167,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
|
|||
locationProvider = location.getProvider();
|
||||
if (settings.DRIVING_REGION_AUTOMATIC.get() && !drivingRegionUpdated && !app.isApplicationInitializing()) {
|
||||
drivingRegionUpdated = true;
|
||||
app.getRoutingHelper().cacheStartLocation(location);
|
||||
app.getRoutingHelper().checkAndUpdateStartLocation(location);
|
||||
}
|
||||
}
|
||||
if (mapView != null) {
|
||||
|
@ -444,7 +444,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
|
|||
isUserZoomed = true;
|
||||
}
|
||||
|
||||
private static class DetectDrivingRegionTask extends AsyncTask<LatLon, Void, BinaryMapDataObject> {
|
||||
private static class DetectDrivingRegionTask extends AsyncTask<LatLon, Void, WorldRegion> {
|
||||
|
||||
private OsmandApplication app;
|
||||
|
||||
|
@ -453,10 +453,10 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
|
|||
}
|
||||
|
||||
@Override
|
||||
protected BinaryMapDataObject doInBackground(LatLon... latLons) {
|
||||
protected WorldRegion doInBackground(LatLon... latLons) {
|
||||
try {
|
||||
if (latLons != null && latLons.length > 0) {
|
||||
return app.getRegions().getSmallestBinaryMapDataObjectAt(latLons[0]);
|
||||
return app.getRegions().getSmallestBinaryMapDataObjectAt(latLons[0]).getKey();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
|
@ -465,13 +465,9 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(BinaryMapDataObject o) {
|
||||
if (o != null) {
|
||||
String fullName = app.getRegions().getFullName(o);
|
||||
WorldRegion worldRegion = app.getRegions().getRegionData(fullName);
|
||||
if (worldRegion != null) {
|
||||
app.setupDrivingRegion(worldRegion);
|
||||
}
|
||||
protected void onPostExecute(WorldRegion worldRegion) {
|
||||
if (worldRegion != null) {
|
||||
app.setupDrivingRegion(worldRegion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -468,7 +468,7 @@ public class DownloadResources extends DownloadResourceGroup {
|
|||
List<IndexItem> res = new ArrayList<>();
|
||||
OsmandRegions regions = app.getRegions();
|
||||
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
List<WorldRegion> downloadRegions = regions.getWoldRegionsAt(latLon);
|
||||
List<WorldRegion> downloadRegions = regions.getWorldRegionsAt(latLon);
|
||||
for (WorldRegion downloadRegion : downloadRegions) {
|
||||
if (includeDownloaded || !isIndexItemDownloaded(downloadThread, type, downloadRegion, res)) {
|
||||
addIndexItem(downloadThread, type, downloadRegion, res);
|
||||
|
|
|
@ -417,14 +417,13 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
|
|||
protected IndexItem doInBackground(Void... params) {
|
||||
Amenity amenity = cityItem.getAmenity();
|
||||
BinaryMapDataObject o = null;
|
||||
WorldRegion downloadRegion = null;
|
||||
try {
|
||||
o = osmandRegions.getSmallestBinaryMapDataObjectAt(amenity.getLocation());
|
||||
downloadRegion = osmandRegions.getSmallestBinaryMapDataObjectAt(amenity.getLocation()).getKey();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
if (o != null) {
|
||||
String selectedFullName = osmandRegions.getFullName(o);
|
||||
WorldRegion downloadRegion = osmandRegions.getRegionData(selectedFullName);
|
||||
if (downloadRegion != null) {
|
||||
List<IndexItem> indexItems = ctx.getDownloadThread().getIndexes().getIndexItems(downloadRegion);
|
||||
for (IndexItem item : indexItems) {
|
||||
if (item.getType() == DownloadActivityType.NORMAL_FILE) {
|
||||
|
|
|
@ -39,6 +39,7 @@ public class RoutingHelper {
|
|||
private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(RoutingHelper.class);
|
||||
|
||||
private static final float POSITION_TOLERANCE = 60;
|
||||
private static final int CACHE_RADIUS = 100000;
|
||||
|
||||
private List<WeakReference<IRouteInformationListener>> listeners = new LinkedList<>();
|
||||
private List<WeakReference<IRoutingDataUpdateListener>> updateListeners = new LinkedList<>();
|
||||
|
@ -57,7 +58,6 @@ public class RoutingHelper {
|
|||
private List<LatLon> intermediatePoints;
|
||||
private Location lastProjection;
|
||||
private Location lastFixedLocation;
|
||||
private LatLon lastStartLocation = null;
|
||||
|
||||
private static final int RECALCULATE_THRESHOLD_COUNT_CAUSING_FULL_RECALCULATE = 3;
|
||||
private static final int RECALCULATE_THRESHOLD_CAUSING_FULL_RECALCULATE_INTERVAL = 2*60*1000;
|
||||
|
@ -174,8 +174,8 @@ public class RoutingHelper {
|
|||
}
|
||||
|
||||
public synchronized void setFinalAndCurrentLocation(LatLon finalLocation, List<LatLon> intermediatePoints, Location currentLocation){
|
||||
checkAndUpdateStartLocation(currentLocation);
|
||||
RouteCalculationResult previousRoute = route;
|
||||
cacheStartLocation(currentLocation);
|
||||
clearCurrentRoute(finalLocation, intermediatePoints);
|
||||
// to update route
|
||||
setCurrentLocation(currentLocation, false, previousRoute, true);
|
||||
|
@ -261,15 +261,15 @@ public class RoutingHelper {
|
|||
public LatLon getFinalLocation() {
|
||||
return finalLocation;
|
||||
}
|
||||
public void checkAndUpdateStartLocation(Location nextStartLocation) {
|
||||
checkAndUpdateStartLocation(new LatLon(nextStartLocation.getLatitude(), nextStartLocation.getLongitude()));
|
||||
}
|
||||
|
||||
public void cacheStartLocation(Location nextStartLocation) {
|
||||
LatLon start = new LatLon(nextStartLocation.getLatitude(), nextStartLocation.getLongitude());
|
||||
if (lastStartLocation == null) {
|
||||
lastStartLocation = new LatLon(nextStartLocation.getLatitude(), nextStartLocation.getLongitude());
|
||||
app.getMapViewTrackingUtilities().detectDrivingRegion(lastStartLocation);
|
||||
} else if (MapUtils.getDistance(start, lastStartLocation) > 100000) {
|
||||
lastStartLocation = start;
|
||||
app.getMapViewTrackingUtilities().detectDrivingRegion(lastStartLocation);
|
||||
public void checkAndUpdateStartLocation(LatLon newStartLocation) {
|
||||
LatLon lastStartLocation = app.getSettings().getLastStartPoint();
|
||||
if (lastStartLocation == null || MapUtils.getDistance(newStartLocation, lastStartLocation) > CACHE_RADIUS) {
|
||||
app.getMapViewTrackingUtilities().detectDrivingRegion(newStartLocation);
|
||||
app.getSettings().setLastStartPoint(newStartLocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,8 +45,10 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
|
@ -250,7 +252,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
|
|||
&& zoom >= ZOOM_MIN_TO_SHOW_DOWNLOAD_DIALOG && zoom <= ZOOM_MAX_TO_SHOW_DOWNLOAD_DIALOG
|
||||
&& currentObjects != null) {
|
||||
WorldRegion regionData;
|
||||
List<BinaryMapDataObject> selectedObjects = new ArrayList<>();
|
||||
Map<WorldRegion, BinaryMapDataObject> selectedObjects = new LinkedHashMap<>();
|
||||
for (int i = 0; i < currentObjects.size(); i++) {
|
||||
final BinaryMapDataObject o = currentObjects.get(i);
|
||||
String fullName = osmandRegions.getFullName(o);
|
||||
|
@ -262,7 +264,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
|
|||
hideDownloadMapToolbar();
|
||||
return;
|
||||
} else {
|
||||
selectedObjects.add(o);
|
||||
selectedObjects.put(regionData, o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -270,11 +272,8 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
|
|||
|
||||
IndexItem indexItem = null;
|
||||
String name = null;
|
||||
BinaryMapDataObject smallestRegion = app.getRegions().getSmallestBinaryMapDataObjectAt(selectedObjects);
|
||||
if (smallestRegion != null) {
|
||||
String fullName = osmandRegions.getFullName(smallestRegion);
|
||||
regionData = osmandRegions.getRegionData(fullName);
|
||||
|
||||
regionData = app.getRegions().getSmallestBinaryMapDataObjectAt(selectedObjects).getKey();
|
||||
if (regionData != null) {
|
||||
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
List<IndexItem> indexItems = downloadThread.getIndexes().getIndexItems(regionData);
|
||||
if (indexItems.size() == 0) {
|
||||
|
|
|
@ -107,7 +107,7 @@ public class WikiArticleHelper {
|
|||
List<WorldRegion> regions = null;
|
||||
if (articleLatLon != null) {
|
||||
try {
|
||||
regions = application.getRegions().getWoldRegionsAt(articleLatLon);
|
||||
regions = application.getRegions().getWorldRegionsAt(articleLatLon);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue