Ejemplo n.º 1
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    drawChart(canvas);
    drawAxis(canvas);

    if (touchedBarIndex != INVALID_BAR_INDEX) {
      Bar bar = barList.get(touchedBarIndex);
      mPaint.setColor(Color.BLUE);
      bar.drawSelf(canvas, mPaint);
      textPaint.setTextSize(detailText1Size);
      float text1Length = textPaint.measureText(bar.yValue) + detailText1Size;
      textPaint.setTextSize(detailText2Size);
      float text2Length = textPaint.measureText(bar.xValue) + detailText2Size;
      int detailWidth = (int) (Math.max(text1Length, text2Length) * 1.5f);
      int detailHeight = (int) (1.2f * (detailText1Size + detailText2Size));
      float start_x = (bar.middle - 0.5f * detailWidth);
      float end_x = start_x + detailWidth;
      float start_y = 0;
      float end_y = 0;
      if (bar.withdrawal >= 0) {
        start_y = bar.top - detailHeight;
        end_y = bar.top;
      } else {
        start_y = bar.bottom;
        end_y = bar.bottom + detailHeight;
      }

      detailedRect.set(start_x, start_y, end_x, end_y);
      mPaint.setColor(HALF_TRANSPARENT_BLUE);
      canvas.drawRoundRect(detailedRect, detailRoundR, detailRoundR, mPaint);

      textPaint.setColor(Color.WHITE);
      textPaint.setTextAlign(Paint.Align.CENTER);
      textPaint.setTextSize(detailText1Size);
      float text1Y = start_y + 1f * detailText1Size;
      canvas.drawText(bar.yValue, bar.middle, text1Y, textPaint);

      textPaint.setTextSize(detailText2Size);
      float text2Y = end_y - 0.5f * detailText2Size;
      canvas.drawText(bar.xValue, bar.middle, text2Y, textPaint);
    }
  }