Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
5db140a223
4 changed files with 117 additions and 139 deletions
|
@ -447,6 +447,10 @@ public class MapUtils {
|
|||
// return measuredDist(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
public static double measuredDist31(int x1, int y1, int x2, int y2) {
|
||||
return getDistance(MapUtils.get31LatitudeY(y1), MapUtils.get31LongitudeX(x1), MapUtils.get31LatitudeY(y2), MapUtils.get31LongitudeX(x2));
|
||||
}
|
||||
|
||||
public static double squareDist31TileMetric(int x1, int y1, int x2, int y2) {
|
||||
// translate into meters
|
||||
double dy = convert31YToMeters(y1, y2);
|
||||
|
@ -462,21 +466,6 @@ public class MapUtils {
|
|||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String s = "";
|
||||
// s = "القاهرة"; // cairo
|
||||
// s = "東京"; //tokyo
|
||||
// s = "北京"; // beijing
|
||||
// s = "יְרוּשָׁלַיִם"; // jerusalem
|
||||
|
||||
System.out.println(s);
|
||||
for(int i = 0; i < s.length(); i++ ) {
|
||||
System.out.print(s.charAt(i) + "\n");
|
||||
}
|
||||
for(int i = 0; i < s.length(); i++ ) {
|
||||
System.out.print("\\u0"+Integer.toHexString(s.charAt(i)) + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -32,26 +32,26 @@ import org.xmlpull.v1.XmlPullParser;
|
|||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
|
||||
|
||||
public class GPXUtilities {
|
||||
public final static Log log = PlatformUtil.getLog(GPXUtilities.class);
|
||||
|
||||
private final static String GPX_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$
|
||||
private final static String GPX_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$
|
||||
|
||||
private final static NumberFormat latLonFormat = new DecimalFormat("0.00#####", new DecimalFormatSymbols(new Locale("EN", "US")));
|
||||
private final static NumberFormat latLonFormat = new DecimalFormat("0.00#####", new DecimalFormatSymbols(
|
||||
new Locale("EN", "US")));
|
||||
|
||||
public static class GPXExtensions {
|
||||
Map<String, String> extensions = null;
|
||||
|
||||
public Map<String, String> getExtensionsToRead() {
|
||||
if(extensions == null){
|
||||
if (extensions == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return extensions;
|
||||
}
|
||||
|
||||
public Map<String, String> getExtensionsToWrite() {
|
||||
if(extensions == null){
|
||||
if (extensions == null) {
|
||||
extensions = new LinkedHashMap<String, String>();
|
||||
}
|
||||
return extensions;
|
||||
|
@ -71,7 +71,8 @@ public class GPXUtilities {
|
|||
public double speed = 0;
|
||||
public double hdop = Double.NaN;
|
||||
|
||||
public WptPt() {}
|
||||
public WptPt() {
|
||||
}
|
||||
|
||||
public WptPt(double lat, double lon, long time, double ele, double speed, double hdop) {
|
||||
this.lat = lat;
|
||||
|
@ -114,33 +115,33 @@ public class GPXUtilities {
|
|||
|
||||
public List<List<WptPt>> processedPointsToDisplay = new ArrayList<List<WptPt>>();
|
||||
|
||||
public boolean isCloudmadeRouteFile(){
|
||||
public boolean isCloudmadeRouteFile() {
|
||||
return "cloudmade".equalsIgnoreCase(author);
|
||||
}
|
||||
|
||||
public void proccessPoints(){
|
||||
public void proccessPoints() {
|
||||
List<List<WptPt>> tpoints = new ArrayList<List<WptPt>>();
|
||||
boolean created = false;
|
||||
for (Track t : tracks) {
|
||||
for (TrkSegment ts : t.segments) {
|
||||
if(ts.points.size() > 0) {
|
||||
if (ts.points.size() > 0) {
|
||||
created = true;
|
||||
tpoints.add(ts.points);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!created && routes.size() > 0) {
|
||||
for(Route r : routes) {
|
||||
if (!created && routes.size() > 0) {
|
||||
for (Route r : routes) {
|
||||
tpoints.add(r.points);
|
||||
}
|
||||
}
|
||||
processedPointsToDisplay = tpoints;
|
||||
}
|
||||
|
||||
public WptPt findPointToShow(){
|
||||
for(Track t : tracks){
|
||||
for(TrkSegment s : t.segments){
|
||||
if(s.points.size() > 0){
|
||||
public WptPt findPointToShow() {
|
||||
for (Track t : tracks) {
|
||||
for (TrkSegment s : t.segments) {
|
||||
if (s.points.size() > 0) {
|
||||
return s.points.get(0);
|
||||
}
|
||||
}
|
||||
|
@ -170,31 +171,29 @@ public class GPXUtilities {
|
|||
return points.isEmpty() && routes.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String writeGpxFile(File fout, GPXFile file, ClientContext ctx) {
|
||||
FileOutputStream output = null;
|
||||
try {
|
||||
FileOutputStream output = null;
|
||||
try {
|
||||
SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT);
|
||||
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
output = new FileOutputStream(fout);
|
||||
output = new FileOutputStream(fout);
|
||||
XmlSerializer serializer = ctx.getInternalAPI().newSerializer();
|
||||
serializer.setOutput(output, "UTF-8"); //$NON-NLS-1$
|
||||
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); //$NON-NLS-1$
|
||||
serializer.startDocument("UTF-8", true); //$NON-NLS-1$
|
||||
serializer.startTag(null, "gpx"); //$NON-NLS-1$
|
||||
serializer.attribute(null, "version", "1.1"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
if(file.author == null ){
|
||||
if (file.author == null) {
|
||||
serializer.attribute(null, "creator", Version.getAppName(ctx)); //$NON-NLS-1$
|
||||
} else {
|
||||
serializer.attribute(null, "creator", file.author); //$NON-NLS-1$
|
||||
}
|
||||
serializer.attribute(null, "xmlns", "http://www.topografix.com/GPX/1/1"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
serializer.attribute(null, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
||||
serializer.attribute(null, "xsi:schemaLocation", "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd");
|
||||
|
||||
serializer.attribute(null, "xsi:schemaLocation",
|
||||
"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd");
|
||||
|
||||
for (Track track : file.tracks) {
|
||||
serializer.startTag(null, "trk"); //$NON-NLS-1$
|
||||
|
@ -242,21 +241,20 @@ public class GPXUtilities {
|
|||
} catch (IOException e) {
|
||||
log.error("Error saving gpx", e); //$NON-NLS-1$
|
||||
return ctx.getString(R.string.error_occurred_saving_gpx);
|
||||
} finally {
|
||||
if (output != null) {
|
||||
try {
|
||||
output.close();
|
||||
} catch (IOException ignore) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (output != null) {
|
||||
try {
|
||||
output.close();
|
||||
} catch (IOException ignore) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void writeNotNullText(XmlSerializer serializer, String tag, String value) throws IOException {
|
||||
if(value != null){
|
||||
private static void writeNotNullText(XmlSerializer serializer, String tag, String value) throws IOException {
|
||||
if (value != null) {
|
||||
serializer.startTag(null, tag);
|
||||
serializer.text(value);
|
||||
serializer.endTag(null, tag);
|
||||
|
@ -277,25 +275,24 @@ public class GPXUtilities {
|
|||
serializer.attribute(null, "lat", latLonFormat.format(p.lat)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
serializer.attribute(null, "lon", latLonFormat.format(p.lon)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
if(!Double.isNaN(p.ele)){
|
||||
writeNotNullText(serializer, "ele", p.ele+"");
|
||||
if (!Double.isNaN(p.ele)) {
|
||||
writeNotNullText(serializer, "ele", p.ele + "");
|
||||
}
|
||||
writeNotNullText(serializer, "name", p.name);
|
||||
writeNotNullText(serializer, "category", p.category);
|
||||
writeNotNullText(serializer, "desc", p.desc);
|
||||
if(!Double.isNaN(p.hdop)){
|
||||
writeNotNullText(serializer, "hdop", p.hdop+"");
|
||||
if (!Double.isNaN(p.hdop)) {
|
||||
writeNotNullText(serializer, "hdop", p.hdop + "");
|
||||
}
|
||||
if(p.time != 0){
|
||||
if (p.time != 0) {
|
||||
writeNotNullText(serializer, "time", format.format(new Date(p.time)));
|
||||
}
|
||||
if (p.speed > 0) {
|
||||
p.getExtensionsToWrite().put("speed", p.speed+"");
|
||||
p.getExtensionsToWrite().put("speed", p.speed + "");
|
||||
}
|
||||
writeExtensions(serializer, p);
|
||||
}
|
||||
|
||||
|
||||
public static class GPXFileResult {
|
||||
public ArrayList<List<Location>> locations = new ArrayList<List<Location>>();
|
||||
public ArrayList<WptPt> wayPoints = new ArrayList<WptPt>();
|
||||
|
@ -305,10 +302,10 @@ public class GPXUtilities {
|
|||
public boolean cloudMadeFile;
|
||||
public String error;
|
||||
|
||||
public Location findFistLocation(){
|
||||
for(List<Location> l : locations){
|
||||
for(Location ls : l){
|
||||
if(ls != null){
|
||||
public Location findFistLocation() {
|
||||
for (List<Location> l : locations) {
|
||||
for (Location ls : l) {
|
||||
if (ls != null) {
|
||||
return ls;
|
||||
}
|
||||
}
|
||||
|
@ -317,15 +314,14 @@ public class GPXUtilities {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private static String readText(XmlPullParser parser, String key) throws XmlPullParserException, IOException {
|
||||
int tok;
|
||||
String text = null;
|
||||
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
|
||||
if(tok == XmlPullParser.END_TAG && parser.getName().equals(key)){
|
||||
if (tok == XmlPullParser.END_TAG && parser.getName().equals(key)) {
|
||||
break;
|
||||
} else if(tok == XmlPullParser.TEXT){
|
||||
if(text == null){
|
||||
} else if (tok == XmlPullParser.TEXT) {
|
||||
if (text == null) {
|
||||
text = parser.getText();
|
||||
} else {
|
||||
text += parser.getText();
|
||||
|
@ -337,9 +333,9 @@ public class GPXUtilities {
|
|||
}
|
||||
|
||||
public static GPXFile loadGPXFile(ClientContext ctx, File f, boolean convertCloudmadeSource) {
|
||||
FileInputStream fis = null;
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(f);
|
||||
fis = new FileInputStream(f);
|
||||
GPXFile file = loadGPXFile(ctx, fis, convertCloudmadeSource);
|
||||
file.path = f.getAbsolutePath();
|
||||
return file;
|
||||
|
@ -350,12 +346,13 @@ public class GPXUtilities {
|
|||
res.warning = ctx.getString(R.string.error_reading_gpx);
|
||||
return res;
|
||||
} finally {
|
||||
try {
|
||||
if (fis != null) fis.close();
|
||||
} catch (IOException ignore) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (fis != null)
|
||||
fis.close();
|
||||
} catch (IOException ignore) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static GPXFile loadGPXFile(ClientContext ctx, InputStream f, boolean convertCloudmadeSource) {
|
||||
|
@ -480,37 +477,37 @@ public class GPXUtilities {
|
|||
extensionReadMode = false;
|
||||
}
|
||||
|
||||
if(tag.equals("trkpt")){
|
||||
if (tag.equals("trkpt")) {
|
||||
Object pop = parserState.pop();
|
||||
assert pop instanceof WptPt;
|
||||
} else if(tag.equals("wpt")){
|
||||
} else if (tag.equals("wpt")) {
|
||||
Object pop = parserState.pop();
|
||||
assert pop instanceof WptPt;
|
||||
} else if(tag.equals("rtept")){
|
||||
} else if (tag.equals("rtept")) {
|
||||
Object pop = parserState.pop();
|
||||
assert pop instanceof WptPt;
|
||||
} else if(tag.equals("trk")){
|
||||
} else if (tag.equals("trk")) {
|
||||
Object pop = parserState.pop();
|
||||
assert pop instanceof Track;
|
||||
} else if(tag.equals("rte")){
|
||||
} else if (tag.equals("rte")) {
|
||||
Object pop = parserState.pop();
|
||||
assert pop instanceof Route;
|
||||
} else if(tag.equals("trkseg")){
|
||||
} else if (tag.equals("trkseg")) {
|
||||
Object pop = parserState.pop();
|
||||
assert pop instanceof TrkSegment;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(convertCloudmadeSource && res.isCloudmadeRouteFile()){
|
||||
if (convertCloudmadeSource && res.isCloudmadeRouteFile()) {
|
||||
Track tk = new Track();
|
||||
res.tracks.add(tk);
|
||||
TrkSegment segment = new TrkSegment();
|
||||
tk.segments.add(segment);
|
||||
|
||||
for(WptPt wp : res.points){
|
||||
for (WptPt wp : res.points) {
|
||||
segment.points.add(wp);
|
||||
}
|
||||
res.points.clear();
|
||||
res.points.clear();
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
log.error("Error reading gpx", e); //$NON-NLS-1$
|
||||
|
@ -533,17 +530,15 @@ public class GPXUtilities {
|
|||
boolean reset = true;
|
||||
byte[] t = new byte[3];
|
||||
bis.read(t);
|
||||
if (t[0] == ((byte)0xef) && t[1]== ((byte)0xbb) && t[2] == ((byte)0xbf)) {
|
||||
if (t[0] == ((byte) 0xef) && t[1] == ((byte) 0xbb) && t[2] == ((byte) 0xbf)) {
|
||||
reset = false;
|
||||
}
|
||||
if(reset) {
|
||||
if (reset) {
|
||||
bis.reset();
|
||||
}
|
||||
return new InputStreamReader(bis, "UTF-8");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static WptPt parseWptAttributes(XmlPullParser parser) {
|
||||
WptPt wpt = new WptPt();
|
||||
try {
|
||||
|
@ -555,26 +550,25 @@ public class GPXUtilities {
|
|||
}
|
||||
|
||||
public static void mergeGPXFileInto(GPXFile to, GPXFile from) {
|
||||
if(from == null) {
|
||||
if (from == null) {
|
||||
return;
|
||||
}
|
||||
if(from.showCurrentTrack) {
|
||||
if (from.showCurrentTrack) {
|
||||
to.showCurrentTrack = true;
|
||||
}
|
||||
if(from.points != null) {
|
||||
if (from.points != null) {
|
||||
to.points.addAll(from.points);
|
||||
}
|
||||
if(from.tracks != null) {
|
||||
if (from.tracks != null) {
|
||||
to.tracks.addAll(from.tracks);
|
||||
}
|
||||
if(from.routes != null) {
|
||||
if (from.routes != null) {
|
||||
to.routes.addAll(from.routes);
|
||||
}
|
||||
if(from.warning != null) {
|
||||
if (from.warning != null) {
|
||||
to.warning = from.warning;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -47,7 +47,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
private static final int START_SIMULATE_LOCATION_MSG_ID = OsmAndConstants.UI_HANDLER_LOCATION_SERVICE + 2;
|
||||
private static final int RUN_SIMULATE_LOCATION_MSG_ID = OsmAndConstants.UI_HANDLER_LOCATION_SERVICE + 3;
|
||||
private static final long LOST_LOCATION_CHECK_DELAY = 18000;
|
||||
private static final long START_LOCATION_SIMULATION_DELAY = 3000;
|
||||
private static final long START_LOCATION_SIMULATION_DELAY = 2000;
|
||||
|
||||
private static final float ACCURACY_FOR_GPX_AND_ROUTING = 50;
|
||||
|
||||
|
@ -102,12 +102,6 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
private OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS;
|
||||
private OsmandPreference<Boolean> USE_FILTER_FOR_COMPASS;
|
||||
|
||||
private static double squareDist(int x1, int y1, int x2, int y2) {
|
||||
// translate into meters
|
||||
double dy = MapUtils.convert31YToMeters(y1, y2);
|
||||
double dx = MapUtils. convert31XToMeters(x1, x2);
|
||||
return dx * dx + dy * dy;
|
||||
}
|
||||
|
||||
public class SimulationProvider {
|
||||
private int currentRoad;
|
||||
|
@ -137,7 +131,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
RouteDataObject obj = road.getObject();
|
||||
QuadPoint proj = MapUtils.getProjectionPoint31(px, py, obj.getPoint31XTile(j-1), obj.getPoint31YTile(j-1),
|
||||
obj.getPoint31XTile(j), obj.getPoint31YTile(j));
|
||||
double dd = squareDist((int)proj.x, (int)proj.y, px, py);
|
||||
double dd = MapUtils.squareRootDist31((int)proj.x, (int)proj.y, px, py);
|
||||
if (dd < dist) {
|
||||
dist = dd;
|
||||
currentRoad = i;
|
||||
|
@ -166,7 +160,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
st31x = (int) currentPoint.x;
|
||||
st31y = (int) currentPoint.y;
|
||||
}
|
||||
double dd = MapUtils.squareRootDist31(st31x, st31y, end31x, end31y);
|
||||
double dd = MapUtils.measuredDist31(st31x, st31y, end31x, end31y);
|
||||
if(meters > dd && !last){
|
||||
meters -= dd;
|
||||
} else {
|
||||
|
@ -194,7 +188,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
loc.setSpeed(startLocation.getSpeed());
|
||||
loc.setAltitude(startLocation.getAltitude());
|
||||
loc.setTime(System.currentTimeMillis());
|
||||
float meters = (System.currentTimeMillis() - startLocation.getTime()) / startLocation.getSpeed();
|
||||
float meters = startLocation.getSpeed() * ((System.currentTimeMillis() - startLocation.getTime()) / 1000);
|
||||
float proc = proceedMeters(meters, loc);
|
||||
if(proc < 0 || proc >= 100){
|
||||
return null;
|
||||
|
@ -689,7 +683,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
public void run() {
|
||||
simulatePositionImpl();
|
||||
}
|
||||
}, 1000);
|
||||
}, 600);
|
||||
}
|
||||
|
||||
private void simulatePositionImpl() {
|
||||
|
|
|
@ -636,7 +636,8 @@ public class OsmandSettings {
|
|||
new BooleanAccessibilityPreference("accessibility_extensions", false).makeGlobal();
|
||||
|
||||
|
||||
public final OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS = new BooleanPreference("use_magnetic_field_sensor_compass", true).makeGlobal().cache();
|
||||
// magnetic field doesn'torkmost of the time on some phones
|
||||
public final OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS = new BooleanPreference("use_magnetic_field_sensor_compass", false).makeGlobal().cache();
|
||||
public final OsmandPreference<Boolean> USE_KALMAN_FILTER_FOR_COMPASS = new BooleanPreference("use_kalman_filter_compass", true).makeGlobal().cache();
|
||||
|
||||
public final CommonPreference<Float> MAP_ZOOM_SCALE_BY_DENSITY = new FloatPreference("map_zoom_scale_wo_density", 0f).makeProfile().cache();
|
||||
|
|
Loading…
Reference in a new issue