From 0f86f53b5e6acfa4103d4000db1e2c4d77c9d2b1 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 28 Mar 2016 15:10:47 +0200 Subject: [PATCH] Fix turn lanes --- .../src/net/osmand/router/TurnType.java | 4 +- .../net/osmand/plus/views/TurnPathHelper.java | 60 ++++++++++--------- .../mapwidgets/RouteInfoWidgetsFactory.java | 31 ++++++---- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/TurnType.java b/OsmAnd-java/src/net/osmand/router/TurnType.java index 7e01406590..d9d6241a03 100644 --- a/OsmAnd-java/src/net/osmand/router/TurnType.java +++ b/OsmAnd-java/src/net/osmand/router/TurnType.java @@ -252,11 +252,11 @@ public class TurnType { } public static boolean isLeftTurn(int type) { - return type == TL || type == TSHL || type == TSLL || type == TRU; + return type == TL || type == TSHL || type == TSLL || type == TU || type == KL; } public static boolean isRightTurn(int type) { - return type == TR || type == TSHR || type == TSLR || type == TU; + return type == TR || type == TSHR || type == TSLR || type == TRU || type == KR; } public static boolean isSlightTurn(int type) { diff --git a/OsmAnd/src/net/osmand/plus/views/TurnPathHelper.java b/OsmAnd/src/net/osmand/plus/views/TurnPathHelper.java index fb351f99f2..f3274f8363 100644 --- a/OsmAnd/src/net/osmand/plus/views/TurnPathHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/TurnPathHelper.java @@ -405,58 +405,64 @@ public class TurnPathHelper { } - public static Bitmap getBitmapFromTurnType(Resources res, Map cache, int firstTurn, int secondTurn, int thirdTurn, int turnIndex, Bitmap defaultType, float coef, boolean leftSide) { + public static Bitmap getBitmapFromTurnType(Resources res, Map cache, int firstTurn, + int secondTurn, int thirdTurn, int turnIndex, float coef, boolean leftSide) { int firstTurnType = TurnType.valueOf(firstTurn, leftSide).getValue(); int secondTurnType = TurnType.valueOf(secondTurn, leftSide).getValue(); int thirdTurnType = TurnType.valueOf(thirdTurn, leftSide).getValue(); - TurnResource turnResource = new TurnResource(R.drawable.map_turn_forward_small, false); + TurnResource turnResource = null; - if(turnIndex == FIRST_TURN){ - if(firstTurn == 0) return defaultType; - if(secondTurnType == 0) { + if (turnIndex == FIRST_TURN) { + if (secondTurnType == 0) { turnResource = getTallArrow(firstTurnType); - }else if(secondTurnType != TurnType.C){ - if(firstTurnType == TurnType.TU || firstTurnType == TurnType.TRU){ + } else if (secondTurnType != TurnType.C) { + if (firstTurnType == TurnType.TU || firstTurnType == TurnType.TRU) { turnResource = getShortArrow(firstTurnType); - }else { + } else { turnResource = getTallArrow(firstTurnType); } - }else{ + } else { // get the small one turnResource = getShortArrow(firstTurnType); } - }else if(turnIndex == SECOND_TURN){ - if(firstTurnType == TurnType.C || firstTurnType == TurnType.TR){ + } else if (turnIndex == SECOND_TURN) { + if (TurnType.isLeftTurn(firstTurnType) && TurnType.isLeftTurn(secondTurnType)) { + turnResource = null; + } else if (TurnType.isRightTurn(firstTurnType) && TurnType.isRightTurn(secondTurnType)) { + turnResource = null; + } else if (firstTurnType == TurnType.C || thirdTurnType == TurnType.C) { // get the small one turnResource = getShortArrow(secondTurnType); - }else{ + } else { turnResource = getTallArrow(secondTurnType); } - }else if(turnIndex == THIRD_TURN){ - if(secondTurnType == TurnType.C){ - // get the small one - turnResource = getShortArrow(thirdTurnType); - }else{ - // ? slightly turn? + } else if (turnIndex == THIRD_TURN) { + if ((TurnType.isLeftTurn(firstTurnType) || TurnType.isLeftTurn(secondTurnType)) && TurnType.isLeftTurn(thirdTurnType)) { + turnResource = null; + } else if ((TurnType.isRightTurn(firstTurnType) || TurnType.isRightTurn(secondTurnType)) && TurnType.isRightTurn(thirdTurnType)) { + turnResource = null; + } else { + turnResource = getShortArrow(secondTurnType); } } + if (turnResource == null) { + return null; + } Bitmap b = cache.get(turnResource); - if(b == null) { - b = turnResource.flip ? getFlippedBitmap(res, turnResource.resourceId) : BitmapFactory.decodeResource(res, turnResource.resourceId); + if (b == null) { + b = turnResource.flip ? getFlippedBitmap(res, turnResource.resourceId) : BitmapFactory.decodeResource(res, + turnResource.resourceId); cache.put(turnResource, b); } - //Maybe redundant scaling + // Maybe redundant scaling /* - float bRatio = (float)b.getWidth() / (float)b.getHeight(); - float s = 72f * coef; - int wq = Math.round(s / bRatio); - int hq = Math.round(s); - b = Bitmap.createScaledBitmap(b, wq, hq, false); - */ + * float bRatio = (float)b.getWidth() / (float)b.getHeight(); float s = 72f * coef; int wq = Math.round(s / + * bRatio); int hq = Math.round(s); b = Bitmap.createScaledBitmap(b, wq, hq, false); + */ return b; } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index 423c5616d0..131da2d07a 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -692,32 +692,39 @@ public class RouteInfoWidgetsFactory { canvas.save(); // canvas.translate((int) (16 * scaleCoefficient), 0); for (int i = 0; i < lanes.length; i++) { - int turnType; - int secondTurnType; if ((lanes[i] & 1) == 1) { paintRouteDirection.setColor(imminent ? ctx.getResources().getColor(R.color.nav_arrow_imminent) : ctx.getResources().getColor(R.color.nav_arrow)); } else { paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_distant)); } - turnType = TurnType.getPrimaryTurn(lanes[i]); - secondTurnType = TurnType.getSecondaryTurn(lanes[i]); + int turnType = TurnType.getPrimaryTurn(lanes[i]); + int secondTurnType = TurnType.getSecondaryTurn(lanes[i]); + int thirdTurnType = TurnType.getTertiaryTurn(lanes[i]); float coef = scaleCoefficient / miniCoeff; - Bitmap b = TurnPathHelper.getBitmapFromTurnType(ctx.getResources(), bitmapCache, turnType, secondTurnType, 0, TurnPathHelper.FIRST_TURN, laneStraightBitmap, coef, leftSide); - - if(secondTurnType > 0){ + if(thirdTurnType > 0){ Bitmap bSecond = null; - bSecond = TurnPathHelper.getBitmapFromTurnType(ctx.getResources(), bitmapCache, turnType, secondTurnType, 0, TurnPathHelper.SECOND_TURN, laneStraightBitmap, coef, leftSide); + bSecond = TurnPathHelper.getBitmapFromTurnType(ctx.getResources(), bitmapCache, turnType, secondTurnType, thirdTurnType, TurnPathHelper.THIRD_TURN, coef, leftSide); if (bSecond != null){ paintSecondTurn.setColorFilter(new PorterDuffColorFilter(paintSecondTurn.getColor(), PorterDuff.Mode.SRC_ATOP)); canvas.drawBitmap(bSecond, 0f, 0f, paintSecondTurn); } } - - paintRouteDirection.setColorFilter(new PorterDuffColorFilter(paintRouteDirection.getColor(), PorterDuff.Mode.SRC_ATOP)); - canvas.drawBitmap(b, 0f, 0f, paintRouteDirection); - canvas.translate(w, 0); + if(secondTurnType > 0){ + Bitmap bSecond = null; + bSecond = TurnPathHelper.getBitmapFromTurnType(ctx.getResources(), bitmapCache, turnType, secondTurnType, thirdTurnType, TurnPathHelper.SECOND_TURN, coef, leftSide); + if (bSecond != null){ + paintSecondTurn.setColorFilter(new PorterDuffColorFilter(paintSecondTurn.getColor(), PorterDuff.Mode.SRC_ATOP)); + canvas.drawBitmap(bSecond, 0f, 0f, paintSecondTurn); + } + } + Bitmap b = TurnPathHelper.getBitmapFromTurnType(ctx.getResources(), bitmapCache, turnType, secondTurnType, thirdTurnType, TurnPathHelper.FIRST_TURN, coef, leftSide); + if(b != null) { + paintRouteDirection.setColorFilter(new PorterDuffColorFilter(paintRouteDirection.getColor(), PorterDuff.Mode.SRC_ATOP)); + canvas.drawBitmap(b, 0f, 0f, paintRouteDirection); + canvas.translate(w, 0); + } } canvas.restore(); }