From 2a38cff3d3dc44d038588cc67cf3ec1e569df998 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 19 Jun 2012 00:26:58 +0200 Subject: [PATCH] Small refactoring --- .../plus/activities/ShowRouteInfoActivity.java | 2 +- .../plus/routing/RouteCalculationResult.java | 2 +- .../osmand/plus/routing/RouteDirectionInfo.java | 10 +++++++++- .../net/osmand/plus/routing/RouteProvider.java | 17 +++++++++-------- .../net/osmand/plus/views/RouteInfoLayer.java | 8 ++++---- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java index 59a7034d8a..03f5388658 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java @@ -118,7 +118,7 @@ public class ShowRouteInfoActivity extends OsmandListActivity { } ((TurnPathHelper.RouteDrawable) icon.getDrawable()).setRouteType(model.getTurnType()); distanceLabel.setText(OsmAndFormatter.getFormattedDistance(model.distance, ShowRouteInfoActivity.this)); - label.setText(model.descriptionRoute); + label.setText(model.getDescriptionRoute()); int seconds = model.getExpectedTime() % 60; int min = (model.getExpectedTime() / 60) % 60; int hours = (model.getExpectedTime() / 3600); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index e0ff3b70a5..1f228292dd 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -147,7 +147,7 @@ public class RouteCalculationResult { RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(), TurnType.valueOf(TurnType.C, false)); 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); } } diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteDirectionInfo.java b/OsmAnd/src/net/osmand/plus/routing/RouteDirectionInfo.java index 7787528b60..988eadb6de 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteDirectionInfo.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteDirectionInfo.java @@ -1,7 +1,7 @@ package net.osmand.plus.routing; public class RouteDirectionInfo { - public String descriptionRoute = ""; //$NON-NLS-1$ + private String descriptionRoute = ""; //$NON-NLS-1$ private float averageSpeed; // Constructor to verify average speed always > 0 @@ -9,6 +9,14 @@ public class RouteDirectionInfo { this.averageSpeed = averageSpeed == 0 ? 1 : averageSpeed; this.turnType = turnType; } + + public String getDescriptionRoute() { + return descriptionRoute; + } + + public void setDescriptionRoute(String descriptionRoute) { + this.descriptionRoute = descriptionRoute; + } public float getAverageSpeed() { return averageSpeed; diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 381b6c8f86..79af5911e1 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -222,7 +222,7 @@ public class RouteProvider { if(info.routePointOffset >= startI && info.routePointOffset < endI){ RouteDirectionInfo ch = new RouteDirectionInfo(info.getAverageSpeed(), info.getTurnType()); ch.routePointOffset = info.routePointOffset - startI; - ch.descriptionRoute = info.descriptionRoute; + ch.setDescriptionRoute(info.getDescriptionRoute()); // recalculate ch.distance = 0; @@ -269,7 +269,7 @@ public class RouteProvider { int prevBearingLocation = 0; RouteDirectionInfo previousInfo = new RouteDirectionInfo(speed, TurnType.valueOf(TurnType.C, leftSide)); previousInfo.routePointOffset = 0; - previousInfo.descriptionRoute = getString(ctx, R.string.route_head); + previousInfo.setDescriptionRoute(getString(ctx, R.string.route_head)); directions.add(previousInfo); int distForTurn = 0; @@ -344,10 +344,11 @@ public class RouteProvider { // calculate for previousRoute 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); previousInfo = new RouteDirectionInfo(speed, type); - previousInfo.descriptionRoute = description; + previousInfo.setDescriptionRoute(description); previousInfo.routePointOffset = startTurnPoint; directions.add(previousInfo); previousLocation = startTurnPoint; @@ -358,13 +359,13 @@ public class RouteProvider { } 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) if(previousInfo.distance > 80){ RouteDirectionInfo info = new RouteDirectionInfo(speed, TurnType.valueOf(TurnType.C, leftSide)); info.distance = 0; - info.descriptionRoute = ""; //$NON-NLS-1$ info.routePointOffset = locations.size() - 1; directions.add(info); } @@ -609,7 +610,7 @@ public class RouteProvider { turnType.setTurnAngle((float) Double.parseDouble(sturn)); } RouteDirectionInfo dirInfo = new RouteDirectionInfo(avgSpeed, turnType); - dirInfo.descriptionRoute = item.desc; //$NON-NLS-1$ + dirInfo.setDescriptionRoute(item.desc); //$NON-NLS-1$ dirInfo.routePointOffset = offset; if (previous != null && !TurnType.C.equals(previous.getTurnType().getValue()) && !osmandRouter) { @@ -770,7 +771,7 @@ public class RouteProvider { WptPt pt = new WptPt(); pt.lat = loc.getLatitude(); pt.lon = loc.getLongitude(); - pt.desc = dirInfo.descriptionRoute; + pt.desc = dirInfo.getDescriptionRoute(); Map extensions = pt.getExtensionsToWrite(); extensions.put("time", dirInfo.getExpectedTime() + ""); String turnType = dirInfo.getTurnType().getValue(); diff --git a/OsmAnd/src/net/osmand/plus/views/RouteInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteInfoLayer.java index f3412b30c8..846545fcc9 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteInfoLayer.java @@ -70,8 +70,8 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL if(routingHelper.getRouteDirections().size() > directionInfo){ RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo); Location l = routingHelper.getLocationFromRouteDirection(info); - if(info.descriptionRoute != null) { - contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.descriptionRoute); + if(info.getDescriptionRoute() != null) { + contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute()); } view.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), view.getZoom(), true); } @@ -88,8 +88,8 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL directionInfo++; RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo); Location l = routingHelper.getLocationFromRouteDirection(info); - if(info.descriptionRoute != null){ - contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.descriptionRoute); + if(info.getDescriptionRoute() != null){ + contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute()); } view.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), view.getZoom(), true); }