Example usage for android.graphics Canvas getHeight

List of usage examples for android.graphics Canvas getHeight

Introduction

In this page you can find the example usage for android.graphics Canvas getHeight.

Prototype

public int getHeight() 

Source Link

Document

Returns the height of the current drawing layer

Usage

From source file:com.jjoe64.graphview.GridLabelRenderer.java

/**
 * draws the horizontal steps/*from  w  w  w  .  j a  va  2s.  c o m*/
 * vertical lines and horizontal labels
 *
 * @param canvas canvas
 */
protected void drawHorizontalSteps(Canvas canvas) {
    // draw horizontal steps (vertical lines and horizontal labels)
    mPaintLabel.setColor(getHorizontalLabelsColor());
    int i = 0;
    for (Map.Entry<Integer, Double> e : mStepsHorizontal.entrySet()) {
        // draw line
        if (mStyles.highlightZeroLines) {
            if (e.getValue() == 0d) {
                mPaintLine.setStrokeWidth(5);
            } else {
                mPaintLine.setStrokeWidth(0);
            }
        }
        if (mStyles.gridStyle.drawVertical()) {
            canvas.drawLine(mGraphView.getGraphContentLeft() + e.getKey(), mGraphView.getGraphContentTop(),
                    mGraphView.getGraphContentLeft() + e.getKey(),
                    mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), mPaintLine);
        }

        // draw label
        if (isHorizontalLabelsVisible()) {
            if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) {
                if (mStyles.horizontalLabelsAngle < 90f) {
                    mPaintLabel.setTextAlign((Paint.Align.RIGHT));
                } else if (mStyles.horizontalLabelsAngle <= 180f) {
                    mPaintLabel.setTextAlign((Paint.Align.LEFT));
                }
            } else {
                mPaintLabel.setTextAlign(Paint.Align.CENTER);
                if (i == mStepsHorizontal.size() - 1)
                    mPaintLabel.setTextAlign(Paint.Align.RIGHT);
                if (i == 0)
                    mPaintLabel.setTextAlign(Paint.Align.LEFT);
            }

            // multiline labels
            String label = mLabelFormatter.formatLabel(e.getValue(), true);
            if (label == null) {
                label = "";
            }
            String[] lines = label.split("\n");

            // If labels are angled, calculate adjustment to line them up with the grid
            int labelWidthAdj = 0;
            if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) {
                Rect textBounds = new Rect();
                mPaintLabel.getTextBounds(lines[0], 0, lines[0].length(), textBounds);
                labelWidthAdj = (int) Math
                        .abs(textBounds.width() * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle)));
            }
            for (int li = 0; li < lines.length; li++) {
                // for the last line y = height
                float y = (canvas.getHeight() - mStyles.padding - getHorizontalAxisTitleHeight())
                        - (lines.length - li - 1) * getTextSize() * 1.1f + mStyles.labelsSpace;
                float x = mGraphView.getGraphContentLeft() + e.getKey();
                if (mStyles.horizontalLabelsAngle > 0 && mStyles.horizontalLabelsAngle < 90f) {
                    canvas.save();
                    canvas.rotate(mStyles.horizontalLabelsAngle, x + labelWidthAdj, y);
                    canvas.drawText(lines[li], x + labelWidthAdj, y, mPaintLabel);
                    canvas.restore();
                } else if (mStyles.horizontalLabelsAngle > 0 && mStyles.horizontalLabelsAngle <= 180f) {
                    canvas.save();
                    canvas.rotate(mStyles.horizontalLabelsAngle - 180f, x - labelWidthAdj, y);
                    canvas.drawText(lines[li], x - labelWidthAdj, y, mPaintLabel);
                    canvas.restore();
                } else {
                    canvas.drawText(lines[li], x, y, mPaintLabel);
                }
            }
        }
        i++;
    }
}