Add artificial circle to roundabout

This commit is contained in:
Victor Shcherb 2016-06-17 09:27:51 +02:00
parent 2c9027122d
commit 20c630c473
3 changed files with 25 additions and 10 deletions

View file

@ -5,6 +5,7 @@ import net.osmand.plus.R;
import net.osmand.router.TurnType;
import android.content.res.Resources;
import android.graphics.Paint.Style;
import android.graphics.Path.Direction;
import android.graphics.drawable.Drawable;
import java.util.Map;
@ -19,7 +20,7 @@ public class TurnPathHelper {
private static final boolean SHOW_STEPS = true;
// 72x72
public static void calcTurnPath(Path pathForTurn, TurnType turnType, Matrix transform) {
public static void calcTurnPath(Path pathForTurn, Path outlay, TurnType turnType, Matrix transform) {
if(turnType == null){
return;
}
@ -206,6 +207,10 @@ public class TurnPathHelper {
RectF qrOut = new RectF(cx - radOut, cy - radOut, cx + radOut, cy + radOut);
RectF qrIn = new RectF(cx - radIn, cy - radIn, cx + radIn, cy + radIn);
if(outlay != null) {
outlay.addOval(qrOut, Direction.CW);
outlay.addOval(qrIn, Direction.CW);
}
// move to bottom ring
pathForTurn.moveTo(getProjX(dfOut, cx, cy, radOut), getProjY(dfOut, cx, cy, radOut));
@ -421,15 +426,22 @@ public class TurnPathHelper {
public static class RouteDrawable extends Drawable {
Paint paintRouteDirection;
Paint paintRouteDirectionOutlay;
Path p = new Path();
Path dp = new Path();
Path pOutlay = new Path();
Path dpOutlay = new Path();
public RouteDrawable(Resources resources){
paintRouteDirection = new Paint();
paintRouteDirection.setStyle(Style.FILL_AND_STROKE);
paintRouteDirection.setColor(resources.getColor(R.color.nav_arrow_distant));
paintRouteDirection.setAntiAlias(true);
TurnPathHelper.calcTurnPath(dp, TurnType.straight(), null);
paintRouteDirectionOutlay = new Paint();
paintRouteDirectionOutlay.setStyle(Style.STROKE);
paintRouteDirectionOutlay.setColor(Color.BLACK);
paintRouteDirectionOutlay.setAntiAlias(true);
TurnPathHelper.calcTurnPath(dp, dpOutlay, TurnType.straight(), null);
}
@Override
@ -437,15 +449,17 @@ public class TurnPathHelper {
Matrix m = new Matrix();
m.setScale(bounds.width() / 72f, bounds.height() / 72f);
p.transform(m, dp);
pOutlay.transform(m, dpOutlay);
}
public void setRouteType(TurnType t){
TurnPathHelper.calcTurnPath(p, t, null);
TurnPathHelper.calcTurnPath(p, pOutlay, t, null);
onBoundsChange(getBounds());
}
@Override
public void draw(Canvas canvas) {
canvas.drawPath(dpOutlay, paintRouteDirectionOutlay);
canvas.drawPath(dp, paintRouteDirection);
}

View file

@ -113,6 +113,7 @@ public class NextTurnInfoWidget extends TextInfoWidget {
protected Paint paintBlack;
protected Paint paintRouteDirection;
protected Path pathForTurn = new Path();
protected Path pathForTurnOutlay = new Path();
protected TurnType turnType = null;
protected int turnImminent;
protected boolean deviatedFromRoute;
@ -135,11 +136,10 @@ public class NextTurnInfoWidget extends TextInfoWidget {
@Override
protected void onBoundsChange(Rect bounds) {
if (pathForTurn != null) {
Matrix m = new Matrix();
m.setScale(bounds.width() / 72f, bounds.height() / 72f);
pathForTurn.transform(m, pathForTurn);
}
Matrix m = new Matrix();
m.setScale(bounds.width() / 72f, bounds.height() / 72f);
pathForTurn.transform(m, pathForTurn);
pathForTurnOutlay.transform(m, pathForTurnOutlay);
}
public void setTurnImminent(int turnImminent, boolean deviatedFromRoute) {
@ -163,6 +163,7 @@ public class NextTurnInfoWidget extends TextInfoWidget {
public void draw(Canvas canvas) {
/// small indent
// canvas.translate(0, 3 * scaleCoefficient);
canvas.drawPath(pathForTurnOutlay, paintBlack);
canvas.drawPath(pathForTurn, paintRouteDirection);
canvas.drawPath(pathForTurn, paintBlack);
}
@ -185,7 +186,7 @@ public class NextTurnInfoWidget extends TextInfoWidget {
public boolean setTurnType(TurnType turnType) {
if(turnType != this.turnType) {
this.turnType = turnType;
TurnPathHelper.calcTurnPath(pathForTurn, turnType, null);
TurnPathHelper.calcTurnPath(pathForTurn, pathForTurnOutlay, turnType, null);
onBoundsChange(getBounds());
return true;
}

View file

@ -746,7 +746,7 @@ public class RouteInfoWidgetsFactory {
Matrix pathTransform = new Matrix();
pathTransform.postScale(coef, coef );
TurnType tp = TurnType.valueOf(laneType, false);
TurnPathHelper.calcTurnPath(p, tp, pathTransform);
TurnPathHelper.calcTurnPath(p, null, tp, pathTransform);
paths.set(laneType, p);
return p;
}