@Override
 public void draw(Canvas canvas) {
   float w = 72 * scaleCoefficient / miniCoeff;
   // to change color immediately when needed
   if (lanes != null && lanes.length > 0) {
     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
                 ? ctx.getResources().getColor(R.color.nav_arrow_imminent)
                 : ctx.getResources().getColor(R.color.nav_arrow));
         turnType = TurnType.getPrimaryTurn(lanes[i]);
       } else {
         paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_distant));
         turnType = TurnType.getPrimaryTurn(lanes[i]);
       }
       Path p = getPathFromTurnType(paths, turnType, laneStraight, scaleCoefficient / miniCoeff);
       canvas.drawPath(p, paintBlack);
       canvas.drawPath(p, paintRouteDirection);
       canvas.translate(w, 0);
     }
     canvas.restore();
   }
 }
 public void setTurnType(TurnType turnType) {
   boolean vis = updateVisibility(turnType != null);
   if (turnDrawable.setTurnType(turnType) || vis) {
     if (horisontalMini) {
       setImageDrawable(turnDrawable, false);
     } else {
       setTopImageDrawable(
           turnDrawable,
           turnType == null || turnType.getExitOut() == 0 ? "" : turnType.getExitOut() + "");
     }
   }
 }
Beispiel #3
0
 private String getTurnType(TurnType t) {
   if (TurnType.TL.equals(t.getValue())) {
     return AbstractPrologCommandPlayer.A_LEFT;
   } else if (TurnType.TSHL.equals(t.getValue())) {
     return AbstractPrologCommandPlayer.A_LEFT_SH;
   } else if (TurnType.TSLL.equals(t.getValue())) {
     return AbstractPrologCommandPlayer.A_LEFT_SL;
   } else if (TurnType.TR.equals(t.getValue())) {
     return AbstractPrologCommandPlayer.A_RIGHT;
   } else if (TurnType.TSHR.equals(t.getValue())) {
     return AbstractPrologCommandPlayer.A_RIGHT_SH;
   } else if (TurnType.TSLR.equals(t.getValue())) {
     return AbstractPrologCommandPlayer.A_RIGHT_SL;
   } else if (TurnType.KL.equals(t.getValue())) {
     return AbstractPrologCommandPlayer.A_LEFT_KEEP;
   } else if (TurnType.KR.equals(t.getValue())) {
     return AbstractPrologCommandPlayer.A_RIGHT_KEEP;
   }
   return null;
 }
Beispiel #4
0
 private void playMakeTurnIn(
     RouteDirectionInfo next, int dist, RouteDirectionInfo pronounceNextNext) {
   CommandBuilder play = getNewCommandPlayerToPlay();
   if (play != null) {
     String tParam = getTurnType(next.getTurnType());
     boolean isPlay = true;
     if (tParam != null) {
       play.turn(tParam, dist);
     } else if (next.getTurnType().isRoundAbout()) {
       play.roundAbout(dist, next.getTurnType().getTurnAngle(), next.getTurnType().getExitOut());
     } else if (next.getTurnType().getValue().equals(TurnType.TU)
         || next.getTurnType().getValue().equals(TurnType.TRU)) {
       play.makeUT(dist);
     } else {
       isPlay = false;
     }
     // small preparation to next after next
     if (pronounceNextNext != null) {
       TurnType t = pronounceNextNext.getTurnType();
       isPlay = true;
       if (next.getTurnType().getValue().equals(TurnType.C) && !TurnType.C.equals(t.getValue())) {
         play.goAhead(dist);
       }
       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())) {
         play.then().bearLeft();
       } else if (TurnType.TR.equals(t.getValue())
           || TurnType.TSHR.equals(t.getValue())
           || TurnType.TSLR.equals(t.getValue())
           || TurnType.KR.equals(t.getValue())) {
         play.then().bearRight();
       }
     }
     if (isPlay) {
       play.play();
     }
   }
 }
 private static Path getPathFromTurnType(
     List<Path> paths, int laneType, Path defaultType, float coef) {
   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(coef, coef);
   TurnType tp = TurnType.valueOf(laneType, false);
   TurnPathHelper.calcTurnPath(p, tp, pathTransform);
   paths.set(laneType, p);
   return p;
 }
Beispiel #6
0
  private MapInfoControl createLanesControl() {
    final Path laneStraight = new Path();
    Matrix pathTransform = new Matrix();
    pathTransform.postScale(scaleCoefficient / miniCoeff, scaleCoefficient / miniCoeff);
    TurnPathHelper.calcTurnPath(laneStraight, TurnType.valueOf(TurnType.C, false), pathTransform);
    final Paint paintBlack = new Paint();
    paintBlack.setStyle(Style.STROKE);
    paintBlack.setColor(Color.BLACK);
    paintBlack.setAntiAlias(true);
    paintBlack.setStrokeWidth(2.5f);

    final Paint paintRouteDirection = new Paint();
    paintRouteDirection.setStyle(Style.FILL);
    paintRouteDirection.setColor(view.getResources().getColor(R.color.nav_arrow));
    paintRouteDirection.setAntiAlias(true);
    final float w = 72 * scaleCoefficient / miniCoeff;

    final RoutingHelper routingHelper = routeLayer.getHelper();
    final MapInfoControl lanesControl =
        new MapInfoControl(map) {
          int[] lanes = null;

          boolean imminent = false;

          @Override
          protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int ls = (int) (lanes == null ? 0 : lanes.length * w);
            setWDimensions(ls, (int) (w + 3 * scaleCoefficient));
          }

          @Override
          protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            // to change color immediately when needed
            if (lanes != null && lanes.length > 0) {
              canvas.save();
              // canvas.translate((int) (16 * scaleCoefficient), 0);
              for (int i = 0; i < lanes.length; i++) {
                if ((lanes[i] & 1) == 1) {
                  paintRouteDirection.setColor(
                      imminent
                          ? getResources().getColor(R.color.nav_arrow_imminent)
                          : getResources().getColor(R.color.nav_arrow));
                } else {
                  paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow_distant));
                }
                canvas.drawPath(laneStraight, paintBlack);
                canvas.drawPath(laneStraight, paintRouteDirection);
                canvas.translate(w, 0);
              }
              canvas.restore();
            }
          }

          @Override
          public boolean updateInfo() {
            boolean visible = false;
            int locimminent = -1;
            int[] loclanes = null;
            if (routeLayer != null && routingHelper.isRouteCalculated()) {
              if (routingHelper.isRouterEnabled() && routingHelper.isFollowingMode()) {
                NextDirectionInfo r =
                    routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), false);
                if (r != null && r.directionInfo != null && r.directionInfo.getTurnType() != null) {
                  loclanes = r.directionInfo.getTurnType().getLanes();
                  locimminent = r.imminent;
                  // Do not show too far
                  if (locimminent == 2 || locimminent < 0) {
                    loclanes = null;
                  }
                }
              } else {
                int di = map.getMapLayers().getRouteInfoLayer().getDirectionInfo();
                if (di >= 0 && map.getMapLayers().getRouteInfoLayer().isVisible()) {
                  RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
                  if (next != null) {
                    loclanes = next.getTurnType().getLanes();
                  }
                }
              }
            }
            visible = loclanes != null && loclanes.length > 0;
            if (visible) {
              if (!Arrays.equals(lanes, loclanes)) {
                lanes = loclanes;
                requestLayout();
                invalidate();
              }
              if ((locimminent == 0) != imminent) {
                imminent = (locimminent == 0);
                invalidate();
              }
            }
            updateVisibility(visible);
            return true;
          }
        };

    return lanesControl;
  }