Beispiel #1
0
  private void drawRouteInfo(Canvas canvas) {
    if (routeLayer != null && routeLayer.getHelper().isRouterEnabled()) {
      if (routeLayer.getHelper().isFollowingMode()) {
        int d = routeLayer.getHelper().getDistanceToNextRouteDirection();
        if (showMiniMap || d == 0) {
          if (!routeLayer.getPath().isEmpty()) {
            canvas.save();
            canvas.clipRect(boundsForMiniRoute);
            canvas.drawRoundRect(boundsForMiniRoute, roundCorner, roundCorner, paintAlphaGray);
            canvas.drawRoundRect(boundsForMiniRoute, roundCorner, roundCorner, paintBlack);
            canvas.translate(
                centerMiniRouteX - view.getCenterPointX(),
                centerMiniRouteY - view.getCenterPointY());
            canvas.scale(
                scaleMiniRoute, scaleMiniRoute, view.getCenterPointX(), view.getCenterPointY());
            canvas.rotate(view.getRotate(), view.getCenterPointX(), view.getCenterPointY());
            canvas.drawCircle(
                view.getCenterPointX(), view.getCenterPointY(), 3 / scaleMiniRoute, fillBlack);
            canvas.drawPath(routeLayer.getPath(), paintMiniRoute);
            canvas.restore();
          }
        } else {
          canvas.drawRoundRect(boundsForMiniRoute, roundCorner, roundCorner, paintAlphaGray);
          canvas.drawRoundRect(boundsForMiniRoute, roundCorner, roundCorner, paintBlack);
          RouteDirectionInfo next = routeLayer.getHelper().getNextRouteDirectionInfo();
          if (next != null) {
            if (!Algoritms.objectEquals(cachedTurnType, next.turnType)) {
              cachedTurnType = next.turnType;
              calcTurnPath(pathForTurn, cachedTurnType, pathTransform);
              if (cachedTurnType.getExitOut() > 0) {
                cachedExitOut = cachedTurnType.getExitOut() + ""; // $NON-NLS-1$
              } else {
                cachedExitOut = null;
              }
            }
            canvas.drawPath(pathForTurn, paintRouteDirection);
            canvas.drawPath(pathForTurn, paintBlack);
            if (cachedExitOut != null) {
              canvas.drawText(
                  cachedExitOut,
                  boundsForMiniRoute.centerX() - 6 * scaleCoefficient,
                  boundsForMiniRoute.centerY() - 9 * scaleCoefficient,
                  paintBlack);
            }
            canvas.drawText(
                OsmAndFormatter.getFormattedDistance(d, map),
                boundsForMiniRoute.left + 10 * scaleCoefficient,
                boundsForMiniRoute.bottom - 9 * scaleCoefficient,
                paintBlack);
          }
        }
      }

      boolean followingMode = routeLayer.getHelper().isFollowingMode();
      int time = routeLayer.getHelper().getLeftTime();
      if (time == 0) {
        cachedLeftTime = 0;
        cachedLeftTimeString = null;
      } else {
        if (followingMode && showArrivalTime) {
          long toFindTime = time * 1000 + System.currentTimeMillis();
          if (Math.abs(toFindTime - cachedLeftTime) > 30000) {
            cachedLeftTime = toFindTime;
            if (DateFormat.is24HourFormat(map)) {
              cachedLeftTimeString =
                  DateFormat.format("kk:mm", toFindTime).toString(); // $NON-NLS-1$
            } else {
              cachedLeftTimeString =
                  DateFormat.format("k:mm aa", toFindTime).toString(); // $NON-NLS-1$
            }
            boundsForLeftTime.left =
                -paintBlack.measureText(cachedLeftTimeString)
                    - 10 * scaleCoefficient
                    + boundsForLeftTime.right;
          }
        } else {
          if (Math.abs(time - cachedLeftTime) > 30) {
            cachedLeftTime = time;
            int hours = time / (60 * 60);
            int minutes = (time / 60) % 60;
            cachedLeftTimeString = String.format("%d:%02d", hours, minutes); // $NON-NLS-1$
            boundsForLeftTime.left =
                -paintBlack.measureText(cachedLeftTimeString)
                    - 10 * scaleCoefficient
                    + boundsForLeftTime.right;
          }
        }
      }
      if (cachedLeftTimeString != null) {
        int w = (int) (boundsForLeftTime.right - boundsForLeftTime.left);
        boundsForLeftTime.right = view.getWidth();
        boundsForLeftTime.left = view.getWidth() - w;
        canvas.drawRoundRect(boundsForLeftTime, roundCorner, roundCorner, paintAlphaGray);
        canvas.drawRoundRect(boundsForLeftTime, roundCorner, roundCorner, paintBlack);
        canvas.drawText(
            cachedLeftTimeString,
            boundsForLeftTime.left + 5 * scaleCoefficient,
            boundsForLeftTime.bottom - 9 * scaleCoefficient,
            paintBlack);
      }
    }
  }