Small refactoring

This commit is contained in:
Victor Shcherb 2011-08-24 00:32:25 +02:00
parent 53bc7a478c
commit c091d0474f
2 changed files with 37 additions and 32 deletions

View file

@ -35,6 +35,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.AsyncTask;
import android.os.Handler;
import android.text.format.DateFormat;
import android.util.Log;

View file

@ -6,7 +6,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
@ -23,7 +22,6 @@ import net.osmand.osm.MapUtils;
import net.osmand.plus.R;
import net.osmand.plus.activities.RoutingHelper.RouteDirectionInfo;
import net.osmand.plus.activities.RoutingHelper.TurnType;
import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.router.BicycleRouter;
import net.osmand.router.BinaryRoutePlanner;
import net.osmand.router.CarRouter;
@ -180,6 +178,36 @@ public class RouteProvider {
try {
RouteCalculationResult res;
if(gpxRoute != null && !gpxRoute.isEmpty()){
res = calculateGpxRoute(start, end, gpxRoute);
addMissingTurnsToRoute(res, start, end, mode, ctx);
} else if (type == RouteService.YOURS) {
res = findYOURSRoute(start, end, mode, fast);
addMissingTurnsToRoute(res, start, end, mode, ctx);
} else if (type == RouteService.OSMAND) {
res = findVectorMapsRoute(start, end, mode, fast, (OsmandApplication)ctx.getApplicationContext());
addMissingTurnsToRoute(res, start, end, mode, ctx);
} else {
res = findCloudMadeRoute(start, end, mode, ctx, fast);
// for test purpose
addMissingTurnsToRoute(res, start, end, mode, ctx);
}
if(log.isInfoEnabled() && res.locations != null){
log.info("Finding route contained " + res.locations.size() + " points for " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return res;
} catch (IOException e) {
log.error("Failed to find route ", e); //$NON-NLS-1$
} catch (ParserConfigurationException e) {
log.error("Failed to find route ", e); //$NON-NLS-1$
} catch (SAXException e) {
log.error("Failed to find route ", e); //$NON-NLS-1$
}
}
return new RouteCalculationResult(null);
}
private RouteCalculationResult calculateGpxRoute(Location start, LatLon end, List<Location> gpxRoute) {
RouteCalculationResult res;
// get the closest point to start and to end
float minDist = Integer.MAX_VALUE;
int startI = 0;
@ -209,31 +237,7 @@ public class RouteProvider {
}
}
res = new RouteCalculationResult(new ArrayList<Location>(gpxRoute.subList(startI, endI)), null, start, end, null);
addMissingTurnsToRoute(res, start, end, mode, ctx);
} else if (type == RouteService.YOURS) {
res = findYOURSRoute(start, end, mode, fast);
addMissingTurnsToRoute(res, start, end, mode, ctx);
} else if (type == RouteService.OSMAND) {
res = findVectorMapsRoute(start, end, mode, fast, (OsmandApplication)ctx.getApplicationContext());
addMissingTurnsToRoute(res, start, end, mode, ctx);
} else {
res = findCloudMadeRoute(start, end, mode, ctx, fast);
// for test purpose
addMissingTurnsToRoute(res, start, end, mode, ctx);
}
if(log.isInfoEnabled() && res.locations != null){
log.info("Finding route contained " + res.locations.size() + " points for " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return res;
} catch (IOException e) {
log.error("Failed to find route ", e); //$NON-NLS-1$
} catch (ParserConfigurationException e) {
log.error("Failed to find route ", e); //$NON-NLS-1$
} catch (SAXException e) {
log.error("Failed to find route ", e); //$NON-NLS-1$
}
}
return new RouteCalculationResult(null);
}
protected String getString(Context ctx, int resId){
@ -579,7 +583,7 @@ public class RouteProvider {
URLConnection connection = url.openConnection();
DocumentBuilder dom = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = dom.parse(new InputSource(new InputStreamReader(connection.getInputStream())));
// TODO how to find that error occurred ? API gpx doesn't say nothing
// TODO how to find that error occurred ? Gpx API doesn't say anything
NodeList list = doc.getElementsByTagName("wpt"); //$NON-NLS-1$
for (int i = 0; i < list.getLength(); i++) {
Element item = (Element) list.item(i);