Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2014-10-02 17:50:28 +02:00
commit a20dbb79d8
10 changed files with 299 additions and 402 deletions

View file

@ -267,6 +267,16 @@ public class RouteDataObject {
public String getHighway() { public String getHighway() {
return getHighway(types, region); return getHighway(types, region);
} }
public String getValue(String tag) {
for (int i = 0; i < types.length; i++) {
RouteTypeRule r = region.quickGetEncodingRule(types[i]);
if (r.getTag().equals(tag)) {
return r.getValue();
}
}
return null;
}
public static String getHighway(int[] types, RouteRegion region) { public static String getHighway(int[] types, RouteRegion region) {
String highway = null; String highway = null;
@ -351,6 +361,7 @@ public class RouteDataObject {
return Math.abs(px - x) * 0.011d + Math.abs(py - y) * 0.01863d; return Math.abs(px - x) * 0.011d + Math.abs(py - y) * 0.01863d;
} }
@Override @Override
public String toString() { public String toString() {
String name = getName(); String name = getName();

View file

@ -338,8 +338,8 @@ public class RouteResultPreparation {
t = getTurnInfo(result, i, leftside); t = getTurnInfo(result, i, leftside);
// justify turn // justify turn
if(t != null && i < result.size() - 1) { if(t != null && i < result.size() - 1) {
boolean tl = TurnType.TL.equals(t.getValue()); boolean tl = TurnType.TL == t.getValue();
boolean tr = TurnType.TR.equals(t.getValue()); boolean tr = TurnType.TR == t.getValue();
if(tl || tr) { if(tl || tr) {
TurnType tnext = getTurnInfo(result, i + 1, leftside); TurnType tnext = getTurnInfo(result, i + 1, leftside);
if (tnext != null && result.get(i).getDistance() < 35) { // if (tnext != null && result.get(i).getDistance() < 35) { //
@ -357,10 +357,10 @@ public class RouteResultPreparation {
ut = false; ut = false;
} }
if (ut) { if (ut) {
if (tl && TurnType.TL.equals(tnext.getValue())) { if (tl && TurnType.TL == tnext.getValue()) {
next = i + 2; next = i + 2;
t = TurnType.valueOf(TurnType.TU, false); t = TurnType.valueOf(TurnType.TU, false);
} else if (tr && TurnType.TR.equals(tnext.getValue())) { } else if (tr && TurnType.TR == tnext.getValue()) {
next = i + 2; next = i + 2;
t = TurnType.valueOf(TurnType.TU, true); t = TurnType.valueOf(TurnType.TU, true);
} }
@ -486,7 +486,7 @@ public class RouteResultPreparation {
} }
} }
// combine all roundabouts // combine all roundabouts
TurnType t = TurnType.valueOf("EXIT"+exit, leftSide); TurnType t = TurnType.getExitTurn(exit, 0, leftSide);
t.setTurnAngle((float) MapUtils.degreesDiff(last.getBearingBegin(), prev.getBearingEnd())) ; t.setTurnAngle((float) MapUtils.degreesDiff(last.getBearingBegin(), prev.getBearingEnd())) ;
return t; return t;
} }
@ -516,7 +516,7 @@ public class RouteResultPreparation {
kl = true; kl = true;
int lns = attached.getObject().getLanes(); int lns = attached.getObject().getLanes();
if(attached.getObject().getOneway() == 0) { if(attached.getObject().getOneway() == 0) {
lns = (lns + 1) / 2; lns = countLines(attached, lns);
} }
if (lns > 0) { if (lns > 0) {
right += lns; right += lns;
@ -526,7 +526,7 @@ public class RouteResultPreparation {
kr = true; kr = true;
int lns = attached.getObject().getLanes(); int lns = attached.getObject().getLanes();
if(attached.getObject().getOneway() == 0) { if(attached.getObject().getOneway() == 0) {
lns = (lns + 1) / 2; lns = countLines(attached, lns);
} }
if (lns > 0) { if (lns > 0) {
left += lns; left += lns;
@ -542,8 +542,9 @@ public class RouteResultPreparation {
right = 1; right = 1;
} }
int current = currentSegm.getObject().getLanes(); int current = currentSegm.getObject().getLanes();
if(currentSegm.getObject().getOneway() == 0) { // attachedRoutes covers all allowed outbound routes at that point except currentSegm.
current = (current + 1) / 2; if (currentSegm.getObject().getOneway() == 0) {
current = countLines(currentSegm, current);
} }
if (current <= 0) { if (current <= 0) {
current = 1; current = 1;
@ -579,6 +580,19 @@ public class RouteResultPreparation {
} }
return t; return t;
} }
protected int countLines(RouteSegmentResult attached, int lns) {
try {
if (attached.isForwardDirection() && attached.getObject().getValue("lanes:forward") != null) {
return Integer.parseInt(attached.getObject().getValue("lanes:forward"));
} else if (!attached.isForwardDirection() && attached.getObject().getValue("lanes:backward") != null) {
return Integer.parseInt(attached.getObject().getValue("lanes:backward"));
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
return (lns + 1) / 2;
}
private boolean isMotorway(RouteSegmentResult s){ private boolean isMotorway(RouteSegmentResult s){
String h = s.getObject().getHighway(); String h = s.getObject().getHighway();

View file

@ -140,6 +140,11 @@ public class RouteSegmentResult {
return convertPoint(object, endPointIndex); return convertPoint(object, endPointIndex);
} }
public boolean isForwardDirection() {
return endPointIndex - startPointIndex > 0;
}
private LatLon convertPoint(RouteDataObject o, int ind){ private LatLon convertPoint(RouteDataObject o, int ind){
return new LatLon(MapUtils.get31LatitudeY(o.getPoint31YTile(ind)), MapUtils.get31LongitudeX(o.getPoint31XTile(ind))); return new LatLon(MapUtils.get31LatitudeY(o.getPoint31YTile(ind)), MapUtils.get31LongitudeX(o.getPoint31XTile(ind)));
} }

View file

@ -1,77 +1,148 @@
package net.osmand.router; package net.osmand.router;
public class TurnType { public class TurnType {
public static final String C = "C"; // continue (go straight) //$NON-NLS-1$ public static final int C = 1;//"C"; // continue (go straight) //$NON-NLS-1$
public static final String TL = "TL"; // turn left //$NON-NLS-1$ public static final int TL = 2; // turn left //$NON-NLS-1$
public static final String TSLL = "TSLL"; // turn slightly left //$NON-NLS-1$ public static final int TSLL = 3; // turn slightly left //$NON-NLS-1$
public static final String TSHL = "TSHL"; // turn sharply left //$NON-NLS-1$ public static final int TSHL = 4; // turn sharply left //$NON-NLS-1$
public static final String TR = "TR"; // turn right //$NON-NLS-1$ public static final int TR = 5; // turn right //$NON-NLS-1$
public static final String TSLR = "TSLR"; // turn slightly right //$NON-NLS-1$ public static final int TSLR = 6; // turn slightly right //$NON-NLS-1$
public static final String TSHR = "TSHR"; // turn sharply right //$NON-NLS-1$ public static final int TSHR = 7; // turn sharply right //$NON-NLS-1$
public static final String KL = "KL"; // keep left //$NON-NLS-1$ public static final int KL = 8; // keep left //$NON-NLS-1$
public static final String KR = "KR"; // keep right//$NON-NLS-1$ public static final int KR = 9; // keep right//$NON-NLS-1$
public static final String TU = "TU"; // U-turn //$NON-NLS-1$ public static final int TU = 10; // U-turn //$NON-NLS-1$
public static final String TRU = "TRU"; // Right U-turn //$NON-NLS-1$ public static final int TRU = 11; // Right U-turn //$NON-NLS-1$
public static final String OFFR = "OFFR"; // Off route //$NON-NLS-1$ public static final int OFFR = 12; // Off route //$NON-NLS-1$
public static String[] predefinedTypes = new String[] { C, KL, KR, TL, TSLL, TSHL, TR, TSLR, TSHR, TU, TRU, OFFR }; public static final int RNDB = 13; // Roundabout
public static final int RNLB = 14; // Roundabout left
public static TurnType sraight() { public static TurnType straight() {
return valueOf(C, false); return valueOf(C, false);
} }
public static TurnType valueOf(String s, boolean leftSide) { public String toXmlString() {
for (String v : predefinedTypes) { switch (value) {
if (v.equals(s)) { case C:
if (leftSide && TU.equals(v)) { return "C";
v = TRU; case TL:
} return "TL";
return new TurnType(v); case TSLL:
return "TSLL";
case TSHL:
return "TSHL";
case TR:
return "TR";
case TSLR:
return "TSLR";
case TSHR:
return "TSHR";
case KL:
return "KL";
case KR:
return "KR";
case TU:
return "TU";
case TRU:
return "TRU";
case OFFR:
return "OFFR";
case RNDB:
return "RNDB"+exitOut;
case RNLB:
return "RNLB"+exitOut;
}
return "C";
}
public static TurnType fromString(String s, boolean leftSide) {
TurnType t = null;
if ("C".equals(s)) {
t = TurnType.valueOf(C, leftSide);
} else if ("TL".equals(s)) {
t = TurnType.valueOf(TL, leftSide);
} else if ("TSLL".equals(s)) {
t = TurnType.valueOf(TSLL, leftSide);
} else if ("TSHL".equals(s)) {
t = TurnType.valueOf(TSHL, leftSide);
} else if ("TR".equals(s)) {
t = TurnType.valueOf(TR, leftSide);
} else if ("TSLR".equals(s)) {
t = TurnType.valueOf(TSLR, leftSide);
} else if ("TSHR".equals(s)) {
t = TurnType.valueOf(TSHR, leftSide);
} else if ("KL".equals(s)) {
t = TurnType.valueOf(KL, leftSide);
} else if ("KR".equals(s)) {
t = TurnType.valueOf(KR, leftSide);
} else if ("TU".equals(s)) {
t = TurnType.valueOf(TU, leftSide);
} else if ("TRU".equals(s)) {
t = TurnType.valueOf(TRU, leftSide);
} else if ("OFFR".equals(s)) {
t = TurnType.valueOf(OFFR, leftSide);
} else if (s != null && (s.startsWith("EXIT") ||
s.startsWith("RNDB") || s.startsWith("RNLB"))) {
try {
t = TurnType.getExitTurn(Integer.parseInt(s.substring(4)), 0, leftSide);
} catch (NumberFormatException e) {
e.printStackTrace();
} }
} }
if (s != null && s.startsWith("EXIT")) { //$NON-NLS-1$ if(t == null) {
return getExitTurn(Integer.parseInt(s.substring(4)), 0, leftSide); t = TurnType.straight();
} }
return null; return t;
}
public static TurnType valueOf(int vs, boolean leftSide) {
if(vs == TU && leftSide) {
vs = TRU;
} else if(vs == RNDB && leftSide) {
vs = RNLB;
}
return new TurnType(vs);
// if (s != null && s.startsWith("EXIT")) { //$NON-NLS-1$
// return getExitTurn(Integer.parseInt(s.substring(4)), 0, leftSide);
// }
// return null;
} }
private final String value; private final int value;
private int exitOut; private int exitOut;
private boolean isLeftSide;
// calculated clockwise head rotation if previous direction to NORTH // calculated clockwise head rotation if previous direction to NORTH
private float turnAngle; private float turnAngle;
private boolean skipToSpeak; private boolean skipToSpeak;
private int[] lanes; private int[] lanes;
private static TurnType getExitTurn(int out, float angle, boolean leftSide) { public static TurnType getExitTurn(int out, float angle, boolean leftSide) {
TurnType r = new TurnType("EXIT", out, leftSide); //$NON-NLS-1$ TurnType r = valueOf(RNDB, leftSide); //$NON-NLS-1$
r.exitOut = out;
r.setTurnAngle(angle); r.setTurnAngle(angle);
return r; return r;
} }
private TurnType(String value, int exitOut, boolean leftSide) {
this.value = value; private TurnType(int vl) {
this.exitOut = exitOut; this.value = vl;
this.isLeftSide = leftSide;
} }
// calculated Clockwise head rotation if previous direction to NORTH // calculated Clockwise head rotation if previous direction to NORTH
public float getTurnAngle() { public float getTurnAngle() {
return turnAngle; return turnAngle;
} }
public boolean isLeftSide() { public boolean isLeftSide() {
return isLeftSide; return value == RNLB || value == TRU;
} }
public void setTurnAngle(float turnAngle) { public void setTurnAngle(float turnAngle) {
this.turnAngle = turnAngle; this.turnAngle = turnAngle;
} }
private TurnType(String value) {
this.value = value;
}
public String getValue() { public int getValue() {
return value; return value;
} }
@ -80,66 +151,88 @@ public class TurnType {
} }
public boolean isRoundAbout() { public boolean isRoundAbout() {
return value.equals("EXIT"); //$NON-NLS-1$ return value == RNDB || value == RNLB; //$NON-NLS-1$
} }
// lanes encoded as array of int // lanes encoded as array of int
// last bit is 1, 0 (should we take this lane) // 0 byte - 0/1 - to use or not
// first bits 0 - left, 1 - straight, 2 - right // 1-5 byte - additional turn info
// 6-10 byte - secondary turn
public void setLanes(int[] lanes) { public void setLanes(int[] lanes) {
this.lanes = lanes; this.lanes = lanes;
} }
// Note that there is no "weight" or ordering between the primary and secondary turns.
public void setPrimaryTurn(int lane, int turnType) {
lanes[lane] |= (turnType << 1);
}
public static int getPrimaryTurn(int laneValue) {
// Get the primary turn modifier for the lane
return (laneValue >> 1) & ((1 << 4) - 1);
}
public void setSecondaryTurn(int lane, int turnType) {
lanes[lane] |= (turnType << 5);
}
public static int getSecondaryTurn(int laneValue) {
// Get the primary turn modifier for the lane
return (laneValue >> 5);
}
public int[] getLanes() { public int[] getLanes() {
return lanes; return lanes;
} }
public boolean keepLeft() { public boolean keepLeft() {
return value.equals(KL); return value == KL;
} }
public boolean keepRight() { public boolean keepRight() {
return value.equals(KR); return value == KR;
} }
public boolean goAhead() { public boolean goAhead() {
return value.equals(C); return value == C;
} }
public boolean isSkipToSpeak() { public boolean isSkipToSpeak() {
return skipToSpeak; return skipToSpeak;
} }
public void setSkipToSpeak(boolean skipToSpeak) { public void setSkipToSpeak(boolean skipToSpeak) {
this.skipToSpeak = skipToSpeak; this.skipToSpeak = skipToSpeak;
} }
@Override @Override
public String toString() { public String toString() {
if(isRoundAbout()){ if (isRoundAbout()) {
return "Take " + getExitOut() + " exit"; return "Take " + getExitOut() + " exit";
} else if(value.equals(C)) { } else if (value == C) {
return "Go ahead"; return "Go ahead";
} else if(value.equals(TSLL)) { } else if (value == TSLL) {
return "Turn slightly left"; return "Turn slightly left";
} else if(value.equals(TL)) { } else if (value == TL) {
return "Turn left"; return "Turn left";
} else if(value.equals(TSHL)) { } else if (value == TSHL) {
return "Turn sharply left"; return "Turn sharply left";
} else if(value.equals(TSLR)) { } else if (value == TSLR) {
return "Turn slightly right"; return "Turn slightly right";
} else if(value.equals(TR)) { } else if (value == TR) {
return "Turn right"; return "Turn right";
} else if(value.equals(TSHR)) { } else if (value == TSHR) {
return "Turn sharply right"; return "Turn sharply right";
} else if(value.equals(TU)) { } else if (value == TU) {
return "Make uturn"; return "Make uturn";
} else if(value.equals(TRU)) { } else if (value == TRU) {
return "Make uturn"; return "Make uturn";
} else if(value.equals(KL)) { } else if (value == KL) {
return "Keep left"; return "Keep left";
} else if(value.equals(KR)) { } else if (value == KR) {
return "Keep right"; return "Keep right";
} else if(value.equals(OFFR)) { } else if (value == OFFR) {
return "Off route"; return "Off route";
} }
return super.toString(); return super.toString();

View file

@ -149,7 +149,7 @@ public class RouteCalculationResult {
if (locationIndex > interLocations[currentIntermediate] if (locationIndex > interLocations[currentIntermediate]
&& getDistanceToLocation(locations, intermediates.get(currentIntermediate), locationIndex) > 50) { && getDistanceToLocation(locations, intermediates.get(currentIntermediate), locationIndex) > 50) {
RouteDirectionInfo toSplit = localDirections.get(currentDirection); RouteDirectionInfo toSplit = localDirections.get(currentDirection);
RouteDirectionInfo info = new RouteDirectionInfo(localDirections.get(currentDirection).getAverageSpeed(), TurnType.sraight()); RouteDirectionInfo info = new RouteDirectionInfo(localDirections.get(currentDirection).getAverageSpeed(), TurnType.straight());
info.setRef(toSplit.getRef()); info.setRef(toSplit.getRef());
info.setStreetName(toSplit.getStreetName()); info.setStreetName(toSplit.getStreetName());
info.setDestinationName(toSplit.getDestinationName()); info.setDestinationName(toSplit.getDestinationName());
@ -296,7 +296,7 @@ public class RouteCalculationResult {
int previousLocation = 0; int previousLocation = 0;
int prevBearingLocation = 0; int prevBearingLocation = 0;
RouteDirectionInfo previousInfo = new RouteDirectionInfo(speed, TurnType.sraight()); RouteDirectionInfo previousInfo = new RouteDirectionInfo(speed, TurnType.straight());
previousInfo.routePointOffset = 0; previousInfo.routePointOffset = 0;
previousInfo.setDescriptionRoute(ctx.getString( R.string.route_head)); previousInfo.setDescriptionRoute(ctx.getString( R.string.route_head));
computeDirections.add(previousInfo); computeDirections.add(previousInfo);
@ -443,27 +443,27 @@ public class RouteCalculationResult {
public static String toString(TurnType type, Context ctx) { public static String toString(TurnType type, Context ctx) {
if(type.isRoundAbout()){ if(type.isRoundAbout()){
return ctx.getString(R.string.route_roundabout, type.getExitOut()); return ctx.getString(R.string.route_roundabout, type.getExitOut());
} else if(type.getValue().equals(TurnType.C)) { } else if(type.getValue() == TurnType.C) {
return ctx.getString(R.string.route_head); return ctx.getString(R.string.route_head);
} else if(type.getValue().equals(TurnType.TSLL)) { } else if(type.getValue() == TurnType.TSLL) {
return ctx.getString(R.string.route_tsll); return ctx.getString(R.string.route_tsll);
} else if(type.getValue().equals(TurnType.TL)) { } else if(type.getValue() == TurnType.TL) {
return ctx.getString(R.string.route_tl); return ctx.getString(R.string.route_tl);
} else if(type.getValue().equals(TurnType.TSHL)) { } else if(type.getValue() == TurnType.TSHL) {
return ctx.getString(R.string.route_tshl); return ctx.getString(R.string.route_tshl);
} else if(type.getValue().equals(TurnType.TSLR)) { } else if(type.getValue() == TurnType.TSLR) {
return ctx.getString(R.string.route_tslr); return ctx.getString(R.string.route_tslr);
} else if(type.getValue().equals(TurnType.TR)) { } else if(type.getValue() == TurnType.TR) {
return ctx.getString(R.string.route_tr); return ctx.getString(R.string.route_tr);
} else if(type.getValue().equals(TurnType.TSHR)) { } else if(type.getValue() == TurnType.TSHR) {
return ctx.getString(R.string.route_tshr); return ctx.getString(R.string.route_tshr);
} else if(type.getValue().equals(TurnType.TU)) { } else if(type.getValue() == TurnType.TU) {
return ctx.getString(R.string.route_tu); return ctx.getString(R.string.route_tu);
} else if(type.getValue().equals(TurnType.TRU)) { } else if(type.getValue() == TurnType.TRU) {
return ctx.getString(R.string.route_tu); return ctx.getString(R.string.route_tu);
} else if(type.getValue().equals(TurnType.KL)) { } else if(type.getValue() == TurnType.KL) {
return ctx.getString(R.string.route_kl); return ctx.getString(R.string.route_kl);
} else if(type.getValue().equals(TurnType.KR)) { } else if(type.getValue() == TurnType.KR) {
return ctx.getString(R.string.route_kr); return ctx.getString(R.string.route_kr);
} }
return ""; return "";
@ -483,7 +483,7 @@ public class RouteCalculationResult {
if (directions != null && directions.size() > 1) { if (directions != null && directions.size() > 1) {
for (int i = 1; i < directions.size();) { for (int i = 1; i < directions.size();) {
RouteDirectionInfo r = directions.get(i); RouteDirectionInfo r = directions.get(i);
if (r.getTurnType().getValue().equals(TurnType.C)) { if (r.getTurnType().getValue() == TurnType.C) {
RouteDirectionInfo prev = directions.get(i - 1); RouteDirectionInfo prev = directions.get(i - 1);
prev.setAverageSpeed((prev.distance + r.distance) prev.setAverageSpeed((prev.distance + r.distance)
/ (prev.distance / prev.getAverageSpeed() + r.distance / r.getAverageSpeed())); / (prev.distance / prev.getAverageSpeed() + r.distance / r.getAverageSpeed()));
@ -536,7 +536,7 @@ public class RouteCalculationResult {
i.routePointOffset++; i.routePointOffset++;
} }
RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(), RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(),
TurnType.sraight()); TurnType.straight());
info.routePointOffset = 0; info.routePointOffset = 0;
// info.setDescriptionRoute(ctx.getString( R.string.route_head));//; //$NON-NLS-1$ // info.setDescriptionRoute(ctx.getString( R.string.route_head));//; //$NON-NLS-1$
directions.add(0, info); directions.add(0, info);
@ -544,7 +544,7 @@ public class RouteCalculationResult {
} }
RouteDirectionInfo lastDirInf = directions.size() > 0 ? directions.get(directions.size() - 1) : null; RouteDirectionInfo lastDirInf = directions.size() > 0 ? directions.get(directions.size() - 1) : null;
if((lastDirInf == null || lastDirInf.routePointOffset < locations.size() - 1) && locations.size() - 1 > 0) { if((lastDirInf == null || lastDirInf.routePointOffset < locations.size() - 1) && locations.size() - 1 > 0) {
String type = TurnType.C; int type = TurnType.C;
Location prevLast = locations.get(locations.size() - 2); Location prevLast = locations.get(locations.size() - 2);
float lastBearing = prevLast.bearingTo(locations.get(locations.size() - 1)); float lastBearing = prevLast.bearingTo(locations.get(locations.size() - 1));
float[] compute = new float[2]; float[] compute = new float[2];

View file

@ -850,9 +850,9 @@ public class RouteProvider {
String stype = item.getExtensionsToRead().get("turn"); //$NON-NLS-1$ String stype = item.getExtensionsToRead().get("turn"); //$NON-NLS-1$
TurnType turnType; TurnType turnType;
if (stype != null) { if (stype != null) {
turnType = TurnType.valueOf(stype.toUpperCase(), leftSide); turnType = TurnType.fromString(stype.toUpperCase(), leftSide);
} else { } else {
turnType = TurnType.sraight(); turnType = TurnType.straight();
} }
String sturn = item.getExtensionsToRead().get("turn-angle"); //$NON-NLS-1$ String sturn = item.getExtensionsToRead().get("turn-angle"); //$NON-NLS-1$
if (sturn != null) { if (sturn != null) {
@ -861,7 +861,7 @@ public class RouteProvider {
RouteDirectionInfo dirInfo = new RouteDirectionInfo(avgSpeed, turnType); RouteDirectionInfo dirInfo = new RouteDirectionInfo(avgSpeed, turnType);
dirInfo.setDescriptionRoute(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 != previous.getTurnType().getValue() &&
!osmandRouter) { !osmandRouter) {
// calculate angle // calculate angle
if (previous.routePointOffset > 0) { if (previous.routePointOffset > 0) {
@ -897,7 +897,7 @@ public class RouteProvider {
} }
} }
} }
if (previous != null && !TurnType.C.equals(previous.getTurnType().getValue())) { if (previous != null && TurnType.C != previous.getTurnType().getValue()) {
// calculate angle // calculate angle
if (previous.routePointOffset > 0 && previous.routePointOffset < res.size() - 1) { if (previous.routePointOffset > 0 && previous.routePointOffset < res.size() - 1) {
float paz = res.get(previous.routePointOffset - 1).bearingTo(res.get(previous.routePointOffset)); float paz = res.get(previous.routePointOffset - 1).bearingTo(res.get(previous.routePointOffset));
@ -1035,12 +1035,9 @@ public class RouteProvider {
pt.desc = dirInfo.getDescriptionRoute(ctx); 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(); int turnType = dirInfo.getTurnType().getValue();
if (dirInfo.getTurnType().isRoundAbout()) { if(TurnType.C != turnType){
turnType += dirInfo.getTurnType().getExitOut(); extensions.put("turn", dirInfo.getTurnType().toXmlString());
}
if(!TurnType.C.equals(turnType)){
extensions.put("turn", turnType);
extensions.put("turn-angle", dirInfo.getTurnType().getTurnAngle() + ""); extensions.put("turn-angle", dirInfo.getTurnType().getTurnAngle() + "");
} }
extensions.put("offset", (dirInfo.routePointOffset - cRoute) + ""); extensions.put("offset", (dirInfo.routePointOffset - cRoute) + "");

View file

@ -4,14 +4,10 @@ package net.osmand.plus.routing;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import android.media.AudioManager;
import android.media.SoundPool;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.binary.RouteDataObject; import net.osmand.binary.RouteDataObject;
import net.osmand.data.LocationPoint;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType; import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
@ -25,6 +21,8 @@ import net.osmand.util.MapUtils;
import alice.tuprolog.Struct; import alice.tuprolog.Struct;
import alice.tuprolog.Term; import alice.tuprolog.Term;
import android.content.Context; import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
public class VoiceRouter { public class VoiceRouter {
@ -567,7 +565,7 @@ public class VoiceRouter {
play.prepareTurn(tParam, dist, getSpeakableStreetName(currentSegment, next)).play(); play.prepareTurn(tParam, dist, getSpeakableStreetName(currentSegment, next)).play();
} else if(next.getTurnType().isRoundAbout()){ } else if(next.getTurnType().isRoundAbout()){
play.prepareRoundAbout(dist, next.getTurnType().getExitOut(), getSpeakableStreetName(currentSegment, next)).play(); play.prepareRoundAbout(dist, next.getTurnType().getExitOut(), getSpeakableStreetName(currentSegment, next)).play();
} else if(next.getTurnType().getValue().equals(TurnType.TU) || next.getTurnType().getValue().equals(TurnType.TRU)){ } else if(next.getTurnType().getValue() == TurnType.TU || next.getTurnType().getValue() == TurnType.TRU){
play.prepareMakeUT(dist, getSpeakableStreetName(currentSegment, next)).play(); play.prepareMakeUT(dist, getSpeakableStreetName(currentSegment, next)).play();
} }
} }
@ -582,7 +580,7 @@ public class VoiceRouter {
play.turn(tParam, dist, getSpeakableStreetName(currentSegment, next)); play.turn(tParam, dist, getSpeakableStreetName(currentSegment, next));
} else if (next.getTurnType().isRoundAbout()) { } else if (next.getTurnType().isRoundAbout()) {
play.roundAbout(dist, next.getTurnType().getTurnAngle(), next.getTurnType().getExitOut(), getSpeakableStreetName(currentSegment, next)); play.roundAbout(dist, next.getTurnType().getTurnAngle(), next.getTurnType().getExitOut(), getSpeakableStreetName(currentSegment, next));
} else if (next.getTurnType().getValue().equals(TurnType.TU) || next.getTurnType().getValue().equals(TurnType.TRU)) { } else if (next.getTurnType().getValue() == TurnType.TU || next.getTurnType().getValue() == TurnType.TRU) {
play.makeUT(dist, getSpeakableStreetName(currentSegment, next)); play.makeUT(dist, getSpeakableStreetName(currentSegment, next));
} else { } else {
isPlay = false; isPlay = false;
@ -591,15 +589,15 @@ public class VoiceRouter {
if (pronounceNextNext != null) { if (pronounceNextNext != null) {
TurnType t = pronounceNextNext.getTurnType(); TurnType t = pronounceNextNext.getTurnType();
isPlay = true; isPlay = true;
if (next.getTurnType().getValue().equals(TurnType.C) && if (next.getTurnType().getValue() == TurnType.C &&
!TurnType.C.equals(t.getValue())) { TurnType.C != t.getValue()) {
play.goAhead(dist, getSpeakableStreetName(currentSegment, next)); play.goAhead(dist, getSpeakableStreetName(currentSegment, next));
} }
if (TurnType.TL.equals(t.getValue()) || TurnType.TSHL.equals(t.getValue()) || TurnType.TSLL.equals(t.getValue()) if (TurnType.TL == t.getValue() || TurnType.TSHL == t.getValue() || TurnType.TSLL == t.getValue()
|| TurnType.TU.equals(t.getValue()) || TurnType.KL.equals(t.getValue())) { || TurnType.TU == t.getValue() || TurnType.KL == t.getValue()) {
play.then().bearLeft( getSpeakableStreetName(currentSegment, next)); play.then().bearLeft( getSpeakableStreetName(currentSegment, next));
} else if (TurnType.TR.equals(t.getValue()) || TurnType.TSHR.equals(t.getValue()) || TurnType.TSLR.equals(t.getValue()) } else if (TurnType.TR == t.getValue() || TurnType.TSHR == t.getValue() || TurnType.TSLR == t.getValue()
|| TurnType.KR.equals(t.getValue())) { || TurnType.KR == t.getValue()) {
play.then().bearRight( getSpeakableStreetName(currentSegment, next)); play.then().bearRight( getSpeakableStreetName(currentSegment, next));
} }
} }
@ -632,10 +630,10 @@ public class VoiceRouter {
play.turn(tParam, getSpeakableStreetName(currentSegment, next)); play.turn(tParam, getSpeakableStreetName(currentSegment, next));
} else if(next.getTurnType().isRoundAbout()){ } else if(next.getTurnType().isRoundAbout()){
play.roundAbout(next.getTurnType().getTurnAngle(), next.getTurnType().getExitOut(), getSpeakableStreetName(currentSegment, next)); play.roundAbout(next.getTurnType().getTurnAngle(), next.getTurnType().getExitOut(), getSpeakableStreetName(currentSegment, next));
} else if(next.getTurnType().getValue().equals(TurnType.TU) || next.getTurnType().getValue().equals(TurnType.TRU)){ } else if(next.getTurnType().getValue() == TurnType.TU || next.getTurnType().getValue() == TurnType.TRU){
play.makeUT( getSpeakableStreetName(currentSegment, next)); play.makeUT( getSpeakableStreetName(currentSegment, next));
// do not say it // do not say it
// } else if(next.getTurnType().getValue().equals(TurnType.C)){ // } else if(next.getTurnType().getValue() == TurnType.C)){
// play.goAhead(); // play.goAhead();
} else { } else {
isplay = false; isplay = false;
@ -649,7 +647,7 @@ public class VoiceRouter {
} else if (nextNext.getTurnType().isRoundAbout()) { } else if (nextNext.getTurnType().isRoundAbout()) {
if(isplay) { play.then(); } if(isplay) { play.then(); }
play.roundAbout(next.distance, nextNext.getTurnType().getTurnAngle(), nextNext.getTurnType().getExitOut(), empty); play.roundAbout(next.distance, nextNext.getTurnType().getTurnAngle(), nextNext.getTurnType().getExitOut(), empty);
} else if (nextNext.getTurnType().getValue().equals(TurnType.TU)) { } else if (nextNext.getTurnType().getValue() == TurnType.TU) {
if(isplay) { play.then(); } if(isplay) { play.then(); }
play.makeUT(next.distance, empty); play.makeUT(next.distance, empty);
} }
@ -662,21 +660,21 @@ public class VoiceRouter {
} }
private String getTurnType(TurnType t){ private String getTurnType(TurnType t){
if(TurnType.TL.equals(t.getValue())){ if(TurnType.TL == t.getValue()){
return AbstractPrologCommandPlayer.A_LEFT; return AbstractPrologCommandPlayer.A_LEFT;
} else if(TurnType.TSHL.equals(t.getValue())){ } else if(TurnType.TSHL == t.getValue()){
return AbstractPrologCommandPlayer.A_LEFT_SH; return AbstractPrologCommandPlayer.A_LEFT_SH;
} else if(TurnType.TSLL.equals(t.getValue())){ } else if(TurnType.TSLL == t.getValue()){
return AbstractPrologCommandPlayer.A_LEFT_SL; return AbstractPrologCommandPlayer.A_LEFT_SL;
} else if(TurnType.TR.equals(t.getValue())){ } else if(TurnType.TR == t.getValue()){
return AbstractPrologCommandPlayer.A_RIGHT; return AbstractPrologCommandPlayer.A_RIGHT;
} else if(TurnType.TSHR.equals(t.getValue())){ } else if(TurnType.TSHR == t.getValue()){
return AbstractPrologCommandPlayer.A_RIGHT_SH; return AbstractPrologCommandPlayer.A_RIGHT_SH;
} else if(TurnType.TSLR.equals(t.getValue())){ } else if(TurnType.TSLR == t.getValue()){
return AbstractPrologCommandPlayer.A_RIGHT_SL; return AbstractPrologCommandPlayer.A_RIGHT_SL;
} else if(TurnType.KL.equals(t.getValue())){ } else if(TurnType.KL == t.getValue()){
return AbstractPrologCommandPlayer.A_LEFT_KEEP; return AbstractPrologCommandPlayer.A_LEFT_KEEP;
} else if(TurnType.KR.equals(t.getValue())){ } else if(TurnType.KR == t.getValue()){
return AbstractPrologCommandPlayer.A_RIGHT_KEEP; return AbstractPrologCommandPlayer.A_RIGHT_KEEP;
} }
return null; return null;

View file

@ -1,264 +0,0 @@
package net.osmand.plus.sherpafy;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.SystemClock;
import android.support.v4.widget.DrawerLayout;
import android.text.Spannable;
import android.text.style.ForegroundColorSpan;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import net.osmand.Location;
import net.osmand.data.LocationPoint;
import net.osmand.plus.*;
import net.osmand.plus.activities.FavouritesActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.views.MapControlsLayer;
import net.osmand.util.MapUtils;
import java.util.List;
/**
* Created by Denis on 25.07.2014.
*/
public class WaypointDialogHelper {
private MapActivity mapActivity;
private OsmandApplication app;
private FrameLayout mainLayout;
private OsmAndLocationProvider locationProvider;
public static boolean OVERLAP_LAYOUT = true;
private long uiModified;
private View closePointDialog;
public WaypointDialogHelper(MapActivity mapActivity) {
this.app = mapActivity.getMyApplication();
locationProvider = this.app.getLocationProvider();
this.mapActivity = mapActivity;
this.mainLayout = (FrameLayout) ((DrawerLayout) ((FrameLayout) mapActivity.getLayout()).getChildAt(0)).getChildAt(0);
}
public void updateDialog() {
List<LocationPoint> vlp = locationProvider.getVisibleLocationPoints();
long locationPointsModified = locationProvider.getLocationPointsModified();
if (locationPointsModified != uiModified) {
uiModified = locationPointsModified;
if (vlp.isEmpty()) {
removeDialog();
} else {
final LocationPoint point = vlp.get(0);
boolean created = false;
if (closePointDialog == null) {
created = true;
final LayoutInflater vi = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
closePointDialog = vi.inflate(R.layout.waypoint_reached, null);
}
updatePointInfoView(closePointDialog, point);
closePointDialog.setBackgroundColor(mapActivity.getResources().getColor(R.color.color_black));
((TextView)closePointDialog.findViewById(R.id.waypoint_text)).setTextColor(Color.WHITE);
View all = closePointDialog.findViewById(R.id.all_points);
all.setVisibility(vlp.size() <= 1 ? View.GONE : View.VISIBLE);
all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showAllDialog();
}
});
View btnN = closePointDialog.findViewById(R.id.info_close);
btnN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
locationProvider.removeVisibleLocationPoint(point);
updateDialog();
}
});
if (created) {
mainLayout.addView(closePointDialog, getDialogLayoutParams());
waitBeforeLayoutIsResized(closePointDialog);
}
}
}
}
private void updatePointInfoView(View localView, final LocationPoint point) {
TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
itemClick(point);
}
});
((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(FavoriteImageDrawable.getOrCreate(mapActivity, point.getColor()));
Location lastKnownMapLocation = app.getLocationProvider().getLastKnownLocation();
String distance;
if (lastKnownMapLocation != null) {
int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
distance = OsmAndFormatter.getFormattedDistance(dist, app) + " ";
} else {
distance = "";
}
text.setText(distance + point.getName(), TextView.BufferType.SPANNABLE);
if (distance.length() > 0) {
((Spannable) text.getText()).setSpan(
new ForegroundColorSpan(mapActivity.getResources().getColor(R.color.color_distance)), 0, distance.length() - 1,
0);
}
}
private void itemClick(LocationPoint point) {
final Intent favorites = new Intent(mapActivity, app.getAppCustomization().getFavoritesActivity());
favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
favorites.putExtra(FavouritesActivity.TAB_PARAM,
point instanceof GPXUtilities.WptPt ? FavouritesActivity.GPX_TAB : FavouritesActivity.FAVORITES_TAB);
mapActivity.startActivity(favorites);
}
public void removeDialog() {
if (closePointDialog != null) {
mainLayout.removeView(closePointDialog);
closePointDialog = null;
shiftButtons(0);
}
}
private FrameLayout.LayoutParams getDialogLayoutParams() {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
return params;
}
private boolean checkIfDialogExists() {
if (mainLayout == null) {
return true;
}
if (mainLayout.findViewById(R.id.package_delivered_layout) != null) {
return false;
}
return true;
}
private void shiftButtons(int height) {
MapControlsLayer mapControls = mapActivity.getMapLayers().getMapControlsLayer();
if (mapControls != null) {
mapControls.shiftLayout(height);
}
}
private void waitBeforeLayoutIsResized(View reachedView) {
//this async task is needed because layout height is not set
// right after you add it so we need to w8 some time
new AsyncTask<View, Void, Void>() {
int height;
@Override
protected Void doInBackground(View... params) {
for (int i = 0; i < 10; i++) {
SystemClock.sleep(50);
height = params[0].getHeight();
if (params[0].getHeight() > 0) {
break;
}
}
return null;
}
protected void onPostExecute(Void result) {
if (height > 0 && OVERLAP_LAYOUT) {
shiftButtons(height);
}
}
}.execute(reachedView);
}
public void showAllDialog(){
final List<LocationPoint> visibleLocationPoints = locationProvider.getVisibleLocationPoints();
final ArrayAdapter<LocationPoint> listAdapter = new ArrayAdapter<LocationPoint>(mapActivity, R.layout.waypoint_reached, R.id.title,
visibleLocationPoints) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
v = mapActivity.getLayoutInflater().inflate(R.layout.waypoint_reached, null);
int vl = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, mapActivity.getResources()
.getDisplayMetrics());
final LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(vl, vl);
ll.setMargins(vl / 4, vl / 4, vl / 4, vl / 4);
v.findViewById(R.id.waypoint_icon).setLayoutParams(ll);
}
updatePointInfoView(v, getItem(position));
TextView text = (TextView) v.findViewById(R.id.waypoint_text);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showOnMap(visibleLocationPoints.get(position));
}
});
View remove = v.findViewById(R.id.info_close);
((ImageButton) remove).setImageDrawable(mapActivity.getResources().getDrawable(
app.getSettings().isLightContent()? R.drawable.ic_action_gremove_light:
R.drawable.ic_action_gremove_dark));
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LocationPoint point = locationProvider.getVisibleLocationPoints().get(position);
remove(point);
locationProvider.removeVisibleLocationPoint(point);
notifyDataSetChanged();
}
});
return v;
}
};
ListView listView = new ListView(mapActivity);
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
showOnMap(visibleLocationPoints.get(i));
}
});
// Dialog dlg = new Dialog(mapActivity);
// dlg.setContentView(listView);
// dlg.show();
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
builder.setView(listView);
builder.setPositiveButton(R.string.default_buttons_ok, null);
builder.setNegativeButton(mapActivity.getString(R.string.hide_all_waypoints), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
locationProvider.clearAllVisiblePoints();
updateDialog();
}
});
builder.show();
}
private void showOnMap(LocationPoint locationPoint) {
// AnimateDraggingMapThread thread = mapActivity.getMapView().getAnimatedDraggingThread();
int fZoom = mapActivity.getMapView().getZoom() < 15 ? 15 : mapActivity.getMapView().getZoom();
// thread.startMoving(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true);
mapActivity.getMapView().setIntZoom(fZoom);
mapActivity.getMapView().setLatLon(locationPoint.getLatitude(), locationPoint.getLongitude());
}
}

View file

@ -32,7 +32,7 @@ public class TurnPathHelper {
float spartArrowL = (float) ((sarrowL - th / Math.sqrt(2)) / 2); float spartArrowL = (float) ((sarrowL - th / Math.sqrt(2)) / 2);
float hpartArrowL = (float) (harrowL - th) / 2; float hpartArrowL = (float) (harrowL - th) / 2;
if (TurnType.C.equals(turnType.getValue())) { if (TurnType.C == turnType.getValue()) {
int h = (int) (ha - hpartArrowL - 16); int h = (int) (ha - hpartArrowL - 16);
pathForTurn.rMoveTo(th, 0); pathForTurn.rMoveTo(th, 0);
pathForTurn.rLineTo(0, -h); pathForTurn.rLineTo(0, -h);
@ -41,8 +41,8 @@ public class TurnPathHelper {
pathForTurn.rLineTo(-harrowL / 2, harrowL / 2); pathForTurn.rLineTo(-harrowL / 2, harrowL / 2);
pathForTurn.rLineTo(hpartArrowL, 0); pathForTurn.rLineTo(hpartArrowL, 0);
pathForTurn.rLineTo(0, h); pathForTurn.rLineTo(0, h);
} else if (TurnType.TR.equals(turnType.getValue())|| TurnType.TL.equals(turnType.getValue())) { } else if (TurnType.TR == turnType.getValue()|| TurnType.TL == turnType.getValue()) {
int b = TurnType.TR.equals(turnType.getValue())? 1 : -1; int b = TurnType.TR == turnType.getValue()? 1 : -1;
float quadShiftX = 18; float quadShiftX = 18;
float quadShiftY = 18; float quadShiftY = 18;
int wl = 10; // width int wl = 10; // width
@ -62,8 +62,8 @@ public class TurnPathHelper {
pathForTurn.rLineTo(-b * wl, 0); pathForTurn.rLineTo(-b * wl, 0);
pathForTurn.rQuadTo(-b * (quadShiftX + th), 0, -b * (quadShiftX + th), quadShiftY + th); pathForTurn.rQuadTo(-b * (quadShiftX + th), 0, -b * (quadShiftX + th), quadShiftY + th);
pathForTurn.rLineTo(0, h); pathForTurn.rLineTo(0, h);
} else if (TurnType.KL.equals(turnType.getValue()) || TurnType.KR.equals(turnType.getValue())) { } else if (TurnType.KL == turnType.getValue() || TurnType.KR == turnType.getValue()) {
int b = TurnType.KR.equals(turnType.getValue())? 1 : -1; int b = TurnType.KR == turnType.getValue()? 1 : -1;
float quadShiftX = 14; float quadShiftX = 14;
float quadShiftY = 14; float quadShiftY = 14;
th = 10; th = 10;
@ -92,8 +92,8 @@ public class TurnPathHelper {
pathForTurn.rQuadTo(-b * (quadShiftX + th), 0, -b * (quadShiftX + th ), quadShiftY + th); pathForTurn.rQuadTo(-b * (quadShiftX + th), 0, -b * (quadShiftX + th ), quadShiftY + th);
pathForTurn.rLineTo(0, lh ); pathForTurn.rLineTo(0, lh );
} else if (TurnType.TSLR.equals(turnType.getValue()) || TurnType.TSLL.equals(turnType.getValue())) { } else if (TurnType.TSLR == turnType.getValue() || TurnType.TSLL == turnType.getValue()) {
int b = TurnType.TSLR.equals(turnType.getValue()) ? 1 : -1; int b = TurnType.TSLR == turnType.getValue() ? 1 : -1;
int h = 24; int h = 24;
int quadShiftY = 22; int quadShiftY = 22;
float quadShiftX = (float) (quadShiftY / (1 + Math.sqrt(2))); float quadShiftX = (float) (quadShiftY / (1 + Math.sqrt(2)));
@ -109,8 +109,8 @@ public class TurnPathHelper {
pathForTurn.rLineTo(b * spartArrowL, spartArrowL); pathForTurn.rLineTo(b * spartArrowL, spartArrowL);
pathForTurn.rQuadTo(b * nQuadShiftX, -nQuadShiftX, b * nQuadShiftX, nQuadShifty); pathForTurn.rQuadTo(b * nQuadShiftX, -nQuadShiftX, b * nQuadShiftX, nQuadShifty);
pathForTurn.rLineTo(0, h); pathForTurn.rLineTo(0, h);
} else if (TurnType.TSHR.equals(turnType.getValue()) || TurnType.TSHL.equals(turnType.getValue())) { } else if (TurnType.TSHR == turnType.getValue() || TurnType.TSHL == turnType.getValue()) {
int b = TurnType.TSHR.equals(turnType.getValue()) ? 1 : -1; int b = TurnType.TSHR == turnType.getValue() ? 1 : -1;
int h = 28; int h = 28;
float quadShiftX = 22; float quadShiftX = 22;
int sh = 10; int sh = 10;
@ -127,10 +127,10 @@ public class TurnPathHelper {
pathForTurn.rLineTo(-b * spartArrowL, spartArrowL); pathForTurn.rLineTo(-b * spartArrowL, spartArrowL);
pathForTurn.rCubicTo(b * nQuadShiftX / 2, nQuadShiftX / 2, b * nQuadShiftX, nQuadShiftX / 2, b * nQuadShiftX, nQuadShiftY); pathForTurn.rCubicTo(b * nQuadShiftX / 2, nQuadShiftX / 2, b * nQuadShiftX, nQuadShiftX / 2, b * nQuadShiftX, nQuadShiftY);
pathForTurn.rLineTo(0, h); pathForTurn.rLineTo(0, h);
} else if(TurnType.TU.equals(turnType.getValue()) || TurnType.TRU.equals(turnType.getValue())) { } else if(TurnType.TU == turnType.getValue() || TurnType.TRU == turnType.getValue()) {
int h = 40; int h = 40;
// right left // right left
int b = TurnType.TU.equals(turnType.getValue()) ? 1 : -1; int b = TurnType.TU == turnType.getValue() ? 1 : -1;
float quadShiftX = 10; // 13 float quadShiftX = 10; // 13
float quadShiftY = 10; // 13 float quadShiftY = 10; // 13
int sm = 10; int sm = 10;
@ -150,7 +150,7 @@ public class TurnPathHelper {
pathForTurn.rQuadTo(0, -quadShiftX, b *quadShiftX, -quadShiftY); pathForTurn.rQuadTo(0, -quadShiftX, b *quadShiftX, -quadShiftY);
pathForTurn.rQuadTo(b * quadShiftX, 0, b * quadShiftX, quadShiftY); pathForTurn.rQuadTo(b * quadShiftX, 0, b * quadShiftX, quadShiftY);
pathForTurn.rLineTo(0, h); pathForTurn.rLineTo(0, h);
} else if (TurnType.OFFR.equals(turnType.getValue())){ } else if (TurnType.OFFR == turnType.getValue()){
int h = (int) (ha - hpartArrowL - 16); int h = (int) (ha - hpartArrowL - 16);
pathForTurn.rMoveTo(th, 0); //12 0 pathForTurn.rMoveTo(th, 0); //12 0
//first square //first square
@ -260,7 +260,7 @@ public class TurnPathHelper {
paintRouteDirection.setStyle(Style.FILL_AND_STROKE); paintRouteDirection.setStyle(Style.FILL_AND_STROKE);
paintRouteDirection.setColor(resources.getColor(R.color.nav_arrow_distant)); paintRouteDirection.setColor(resources.getColor(R.color.nav_arrow_distant));
paintRouteDirection.setAntiAlias(true); paintRouteDirection.setAntiAlias(true);
TurnPathHelper.calcTurnPath(dp, TurnType.sraight(), null); TurnPathHelper.calcTurnPath(dp, TurnType.straight(), null);
} }
@Override @Override

View file

@ -1,7 +1,9 @@
package net.osmand.plus.views.mapwidgets; package net.osmand.plus.views.mapwidgets;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.binary.RouteDataObject; import net.osmand.binary.RouteDataObject;
@ -55,7 +57,7 @@ public class RouteInfoWidgetsFactory {
final OsmandSettings settings, Paint textPaint, Paint subtextPaint, boolean horisontalMini) { final OsmandSettings settings, Paint textPaint, Paint subtextPaint, boolean horisontalMini) {
final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(ctx, textPaint, subtextPaint, horisontalMini) { final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(ctx, textPaint, subtextPaint, horisontalMini) {
NextDirectionInfo calc1 = new NextDirectionInfo(); NextDirectionInfo calc1 = new NextDirectionInfo();
TurnType straight = TurnType.sraight(); TurnType straight = TurnType.straight();
@Override @Override
public boolean updateInfo(DrawSettings drawSettings) { public boolean updateInfo(DrawSettings drawSettings) {
@ -522,11 +524,31 @@ public class RouteInfoWidgetsFactory {
} }
private static final float miniCoeff = 2f; private static final float miniCoeff = 2f;
public BaseMapWidget createLanesControl(final RoutingHelper routingHelper, final OsmandMapTileView view) {
final Path laneStraight = new Path(); private Path getPathFromTurnType(List<Path> paths, int laneType, Path defaultType) {
if(laneType == 0) {
return defaultType;
}
while (paths.size() <= laneType) {
paths.add(null);
}
Path p = paths.get(laneType);
if (p != null) {
return p;
}
p = new Path();
Matrix pathTransform = new Matrix(); Matrix pathTransform = new Matrix();
pathTransform.postScale(scaleCoefficient / miniCoeff, scaleCoefficient / miniCoeff); pathTransform.postScale(scaleCoefficient / miniCoeff, scaleCoefficient / miniCoeff);
TurnPathHelper.calcTurnPath(laneStraight, TurnType.sraight(), pathTransform); TurnType tp = TurnType.valueOf(laneType, false);
TurnPathHelper.calcTurnPath(p, tp, pathTransform);
paths.set(laneType, p);
return p;
}
public BaseMapWidget createLanesControl(final RoutingHelper routingHelper, final OsmandMapTileView view) {
final List<Path> paths = new ArrayList<Path>();
final Path laneStraight = getPathFromTurnType(paths, TurnType.C, null);
final Paint paintBlack = new Paint(); final Paint paintBlack = new Paint();
paintBlack.setStyle(Style.STROKE); paintBlack.setStyle(Style.STROKE);
paintBlack.setColor(Color.BLACK); paintBlack.setColor(Color.BLACK);
@ -542,8 +564,9 @@ public class RouteInfoWidgetsFactory {
final BaseMapWidget lanesControl = new BaseMapWidget(view.getContext()) { final BaseMapWidget lanesControl = new BaseMapWidget(view.getContext()) {
int[] lanes = null; int[] lanes = null;
private TurnType turn;
boolean imminent = false; boolean imminent = false;
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@ -559,13 +582,21 @@ public class RouteInfoWidgetsFactory {
canvas.save(); canvas.save();
// canvas.translate((int) (16 * scaleCoefficient), 0); // canvas.translate((int) (16 * scaleCoefficient), 0);
for (int i = 0; i < lanes.length; i++) { for (int i = 0; i < lanes.length; i++) {
int turnType;
if ((lanes[i] & 1) == 1) { if ((lanes[i] & 1) == 1) {
paintRouteDirection.setColor(imminent ? getResources().getColor(R.color.nav_arrow_imminent) : getResources().getColor(R.color.nav_arrow)); paintRouteDirection.setColor(imminent ? getResources().getColor(R.color.nav_arrow_imminent) : getResources().getColor(R.color.nav_arrow));
if(turn != null) {
turnType = turn.getValue();
} else {
turnType = TurnType.getPrimaryTurn(lanes[i]);
}
} else { } else {
paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow_distant)); paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow_distant));
turnType = TurnType.getPrimaryTurn(lanes[i]);
} }
canvas.drawPath(laneStraight, paintBlack); Path p = getPathFromTurnType(paths, turnType, laneStraight);
canvas.drawPath(laneStraight, paintRouteDirection); canvas.drawPath(p, paintBlack);
canvas.drawPath(p, paintRouteDirection);
canvas.translate(w, 0); canvas.translate(w, 0);
} }
canvas.restore(); canvas.restore();
@ -577,11 +608,13 @@ public class RouteInfoWidgetsFactory {
boolean visible = false; boolean visible = false;
int locimminent = -1; int locimminent = -1;
int[] loclanes = null; int[] loclanes = null;
TurnType primary = null;
if (routingHelper != null && routingHelper.isRouteCalculated() && view.getSettings().SHOW_LANES.get()) { if (routingHelper != null && routingHelper.isRouteCalculated() && view.getSettings().SHOW_LANES.get()) {
if (routingHelper.isFollowingMode()) { if (routingHelper.isFollowingMode()) {
NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), false); NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), false);
if(r != null && r.directionInfo != null && r.directionInfo.getTurnType() != null) { if(r != null && r.directionInfo != null && r.directionInfo.getTurnType() != null) {
loclanes = r.directionInfo.getTurnType().getLanes(); loclanes = r.directionInfo.getTurnType().getLanes();
primary = r.directionInfo.getTurnType();
locimminent = r.imminent; locimminent = r.imminent;
// Do not show too far // Do not show too far
if ((r.distanceTo > 700 && r.directionInfo.getTurnType().isSkipToSpeak()) || r.distanceTo > 1200) { if ((r.distanceTo > 700 && r.directionInfo.getTurnType().isSkipToSpeak()) || r.distanceTo > 1200) {
@ -595,6 +628,7 @@ public class RouteInfoWidgetsFactory {
RouteDirectionInfo next = routingHelper.getRouteDirections().get(di); RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
if (next != null) { if (next != null) {
loclanes = next.getTurnType().getLanes(); loclanes = next.getTurnType().getLanes();
primary = next.getTurnType();
} }
} }
} }
@ -603,6 +637,7 @@ public class RouteInfoWidgetsFactory {
if (visible) { if (visible) {
if (!Arrays.equals(lanes, loclanes)) { if (!Arrays.equals(lanes, loclanes)) {
lanes = loclanes; lanes = loclanes;
turn = primary;
requestLayout(); requestLayout();
invalidate(); invalidate();
} }
@ -619,6 +654,14 @@ public class RouteInfoWidgetsFactory {
return lanesControl; return lanesControl;
} }
protected Path straight() {
final Path laneStraight = new Path();
Matrix pathTransform = new Matrix();
pathTransform.postScale(scaleCoefficient / miniCoeff, scaleCoefficient / miniCoeff);
TurnPathHelper.calcTurnPath(laneStraight, TurnType.straight(), pathTransform);
return laneStraight;
}
public BaseMapWidget createAlarmInfoControl(final OsmandApplication app, MapActivity ma) { public BaseMapWidget createAlarmInfoControl(final OsmandApplication app, MapActivity ma) {
final RoutingHelper rh = app.getRoutingHelper(); final RoutingHelper rh = app.getRoutingHelper();