Example usage for android.graphics Canvas drawText

List of usage examples for android.graphics Canvas drawText

Introduction

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

Prototype

public void drawText(@NonNull String text, float x, float y, @NonNull Paint paint) 

Source Link

Document

Draw the text, with origin at (x,y), using the specified paint.

Usage

From source file:com.ameron32.apps.tapnotes._trial.ui.CollapsingTitleLayout.java

@Override
public void draw(Canvas canvas) {
    final int saveCount = canvas.save();

    final int toolbarHeight = mToolbar.getHeight();
    canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, mScrollOffset));

    // Now call super and let it draw the background, etc
    super.draw(canvas);

    if (mTitleToDraw != null) {
        float x = mTextLeft;
        float y = mTextTop;

        final float ascent = mTextPaint.ascent() * mScale;
        final float descent = mTextPaint.descent() * mScale;
        final float h = descent - ascent;

        if (DEBUG_DRAW) {
            // Just a debug tool, which drawn a Magneta rect in the text bounds
            canvas.drawRect(mTextLeft, y - h + descent, mTextRight, y + descent, DEBUG_DRAW_PAINT);
        }/*from   w  w  w . j ava2 s. c o m*/

        if (mUseTexture) {
            y = y - h + descent;
        }

        if (mScale != 1f) {
            canvas.scale(mScale, mScale, x, y);
        }

        if (mUseTexture && mExpandedTitleTexture != null) {
            // If we should use a texture, draw it instead of text
            canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint);
        } else {
            canvas.drawText(mTitleToDraw, x, y, mTextPaint);
        }
    }

    canvas.restoreToCount(saveCount);
}

From source file:com.dirkgassen.wator.ui.view.RangeSlider.java

/**
 * Draws the view//from   w ww.j ava2 s .c o m
 * @param canvas canvas to paint on
 */
@Override
protected void onDraw(Canvas canvas) {
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    int paddingRight = getPaddingRight();
    int paddingBottom = getPaddingBottom();
    int sliderY = (getHeight() - paddingTop - paddingBottom) / 2 + paddingTop;

    canvas.drawLine(paddingLeft + thumbSize / 2, sliderY, getWidth() - paddingRight - thumbSize / 2, sliderY,
            sliderPaint);

    String valueString = String.format(Locale.getDefault(), thumbFormat, value);
    final float valueWidth = (thumbTextPaint.measureText(valueString, 0, valueString.length()));

    float thumbTip = positionFromValue(paddingLeft, paddingRight);
    if (thumbPath.isEmpty()) {
        thumbPath.addCircle(thumbTip, sliderY, thumbSize / 2, Path.Direction.CW);
    } else {
        thumbPath.offset(thumbTip, 0);
    }

    canvas.drawPath(thumbPath, thumbBackgroundPaint);

    canvas.drawText(valueString, thumbTip - valueWidth / 2, sliderY + (-thumbTextPaint.ascent()) / 2,
            thumbTextPaint);

    thumbPath.offset(-thumbTip, 0);
}

From source file:com.olacabs.customer.ui.TrackRideActivity.java

private Bitmap m13911a(int i, String str) {
    int i2 = 50;//w  ww .  ja  va2 s.c  o  m
    Typeface createFromAsset = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
    int i3 = (int) getResources().getDisplayMetrics().scaledDensity;
    int i4 = i3 * 60;
    int i5 = i3 * 76;
    Config config = Config.ARGB_8888;
    if (i4 <= 0) {
        i4 = 50;
    }
    if (i5 > 0) {
        i2 = i5;
    }
    Bitmap createScaledBitmap = Bitmap
            .createScaledBitmap(BitmapFactoryInstrumentation.decodeResource(getResources(), i), i4, i2, true);
    Canvas canvas = new Canvas(createScaledBitmap);
    float f = (float) (i4 / 2);
    float f2 = (float) (i4 / 2);
    Paint paint = new Paint(1);
    paint.setColor(Color.parseColor("#d4db28"));
    paint.setStyle(Style.FILL);
    paint.setTextSize((float) (i3 * 18));
    paint.setTypeface(createFromAsset);
    if (str.length() == 3) {
        canvas.drawText(str, f - ((float) (i3 * 15)), f2, paint);
    } else if (str.length() == 2) {
        canvas.drawText(str, f - ((float) (i3 * 10)), f2, paint);
    } else if (str.length() == 1) {
        canvas.drawText(str, f - ((float) (i3 * 6)), f2, paint);
    }
    paint.setTextSize((float) (i3 * 16));
    canvas.drawText(" min ", f - ((float) (i3 * 18)), f2 + ((float) (i3 * 15)), paint);
    return createScaledBitmap;
}

From source file:com.leeon.blank.widget.RangeBarNew.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    final int length = mTextArray.length;

    /*** Draw text marks ***/
    mPaint.setTextSize(mTextSize);/*ww  w .  j a va 2 s .  co  m*/
    mPaint.setColor(mTextColorNormal);
    for (int i = 0; i < length; i++) {
        final String text2draw = mTextArray[i] == -1 ? "" : mTextArray[i] + "";
        final float textWidth = mTextWidthArray[i];
        float textDrawLeft;
        // The last text mark's draw location should be adjust.
        if (i == length - 1) {
            textDrawLeft = mRangeBarRect.right - textWidth / 2;
        } else {
            textDrawLeft = mRangeBarRect.left + i * mPartLength - textWidth / 2;
        }
        canvas.drawText(text2draw, textDrawLeft, mRangeBarRect.top - 24 - mMarginBetween, mPaint);

        //draw lines
        float lineDrawLeft = mRangeBarRect.left + i * mPartLength;
        canvas.drawLine(lineDrawLeft, mRangeBarRect.top, lineDrawLeft, mRangeBarRect.top - 24, mPaint);

        //draw short lines
        if (i != length - 1) {
            for (int j = 1; j < 5; j++) {
                float lineDrawLeft_short = lineDrawLeft + j * mTinyPartLength;
                canvas.drawLine(lineDrawLeft_short, mRangeBarRect.top, lineDrawLeft_short,
                        mRangeBarRect.top - 18, mPaint);
            }
        }
    }

    /*** Draw seekBar ***/
    final float radius = mRangeBarHeight / 4f;
    mRangeBarRectSelected.left = mRangeBarRect.left + mTinyPartLength * mLeftCursorIndex;
    mRangeBarRectSelected.right = mRangeBarRect.left + mTinyPartLength * mRightCursorIndex;
    // If whole of seekbar is selected, just draw seekbar with selectedcolor.
    if (mLeftCursorIndex == 0 && mRightCursorIndex == (length - 1) * 5) {
        mPaint.setColor(mRangeBarColorSelected);
        canvas.drawRoundRect(mRangeBarRect, radius, radius, mPaint);
    } else {
        // Draw background first.
        mPaint.setColor(mRangeBarColorNormal);
        canvas.drawRoundRect(mRangeBarRect, radius, radius, mPaint);

        // Draw selected part.
        mPaint.setColor(mRangeBarColorSelected);
        // Can draw rounded rectangle, but original rectangle is enough.
        // Because edges of selected part will be covered by cursors.
        canvas.drawRect(mRangeBarRectSelected, mPaint);
    }

    /*** Draw cursors ***/
    // left cursor first
    final int leftWidth = mLeftCursorBG.getIntrinsicWidth();
    final int leftHeight = mLeftCursorBG.getIntrinsicHeight();
    final int leftLeft = (int) (mRangeBarRectSelected.left - leftWidth / 2f);
    final int leftTop = (int) (mRangeBarRect.bottom + mMarginBetween);
    mLeftCursorRect.left = leftLeft;
    mLeftCursorRect.top = leftTop;
    mLeftCursorRect.right = leftLeft + leftWidth;
    mLeftCursorRect.bottom = leftTop + leftHeight;
    mLeftCursorBG.setBounds(mLeftCursorRect);
    mLeftCursorBG.draw(canvas);

    // right cursor second
    final int rightWidth = mRightCursorBG.getIntrinsicWidth();
    final int rightHeight = mRightCursorBG.getIntrinsicHeight();
    final int rightLeft = (int) (mRangeBarRectSelected.right - rightWidth / 2f);
    final int rightTop = (int) (mRangeBarRect.bottom + mMarginBetween);
    mRightCursorRect.left = rightLeft;
    mRightCursorRect.top = rightTop;
    mRightCursorRect.right = rightLeft + rightWidth;
    mRightCursorRect.bottom = rightTop + rightHeight;
    mRightCursorBG.setBounds(mRightCursorRect);
    mRightCursorBG.draw(canvas);

    //Draw indicators
    final int indicatorWidth = Math.max(indicatorDrawable.getIntrinsicWidth(), (int) mPaint.measureText("888"));
    if (mLeftHit && mLeftPointerID != -1) {
        final int indicatorLeft = (int) (mRangeBarRectSelected.left - (float) indicatorWidth / 2);
        final int indicatorTop = mPaddingRect.top;
        mLeftIndicatorRect.left = indicatorLeft;
        mLeftIndicatorRect.top = indicatorTop;
        mLeftIndicatorRect.right = indicatorLeft + indicatorWidth;
        mLeftIndicatorRect.bottom = indicatorTop + indicatorHeight;
        indicatorDrawable.setBounds(mLeftIndicatorRect);
        indicatorDrawable.draw(canvas);
        mPaint.setColor(Color.WHITE);
        mValueLeft = getValueByIndex(mLeftCursorIndex);
        canvas.drawText(mValueLeft + "", mLeftIndicatorRect.centerX() - mPaint.measureText(mValueLeft + "") / 2,
                mLeftIndicatorRect.centerY() + mTextSize / 4, mPaint);
    }

    if (mRightHit && mRightPointerID != -1) {
        final int indicatorRightLeft = (int) (mRangeBarRectSelected.right - (float) rightWidth / 2);
        final int indicatorRightTop = mPaddingRect.top;
        mRightIndicatorRect.left = indicatorRightLeft;
        mRightIndicatorRect.top = indicatorRightTop;
        mRightIndicatorRect.right = indicatorRightLeft + indicatorWidth;
        mRightIndicatorRect.bottom = indicatorRightTop + indicatorHeight;
        indicatorDrawable.setBounds(mRightIndicatorRect);
        indicatorDrawable.draw(canvas);
        mPaint.setColor(Color.WHITE);
        mValueRight = getValueByIndex(mRightCursorIndex);
        if (mValueRight == -1) {
            canvas.drawText("", mRightIndicatorRect.centerX() - mPaint.measureText("") / 2,
                    mRightIndicatorRect.centerY() + mTextSize / 4, mPaint);
        } else {
            canvas.drawText(mValueRight + "",
                    mRightIndicatorRect.centerX() - mPaint.measureText(mValueRight + "") / 2,
                    mRightIndicatorRect.centerY() + mTextSize / 4, mPaint);
        }
    }

    triggerCallback();
}

From source file:com.binu.LogarithmicGraph.DrawGraphAsyncTask.java

@Override
protected Object doInBackground(Object[] params) {

    Bitmap bitmapBackground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888);

    Canvas canvasBackground = new Canvas(bitmapBackground);
    Paint paint = new Paint();
    paint.setStrokeWidth(1f);//from ww  w  .j  a v  a  2  s  .  com
    int starty = 0;
    int endy = mViewHeight;
    canvasBackground.drawColor(Color.BLACK);
    double ratio = Math.pow(Math.E, Math.log(MAX_FREQUENCY / MIN_FREQUENCY) / mViewWidth);
    mLogScaledX_values = new double[mViewWidth];
    for (int i = 0; i < mViewWidth; i++) {
        if (i == 0) {
            mLogScaledX_values[i] = 20;
        } else {
            mLogScaledX_values[i] = mLogScaledX_values[i - 1] * ratio;
        }
    }

    //Major lines
    for (int i = 0; i < MAJOR_GRIDLINE_POINTS.length; i++) {
        paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color));
        float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MAJOR_GRIDLINE_POINTS[i]);
        float textSize = (getPixelDensity(mContext) * mLabelTextSize) / 480;
        paint.setTextSize(textSize);
        Log.i("Density", "" + getPixelDensity(mContext));
        if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20) {
            if (isShowLabels())
                canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]),
                        xStart + (getPixelDensity(mContext) * 10) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
        } else if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20000) {
            if (isShowLabels())
                canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]),
                        xStart - (getPixelDensity(mContext) * 70) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
        } else {
            if (isShowLabels())
                canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]),
                        xStart - (getPixelDensity(mContext) * 30) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
            canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint);
        }
    }

    //Minor lines
    for (int i = 0; i < MINOR_GRIDLINE_POINTS.length; i++) {
        paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull));
        float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MINOR_GRIDLINE_POINTS[i]);
        canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint);

        if (isShowLabels()) {
            paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color));
            if (MINOR_GRIDLINE_POINTS[i] == 50 || MINOR_GRIDLINE_POINTS[i] == 500
                    || MINOR_GRIDLINE_POINTS[i] == 5000)
                canvasBackground.drawText(getFormattedLabel(MINOR_GRIDLINE_POINTS[i]),
                        xStart - (getPixelDensity(mContext) * 30) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
        }
    }

    float[] Y_points = calculateGraphYAxis();
    float div = mViewHeight / (Y_points.length - 1);
    //Level lines
    for (int i = 0; i < Y_points.length - 1; i++) {
        paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull));
        canvasBackground.drawLine(0, div * (i + 1), mViewWidth, (div * (i + 1)) + 1, paint);
    }

    //Level labels
    if (isShowLabels()) {
        for (int i = 0; i < Y_points.length; i++) {
            paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color));
            if (i == 0)
                canvasBackground.drawText("dB", 0, (div * i) + (getPixelDensity(mContext) * 50) / 480, paint);
            else if (i == Y_points.length - 1)
                canvasBackground.drawText("", 0, div * i, paint);
            else
                canvasBackground.drawText("" + Math.round(Y_points[i]), 0, div * i, paint);
        }
    }

    BitmapDrawable drawable = new BitmapDrawable(mContext.getResources(), bitmapBackground);
    mDrawableBackground = drawable;

    //Plotting the curve points

    Bitmap bitmapForeground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888);
    Canvas canvasForeground = new Canvas(bitmapForeground);
    Paint plotPaint = new Paint();
    plotPaint.setStyle(Paint.Style.STROKE);
    plotPaint.setStrokeCap(Paint.Cap.ROUND);
    plotPaint.setStrokeWidth(PLOT_THICKNESS);
    plotPaint.setAntiAlias(true);
    plotPaint.setColor(ContextCompat.getColor(mContext, R.color.graph_plot_color));

    for (int i = 0; i < X_values.length; i++) {
        //            canvasForeground.drawCircle(i, mViewHeight - mPlotPoint[i], 2f, plotPaint);
        /*float startX, float startY, float stopX, float stopY,
        @NonNull Paint paint*/
        float startX = (float) getGetPixelValueForX(X_values[i]);
        float startY = mViewHeight
                - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]);
        float stopX;
        float stopY;
        if (i == X_values.length - 1) {
            stopX = (float) getGetPixelValueForX(X_values[i]);
            stopY = mViewHeight - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]);
        } else {
            stopX = (float) getGetPixelValueForX(X_values[i + 1]);
            stopY = mViewHeight
                    - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i + 1]);
        }

        canvasForeground.drawLine(startX, startY, stopX, stopY, plotPaint);

    }

    BitmapDrawable drawableFore = new BitmapDrawable(mContext.getResources(), bitmapForeground);
    mDrawableForeground = drawableFore;
    return null;
}

From source file:org.stockchart.core.Crosshair.java

public void draw(Plot plot, Canvas c, Rect clipRect) {
    float xxx = fX * c.getWidth();
    float yyy = fY * c.getHeight();

    PointF p = plot.getRelativePosition(xxx, yyy);

    this.fAppearance.applyOutline(fPaint);

    if (this.fDrawVertical)
        PaintUtils.drawLine(c, p.x, clipRect.top, p.x, clipRect.bottom, fPaint);

    if (this.fDrawHorizontal)
        PaintUtils.drawLine(c, clipRect.left, p.y, clipRect.right, p.y, fPaint);

    Area parent = (Area) plot.getParent();
    Axis hAxis = parent.getAxis(fHorizontalAxis);
    Axis vAxis = parent.getAxis(fVerticalAxis);

    double realXValue = hAxis.getValueByCoordinate(p.x, false);
    double realYValue = vAxis.getValueByCoordinate(p.y, false);

    String text = null;/*  w  w  w  .j a  v  a  2  s . co m*/

    if (fLabelFormatProvider != null)
        text = fLabelFormatProvider.getLabel(this, plot, realXValue, realYValue);
    else
        text = String.format("X: %.2f, Y: %.2f", realXValue, realYValue);

    if (null != text) {
        fAppearance.applyText(fPaint);
        SizeF f = fAppearance.measureTextSize(text, fPaint, false);

        float ow = fAppearance.getOutlineWidth() + 1f;

        float textX = clipRect.right - p.x > p.x ? p.x + ow : p.x - f.width - ow;
        float textY = clipRect.bottom - p.y > p.y ? p.y + f.height + ow : p.y - f.height;

        if (!fDrawVertical)
            textX = 1f;

        if (!fDrawHorizontal)
            textY = f.height + 1f;

        c.drawText(text, textX, textY, fPaint);
    }
}

From source file:com.vincestyling.traversaless_testcase.TopTabIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mViewPager == null)
        return;/*from  w ww. j av  a  2s.c  o m*/

    final int count = getCount();
    if (count == 0)
        return;

    Rect areaRect = new Rect();
    areaRect.left = getPaddingLeft();
    areaRect.right = getWidth() - getPaddingRight();
    areaRect.top = getPaddingTop();
    areaRect.bottom = getHeight() - getPaddingBottom();

    int btnWidth = areaRect.width() / count;

    Rect tabRect = new Rect(areaRect);
    tabRect.top = tabRect.height() - mUnderlineHeight;
    tabRect.left += (mScrollingToPage + mPageOffset) * btnWidth;
    tabRect.right = tabRect.left + btnWidth;
    mPaint.setColor(mUnderlineColor);
    canvas.drawRect(tabRect, mPaint);

    mPaint.setColor(mTextColor);
    mPaint.setTextSize(mTextSize);

    for (int pos = 0; pos < count; pos++) {
        tabRect.set(areaRect);
        tabRect.left += pos * btnWidth;
        tabRect.right = tabRect.left + btnWidth;

        String pageTitle = getPageTitle(pos);

        RectF bounds = new RectF(tabRect);
        bounds.right = mPaint.measureText(pageTitle, 0, pageTitle.length());
        bounds.bottom = mPaint.descent() - mPaint.ascent();

        bounds.left += (tabRect.width() - bounds.right) / 2.0f;
        bounds.top += (tabRect.height() - bounds.bottom) / 2.0f;

        canvas.drawText(pageTitle, bounds.left, bounds.top - mPaint.ascent(), mPaint);
    }
}

From source file:com.cssweb.android.view.KlineMini.java

private void drawTimeAix(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {
    String quoteTime = "";
    double apX = klineX;

    int n = 0;//ww  w . j a va 2s  .  co  m
    tPaint.setColor(GlobalColor.colorLabelName);
    tPaint.setTextAlign(Paint.Align.LEFT);
    for (int i = begin; i < (begin + count); i++, n++) {
        quoteTime = quoteData.getJSONArray("K").getJSONArray(i).getString(0);
        if (i == begin) {// ??
            canvas.drawText(quoteTime, (float) apX, height - axisLabelHeight / 4, tPaint);
        } else { // ???
            if (i == begin + count - 1)
                canvas.drawText(quoteTime, (float) (width - tPaint.measureText(quoteTime)),
                        height - axisLabelHeight / 4, tPaint);
        }
    }
}

From source file:com.cssweb.android.view.FTrendView.java

public void drawChart(Canvas canvas) throws JSONException {
    paint = new Paint(Paint.ANTI_ALIAS_FLAG); //
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(1);/*from  w ww . ja v a  2s. c  o  m*/
    tPaint = new Paint();
    tPaint.setStyle(Paint.Style.STROKE);
    tPaint.setTypeface(Typeface.DEFAULT_BOLD);
    tPaint.setAntiAlias(true); //
    dataPaint = new Paint(Paint.ANTI_ALIAS_FLAG); //
    dataPaint.setStyle(Paint.Style.STROKE);
    dataPaint.setStrokeWidth(3);
    tPaint.setTextSize(dTextSize);
    axisLabelHeight = Font.getFontHeight(dTextSize);
    axisLabelWidth = (int) tPaint.measureText("0.00000") + offSet;
    klineWidth = width - axisLabelWidth;
    klineHeight = height - axisLabelHeight * 2 - iSLowerScreen;
    klineX = axisLabelWidth;
    klineY = axisLabelHeight;

    SPACE = Arith.div(klineWidth, count); //klineWidth/count;
    scale = klineHeight / (highPrice - lowPrice); //
    double ratio = (highPrice - lowPrice) / rowNum; //
    rowHeight = klineHeight / rowNum;
    colWeight = klineWidth / colNum;
    tPaint.setColor(GlobalColor.colorLabelName);
    tPaint.setTextAlign(Paint.Align.LEFT);

    /**
     * 
     */
    canvas.drawText(":" + quoteData.getJSONArray(isTrackNumber).getString(0), axisLabelWidth,
            axisLabelHeight - 5, tPaint);
    canvas.drawText(":" + quoteData.getJSONArray(isTrackNumber).getDouble(3), axisLabelWidth + width / 2,
            axisLabelHeight - 5, tPaint);
    paint.setColor(GlobalColor.clrGrayLine);
    /**
     * 
     */

    tPaint.setTextAlign(Paint.Align.RIGHT);
    for (int i = 0; i <= rowNum; i++) {
        if (i == 0 || i == rowNum) {
            canvas.drawLine(klineX, klineY + rowHeight * i, klineX + klineWidth, klineY + rowHeight * i, paint);
        } else {
            Graphics.drawDashline(canvas, klineX, klineY + rowHeight * i, klineX + klineWidth,
                    klineY + rowHeight * i, paint);
        }
        if (i == 0) {
            canvas.drawText(Utils.dataFormation(highPrice, 3), klineX,
                    klineY + rowHeight * i + axisLabelHeight / 2, tPaint);
        } else if (i == rowNum) {
            canvas.drawText(Utils.dataFormation(lowPrice, 3), klineX, klineY + rowHeight * i, tPaint);
        } else {
            double AxisLabelPrice = highPrice - ratio * i;
            canvas.drawText(Utils.dataFormation(AxisLabelPrice, 3), klineX,
                    klineY + rowHeight * i + axisLabelHeight / 2, tPaint);
        }
    }
    /**
     * 
     */
    for (int i = 0; i <= colNum; i++) {
        if (i == 0) {
            canvas.drawLine(klineX, klineY, klineX, klineY + klineHeight, paint);
        } else if (i == colNum) {
            canvas.drawLine(width - 1, klineY, width - 1, klineY + klineHeight, paint);
        } else {
            Graphics.drawDashline(canvas, klineX + colWeight * i, klineY, klineX + colWeight * i,
                    klineY + klineHeight, paint);
        }
    }

    /**
     * ?
     */
    double x1 = 0;
    double y1 = 0;
    double x2 = 0;
    double y2 = 0;
    double temp = 0;
    double tHeight = 0;
    dataPaint.setColor(GlobalColor.colorStockName);
    dataPaint.setStrokeWidth(3);
    for (int i = begin; i < (begin + count); i++) {
        temp = quoteData.getJSONArray(i).getDouble(3);
        if (i - begin == 0) {
            x1 = klineX + SPACE * (i - begin);
            x2 = klineX + SPACE * (i - begin + 1);
            tHeight = (temp - lowPrice) * scale; // tHeight = ( - ) *  
            y1 = axisLabelHeight + klineHeight - tHeight; //  - tHeight 
            y2 = axisLabelHeight + klineHeight - tHeight;
        } else {
            canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, dataPaint);
            x1 = x2;
            x2 = klineX + SPACE * (i - begin + 1);
            tHeight = (temp - lowPrice) * scale;
            y1 = y2;
            y2 = axisLabelHeight + klineHeight - tHeight;
        }
    }
    /**
     * 
     */
    tPaint.setColor(GlobalColor.colorLabelName);
    tPaint.setTextAlign(Paint.Align.LEFT);
    canvas.drawText(quoteData.getJSONArray(begin).getString(0), axisLabelWidth,
            klineHeight + axisLabelHeight * 2 - 5, tPaint);
    canvas.drawText(quoteData.getJSONArray(begin + count - 1).getString(0),
            (float) (width - tPaint.measureText(quoteData.getJSONArray(begin + count - 1).getString(0))),
            klineHeight + axisLabelHeight * 2 - 5, tPaint);

    /**
     * 
     */
    if (isTrackStatus) {
        canvas.save();
        //??
        paint.setColor(GlobalColor.colorLine);
        canvas.drawLine(trackLineV, axisLabelHeight, trackLineV, klineHeight + axisLabelHeight, paint);
        canvas.restore();
    }
}

From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java

private void drawDaysOfWeek(Canvas canvas) {
    final TextPaint p = mDayOfWeekPaint;
    final int headerHeight = mMonthHeight;
    final int rowHeight = mDayOfWeekHeight;
    final int colWidth = mCellWidth;

    // Text is vertically centered within the day of week height.
    final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
    final int rowCenter = headerHeight + rowHeight / 2;

    for (int col = 0; col < DAYS_IN_WEEK; col++) {
        final int colCenter = colWidth * col + colWidth / 2;
        final int colCenterRtl;
        if (ViewCompatUtils.isLayoutRtl(this)) {
            colCenterRtl = mPaddedWidth - colCenter;
        } else {/*w  ww . ja v a  2s.  c om*/
            colCenterRtl = colCenter;
        }

        final int dayOfWeek = (col + mWeekStart) % DAYS_IN_WEEK;
        final String label = getDayOfWeekLabel(dayOfWeek);
        canvas.drawText(label, colCenterRtl, rowCenter - halfLineHeight, p);
    }
}