Small refactoring

This commit is contained in:
Victor Shcherb 2012-06-19 00:26:58 +02:00
parent aea3ac2086
commit 2a38cff3d3
5 changed files with 24 additions and 15 deletions

View file

@ -118,7 +118,7 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
} }
((TurnPathHelper.RouteDrawable) icon.getDrawable()).setRouteType(model.getTurnType()); ((TurnPathHelper.RouteDrawable) icon.getDrawable()).setRouteType(model.getTurnType());
distanceLabel.setText(OsmAndFormatter.getFormattedDistance(model.distance, ShowRouteInfoActivity.this)); distanceLabel.setText(OsmAndFormatter.getFormattedDistance(model.distance, ShowRouteInfoActivity.this));
label.setText(model.descriptionRoute); label.setText(model.getDescriptionRoute());
int seconds = model.getExpectedTime() % 60; int seconds = model.getExpectedTime() % 60;
int min = (model.getExpectedTime() / 60) % 60; int min = (model.getExpectedTime() / 60) % 60;
int hours = (model.getExpectedTime() / 3600); int hours = (model.getExpectedTime() / 3600);

View file

@ -147,7 +147,7 @@ public class RouteCalculationResult {
RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(), RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(),
TurnType.valueOf(TurnType.C, false)); TurnType.valueOf(TurnType.C, false));
info.routePointOffset = 0; info.routePointOffset = 0;
info.descriptionRoute = "";//getString(ctx, R.string.route_head); //$NON-NLS-1$ // info.setDescriptionRoute(getString(ctx, R.string.route_head));//; //$NON-NLS-1$
directions.add(0, info); directions.add(0, info);
} }
} }

View file

@ -1,7 +1,7 @@
package net.osmand.plus.routing; package net.osmand.plus.routing;
public class RouteDirectionInfo { public class RouteDirectionInfo {
public String descriptionRoute = ""; //$NON-NLS-1$ private String descriptionRoute = ""; //$NON-NLS-1$
private float averageSpeed; private float averageSpeed;
// Constructor to verify average speed always > 0 // Constructor to verify average speed always > 0
@ -10,6 +10,14 @@ public class RouteDirectionInfo {
this.turnType = turnType; this.turnType = turnType;
} }
public String getDescriptionRoute() {
return descriptionRoute;
}
public void setDescriptionRoute(String descriptionRoute) {
this.descriptionRoute = descriptionRoute;
}
public float getAverageSpeed() { public float getAverageSpeed() {
return averageSpeed; return averageSpeed;
} }

View file

@ -222,7 +222,7 @@ public class RouteProvider {
if(info.routePointOffset >= startI && info.routePointOffset < endI){ if(info.routePointOffset >= startI && info.routePointOffset < endI){
RouteDirectionInfo ch = new RouteDirectionInfo(info.getAverageSpeed(), info.getTurnType()); RouteDirectionInfo ch = new RouteDirectionInfo(info.getAverageSpeed(), info.getTurnType());
ch.routePointOffset = info.routePointOffset - startI; ch.routePointOffset = info.routePointOffset - startI;
ch.descriptionRoute = info.descriptionRoute; ch.setDescriptionRoute(info.getDescriptionRoute());
// recalculate // recalculate
ch.distance = 0; ch.distance = 0;
@ -269,7 +269,7 @@ public class RouteProvider {
int prevBearingLocation = 0; int prevBearingLocation = 0;
RouteDirectionInfo previousInfo = new RouteDirectionInfo(speed, TurnType.valueOf(TurnType.C, leftSide)); RouteDirectionInfo previousInfo = new RouteDirectionInfo(speed, TurnType.valueOf(TurnType.C, leftSide));
previousInfo.routePointOffset = 0; previousInfo.routePointOffset = 0;
previousInfo.descriptionRoute = getString(ctx, R.string.route_head); previousInfo.setDescriptionRoute(getString(ctx, R.string.route_head));
directions.add(previousInfo); directions.add(previousInfo);
int distForTurn = 0; int distForTurn = 0;
@ -344,10 +344,11 @@ public class RouteProvider {
// calculate for previousRoute // calculate for previousRoute
previousInfo.distance = listDistance[previousLocation]- listDistance[i]; previousInfo.distance = listDistance[previousLocation]- listDistance[i];
previousInfo.descriptionRoute += " " + OsmAndFormatter.getFormattedDistance(previousInfo.distance, ctx); //$NON-NLS-1$ previousInfo.setDescriptionRoute(previousInfo.getDescriptionRoute()
+ " " + OsmAndFormatter.getFormattedDistance(previousInfo.distance, ctx)); //$NON-NLS-1$
type.setTurnAngle(360 - delta); type.setTurnAngle(360 - delta);
previousInfo = new RouteDirectionInfo(speed, type); previousInfo = new RouteDirectionInfo(speed, type);
previousInfo.descriptionRoute = description; previousInfo.setDescriptionRoute(description);
previousInfo.routePointOffset = startTurnPoint; previousInfo.routePointOffset = startTurnPoint;
directions.add(previousInfo); directions.add(previousInfo);
previousLocation = startTurnPoint; previousLocation = startTurnPoint;
@ -358,13 +359,13 @@ public class RouteProvider {
} }
previousInfo.distance = listDistance[previousLocation]; previousInfo.distance = listDistance[previousLocation];
previousInfo.descriptionRoute += " " + OsmAndFormatter.getFormattedDistance(previousInfo.distance, ctx); //$NON-NLS-1$ previousInfo.setDescriptionRoute(previousInfo.getDescriptionRoute()
+ " " + OsmAndFormatter.getFormattedDistance(previousInfo.distance, ctx)); //$NON-NLS-1$
// add last direction go straight (to show arrow in screen after all turns) // add last direction go straight (to show arrow in screen after all turns)
if(previousInfo.distance > 80){ if(previousInfo.distance > 80){
RouteDirectionInfo info = new RouteDirectionInfo(speed, TurnType.valueOf(TurnType.C, leftSide)); RouteDirectionInfo info = new RouteDirectionInfo(speed, TurnType.valueOf(TurnType.C, leftSide));
info.distance = 0; info.distance = 0;
info.descriptionRoute = ""; //$NON-NLS-1$
info.routePointOffset = locations.size() - 1; info.routePointOffset = locations.size() - 1;
directions.add(info); directions.add(info);
} }
@ -609,7 +610,7 @@ public class RouteProvider {
turnType.setTurnAngle((float) Double.parseDouble(sturn)); turnType.setTurnAngle((float) Double.parseDouble(sturn));
} }
RouteDirectionInfo dirInfo = new RouteDirectionInfo(avgSpeed, turnType); RouteDirectionInfo dirInfo = new RouteDirectionInfo(avgSpeed, turnType);
dirInfo.descriptionRoute = item.desc; //$NON-NLS-1$ dirInfo.setDescriptionRoute(item.desc); //$NON-NLS-1$
dirInfo.routePointOffset = offset; dirInfo.routePointOffset = offset;
if (previous != null && !TurnType.C.equals(previous.getTurnType().getValue()) && if (previous != null && !TurnType.C.equals(previous.getTurnType().getValue()) &&
!osmandRouter) { !osmandRouter) {
@ -770,7 +771,7 @@ public class RouteProvider {
WptPt pt = new WptPt(); WptPt pt = new WptPt();
pt.lat = loc.getLatitude(); pt.lat = loc.getLatitude();
pt.lon = loc.getLongitude(); pt.lon = loc.getLongitude();
pt.desc = dirInfo.descriptionRoute; pt.desc = dirInfo.getDescriptionRoute();
Map<String, String> extensions = pt.getExtensionsToWrite(); Map<String, String> extensions = pt.getExtensionsToWrite();
extensions.put("time", dirInfo.getExpectedTime() + ""); extensions.put("time", dirInfo.getExpectedTime() + "");
String turnType = dirInfo.getTurnType().getValue(); String turnType = dirInfo.getTurnType().getValue();

View file

@ -70,8 +70,8 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
if(routingHelper.getRouteDirections().size() > directionInfo){ if(routingHelper.getRouteDirections().size() > directionInfo){
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo); RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
Location l = routingHelper.getLocationFromRouteDirection(info); Location l = routingHelper.getLocationFromRouteDirection(info);
if(info.descriptionRoute != null) { if(info.getDescriptionRoute() != null) {
contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.descriptionRoute); contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute());
} }
view.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), view.getZoom(), true); view.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), view.getZoom(), true);
} }
@ -88,8 +88,8 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
directionInfo++; directionInfo++;
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo); RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
Location l = routingHelper.getLocationFromRouteDirection(info); Location l = routingHelper.getLocationFromRouteDirection(info);
if(info.descriptionRoute != null){ if(info.getDescriptionRoute() != null){
contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.descriptionRoute); contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute());
} }
view.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), view.getZoom(), true); view.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), view.getZoom(), true);
} }