Update LanesDrawable
|
@ -158,6 +158,7 @@ public class TurnType {
|
|||
// 0 bit - 0/1 - to use or not
|
||||
// 1-5 bits - additional turn info
|
||||
// 6-10 bits - secondary turn
|
||||
// 11-15 bits - tertiary turn
|
||||
public void setLanes(int[] lanes) {
|
||||
this.lanes = lanes;
|
||||
}
|
||||
|
@ -183,6 +184,16 @@ public class TurnType {
|
|||
return (laneValue >> 5);
|
||||
}
|
||||
|
||||
public static void setTertiaryTurn(int[] lanes, int lane, int turnType) {
|
||||
lanes[lane] &= ~(15 << 10);
|
||||
lanes[lane] |= (turnType << 10);
|
||||
}
|
||||
|
||||
public static int getTertiaryTurn(int laneValue) {
|
||||
// Get the primary turn modifier for the lane
|
||||
return (laneValue >> 10);
|
||||
}
|
||||
|
||||
|
||||
public int[] getLanes() {
|
||||
return lanes;
|
||||
|
|
BIN
OsmAnd/res/drawable-hdpi/map_turn_forward_keep_right.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
OsmAnd/res/drawable-hdpi/map_turn_forward_keep_right_small.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
OsmAnd/res/drawable-hdpi/map_turn_forward_turn_sharp.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
OsmAnd/res/drawable-hdpi/map_turn_forward_turn_sharp_small.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
OsmAnd/res/drawable-hdpi/map_turn_keep_right.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
OsmAnd/res/drawable-hdpi/map_turn_keep_right_small.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
OsmAnd/res/drawable-hdpi/map_turn_sharp_right.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
OsmAnd/res/drawable-hdpi/map_turn_sharp_right_small.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
OsmAnd/res/drawable-mdpi/map_turn_forward_keep_right.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
OsmAnd/res/drawable-mdpi/map_turn_forward_keep_right_small.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
OsmAnd/res/drawable-mdpi/map_turn_forward_turn_sharp.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
OsmAnd/res/drawable-mdpi/map_turn_forward_turn_sharp_small.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
OsmAnd/res/drawable-mdpi/map_turn_keep_right.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
OsmAnd/res/drawable-mdpi/map_turn_keep_right_small.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
OsmAnd/res/drawable-mdpi/map_turn_sharp_right.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
OsmAnd/res/drawable-mdpi/map_turn_sharp_right_small.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
OsmAnd/res/drawable-xhdpi/map_turn_forward_keep_right.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
OsmAnd/res/drawable-xhdpi/map_turn_forward_keep_right_small.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
OsmAnd/res/drawable-xhdpi/map_turn_forward_turn_sharp.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
OsmAnd/res/drawable-xhdpi/map_turn_forward_turn_sharp_small.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
OsmAnd/res/drawable-xhdpi/map_turn_keep_right.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
OsmAnd/res/drawable-xhdpi/map_turn_keep_right_small.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
OsmAnd/res/drawable-xhdpi/map_turn_sharp_right.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
OsmAnd/res/drawable-xhdpi/map_turn_sharp_right_small.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
OsmAnd/res/drawable-xxhdpi/map_turn_forward_keep_right.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
OsmAnd/res/drawable-xxhdpi/map_turn_forward_keep_right_small.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
OsmAnd/res/drawable-xxhdpi/map_turn_forward_turn_sharp.png
Normal file
After Width: | Height: | Size: 3 KiB |
BIN
OsmAnd/res/drawable-xxhdpi/map_turn_forward_turn_sharp_small.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
OsmAnd/res/drawable-xxhdpi/map_turn_keep_right.png
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
OsmAnd/res/drawable-xxhdpi/map_turn_keep_right_small.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
OsmAnd/res/drawable-xxhdpi/map_turn_sharp_right.png
Normal file
After Width: | Height: | Size: 3 KiB |
BIN
OsmAnd/res/drawable-xxhdpi/map_turn_sharp_right_small.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
|
@ -1,18 +1,14 @@
|
|||
package net.osmand.plus.views;
|
||||
|
||||
import android.graphics.*;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.router.TurnType;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class TurnPathHelper {
|
||||
|
||||
// 72x72
|
||||
|
@ -298,4 +294,187 @@ public class TurnPathHelper {
|
|||
}
|
||||
|
||||
|
||||
public static class TurnResource {
|
||||
boolean flip;
|
||||
int resourceId;
|
||||
|
||||
public TurnResource(){}
|
||||
|
||||
public TurnResource(int resourceId, boolean value) {
|
||||
this.resourceId = resourceId;
|
||||
this.flip = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return resourceId * (flip ? -1 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
private static TurnResource getTallArrow(int tt){
|
||||
|
||||
TurnResource result = new TurnResource();
|
||||
|
||||
switch (tt){
|
||||
case TurnType.C:
|
||||
result.resourceId = R.drawable.map_turn_forward_small;
|
||||
break;
|
||||
case TurnType.TR:
|
||||
case TurnType.TL:
|
||||
result.resourceId = R.drawable.map_turn_right2_small;
|
||||
break;
|
||||
case TurnType.KR:
|
||||
case TurnType.KL:
|
||||
result.resourceId = R.drawable.map_turn_keep_right_small;
|
||||
break;
|
||||
case TurnType.TSLR:
|
||||
case TurnType.TSLL:
|
||||
result.resourceId = R.drawable.map_turn_slight_right_small;
|
||||
break;
|
||||
case TurnType.TSHR:
|
||||
case TurnType.TSHL:
|
||||
result.resourceId = R.drawable.map_turn_sharp_right_small;
|
||||
break;
|
||||
case TurnType.TRU:
|
||||
case TurnType.TU:
|
||||
result.resourceId = R.drawable.map_turn_uturn_small;
|
||||
break;
|
||||
default:
|
||||
result.resourceId = R.drawable.map_turn_forward_small;
|
||||
break;
|
||||
}
|
||||
|
||||
if(tt == TurnType.TL || tt == TurnType.KL || tt == TurnType.TSLL
|
||||
|| tt == TurnType.TSHL || tt == TurnType.TU){
|
||||
result.flip = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private static TurnResource getShortArrow(int tt){
|
||||
|
||||
TurnResource result = new TurnResource();
|
||||
|
||||
switch (tt) {
|
||||
case TurnType.C:
|
||||
result.resourceId = R.drawable.map_turn_forward_small;
|
||||
break;
|
||||
case TurnType.TR:
|
||||
case TurnType.TL:
|
||||
result.resourceId = R.drawable.map_turn_forward_right_turn_small;
|
||||
break;
|
||||
case TurnType.KR:
|
||||
case TurnType.KL:
|
||||
result.resourceId = R.drawable.map_turn_forward_keep_right_small;
|
||||
break;
|
||||
case TurnType.TSLR:
|
||||
case TurnType.TSLL:
|
||||
result.resourceId = R.drawable.map_turn_forward_slight_right_turn_small;
|
||||
break;
|
||||
case TurnType.TSHR:
|
||||
case TurnType.TSHL:
|
||||
result.resourceId = R.drawable.map_turn_forward_turn_sharp_small;
|
||||
break;
|
||||
case TurnType.TRU:
|
||||
case TurnType.TU:
|
||||
result.resourceId = R.drawable.map_turn_forward_uturn_right_small;
|
||||
break;
|
||||
default:
|
||||
result.resourceId = R.drawable.map_turn_forward_small;
|
||||
break;
|
||||
}
|
||||
|
||||
if(tt == TurnType.TL || tt == TurnType.KL || tt == TurnType.TSLL
|
||||
|| tt == TurnType.TSHL || tt == TurnType.TU){
|
||||
result.flip = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static Bitmap getBitmapFromTurnType(Resources res, Map<TurnResource, Bitmap> cache, int firstTurn, int secondTurn, int thirdTurn, int turn, Bitmap defaultType, 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);
|
||||
|
||||
if(turn == 1){
|
||||
if(firstTurn == 0) return defaultType;
|
||||
if(secondTurnType == 0) {
|
||||
turnResource = getTallArrow(firstTurnType);
|
||||
}else if(secondTurnType != TurnType.C){
|
||||
if(firstTurnType == TurnType.TU || firstTurnType == TurnType.TRU){
|
||||
turnResource = getShortArrow(firstTurnType);
|
||||
}else {
|
||||
turnResource = getTallArrow(firstTurnType);
|
||||
}
|
||||
}else{
|
||||
// get the small one
|
||||
turnResource = getShortArrow(firstTurnType);
|
||||
}
|
||||
}else if(turn == 2){
|
||||
if(firstTurnType == TurnType.C){
|
||||
// get the small one
|
||||
turnResource = getShortArrow(secondTurnType);
|
||||
}else{
|
||||
turnResource = getTallArrow(secondTurnType);
|
||||
}
|
||||
}else if(turn == 3){
|
||||
if(secondTurnType == TurnType.C){
|
||||
// get the small one
|
||||
turnResource = getShortArrow(thirdTurnType);
|
||||
}else{
|
||||
// ? slightly turn?
|
||||
}
|
||||
}
|
||||
|
||||
Bitmap b = cache.get(turnResource);
|
||||
if(b == null) {
|
||||
b = turnResource.flip ? getFlippedBitmap(res, turnResource.resourceId) : BitmapFactory.decodeResource(res, turnResource.resourceId);
|
||||
cache.put(turnResource, b);
|
||||
}
|
||||
|
||||
//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);
|
||||
*/
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public static Bitmap getFlippedBitmap(Resources res, int resId){
|
||||
|
||||
BitmapFactory.Options opt = new BitmapFactory.Options();
|
||||
opt.inJustDecodeBounds = true;
|
||||
//Below line is necessary to fill in opt.outWidth, opt.outHeight
|
||||
Bitmap b = BitmapFactory.decodeResource(res, resId, opt);
|
||||
|
||||
b = Bitmap.createBitmap(opt.outWidth, opt.outHeight, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(b);
|
||||
|
||||
Matrix flipHorizontalMatrix = new Matrix();
|
||||
flipHorizontalMatrix.setScale(-1, 1);
|
||||
flipHorizontalMatrix.postTranslate(b.getWidth(), 0);
|
||||
|
||||
Bitmap bb = BitmapFactory.decodeResource(res, resId);
|
||||
canvas.drawBitmap(bb, flipHorizontalMatrix, null);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package net.osmand.plus.views.mapwidgets;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.*;
|
||||
import android.util.ArrayMap;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -515,132 +513,6 @@ public class RouteInfoWidgetsFactory {
|
|||
return p;
|
||||
}
|
||||
|
||||
private static Bitmap getPathBitmapFromTurnType(Resources res, List<Bitmap> paths, int laneType, int secondTurnType, Bitmap defaultType, float coef) {
|
||||
if(laneType == 0) {
|
||||
return defaultType;
|
||||
}
|
||||
/*while (paths.size() <= laneType) {
|
||||
paths.add(null);
|
||||
}
|
||||
|
||||
if(secondTurnType == 0) {
|
||||
Bitmap b = paths.get(laneType);
|
||||
if (b != null) {
|
||||
return b;
|
||||
}
|
||||
}*/
|
||||
|
||||
boolean flip = false;
|
||||
|
||||
int turnResourceId = R.drawable.map_turn_right;
|
||||
if(secondTurnType == 0){
|
||||
TurnType tp = TurnType.valueOf(laneType, false);
|
||||
switch (tp.getValue()){
|
||||
case TurnType.C:
|
||||
turnResourceId = R.drawable.map_turn_forward;
|
||||
break;
|
||||
case TurnType.TR:
|
||||
turnResourceId = R.drawable.map_turn_right;
|
||||
break;
|
||||
case TurnType.TL:
|
||||
turnResourceId = R.drawable.map_turn_right;
|
||||
flip = true;
|
||||
break;
|
||||
case TurnType.KR:
|
||||
turnResourceId = R.drawable.map_turn_right;
|
||||
break;
|
||||
case TurnType.KL:
|
||||
turnResourceId = R.drawable.map_turn_right;
|
||||
flip = true;
|
||||
break;
|
||||
case TurnType.TSLR:
|
||||
turnResourceId = R.drawable.map_turn_slight_right;
|
||||
break;
|
||||
case TurnType.TSLL:
|
||||
turnResourceId = R.drawable.map_turn_slight_right;
|
||||
flip = true;
|
||||
break;
|
||||
case TurnType.TRU:
|
||||
turnResourceId = R.drawable.map_turn_uturn_right;
|
||||
break;
|
||||
case TurnType.TU:
|
||||
turnResourceId = R.drawable.map_turn_uturn;
|
||||
flip = true;
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
TurnType tp = TurnType.valueOf(laneType, false);
|
||||
switch (tp.getValue()) {
|
||||
case TurnType.C:
|
||||
turnResourceId = R.drawable.map_turn_forward;
|
||||
break;
|
||||
case TurnType.TR:
|
||||
turnResourceId = R.drawable.map_turn_forward_right_turn;
|
||||
break;
|
||||
case TurnType.TL:
|
||||
turnResourceId = R.drawable.map_turn_forward_right_turn;
|
||||
flip = true;
|
||||
break;
|
||||
case TurnType.KR:
|
||||
turnResourceId = R.drawable.map_turn_forward_slight_right_turn;
|
||||
break;
|
||||
case TurnType.KL:
|
||||
turnResourceId = R.drawable.map_turn_forward_slight_right_turn;
|
||||
flip = true;
|
||||
break;
|
||||
case TurnType.TSLR:
|
||||
turnResourceId = R.drawable.map_turn_forward_slight_right_turn;
|
||||
break;
|
||||
case TurnType.TSLL:
|
||||
turnResourceId = R.drawable.map_turn_forward_slight_right_turn;
|
||||
flip = true;
|
||||
break;
|
||||
case TurnType.TRU:
|
||||
turnResourceId = R.drawable.map_turn_forward_uturn_right;
|
||||
break;
|
||||
case TurnType.TU:
|
||||
turnResourceId = R.drawable.map_turn_forward_uturn_right;
|
||||
flip = true;
|
||||
break;
|
||||
default:
|
||||
turnResourceId = R.drawable.map_turn_forward_right_turn;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Bitmap b = flip ? getFlippedBitmap(res, turnResourceId) : BitmapFactory.decodeResource(res, turnResourceId);
|
||||
|
||||
//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);
|
||||
|
||||
//paths.set(laneType, b);
|
||||
return b;
|
||||
}
|
||||
|
||||
public static Bitmap getFlippedBitmap(Resources res, int resId){
|
||||
|
||||
BitmapFactory.Options opt = new BitmapFactory.Options();
|
||||
opt.inJustDecodeBounds = true;
|
||||
//Below line is necessary to fill in opt.outWidth, opt.outHeight
|
||||
Bitmap b = BitmapFactory.decodeResource(res, resId, opt);
|
||||
|
||||
b = Bitmap.createBitmap(opt.outWidth, opt.outHeight, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(b);
|
||||
|
||||
Matrix flipHorizontalMatrix = new Matrix();
|
||||
flipHorizontalMatrix.setScale(-1, 1);
|
||||
flipHorizontalMatrix.postTranslate(b.getWidth(), 0);
|
||||
|
||||
Bitmap bb = BitmapFactory.decodeResource(res, resId);
|
||||
canvas.drawBitmap(bb, flipHorizontalMatrix, null);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public static class LanesControl {
|
||||
private MapViewTrackingUtilities trackingUtilities;
|
||||
|
@ -758,7 +630,7 @@ public class RouteInfoWidgetsFactory {
|
|||
boolean imminent = false;
|
||||
private Context ctx;
|
||||
private ArrayList<Path> paths = new ArrayList<Path>();
|
||||
private ArrayList<Bitmap> pathBitmaps = new ArrayList<Bitmap>();
|
||||
private Map<TurnPathHelper.TurnResource, Bitmap> bitmapCache = new ArrayMap<TurnPathHelper.TurnResource, Bitmap>();
|
||||
private Paint paintBlack;
|
||||
private Path laneStraight;
|
||||
private final Bitmap laneStraightBitmap;
|
||||
|
@ -768,12 +640,16 @@ public class RouteInfoWidgetsFactory {
|
|||
private int height;
|
||||
private int width;
|
||||
private static final float miniCoeff = 2f;
|
||||
private final boolean leftSide;
|
||||
|
||||
public LanesDrawable(Context ctx, float scaleCoefficent) {
|
||||
public LanesDrawable(MapActivity ctx, float scaleCoefficent) {
|
||||
this.ctx = ctx;
|
||||
OsmandSettings settings = ctx.getMyApplication().getSettings();
|
||||
leftSide = settings.DRIVING_REGION.get().leftHandDriving;
|
||||
|
||||
this.scaleCoefficient = scaleCoefficent;
|
||||
laneStraight = getPathFromTurnType(paths, TurnType.C, null, scaleCoefficient / miniCoeff);
|
||||
laneStraightBitmap = getPathBitmapFromTurnType(ctx.getResources(), pathBitmaps, TurnType.C, 0, null, scaleCoefficient / miniCoeff);
|
||||
laneStraightBitmap = TurnPathHelper.getBitmapFromTurnType(ctx.getResources(), bitmapCache, TurnType.C, 0, 0, 1, null, scaleCoefficient / miniCoeff, leftSide);
|
||||
paintBlack = new Paint();
|
||||
paintBlack.setStyle(Style.STROKE);
|
||||
paintBlack.setColor(Color.BLACK);
|
||||
|
@ -827,11 +703,12 @@ public class RouteInfoWidgetsFactory {
|
|||
turnType = TurnType.getPrimaryTurn(lanes[i]);
|
||||
secondTurnType = TurnType.getSecondaryTurn(lanes[i]);
|
||||
|
||||
Bitmap b = getPathBitmapFromTurnType(ctx.getResources(), pathBitmaps, turnType, secondTurnType, laneStraightBitmap, scaleCoefficient / miniCoeff);
|
||||
float coef = scaleCoefficient / miniCoeff;
|
||||
Bitmap b = TurnPathHelper.getBitmapFromTurnType(ctx.getResources(), bitmapCache, turnType, secondTurnType, 0, 1, laneStraightBitmap, coef, leftSide);
|
||||
|
||||
if(secondTurnType > 0){
|
||||
Bitmap bSecond = null;
|
||||
bSecond = getPathBitmapFromTurnType(ctx.getResources(), pathBitmaps, secondTurnType, secondTurnType, laneStraightBitmap, scaleCoefficient / miniCoeff);
|
||||
bSecond = TurnPathHelper.getBitmapFromTurnType(ctx.getResources(), bitmapCache, turnType, secondTurnType, 0, 2, laneStraightBitmap, coef, leftSide);
|
||||
if (bSecond != null){
|
||||
paintSecondTurn.setColorFilter(new PorterDuffColorFilter(paintSecondTurn.getColor(), PorterDuff.Mode.SRC_ATOP));
|
||||
canvas.drawBitmap(bSecond, 0f, 0f, paintSecondTurn);
|
||||
|
|