Esempio n. 1
0
  // draw path 96x96
  public static void calcTurnPath(Path pathForTurn, TurnType turnType, Matrix transform) {
    if (turnType == null) {
      return;
    }
    pathForTurn.reset();

    int c = 48;
    int w = 16;
    pathForTurn.moveTo(c, 94);
    float sarrowL = 30; // side of arrow
    float harrowL = (float) Math.sqrt(2) * sarrowL; // hypotenuse of arrow
    float spartArrowL = (float) ((sarrowL - w / Math.sqrt(2)) / 2);
    float hpartArrowL = (float) (harrowL - w) / 2;

    if (TurnType.C.equals(turnType.getValue())) {
      int h = 65;

      pathForTurn.rMoveTo(w / 2, 0);
      pathForTurn.rLineTo(0, -h);
      pathForTurn.rLineTo(hpartArrowL, 0);
      pathForTurn.rLineTo(-harrowL / 2, -harrowL / 2); // center
      pathForTurn.rLineTo(-harrowL / 2, harrowL / 2);
      pathForTurn.rLineTo(hpartArrowL, 0);
      pathForTurn.rLineTo(0, h);
    } else if (TurnType.TR.equals(turnType.getValue()) || TurnType.TL.equals(turnType.getValue())) {
      int b = TurnType.TR.equals(turnType.getValue()) ? 1 : -1;
      int h = 36;
      float quadShiftX = 22;
      float quadShiftY = 22;

      pathForTurn.rMoveTo(-b * 8, 0);
      pathForTurn.rLineTo(0, -h);
      pathForTurn.rQuadTo(0, -quadShiftY, b * quadShiftX, -quadShiftY);
      pathForTurn.rLineTo(0, hpartArrowL);
      pathForTurn.rLineTo(b * harrowL / 2, -harrowL / 2); // center
      pathForTurn.rLineTo(-b * harrowL / 2, -harrowL / 2);
      pathForTurn.rLineTo(0, hpartArrowL);
      pathForTurn.rQuadTo(-b * (quadShiftX + w), 0, -b * (quadShiftX + w), quadShiftY + w);
      pathForTurn.rLineTo(0, h);
    } else if (TurnType.TSLR.equals(turnType.getValue())
        || TurnType.TSLL.equals(turnType.getValue())) {
      int b = TurnType.TSLR.equals(turnType.getValue()) ? 1 : -1;
      int h = 40;
      int quadShiftY = 22;
      float quadShiftX = (float) (quadShiftY / (1 + Math.sqrt(2)));
      float nQuadShiftX = (sarrowL - 2 * spartArrowL) - quadShiftX - w;
      float nQuadShifty = quadShiftY + (sarrowL - 2 * spartArrowL);

      pathForTurn.rMoveTo(-b * 4, 0);
      pathForTurn.rLineTo(0, -h /* + partArrowL */);
      pathForTurn.rQuadTo(
          0,
          -quadShiftY + quadShiftX /*- partArrowL*/,
          b * quadShiftX,
          -quadShiftY /*- partArrowL*/);
      pathForTurn.rLineTo(b * spartArrowL, spartArrowL);
      pathForTurn.rLineTo(0, -sarrowL); // center
      pathForTurn.rLineTo(-b * sarrowL, 0);
      pathForTurn.rLineTo(b * spartArrowL, spartArrowL);
      pathForTurn.rQuadTo(b * nQuadShiftX, -nQuadShiftX, b * nQuadShiftX, nQuadShifty);
      pathForTurn.rLineTo(0, h);
    } else if (TurnType.TSHR.equals(turnType.getValue())
        || TurnType.TSHL.equals(turnType.getValue())) {
      int b = TurnType.TSHR.equals(turnType.getValue()) ? 1 : -1;
      int h = 45;
      float quadShiftX = 22;
      float quadShiftY = -(float) (quadShiftX / (1 + Math.sqrt(2)));
      float nQuadShiftX = -(sarrowL - 2 * spartArrowL) - quadShiftX - w;
      float nQuadShiftY = -quadShiftY + (sarrowL - 2 * spartArrowL);

      pathForTurn.rMoveTo(-b * 8, 0);
      pathForTurn.rLineTo(0, -h);
      pathForTurn.rQuadTo(0, -(quadShiftX - quadShiftY), b * quadShiftX, quadShiftY);
      pathForTurn.rLineTo(-b * spartArrowL, spartArrowL);
      pathForTurn.rLineTo(b * sarrowL, 0); // center
      pathForTurn.rLineTo(0, -sarrowL);
      pathForTurn.rLineTo(-b * spartArrowL, spartArrowL);
      pathForTurn.rCubicTo(
          b * nQuadShiftX / 2,
          nQuadShiftX / 2,
          b * nQuadShiftX,
          nQuadShiftX / 2,
          b * nQuadShiftX,
          nQuadShiftY);
      pathForTurn.rLineTo(0, h);
    } else if (TurnType.TU.equals(turnType.getValue())) {
      int h = 54;
      float quadShiftX = 13;
      float quadShiftY = 13;

      pathForTurn.rMoveTo(28, 0);
      pathForTurn.rLineTo(0, -h);
      pathForTurn.rQuadTo(0, -(quadShiftY + w), -(quadShiftX + w), -(quadShiftY + w));
      pathForTurn.rQuadTo(-(quadShiftX + w), 0, -(quadShiftX + w), (quadShiftY + w));
      pathForTurn.rLineTo(-hpartArrowL, 0);
      pathForTurn.rLineTo(harrowL / 2, harrowL / 2); // center
      pathForTurn.rLineTo(harrowL / 2, -harrowL / 2);
      pathForTurn.rLineTo(-hpartArrowL, 0);
      pathForTurn.rQuadTo(0, -quadShiftX, quadShiftX, -quadShiftY);
      pathForTurn.rQuadTo(quadShiftX, 0, quadShiftX, quadShiftY);
      pathForTurn.rLineTo(0, h);
    } else if (turnType != null && turnType.isRoundAbout()) {
      float t = turnType.getTurnAngle();
      if (t >= 170 && t < 220) {
        t = 220;
      } else if (t > 160 && t < 170) {
        t = 160;
      }
      float sweepAngle = (t - 360) - 180;
      if (sweepAngle < -360) {
        sweepAngle += 360;
      }
      float r1 = 32f;
      float r2 = 24f;
      float angleToRot = 0.3f;

      pathForTurn.moveTo(48, 48 + r1 + 8);
      pathForTurn.lineTo(48, 48 + r1);
      RectF r = new RectF(48 - r1, 48 - r1, 48 + r1, 48 + r1);
      pathForTurn.arcTo(r, 90, sweepAngle);
      float angleRad = (float) ((180 + sweepAngle) * Math.PI / 180f);

      pathForTurn.lineTo(
          48 + (r1 + 4) * FloatMath.sin(angleRad), 48 - (r1 + 4) * FloatMath.cos(angleRad));
      pathForTurn.lineTo(
          48 + (r1 + 6) * FloatMath.sin(angleRad + angleToRot / 2),
          48 - (r1 + 6) * FloatMath.cos(angleRad + angleToRot / 2));
      pathForTurn.lineTo(
          48 + (r1 + 12) * FloatMath.sin(angleRad - angleToRot / 2),
          48 - (r1 + 12) * FloatMath.cos(angleRad - angleToRot / 2));
      pathForTurn.lineTo(
          48 + (r1 + 6) * FloatMath.sin(angleRad - 3 * angleToRot / 2),
          48 - (r1 + 6) * FloatMath.cos(angleRad - 3 * angleToRot / 2));
      pathForTurn.lineTo(
          48 + (r1 + 4) * FloatMath.sin(angleRad - angleToRot),
          48 - (r1 + 4) * FloatMath.cos(angleRad - angleToRot));
      pathForTurn.lineTo(
          48 + r2 * FloatMath.sin(angleRad - angleToRot),
          48 - r2 * FloatMath.cos(angleRad - angleToRot));

      r.set(48 - r2, 48 - r2, 48 + r2, 48 + r2);
      pathForTurn.arcTo(r, 360 + sweepAngle + 90, -sweepAngle);
      pathForTurn.lineTo(40, 48 + r2);
      pathForTurn.lineTo(40, 48 + r1 + 8);
      pathForTurn.close();
    }
    pathForTurn.close();
    if (transform != null) {
      pathForTurn.transform(transform);
    }
  }
Esempio n. 2
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);
      }
    }
  }