Aggregate route info

This commit is contained in:
vshcherb 2014-03-09 20:41:48 +01:00
parent fcdf33ae92
commit 6ff788dba6
5 changed files with 44 additions and 30 deletions

View file

@ -89,7 +89,7 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
RouteInfoLayer.directionInfo = position - 1;
OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings();
settings.setMapLocationToShow(loc.getLatitude(),loc.getLongitude(),
Math.max(13, settings.getLastKnownMapZoom()), null, item.getDescriptionRoute() + " " + getTimeDescription(item), null);
Math.max(13, settings.getLastKnownMapZoom()), null, item.getDescriptionRoute(((OsmandApplication) getApplication())) + " " + getTimeDescription(item), null);
MapActivity.launchMapActivityMoveToTop(this);
}
}
@ -128,7 +128,7 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
distanceLabel.setText(OsmAndFormatter.getFormattedDistance(model.distance, getMyApplication()));
label.setText(model.getDescriptionRoute());
label.setText(model.getDescriptionRoute(((OsmandApplication) getApplication())));
String timeText = getTimeDescription(model);
timeLabel.setText(timeText);
return row;

View file

@ -16,11 +16,11 @@ import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ClientContext;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
import net.osmand.router.RouteSegmentResult;
import net.osmand.router.TurnType;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
public class RouteCalculationResult {
@ -36,6 +36,8 @@ public class RouteCalculationResult {
private final int[] waypointIndexes;
private final float routingTime;
protected int cacheCurrentTextDirectionInfo = -1;
protected List<RouteDirectionInfo> cacheAgreggatedDirections;
// Note always currentRoute > get(currentDirectionInfo).routeOffset,
// but currentRoute <= get(currentDirectionInfo+1).routeOffset
@ -278,7 +280,6 @@ public class RouteCalculationResult {
if(directions.size() > 0 && prevDirectionTime > 0 && prevDirectionDistance > 0) {
RouteDirectionInfo prev = directions.get(directions.size() - 1);
prev.setAverageSpeed(prevDirectionDistance / prevDirectionTime);
prev.setDescriptionRoute(prev.getDescriptionRoute() + " " + OsmAndFormatter.getFormattedDistance(prevDirectionDistance, ctx));
prevDirectionDistance = 0;
prevDirectionTime = 0;
}
@ -290,7 +291,6 @@ public class RouteCalculationResult {
if(directions.size() > 0 && prevDirectionTime > 0 && prevDirectionDistance > 0) {
RouteDirectionInfo prev = directions.get(directions.size() - 1);
prev.setAverageSpeed(prevDirectionDistance / prevDirectionTime);
prev.setDescriptionRoute(prev.getDescriptionRoute() + " " + OsmAndFormatter.getFormattedDistance(prevDirectionDistance, ctx));
}
return segmentsToPopulate;
}
@ -392,8 +392,6 @@ public class RouteCalculationResult {
// calculate for previousRoute
previousInfo.distance = listDistance[previousLocation]- listDistance[i];
previousInfo.setDescriptionRoute(previousInfo.getDescriptionRoute()
+ " " + OsmAndFormatter.getFormattedDistance(previousInfo.distance, ctx)); //$NON-NLS-1$
type.setTurnAngle(360 - delta);
previousInfo = new RouteDirectionInfo(speed, type);
previousInfo.setDescriptionRoute(description);
@ -407,9 +405,6 @@ public class RouteCalculationResult {
}
previousInfo.distance = listDistance[previousLocation];
previousInfo.setDescriptionRoute(previousInfo.getDescriptionRoute()
+ " " + OsmAndFormatter.getFormattedDistance(previousInfo.distance, ctx)); //$NON-NLS-1$
if (originalDirections.isEmpty()) {
originalDirections.addAll(computeDirections);
} else {
@ -850,13 +845,32 @@ public class RouteCalculationResult {
}
public List<RouteDirectionInfo> getRouteDirections() {
if(currentDirectionInfo < directions.size()){
if(currentDirectionInfo == 0){
return directions;
}
if(currentDirectionInfo < directions.size() - 1){
return directions.subList(currentDirectionInfo + 1, directions.size());
if(currentDirectionInfo < directions.size() - 1){
if(cacheCurrentTextDirectionInfo != currentDirectionInfo) {
cacheCurrentTextDirectionInfo = currentDirectionInfo;
List<RouteDirectionInfo> list = currentDirectionInfo == 0 ? directions :
directions.subList(currentDirectionInfo + 1, directions.size());
cacheAgreggatedDirections = new ArrayList<RouteDirectionInfo>();
RouteDirectionInfo p = null;
for(RouteDirectionInfo i : list) {
if(p == null || !i.getTurnType().isSkipToSpeak() ||
(!Algorithms.objectEquals(p.getRef(), i.getRef()) &&
!Algorithms.objectEquals(p.getStreetName(), i.getStreetName()))) {
p = new RouteDirectionInfo(i.getAverageSpeed(), i.getTurnType());
p.routePointOffset = i.routePointOffset;
p.setDestinationName(i.getDestinationName());
p.setRef(i.getRef());
p.setStreetName(i.getStreetName());
p.setDescriptionRoute(i.getDescriptionRoutePart());
cacheAgreggatedDirections.add(p);
}
float time = i.getExpectedTime() + p.getExpectedTime();
p.distance += i.distance;
p.setAverageSpeed(p.distance / time);
p.afterLeftTime = i.afterLeftTime;
}
}
return cacheAgreggatedDirections;
}
return Collections.emptyList();
}

View file

@ -1,5 +1,7 @@
package net.osmand.plus.routing;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.router.TurnType;
public class RouteDirectionInfo {
@ -32,7 +34,11 @@ public class RouteDirectionInfo {
this.turnType = turnType;
}
public String getDescriptionRoute() {
public String getDescriptionRoute(ClientContext ctx) {
return descriptionRoute + " " + OsmAndFormatter.getFormattedDistance(distance, ctx);
}
public String getDescriptionRoutePart() {
return descriptionRoute;
}

View file

@ -302,7 +302,7 @@ public class RouteProvider {
if(info.routePointOffset >= startI[0] && info.routePointOffset < endI[0]){
RouteDirectionInfo ch = new RouteDirectionInfo(info.getAverageSpeed(), info.getTurnType());
ch.routePointOffset = info.routePointOffset - startI[0];
ch.setDescriptionRoute(info.getDescriptionRoute());
ch.setDescriptionRoute(info.getDescriptionRoutePart());
// recalculate
ch.distance = 0;
@ -898,7 +898,7 @@ public class RouteProvider {
WptPt pt = new WptPt();
pt.lat = loc.getLatitude();
pt.lon = loc.getLongitude();
pt.desc = dirInfo.getDescriptionRoute();
pt.desc = dirInfo.getDescriptionRoute(ctx);
Map<String, String> extensions = pt.getExtensionsToWrite();
extensions.put("time", dirInfo.getExpectedTime() + "");
String turnType = dirInfo.getTurnType().getValue();

View file

@ -3,20 +3,18 @@ package net.osmand.plus.views;
import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ClientContext;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.ShowRouteInfoActivity;
import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageButton;
@ -41,7 +39,7 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
this.routingHelper = routingHelper;
this.contextMenu = contextMenu;
routingHelper.addListener(this);
attachListeners();
attachListeners(activity.getMyApplication());
updateVisibility();
activity.accessibleContent.add(prev);
@ -76,7 +74,7 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
this.view = view;
}
private void attachListeners() {
private void attachListeners(final ClientContext ctx) {
prev.setOnClickListener(new View.OnClickListener(){
@Override
@ -86,9 +84,7 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
if(routingHelper.getRouteDirections().size() > directionInfo){
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info);
if(info.getDescriptionRoute() != null) {
contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute());
}
contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute(ctx));
view.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), view.getZoom(), true);
}
}
@ -104,9 +100,7 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
directionInfo++;
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info);
if(info.getDescriptionRoute() != null){
contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute());
}
contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute(ctx));
view.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), view.getZoom(), true);
}
view.refreshMap();