From 2c6b19b775f4b28631c642b6c7c578f72e9c7b80 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 2 Oct 2014 13:47:34 +0200 Subject: [PATCH 1/4] Refactor turn types --- .../osmand/router/RouteResultPreparation.java | 10 +- .../src/net/osmand/router/TurnType.java | 212 +++++++++++++----- .../plus/routing/RouteCalculationResult.java | 32 +-- .../osmand/plus/routing/RouteProvider.java | 17 +- .../net/osmand/plus/routing/VoiceRouter.java | 44 ++-- .../net/osmand/plus/views/TurnPathHelper.java | 26 +-- .../mapwidgets/RouteInfoWidgetsFactory.java | 4 +- 7 files changed, 216 insertions(+), 129 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 1fa0b3afad..89a6c4ead0 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -338,8 +338,8 @@ public class RouteResultPreparation { t = getTurnInfo(result, i, leftside); // justify turn if(t != null && i < result.size() - 1) { - boolean tl = TurnType.TL.equals(t.getValue()); - boolean tr = TurnType.TR.equals(t.getValue()); + boolean tl = TurnType.TL == t.getValue(); + boolean tr = TurnType.TR == t.getValue(); if(tl || tr) { TurnType tnext = getTurnInfo(result, i + 1, leftside); if (tnext != null && result.get(i).getDistance() < 35) { // @@ -357,10 +357,10 @@ public class RouteResultPreparation { ut = false; } if (ut) { - if (tl && TurnType.TL.equals(tnext.getValue())) { + if (tl && TurnType.TL == tnext.getValue()) { next = i + 2; t = TurnType.valueOf(TurnType.TU, false); - } else if (tr && TurnType.TR.equals(tnext.getValue())) { + } else if (tr && TurnType.TR == tnext.getValue()) { next = i + 2; t = TurnType.valueOf(TurnType.TU, true); } @@ -486,7 +486,7 @@ public class RouteResultPreparation { } } // 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())) ; return t; } diff --git a/OsmAnd-java/src/net/osmand/router/TurnType.java b/OsmAnd-java/src/net/osmand/router/TurnType.java index 488286a835..e6d0a35664 100644 --- a/OsmAnd-java/src/net/osmand/router/TurnType.java +++ b/OsmAnd-java/src/net/osmand/router/TurnType.java @@ -1,77 +1,148 @@ package net.osmand.router; public class TurnType { - public static final String C = "C"; // continue (go straight) //$NON-NLS-1$ - public static final String TL = "TL"; // turn left //$NON-NLS-1$ - public static final String TSLL = "TSLL"; // turn slightly left //$NON-NLS-1$ - public static final String TSHL = "TSHL"; // turn sharply left //$NON-NLS-1$ - public static final String TR = "TR"; // turn right //$NON-NLS-1$ - public static final String TSLR = "TSLR"; // turn slightly right //$NON-NLS-1$ - public static final String TSHR = "TSHR"; // turn sharply right //$NON-NLS-1$ - public static final String KL = "KL"; // keep left //$NON-NLS-1$ - public static final String KR = "KR"; // keep right//$NON-NLS-1$ - public static final String TU = "TU"; // U-turn //$NON-NLS-1$ - public static final String TRU = "TRU"; // Right U-turn //$NON-NLS-1$ - public static final String OFFR = "OFFR"; // 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 C = 1;//"C"; // continue (go straight) //$NON-NLS-1$ + public static final int TL = 2; // turn left //$NON-NLS-1$ + public static final int TSLL = 3; // turn slightly left //$NON-NLS-1$ + public static final int TSHL = 4; // turn sharply left //$NON-NLS-1$ + public static final int TR = 5; // turn right //$NON-NLS-1$ + public static final int TSLR = 6; // turn slightly right //$NON-NLS-1$ + public static final int TSHR = 7; // turn sharply right //$NON-NLS-1$ + public static final int KL = 8; // keep left //$NON-NLS-1$ + public static final int KR = 9; // keep right//$NON-NLS-1$ + public static final int TU = 10; // U-turn //$NON-NLS-1$ + public static final int TRU = 11; // Right U-turn //$NON-NLS-1$ + public static final int OFFR = 12; // Off route //$NON-NLS-1$ + 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); } - - public static TurnType valueOf(String s, boolean leftSide) { - for (String v : predefinedTypes) { - if (v.equals(s)) { - if (leftSide && TU.equals(v)) { - v = TRU; - } - return new TurnType(v); + + public String toXmlString() { + switch (value) { + case C: + return "C"; + case TL: + return "TL"; + 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$ - return getExitTurn(Integer.parseInt(s.substring(4)), 0, leftSide); + if(t == null) { + 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 boolean isLeftSide; // calculated clockwise head rotation if previous direction to NORTH private float turnAngle; private boolean skipToSpeak; private int[] lanes; - private static TurnType getExitTurn(int out, float angle, boolean leftSide) { - TurnType r = new TurnType("EXIT", out, leftSide); //$NON-NLS-1$ + public static TurnType getExitTurn(int out, float angle, boolean leftSide) { + TurnType r = valueOf(RNDB, leftSide); //$NON-NLS-1$ + r.exitOut = out; r.setTurnAngle(angle); return r; } - - private TurnType(String value, int exitOut, boolean leftSide) { - this.value = value; - this.exitOut = exitOut; - this.isLeftSide = leftSide; + + + private TurnType(int vl) { + this.value = vl; } + // calculated Clockwise head rotation if previous direction to NORTH public float getTurnAngle() { return turnAngle; } public boolean isLeftSide() { - return isLeftSide; + return value == RNLB || value == TRU; } public void setTurnAngle(float turnAngle) { this.turnAngle = turnAngle; } - - private TurnType(String value) { - this.value = value; - } - public String getValue() { + public int getValue() { return value; } @@ -80,66 +151,87 @@ public class TurnType { } public boolean isRoundAbout() { - return value.equals("EXIT"); //$NON-NLS-1$ + return value == RNDB || value == RNLB; //$NON-NLS-1$ } - // lanes encoded as array of int - // last bit is 1, 0 (should we take this lane) - // first bits 0 - left, 1 - straight, 2 - right + // lanes encoded as array of int + // 0 byte - 0/1 - to use or not + // 1-5 byte - additional turn info + // 6-10 byte - secondary turn public void setLanes(int[] 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 int getPrimaryTurn(int lane) { + // Get the primary turn modifier for the lane + return (lanes[lane] >> 1) & ((1 << 4) - 1); + } + + public void setSecondaryTurn(int lane, int turnType) { + lanes[lane] |= (turnType << 5); + } + + public int getSecondaryTurn(int lane) { + return (lanes[lane] >> 5); + } + + public int[] getLanes() { return lanes; } public boolean keepLeft() { - return value.equals(KL); + return value == KL; } public boolean keepRight() { - return value.equals(KR); + return value == KR; } public boolean goAhead() { - return value.equals(C); + return value == C; } public boolean isSkipToSpeak() { return skipToSpeak; } + public void setSkipToSpeak(boolean skipToSpeak) { this.skipToSpeak = skipToSpeak; } @Override public String toString() { - if(isRoundAbout()){ + if (isRoundAbout()) { return "Take " + getExitOut() + " exit"; - } else if(value.equals(C)) { + } else if (value == C) { return "Go ahead"; - } else if(value.equals(TSLL)) { + } else if (value == TSLL) { return "Turn slightly left"; - } else if(value.equals(TL)) { + } else if (value == TL) { return "Turn left"; - } else if(value.equals(TSHL)) { + } else if (value == TSHL) { return "Turn sharply left"; - } else if(value.equals(TSLR)) { + } else if (value == TSLR) { return "Turn slightly right"; - } else if(value.equals(TR)) { + } else if (value == TR) { return "Turn right"; - } else if(value.equals(TSHR)) { + } else if (value == TSHR) { return "Turn sharply right"; - } else if(value.equals(TU)) { + } else if (value == TU) { return "Make uturn"; - } else if(value.equals(TRU)) { + } else if (value == TRU) { return "Make uturn"; - } else if(value.equals(KL)) { + } else if (value == KL) { return "Keep left"; - } else if(value.equals(KR)) { + } else if (value == KR) { return "Keep right"; - } else if(value.equals(OFFR)) { + } else if (value == OFFR) { return "Off route"; } return super.toString(); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index d3bc32e2b2..a27081fa12 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -149,7 +149,7 @@ public class RouteCalculationResult { if (locationIndex > interLocations[currentIntermediate] && getDistanceToLocation(locations, intermediates.get(currentIntermediate), locationIndex) > 50) { 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.setStreetName(toSplit.getStreetName()); info.setDestinationName(toSplit.getDestinationName()); @@ -296,7 +296,7 @@ public class RouteCalculationResult { int previousLocation = 0; int prevBearingLocation = 0; - RouteDirectionInfo previousInfo = new RouteDirectionInfo(speed, TurnType.sraight()); + RouteDirectionInfo previousInfo = new RouteDirectionInfo(speed, TurnType.straight()); previousInfo.routePointOffset = 0; previousInfo.setDescriptionRoute(ctx.getString( R.string.route_head)); computeDirections.add(previousInfo); @@ -443,27 +443,27 @@ public class RouteCalculationResult { public static String toString(TurnType type, Context ctx) { if(type.isRoundAbout()){ 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); - } else if(type.getValue().equals(TurnType.TSLL)) { + } else if(type.getValue() == TurnType.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); - } else if(type.getValue().equals(TurnType.TSHL)) { + } else if(type.getValue() == TurnType.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); - } else if(type.getValue().equals(TurnType.TR)) { + } else if(type.getValue() == TurnType.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); - } else if(type.getValue().equals(TurnType.TU)) { + } else if(type.getValue() == TurnType.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); - } else if(type.getValue().equals(TurnType.KL)) { + } else if(type.getValue() == TurnType.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 ""; @@ -483,7 +483,7 @@ public class RouteCalculationResult { if (directions != null && directions.size() > 1) { for (int i = 1; i < directions.size();) { RouteDirectionInfo r = directions.get(i); - if (r.getTurnType().getValue().equals(TurnType.C)) { + if (r.getTurnType().getValue() == TurnType.C) { RouteDirectionInfo prev = directions.get(i - 1); prev.setAverageSpeed((prev.distance + r.distance) / (prev.distance / prev.getAverageSpeed() + r.distance / r.getAverageSpeed())); @@ -536,7 +536,7 @@ public class RouteCalculationResult { i.routePointOffset++; } RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(), - TurnType.sraight()); + TurnType.straight()); info.routePointOffset = 0; // info.setDescriptionRoute(ctx.getString( R.string.route_head));//; //$NON-NLS-1$ directions.add(0, info); @@ -544,7 +544,7 @@ public class RouteCalculationResult { } RouteDirectionInfo lastDirInf = directions.size() > 0 ? directions.get(directions.size() - 1) : null; 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); float lastBearing = prevLast.bearingTo(locations.get(locations.size() - 1)); float[] compute = new float[2]; diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 6272a32088..057bb2fcfc 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -850,9 +850,9 @@ public class RouteProvider { String stype = item.getExtensionsToRead().get("turn"); //$NON-NLS-1$ TurnType turnType; if (stype != null) { - turnType = TurnType.valueOf(stype.toUpperCase(), leftSide); + turnType = TurnType.fromString(stype.toUpperCase(), leftSide); } else { - turnType = TurnType.sraight(); + turnType = TurnType.straight(); } String sturn = item.getExtensionsToRead().get("turn-angle"); //$NON-NLS-1$ if (sturn != null) { @@ -861,7 +861,7 @@ public class RouteProvider { RouteDirectionInfo dirInfo = new RouteDirectionInfo(avgSpeed, turnType); dirInfo.setDescriptionRoute(item.desc); //$NON-NLS-1$ dirInfo.routePointOffset = offset; - if (previous != null && !TurnType.C.equals(previous.getTurnType().getValue()) && + if (previous != null && TurnType.C != previous.getTurnType().getValue() && !osmandRouter) { // calculate angle 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 if (previous.routePointOffset > 0 && previous.routePointOffset < res.size() - 1) { float paz = res.get(previous.routePointOffset - 1).bearingTo(res.get(previous.routePointOffset)); @@ -1035,12 +1035,9 @@ public class RouteProvider { pt.desc = dirInfo.getDescriptionRoute(ctx); Map extensions = pt.getExtensionsToWrite(); extensions.put("time", dirInfo.getExpectedTime() + ""); - String turnType = dirInfo.getTurnType().getValue(); - if (dirInfo.getTurnType().isRoundAbout()) { - turnType += dirInfo.getTurnType().getExitOut(); - } - if(!TurnType.C.equals(turnType)){ - extensions.put("turn", turnType); + int turnType = dirInfo.getTurnType().getValue(); + if(TurnType.C != turnType){ + extensions.put("turn", dirInfo.getTurnType().toXmlString()); extensions.put("turn-angle", dirInfo.getTurnType().getTurnAngle() + ""); } extensions.put("offset", (dirInfo.routePointOffset - cRoute) + ""); diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index 0f8584c215..6c0a21c0cb 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -4,14 +4,10 @@ package net.osmand.plus.routing; import java.io.IOException; import java.util.List; -import android.media.AudioManager; -import android.media.SoundPool; import net.osmand.Location; import net.osmand.binary.RouteDataObject; -import net.osmand.data.LocationPoint; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandSettings; -import net.osmand.plus.R; import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; import net.osmand.plus.routing.AlarmInfo.AlarmInfoType; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; @@ -25,6 +21,8 @@ import net.osmand.util.MapUtils; import alice.tuprolog.Struct; import alice.tuprolog.Term; import android.content.Context; +import android.media.AudioManager; +import android.media.SoundPool; public class VoiceRouter { @@ -567,7 +565,7 @@ public class VoiceRouter { play.prepareTurn(tParam, dist, getSpeakableStreetName(currentSegment, next)).play(); } else if(next.getTurnType().isRoundAbout()){ 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(); } } @@ -582,7 +580,7 @@ public class VoiceRouter { play.turn(tParam, dist, getSpeakableStreetName(currentSegment, next)); } else if (next.getTurnType().isRoundAbout()) { 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)); } else { isPlay = false; @@ -591,15 +589,15 @@ public class VoiceRouter { if (pronounceNextNext != null) { TurnType t = pronounceNextNext.getTurnType(); isPlay = true; - if (next.getTurnType().getValue().equals(TurnType.C) && - !TurnType.C.equals(t.getValue())) { + if (next.getTurnType().getValue() == TurnType.C && + TurnType.C != t.getValue()) { play.goAhead(dist, getSpeakableStreetName(currentSegment, next)); } - if (TurnType.TL.equals(t.getValue()) || TurnType.TSHL.equals(t.getValue()) || TurnType.TSLL.equals(t.getValue()) - || TurnType.TU.equals(t.getValue()) || TurnType.KL.equals(t.getValue())) { + if (TurnType.TL == t.getValue() || TurnType.TSHL == t.getValue() || TurnType.TSLL == t.getValue() + || TurnType.TU == t.getValue() || TurnType.KL == t.getValue()) { play.then().bearLeft( getSpeakableStreetName(currentSegment, next)); - } else if (TurnType.TR.equals(t.getValue()) || TurnType.TSHR.equals(t.getValue()) || TurnType.TSLR.equals(t.getValue()) - || TurnType.KR.equals(t.getValue())) { + } else if (TurnType.TR == t.getValue() || TurnType.TSHR == t.getValue() || TurnType.TSLR == t.getValue() + || TurnType.KR == t.getValue()) { play.then().bearRight( getSpeakableStreetName(currentSegment, next)); } } @@ -632,10 +630,10 @@ public class VoiceRouter { play.turn(tParam, getSpeakableStreetName(currentSegment, next)); } else if(next.getTurnType().isRoundAbout()){ 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)); // do not say it -// } else if(next.getTurnType().getValue().equals(TurnType.C)){ +// } else if(next.getTurnType().getValue() == TurnType.C)){ // play.goAhead(); } else { isplay = false; @@ -649,7 +647,7 @@ public class VoiceRouter { } else if (nextNext.getTurnType().isRoundAbout()) { if(isplay) { play.then(); } 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(); } play.makeUT(next.distance, empty); } @@ -662,21 +660,21 @@ public class VoiceRouter { } private String getTurnType(TurnType t){ - if(TurnType.TL.equals(t.getValue())){ + if(TurnType.TL == t.getValue()){ return AbstractPrologCommandPlayer.A_LEFT; - } else if(TurnType.TSHL.equals(t.getValue())){ + } else if(TurnType.TSHL == t.getValue()){ return AbstractPrologCommandPlayer.A_LEFT_SH; - } else if(TurnType.TSLL.equals(t.getValue())){ + } else if(TurnType.TSLL == t.getValue()){ return AbstractPrologCommandPlayer.A_LEFT_SL; - } else if(TurnType.TR.equals(t.getValue())){ + } else if(TurnType.TR == t.getValue()){ return AbstractPrologCommandPlayer.A_RIGHT; - } else if(TurnType.TSHR.equals(t.getValue())){ + } else if(TurnType.TSHR == t.getValue()){ return AbstractPrologCommandPlayer.A_RIGHT_SH; - } else if(TurnType.TSLR.equals(t.getValue())){ + } else if(TurnType.TSLR == t.getValue()){ return AbstractPrologCommandPlayer.A_RIGHT_SL; - } else if(TurnType.KL.equals(t.getValue())){ + } else if(TurnType.KL == t.getValue()){ return AbstractPrologCommandPlayer.A_LEFT_KEEP; - } else if(TurnType.KR.equals(t.getValue())){ + } else if(TurnType.KR == t.getValue()){ return AbstractPrologCommandPlayer.A_RIGHT_KEEP; } return null; diff --git a/OsmAnd/src/net/osmand/plus/views/TurnPathHelper.java b/OsmAnd/src/net/osmand/plus/views/TurnPathHelper.java index a64db6d620..06ca94f1d5 100644 --- a/OsmAnd/src/net/osmand/plus/views/TurnPathHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/TurnPathHelper.java @@ -32,7 +32,7 @@ public class TurnPathHelper { float spartArrowL = (float) ((sarrowL - th / Math.sqrt(2)) / 2); float hpartArrowL = (float) (harrowL - th) / 2; - if (TurnType.C.equals(turnType.getValue())) { + if (TurnType.C == turnType.getValue()) { int h = (int) (ha - hpartArrowL - 16); pathForTurn.rMoveTo(th, 0); pathForTurn.rLineTo(0, -h); @@ -41,8 +41,8 @@ public class TurnPathHelper { pathForTurn.rLineTo(-harrowL / 2, harrowL / 2); pathForTurn.rLineTo(hpartArrowL, 0); pathForTurn.rLineTo(0, h); - } else if (TurnType.TR.equals(turnType.getValue())|| TurnType.TL.equals(turnType.getValue())) { - int b = TurnType.TR.equals(turnType.getValue())? 1 : -1; + } else if (TurnType.TR == turnType.getValue()|| TurnType.TL == turnType.getValue()) { + int b = TurnType.TR == turnType.getValue()? 1 : -1; float quadShiftX = 18; float quadShiftY = 18; int wl = 10; // width @@ -62,8 +62,8 @@ public class TurnPathHelper { pathForTurn.rLineTo(-b * wl, 0); pathForTurn.rQuadTo(-b * (quadShiftX + th), 0, -b * (quadShiftX + th), quadShiftY + th); pathForTurn.rLineTo(0, h); - } else if (TurnType.KL.equals(turnType.getValue()) || TurnType.KR.equals(turnType.getValue())) { - int b = TurnType.KR.equals(turnType.getValue())? 1 : -1; + } else if (TurnType.KL == turnType.getValue() || TurnType.KR == turnType.getValue()) { + int b = TurnType.KR == turnType.getValue()? 1 : -1; float quadShiftX = 14; float quadShiftY = 14; th = 10; @@ -92,8 +92,8 @@ public class TurnPathHelper { pathForTurn.rQuadTo(-b * (quadShiftX + th), 0, -b * (quadShiftX + th ), quadShiftY + th); pathForTurn.rLineTo(0, lh ); - } else if (TurnType.TSLR.equals(turnType.getValue()) || TurnType.TSLL.equals(turnType.getValue())) { - int b = TurnType.TSLR.equals(turnType.getValue()) ? 1 : -1; + } else if (TurnType.TSLR == turnType.getValue() || TurnType.TSLL == turnType.getValue()) { + int b = TurnType.TSLR == turnType.getValue() ? 1 : -1; int h = 24; int quadShiftY = 22; float quadShiftX = (float) (quadShiftY / (1 + Math.sqrt(2))); @@ -109,8 +109,8 @@ public class TurnPathHelper { pathForTurn.rLineTo(b * spartArrowL, spartArrowL); pathForTurn.rQuadTo(b * nQuadShiftX, -nQuadShiftX, b * nQuadShiftX, nQuadShifty); pathForTurn.rLineTo(0, h); - } else if (TurnType.TSHR.equals(turnType.getValue()) || TurnType.TSHL.equals(turnType.getValue())) { - int b = TurnType.TSHR.equals(turnType.getValue()) ? 1 : -1; + } else if (TurnType.TSHR == turnType.getValue() || TurnType.TSHL == turnType.getValue()) { + int b = TurnType.TSHR == turnType.getValue() ? 1 : -1; int h = 28; float quadShiftX = 22; int sh = 10; @@ -127,10 +127,10 @@ public class TurnPathHelper { pathForTurn.rLineTo(-b * spartArrowL, spartArrowL); pathForTurn.rCubicTo(b * nQuadShiftX / 2, nQuadShiftX / 2, b * nQuadShiftX, nQuadShiftX / 2, b * nQuadShiftX, nQuadShiftY); 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; // right left - int b = TurnType.TU.equals(turnType.getValue()) ? 1 : -1; + int b = TurnType.TU == turnType.getValue() ? 1 : -1; float quadShiftX = 10; // 13 float quadShiftY = 10; // 13 int sm = 10; @@ -150,7 +150,7 @@ public class TurnPathHelper { pathForTurn.rQuadTo(0, -quadShiftX, b *quadShiftX, -quadShiftY); pathForTurn.rQuadTo(b * quadShiftX, 0, b * quadShiftX, quadShiftY); pathForTurn.rLineTo(0, h); - } else if (TurnType.OFFR.equals(turnType.getValue())){ + } else if (TurnType.OFFR == turnType.getValue()){ int h = (int) (ha - hpartArrowL - 16); pathForTurn.rMoveTo(th, 0); //12 0 //first square @@ -260,7 +260,7 @@ public class TurnPathHelper { paintRouteDirection.setStyle(Style.FILL_AND_STROKE); paintRouteDirection.setColor(resources.getColor(R.color.nav_arrow_distant)); paintRouteDirection.setAntiAlias(true); - TurnPathHelper.calcTurnPath(dp, TurnType.sraight(), null); + TurnPathHelper.calcTurnPath(dp, TurnType.straight(), null); } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index 0ecf360e9a..2b15b45b5a 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -55,7 +55,7 @@ public class RouteInfoWidgetsFactory { final OsmandSettings settings, Paint textPaint, Paint subtextPaint, boolean horisontalMini) { final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(ctx, textPaint, subtextPaint, horisontalMini) { NextDirectionInfo calc1 = new NextDirectionInfo(); - TurnType straight = TurnType.sraight(); + TurnType straight = TurnType.straight(); @Override public boolean updateInfo(DrawSettings drawSettings) { @@ -526,7 +526,7 @@ public class RouteInfoWidgetsFactory { final Path laneStraight = new Path(); Matrix pathTransform = new Matrix(); pathTransform.postScale(scaleCoefficient / miniCoeff, scaleCoefficient / miniCoeff); - TurnPathHelper.calcTurnPath(laneStraight, TurnType.sraight(), pathTransform); + TurnPathHelper.calcTurnPath(laneStraight, TurnType.straight(), pathTransform); final Paint paintBlack = new Paint(); paintBlack.setStyle(Style.STROKE); paintBlack.setColor(Color.BLACK); From df64fdf9bef1d39644815427b02f7b3f5853d2b3 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 2 Oct 2014 13:56:46 +0200 Subject: [PATCH 2/4] Remove merge consequences --- .../plus/sherpafy/WaypointDialogHelper.java | 264 ------------------ 1 file changed, 264 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java deleted file mode 100644 index 4beef8f2c6..0000000000 --- a/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java +++ /dev/null @@ -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 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() { - 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 visibleLocationPoints = locationProvider.getVisibleLocationPoints(); - final ArrayAdapter listAdapter = new ArrayAdapter(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()); - } -} From e27a425465c6bc3531b2f88e0a262fa4a67c1600 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 2 Oct 2014 14:14:34 +0200 Subject: [PATCH 3/4] Show different turns --- .../net/osmand/binary/RouteDataObject.java | 11 ++++ .../net/osmand/router/RouteSegmentResult.java | 5 ++ .../src/net/osmand/router/TurnType.java | 9 +-- .../mapwidgets/RouteInfoWidgetsFactory.java | 55 +++++++++++++++++-- 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java index 4359cf506d..5fa380dac9 100644 --- a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java +++ b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java @@ -267,6 +267,16 @@ public class RouteDataObject { public String getHighway() { 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) { String highway = null; @@ -351,6 +361,7 @@ public class RouteDataObject { return Math.abs(px - x) * 0.011d + Math.abs(py - y) * 0.01863d; } + @Override public String toString() { String name = getName(); diff --git a/OsmAnd-java/src/net/osmand/router/RouteSegmentResult.java b/OsmAnd-java/src/net/osmand/router/RouteSegmentResult.java index e59d566c46..085e678aac 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteSegmentResult.java +++ b/OsmAnd-java/src/net/osmand/router/RouteSegmentResult.java @@ -140,6 +140,11 @@ public class RouteSegmentResult { return convertPoint(object, endPointIndex); } + public boolean isForwardDirection() { + return endPointIndex - startPointIndex > 0; + } + + private LatLon convertPoint(RouteDataObject o, int ind){ return new LatLon(MapUtils.get31LatitudeY(o.getPoint31YTile(ind)), MapUtils.get31LongitudeX(o.getPoint31XTile(ind))); } diff --git a/OsmAnd-java/src/net/osmand/router/TurnType.java b/OsmAnd-java/src/net/osmand/router/TurnType.java index e6d0a35664..981e4472f9 100644 --- a/OsmAnd-java/src/net/osmand/router/TurnType.java +++ b/OsmAnd-java/src/net/osmand/router/TurnType.java @@ -167,17 +167,18 @@ public class TurnType { lanes[lane] |= (turnType << 1); } - public int getPrimaryTurn(int lane) { + public static int getPrimaryTurn(int laneValue) { // Get the primary turn modifier for the lane - return (lanes[lane] >> 1) & ((1 << 4) - 1); + return (laneValue >> 1) & ((1 << 4) - 1); } public void setSecondaryTurn(int lane, int turnType) { lanes[lane] |= (turnType << 5); } - public int getSecondaryTurn(int lane) { - return (lanes[lane] >> 5); + public static int getSecondaryTurn(int laneValue) { + // Get the primary turn modifier for the lane + return (laneValue >> 5); } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index 2b15b45b5a..0bf9e58ae4 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -1,7 +1,9 @@ package net.osmand.plus.views.mapwidgets; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import net.osmand.Location; import net.osmand.binary.RouteDataObject; @@ -522,11 +524,31 @@ public class RouteInfoWidgetsFactory { } private static final float miniCoeff = 2f; - public BaseMapWidget createLanesControl(final RoutingHelper routingHelper, final OsmandMapTileView view) { - final Path laneStraight = new Path(); + + private Path getPathFromTurnType(List 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(); pathTransform.postScale(scaleCoefficient / miniCoeff, scaleCoefficient / miniCoeff); - TurnPathHelper.calcTurnPath(laneStraight, TurnType.straight(), 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 paths = new ArrayList(); + final Path laneStraight = getPathFromTurnType(paths, TurnType.C, null); + final Paint paintBlack = new Paint(); paintBlack.setStyle(Style.STROKE); paintBlack.setColor(Color.BLACK); @@ -542,8 +564,9 @@ public class RouteInfoWidgetsFactory { final BaseMapWidget lanesControl = new BaseMapWidget(view.getContext()) { int[] lanes = null; - + private TurnType turn; boolean imminent = false; + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @@ -559,13 +582,21 @@ public class RouteInfoWidgetsFactory { canvas.save(); // canvas.translate((int) (16 * scaleCoefficient), 0); for (int i = 0; i < lanes.length; i++) { + int turnType; if ((lanes[i] & 1) == 1) { 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 { paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow_distant)); + turnType = TurnType.getPrimaryTurn(lanes[i]); } - canvas.drawPath(laneStraight, paintBlack); - canvas.drawPath(laneStraight, paintRouteDirection); + Path p = getPathFromTurnType(paths, turnType, laneStraight); + canvas.drawPath(p, paintBlack); + canvas.drawPath(p, paintRouteDirection); canvas.translate(w, 0); } canvas.restore(); @@ -577,11 +608,13 @@ public class RouteInfoWidgetsFactory { boolean visible = false; int locimminent = -1; int[] loclanes = null; + TurnType primary = null; if (routingHelper != null && routingHelper.isRouteCalculated() && view.getSettings().SHOW_LANES.get()) { if (routingHelper.isFollowingMode()) { NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), false); if(r != null && r.directionInfo != null && r.directionInfo.getTurnType() != null) { loclanes = r.directionInfo.getTurnType().getLanes(); + primary = r.directionInfo.getTurnType(); locimminent = r.imminent; // Do not show too far if ((r.distanceTo > 700 && r.directionInfo.getTurnType().isSkipToSpeak()) || r.distanceTo > 1200) { @@ -595,6 +628,7 @@ public class RouteInfoWidgetsFactory { RouteDirectionInfo next = routingHelper.getRouteDirections().get(di); if (next != null) { loclanes = next.getTurnType().getLanes(); + primary = next.getTurnType(); } } } @@ -603,6 +637,7 @@ public class RouteInfoWidgetsFactory { if (visible) { if (!Arrays.equals(lanes, loclanes)) { lanes = loclanes; + turn = primary; requestLayout(); invalidate(); } @@ -619,6 +654,14 @@ public class RouteInfoWidgetsFactory { 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) { final RoutingHelper rh = app.getRoutingHelper(); From 19ef80c33f2859f2d1e326637e65a341a5234d1d Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 2 Oct 2014 17:50:02 +0200 Subject: [PATCH 4/4] count lines differenetly --- .../osmand/router/RouteResultPreparation.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 89a6c4ead0..2d935bb105 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -516,7 +516,7 @@ public class RouteResultPreparation { kl = true; int lns = attached.getObject().getLanes(); if(attached.getObject().getOneway() == 0) { - lns = (lns + 1) / 2; + lns = countLines(attached, lns); } if (lns > 0) { right += lns; @@ -526,7 +526,7 @@ public class RouteResultPreparation { kr = true; int lns = attached.getObject().getLanes(); if(attached.getObject().getOneway() == 0) { - lns = (lns + 1) / 2; + lns = countLines(attached, lns); } if (lns > 0) { left += lns; @@ -542,8 +542,9 @@ public class RouteResultPreparation { right = 1; } int current = currentSegm.getObject().getLanes(); - if(currentSegm.getObject().getOneway() == 0) { - current = (current + 1) / 2; + // attachedRoutes covers all allowed outbound routes at that point except currentSegm. + if (currentSegm.getObject().getOneway() == 0) { + current = countLines(currentSegm, current); } if (current <= 0) { current = 1; @@ -579,6 +580,19 @@ public class RouteResultPreparation { } 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){ String h = s.getObject().getHighway();