示例#1
0
  /** draws all MarkerViews on the highlighted positions */
  protected void drawMarkers(Canvas canvas) {

    // if there is no marker view or drawing marker is disabled
    if (mMarkerView == null || !mDrawMarkerViews || !valuesToHighlight()) return;

    for (int i = 0; i < mIndicesToHighlight.length; i++) {

      Highlight highlight = mIndicesToHighlight[i];
      int xIndex = highlight.getXIndex();
      int dataSetIndex = highlight.getDataSetIndex();

      float deltaX = mXAxis.mAxisRange;

      if (xIndex <= deltaX && xIndex <= deltaX * mAnimator.getPhaseX()) {

        Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]);

        // make sure entry not null
        if (e == null || e.getXIndex() != mIndicesToHighlight[i].getXIndex()) continue;

        float[] pos = getMarkerPosition(e, highlight);

        // check bounds
        if (!mViewPortHandler.isInBounds(pos[0], pos[1])) continue;

        // callbacks to update the content
        mMarkerView.refreshContent(e, highlight);

        // mMarkerView.measure(MeasureSpec.makeMeasureSpec(0,
        // MeasureSpec.UNSPECIFIED),
        // MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        // mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
        // mMarkerView.getMeasuredHeight());
        // mMarkerView.draw(mDrawCanvas, pos[0], pos[1]);

        mMarkerView.measure(
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(), mMarkerView.getMeasuredHeight());

        if (pos[1] - mMarkerView.getHeight() <= 0) {
          float y = mMarkerView.getHeight() - pos[1];
          mMarkerView.draw(canvas, pos[0], pos[1] + y);
        } else {
          mMarkerView.draw(canvas, pos[0], pos[1]);
        }
      }
    }
  }
  // callbacks everytime the MarkerView is redrawn, can be used to update the
  // content (user-interface)
  @Override
  public void refreshContent(Entry e, Highlight highlight) {

    if (e instanceof CandleEntry) {

      CandleEntry ce = (CandleEntry) e;

      tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true));
    } else {

      tvContent.setText("" + Utils.formatNumber(e.getY(), 0, true));
    }

    super.refreshContent(e, highlight);
  }