Example #1
0
  /**
   * * Draw the horizontal and vertical distance tape
   *
   * @param canvas what to draw upon
   * @param scale object for zoom determinations
   * @param pixPerUnit how many pixels per mile/km/nm
   * @param homeX horizontal position of current location on display
   * @param homeY vertical position of current location on display
   * @param top the usable top of the display
   * @param width of the display
   * @param height of the display
   */
  @SuppressLint("DefaultLocale")
  public void draw(
      Canvas canvas,
      Scale scale,
      float pixPerUnit,
      int homeX,
      int homeY,
      int top,
      int width,
      int height) {

    // Set color and transparency for the shadow
    mPaint.setColor(Color.BLACK); // shadow color is black
    mPaint.setAlpha(0x7F); // Make it see-thru

    // the vertical shadow down the left of the display
    mPaint.setStrokeWidth(mBgndWidth); // Line width
    canvas.drawLine(mBgndWidth / 2, top, mBgndWidth / 2, height, mPaint);

    // the horizontal shadow along the top of the display under the display rows
    mPaint.setStrokeWidth(mBgndHeight);
    canvas.drawLine(mBgndWidth - 1, top + mBgndHeight / 2, width, top + mBgndHeight / 2, mPaint);

    // The interval values for the scale indicator
    double step = scale.getStep();

    // text is white in color
    mPaint.setColor(Color.WHITE);

    // the horizontal values use posX and posY
    int posX = homeX - (mTextWidth / 2);
    int posY = top + mBotmMargin;

    // Display the tape values for 20 distances
    for (int idx = 0; idx < 21; idx++) {

      // The current range. Make its label. Calc its display offset
      double inc = idx * step;
      String strLabel = String.format(inc < 10 ? "%1.1f" : "%.0f", inc);
      float offset = (float) step * idx * pixPerUnit;

      // vertical tape on the left side. Show if on the screen
      if (inRangeY(homeY - offset, posY, height))
        canvas.drawText(strLabel, mLeftMargin, homeY - offset, mPaint);
      if (inRangeY(homeY + offset, posY, height))
        canvas.drawText(strLabel, mLeftMargin, homeY + offset, mPaint);

      // Horizontal tape on the top edge. Show if on the screen
      if (inRangeX(posX - offset, mBgndWidth, width))
        canvas.drawText(strLabel, posX - offset, posY, mPaint);
      if (inRangeX(posX + offset, mBgndWidth, width))
        canvas.drawText(strLabel, posX + offset, posY, mPaint);
    }

    return;
  }