Aggregate route info
This commit is contained in:
parent
fcdf33ae92
commit
6ff788dba6
5 changed files with 44 additions and 30 deletions
|
@ -89,7 +89,7 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
|
||||||
RouteInfoLayer.directionInfo = position - 1;
|
RouteInfoLayer.directionInfo = position - 1;
|
||||||
OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings();
|
OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings();
|
||||||
settings.setMapLocationToShow(loc.getLatitude(),loc.getLongitude(),
|
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);
|
MapActivity.launchMapActivityMoveToTop(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ public class ShowRouteInfoActivity extends OsmandListActivity {
|
||||||
|
|
||||||
|
|
||||||
distanceLabel.setText(OsmAndFormatter.getFormattedDistance(model.distance, getMyApplication()));
|
distanceLabel.setText(OsmAndFormatter.getFormattedDistance(model.distance, getMyApplication()));
|
||||||
label.setText(model.getDescriptionRoute());
|
label.setText(model.getDescriptionRoute(((OsmandApplication) getApplication())));
|
||||||
String timeText = getTimeDescription(model);
|
String timeText = getTimeDescription(model);
|
||||||
timeLabel.setText(timeText);
|
timeLabel.setText(timeText);
|
||||||
return row;
|
return row;
|
||||||
|
|
|
@ -16,11 +16,11 @@ import net.osmand.data.LatLon;
|
||||||
import net.osmand.plus.ApplicationMode;
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.ClientContext;
|
import net.osmand.plus.ClientContext;
|
||||||
import net.osmand.plus.GPXUtilities.WptPt;
|
import net.osmand.plus.GPXUtilities.WptPt;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
|
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
|
||||||
import net.osmand.router.RouteSegmentResult;
|
import net.osmand.router.RouteSegmentResult;
|
||||||
import net.osmand.router.TurnType;
|
import net.osmand.router.TurnType;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
public class RouteCalculationResult {
|
public class RouteCalculationResult {
|
||||||
|
@ -36,6 +36,8 @@ public class RouteCalculationResult {
|
||||||
private final int[] waypointIndexes;
|
private final int[] waypointIndexes;
|
||||||
private final float routingTime;
|
private final float routingTime;
|
||||||
|
|
||||||
|
protected int cacheCurrentTextDirectionInfo = -1;
|
||||||
|
protected List<RouteDirectionInfo> cacheAgreggatedDirections;
|
||||||
|
|
||||||
// Note always currentRoute > get(currentDirectionInfo).routeOffset,
|
// Note always currentRoute > get(currentDirectionInfo).routeOffset,
|
||||||
// but currentRoute <= get(currentDirectionInfo+1).routeOffset
|
// but currentRoute <= get(currentDirectionInfo+1).routeOffset
|
||||||
|
@ -278,7 +280,6 @@ public class RouteCalculationResult {
|
||||||
if(directions.size() > 0 && prevDirectionTime > 0 && prevDirectionDistance > 0) {
|
if(directions.size() > 0 && prevDirectionTime > 0 && prevDirectionDistance > 0) {
|
||||||
RouteDirectionInfo prev = directions.get(directions.size() - 1);
|
RouteDirectionInfo prev = directions.get(directions.size() - 1);
|
||||||
prev.setAverageSpeed(prevDirectionDistance / prevDirectionTime);
|
prev.setAverageSpeed(prevDirectionDistance / prevDirectionTime);
|
||||||
prev.setDescriptionRoute(prev.getDescriptionRoute() + " " + OsmAndFormatter.getFormattedDistance(prevDirectionDistance, ctx));
|
|
||||||
prevDirectionDistance = 0;
|
prevDirectionDistance = 0;
|
||||||
prevDirectionTime = 0;
|
prevDirectionTime = 0;
|
||||||
}
|
}
|
||||||
|
@ -290,7 +291,6 @@ public class RouteCalculationResult {
|
||||||
if(directions.size() > 0 && prevDirectionTime > 0 && prevDirectionDistance > 0) {
|
if(directions.size() > 0 && prevDirectionTime > 0 && prevDirectionDistance > 0) {
|
||||||
RouteDirectionInfo prev = directions.get(directions.size() - 1);
|
RouteDirectionInfo prev = directions.get(directions.size() - 1);
|
||||||
prev.setAverageSpeed(prevDirectionDistance / prevDirectionTime);
|
prev.setAverageSpeed(prevDirectionDistance / prevDirectionTime);
|
||||||
prev.setDescriptionRoute(prev.getDescriptionRoute() + " " + OsmAndFormatter.getFormattedDistance(prevDirectionDistance, ctx));
|
|
||||||
}
|
}
|
||||||
return segmentsToPopulate;
|
return segmentsToPopulate;
|
||||||
}
|
}
|
||||||
|
@ -392,8 +392,6 @@ public class RouteCalculationResult {
|
||||||
|
|
||||||
// calculate for previousRoute
|
// calculate for previousRoute
|
||||||
previousInfo.distance = listDistance[previousLocation]- listDistance[i];
|
previousInfo.distance = listDistance[previousLocation]- listDistance[i];
|
||||||
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.setDescriptionRoute(description);
|
previousInfo.setDescriptionRoute(description);
|
||||||
|
@ -407,9 +405,6 @@ public class RouteCalculationResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
previousInfo.distance = listDistance[previousLocation];
|
previousInfo.distance = listDistance[previousLocation];
|
||||||
previousInfo.setDescriptionRoute(previousInfo.getDescriptionRoute()
|
|
||||||
+ " " + OsmAndFormatter.getFormattedDistance(previousInfo.distance, ctx)); //$NON-NLS-1$
|
|
||||||
|
|
||||||
if (originalDirections.isEmpty()) {
|
if (originalDirections.isEmpty()) {
|
||||||
originalDirections.addAll(computeDirections);
|
originalDirections.addAll(computeDirections);
|
||||||
} else {
|
} else {
|
||||||
|
@ -850,13 +845,32 @@ public class RouteCalculationResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RouteDirectionInfo> getRouteDirections() {
|
public List<RouteDirectionInfo> getRouteDirections() {
|
||||||
if(currentDirectionInfo < directions.size()){
|
|
||||||
if(currentDirectionInfo == 0){
|
|
||||||
return directions;
|
|
||||||
}
|
|
||||||
if(currentDirectionInfo < directions.size() - 1){
|
if(currentDirectionInfo < directions.size() - 1){
|
||||||
return directions.subList(currentDirectionInfo + 1, directions.size());
|
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();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package net.osmand.plus.routing;
|
package net.osmand.plus.routing;
|
||||||
|
|
||||||
|
import net.osmand.plus.ClientContext;
|
||||||
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.router.TurnType;
|
import net.osmand.router.TurnType;
|
||||||
|
|
||||||
public class RouteDirectionInfo {
|
public class RouteDirectionInfo {
|
||||||
|
@ -32,7 +34,11 @@ public class RouteDirectionInfo {
|
||||||
this.turnType = turnType;
|
this.turnType = turnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescriptionRoute() {
|
public String getDescriptionRoute(ClientContext ctx) {
|
||||||
|
return descriptionRoute + " " + OsmAndFormatter.getFormattedDistance(distance, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionRoutePart() {
|
||||||
return descriptionRoute;
|
return descriptionRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -302,7 +302,7 @@ public class RouteProvider {
|
||||||
if(info.routePointOffset >= startI[0] && info.routePointOffset < endI[0]){
|
if(info.routePointOffset >= startI[0] && info.routePointOffset < endI[0]){
|
||||||
RouteDirectionInfo ch = new RouteDirectionInfo(info.getAverageSpeed(), info.getTurnType());
|
RouteDirectionInfo ch = new RouteDirectionInfo(info.getAverageSpeed(), info.getTurnType());
|
||||||
ch.routePointOffset = info.routePointOffset - startI[0];
|
ch.routePointOffset = info.routePointOffset - startI[0];
|
||||||
ch.setDescriptionRoute(info.getDescriptionRoute());
|
ch.setDescriptionRoute(info.getDescriptionRoutePart());
|
||||||
|
|
||||||
// recalculate
|
// recalculate
|
||||||
ch.distance = 0;
|
ch.distance = 0;
|
||||||
|
@ -898,7 +898,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.getDescriptionRoute();
|
pt.desc = dirInfo.getDescriptionRoute(ctx);
|
||||||
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();
|
||||||
|
|
|
@ -3,20 +3,18 @@ package net.osmand.plus.views;
|
||||||
|
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
|
import net.osmand.plus.ClientContext;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.ShowRouteInfoActivity;
|
import net.osmand.plus.activities.ShowRouteInfoActivity;
|
||||||
import net.osmand.plus.routing.RouteDirectionInfo;
|
import net.osmand.plus.routing.RouteDirectionInfo;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
|
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
import android.util.DisplayMetrics;
|
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.FrameLayout.LayoutParams;
|
import android.widget.FrameLayout.LayoutParams;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
@ -41,7 +39,7 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
|
||||||
this.routingHelper = routingHelper;
|
this.routingHelper = routingHelper;
|
||||||
this.contextMenu = contextMenu;
|
this.contextMenu = contextMenu;
|
||||||
routingHelper.addListener(this);
|
routingHelper.addListener(this);
|
||||||
attachListeners();
|
attachListeners(activity.getMyApplication());
|
||||||
updateVisibility();
|
updateVisibility();
|
||||||
|
|
||||||
activity.accessibleContent.add(prev);
|
activity.accessibleContent.add(prev);
|
||||||
|
@ -76,7 +74,7 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
|
||||||
this.view = view;
|
this.view = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attachListeners() {
|
private void attachListeners(final ClientContext ctx) {
|
||||||
prev.setOnClickListener(new View.OnClickListener(){
|
prev.setOnClickListener(new View.OnClickListener(){
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -86,9 +84,7 @@ 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);
|
||||||
net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info);
|
net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info);
|
||||||
if(info.getDescriptionRoute() != null) {
|
contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute(ctx));
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,9 +100,7 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
|
||||||
directionInfo++;
|
directionInfo++;
|
||||||
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
|
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
|
||||||
net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info);
|
net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info);
|
||||||
if(info.getDescriptionRoute() != null){
|
contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute(ctx));
|
||||||
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);
|
||||||
}
|
}
|
||||||
view.refreshMap();
|
view.refreshMap();
|
||||||
|
|
Loading…
Reference in a new issue