Make small refactoring

This commit is contained in:
Alex Sytnyk 2018-06-05 20:52:09 +03:00
parent a05ff9c556
commit 3edeeac27c

View file

@ -1462,8 +1462,8 @@ public class GPXUtilities {
formatMillis.setTimeZone(TimeZone.getTimeZone("UTC")); formatMillis.setTimeZone(TimeZone.getTimeZone("UTC"));
try { try {
XmlPullParser parser = PlatformUtil.newXMLPullParser(); XmlPullParser parser = PlatformUtil.newXMLPullParser();
parser.setInput(getUTF8Reader(f)); //$NON-NLS-1$ parser.setInput(getUTF8Reader(f));
Stack<GPXExtensions> parserState = new Stack<GPXExtensions>(); Stack<GPXExtensions> parserState = new Stack<>();
boolean extensionReadMode = false; boolean extensionReadMode = false;
parserState.push(res); parserState.push(res);
int tok; int tok;
@ -1487,64 +1487,64 @@ public class GPXUtilities {
extensionReadMode = true; extensionReadMode = true;
} else { } else {
if (parse instanceof GPXFile) { if (parse instanceof GPXFile) {
if (parser.getName().equals("gpx")) { if (tag.equals("gpx")) {
((GPXFile) parse).author = parser.getAttributeValue("", "creator"); ((GPXFile) parse).author = parser.getAttributeValue("", "creator");
} }
if (parser.getName().equals("metadata")) { if (tag.equals("metadata")) {
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
((GPXFile) parse).metadata = metadata; ((GPXFile) parse).metadata = metadata;
parserState.push(metadata); parserState.push(metadata);
} }
if (parser.getName().equals("trk")) { if (tag.equals("trk")) {
Track track = new Track(); Track track = new Track();
((GPXFile) parse).tracks.add(track); ((GPXFile) parse).tracks.add(track);
parserState.push(track); parserState.push(track);
} }
if (parser.getName().equals("rte")) { if (tag.equals("rte")) {
Route route = new Route(); Route route = new Route();
((GPXFile) parse).routes.add(route); ((GPXFile) parse).routes.add(route);
parserState.push(route); parserState.push(route);
} }
if (parser.getName().equals("wpt")) { if (tag.equals("wpt")) {
WptPt wptPt = parseWptAttributes(parser); WptPt wptPt = parseWptAttributes(parser);
((GPXFile) parse).points.add(wptPt); ((GPXFile) parse).points.add(wptPt);
parserState.push(wptPt); parserState.push(wptPt);
} }
} else if (parse instanceof Metadata) { } else if (parse instanceof Metadata) {
if (parser.getName().equals("desc")) { if (tag.equals("desc")) {
((Metadata) parse).desc = readText(parser, "desc"); ((Metadata) parse).desc = readText(parser, "desc");
} }
} else if (parse instanceof Route) { } else if (parse instanceof Route) {
if (parser.getName().equals("name")) { if (tag.equals("name")) {
((Route) parse).name = readText(parser, "name"); ((Route) parse).name = readText(parser, "name");
} }
if (parser.getName().equals("desc")) { if (tag.equals("desc")) {
((Route) parse).desc = readText(parser, "desc"); ((Route) parse).desc = readText(parser, "desc");
} }
if (parser.getName().equals("rtept")) { if (tag.equals("rtept")) {
WptPt wptPt = parseWptAttributes(parser); WptPt wptPt = parseWptAttributes(parser);
((Route) parse).points.add(wptPt); ((Route) parse).points.add(wptPt);
parserState.push(wptPt); parserState.push(wptPt);
} }
} else if (parse instanceof Track) { } else if (parse instanceof Track) {
if (parser.getName().equals("name")) { if (tag.equals("name")) {
((Track) parse).name = readText(parser, "name"); ((Track) parse).name = readText(parser, "name");
} }
if (parser.getName().equals("desc")) { if (tag.equals("desc")) {
((Track) parse).desc = readText(parser, "desc"); ((Track) parse).desc = readText(parser, "desc");
} }
if (parser.getName().equals("trkseg")) { if (tag.equals("trkseg")) {
TrkSegment trkSeg = new TrkSegment(); TrkSegment trkSeg = new TrkSegment();
((Track) parse).segments.add(trkSeg); ((Track) parse).segments.add(trkSeg);
parserState.push(trkSeg); parserState.push(trkSeg);
} }
} else if (parse instanceof TrkSegment) { } else if (parse instanceof TrkSegment) {
if (parser.getName().equals("trkpt")) { if (tag.equals("trkpt")) {
WptPt wptPt = parseWptAttributes(parser); WptPt wptPt = parseWptAttributes(parser);
((TrkSegment) parse).points.add(wptPt); ((TrkSegment) parse).points.add(wptPt);
parserState.push(wptPt); parserState.push(wptPt);
} }
if (parser.getName().equals("csvattributes")) { if (tag.equals("csvattributes")) {
String segmentPoints = readText(parser, "csvattributes"); String segmentPoints = readText(parser, "csvattributes");
String[] pointsArr = segmentPoints.split("\n"); String[] pointsArr = segmentPoints.split("\n");
for (int i = 0; i < pointsArr.length; i++) { for (int i = 0; i < pointsArr.length; i++) {
@ -1566,20 +1566,20 @@ public class GPXUtilities {
} }
// main object to parse // main object to parse
} else if (parse instanceof WptPt) { } else if (parse instanceof WptPt) {
if (parser.getName().equals("name")) { if (tag.equals("name")) {
((WptPt) parse).name = readText(parser, "name"); ((WptPt) parse).name = readText(parser, "name");
} else if (parser.getName().equals("desc")) { } else if (tag.equals("desc")) {
((WptPt) parse).desc = readText(parser, "desc"); ((WptPt) parse).desc = readText(parser, "desc");
} else if (parser.getName().equals("cmt")) { } else if (tag.equals("cmt")) {
((WptPt) parse).comment = readText(parser, "cmt"); ((WptPt) parse).comment = readText(parser, "cmt");
} else if (parser.getName().equals("speed")) { } else if (tag.equals("speed")) {
try { try {
String value = readText(parser, "speed"); String value = readText(parser, "speed");
((WptPt) parse).speed = Float.parseFloat(value); ((WptPt) parse).speed = Float.parseFloat(value);
((WptPt) parse).getExtensionsToWrite().put("speed", value); ((WptPt) parse).getExtensionsToWrite().put("speed", value);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} }
} else if (parser.getName().equals("link")) { } else if (tag.equals("link")) {
((WptPt) parse).link = parser.getAttributeValue("", "href"); ((WptPt) parse).link = parser.getAttributeValue("", "href");
} else if (tag.equals("category")) { } else if (tag.equals("category")) {
((WptPt) parse).category = readText(parser, "category"); ((WptPt) parse).category = readText(parser, "category");
@ -1587,7 +1587,7 @@ public class GPXUtilities {
if (((WptPt) parse).category == null) { if (((WptPt) parse).category == null) {
((WptPt) parse).category = readText(parser, "type"); ((WptPt) parse).category = readText(parser, "type");
} }
} else if (parser.getName().equals("ele")) { } else if (tag.equals("ele")) {
String text = readText(parser, "ele"); String text = readText(parser, "ele");
if (text != null) { if (text != null) {
try { try {
@ -1595,7 +1595,7 @@ public class GPXUtilities {
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} }
} }
} else if (parser.getName().equals("hdop")) { } else if (tag.equals("hdop")) {
String text = readText(parser, "hdop"); String text = readText(parser, "hdop");
if (text != null) { if (text != null) {
try { try {
@ -1603,7 +1603,7 @@ public class GPXUtilities {
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} }
} }
} else if (parser.getName().equals("time")) { } else if (tag.equals("time")) {
String text = readText(parser, "time"); String text = readText(parser, "time");
if (text != null) { if (text != null) {
try { try {
@ -1651,17 +1651,6 @@ public class GPXUtilities {
} }
} }
} }
// 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) {
// segment.points.add(wp);
// }
// res.points.clear();
// }
} catch (RuntimeException e) { } catch (RuntimeException e) {
log.error("Error reading gpx", e); //$NON-NLS-1$ log.error("Error reading gpx", e); //$NON-NLS-1$
res.warning = ctx.getString(R.string.error_reading_gpx) + " " + e.getMessage(); res.warning = ctx.getString(R.string.error_reading_gpx) + " " + e.getMessage();