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:org.stockchart.core.LegendItem.java

protected void innerDraw(Canvas c, CustomObjects customObjects) {
    c.getClipBounds(this.TempRect());

    float halfHeight = this.TempRect().height() / 2f;

    drawMarker(c, halfHeight, halfHeight, fMarkerSize / 2);

    fAppearance.applyText(this.Paint());

    SizeF sz = fAppearance.measureTextSize(fText, this.Paint(), false);

    c.drawText(fText, fMarkerSize + getOutlineIssues(), halfHeight + sz.height / 2f, this.Paint());
}

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

private void ensureExpandedTexture() {
    if (mExpandedTitleTexture != null)
        return;//from  w  w  w  .j av  a2 s . c o  m

    int w = (int) (getWidth() - mExpandedMarginLeft - mExpandedMarginRight);
    int h = (int) (mTextPaint.descent() - mTextPaint.ascent());

    mExpandedTitleTexture = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(mExpandedTitleTexture);
    c.drawText(mTitleToDraw, 0, h - mTextPaint.descent(), mTextPaint);

    if (mTexturePaint == null) {
        // Make sure we have a paint
        mTexturePaint = new Paint();
        mTexturePaint.setAntiAlias(true);
        mTexturePaint.setFilterBitmap(true);
    }
}

From source file:au.com.zacher.popularmovies.activity.layout.CollapsingTitleLayout.java

private void ensureExpandedTexture() {
    if (this.mExpandedTitleTexture != null) {
        return;//w w w.j a  v  a2  s. c  o  m
    }

    int w = (int) (this.getWidth() - this.mExpandedMarginLeft - this.mExpandedMarginRight);
    int h = (int) (this.mTextPaint.descent() - this.mTextPaint.ascent());

    this.mExpandedTitleTexture = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(this.mExpandedTitleTexture);
    c.drawText(this.mTitleToDraw, 0, h - this.mTextPaint.descent(), this.mTextPaint);

    if (this.mTexturePaint == null) {
        // Make sure we have a paint
        this.mTexturePaint = new Paint();
        this.mTexturePaint.setAntiAlias(true);
        this.mTexturePaint.setFilterBitmap(true);
    }
}

From source file:com.xycode.xylibrary.uiKit.recyclerview.FloatingBarItemDecoration.java

private void drawTitleArea(Canvas c, int left, int right, View child, RecyclerView.LayoutParams params,
        int position) {
    final int rectBottom = child.getTop() - params.topMargin;
    c.drawRect(left, rectBottom - mTitleHeight, right, rectBottom, mBackgroundPaint);
    c.drawText(headerList.get(position), child.getPaddingLeft() + mTextStartMargin,
            rectBottom - (mTitleHeight - mTextHeight) / 2 - mTextBaselineOffset, mTextPaint);
}

From source file:ru.tinkoff.acquiring.sdk.views.KeyView.java

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

    if (contentText != null) {
        final float x = (getWidth() / 2) - (textWidth / 2);
        final float y = (getHeight() / 2) - ((contentPaint.descent() + contentPaint.ascent()) / 2);
        canvas.drawText(contentText, x, y, contentPaint);
    }/*ww w.  j  a  va2  s.c  o  m*/

    if (contentImage != null) {
        canvas.drawBitmap(contentImage, getWidth() / 2 - contentImage.getWidth() / 2,
                getHeight() / 2 - contentImage.getHeight() / 2, contentPaint);
    }

    if (drawingPressAnimation) {
        canvas.drawCircle(circleCenter.x, circleCenter.y, circleRadius, circlePaint);
    }
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.MeasurementsView.java

@Override
protected void onDraw(Canvas canvas) {
    mRectDrawable.setBounds(mTopLeft.x, mTopLeft.y, mTopLeft.x + BOX_WIDTH, mTopLeft.y + BOX_HEIGHT);
    mRectDrawable.draw(canvas);/*from www. j a v  a 2s.c  o m*/

    float xPos = mTopLeft.x + TEXT_GAP;
    float yPos = mTopLeft.y + TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.V_MAX), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.V_MIN), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.V_PP), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.V_TOP), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.V_BASE), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.V_AMP), xPos, yPos, mTextPaint);

    xPos = BOX_WIDTH / 3 + mTopLeft.x;
    yPos = mTopLeft.y + TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.V_AVG), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.V_RMS), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.OVER), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.PRE), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.PERIOD), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.FREQ), xPos, yPos, mTextPaint);

    xPos = BOX_WIDTH * 2 / 3 + mTopLeft.x;
    yPos = mTopLeft.y + TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.RISE), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.FALL), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.P_WIDTH), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.N_WIDTH), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.P_DUTY), xPos, yPos, mTextPaint);

    yPos += TEXT_GAP + TEXT_SIZE;
    canvas.drawText(mMeasureData.getTypeString(MeasureData.MeasureType.N_DUTY), xPos, yPos, mTextPaint);

    super.onDraw(canvas);
}

From source file:org.cicadasong.samples.nextbuses.NextBuses.java

protected void onDraw(Canvas canvas) {
    // Set font for heading
    Paint paint = isWidget() ? metawatch5px : metawatch7px;

    int x = 2;//from  w  w w  .j  av a  2  s. c o  m
    int y = 2 + (int) -paint.ascent();

    canvas.drawText("Next buses at...", x, y, paint);

    y += (int) paint.descent() + 2;

    // Set font for stop name
    paint = isWidget() ? metawatch7px : metawatch11px;
    y += (int) -paint.ascent();

    canvas.drawText(stopName, x, y, paint);

    y += (int) paint.descent() + 2;

    // Set font for "body"
    paint = isWidget() ? metawatch5px : default10pt;
    y += (int) -paint.ascent();

    if (inInitialFetch) {
        canvas.drawText("Fetching...", x, y, paint);
    } else if (predictions == null) {
        canvas.drawText("Network Error", x, y, paint);
    } else if (isWidget()) {
        String singleLineResult = "";
        List<Prediction> allPredictions = predictions.getAllPredictions();
        StringBuilder resultBuilder = new StringBuilder();
        for (Prediction prediction : allPredictions) {
            if (resultBuilder.length() > 0) {
                resultBuilder.append(" ");
            }
            resultBuilder.append(prediction.route);
            resultBuilder.append("~");
            resultBuilder.append(prediction.minutes);
            resultBuilder.append("m");
        }
        singleLineResult = resultBuilder.toString();
        canvas.drawText(singleLineResult, x, y, paint);
    } else {
        // We're in app mode, so we have more screen space to work with
        for (String route : predictions.getRoutes()) {
            StringBuilder resultBuilder = new StringBuilder();
            resultBuilder.append(route);
            resultBuilder.append(":");
            for (Prediction prediction : predictions.getPredictionsForRoute(route)) {
                resultBuilder.append(" ");
                resultBuilder.append(prediction.minutes);
                resultBuilder.append("m");
            }
            canvas.drawText(resultBuilder.toString(), x, y, paint);
            y += paint.getFontSpacing();
        }
    }
}

From source file:com.ifoer.util.NetPOSPrinter.java

public Bitmap drawBitFirst() {
    this.nBitmapFirst = Bitmap.createBitmap(PRINT_WIDTH, 85, Config.RGB_565);
    Canvas canvas = new Canvas(this.nBitmapFirst);
    canvas.drawColor(-1);/* w ww  . java2  s  .  co  m*/
    Paint p = new Paint();
    p.setColor(DefaultRenderer.BACKGROUND_COLOR);
    p.setTextSize(20.0f);
    canvas.drawText(this.mContext.getResources().getString(C0136R.string.print_launch), 0.0f, 20.0f, p);
    canvas.drawLine(0.0f, 40.0f, 384.0f, 40.0f, p);
    canvas.drawText(
            this.mContext.getResources().getString(C0136R.string.print_automobile_fault_diagnosis_test_report),
            20.0f, 70.0f, p);
    canvas.drawLine(0.0f, 80.0f, 384.0f, 80.0f, p);
    return this.nBitmapFirst;
}

From source file:playn.android.AndroidAssetManager.java

private Bitmap createErrorBitmap(Exception e) {
    int height = 100, width = 100;

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);

    android.graphics.Canvas c = new android.graphics.Canvas(bitmap);
    android.graphics.Paint p = new android.graphics.Paint();
    p.setColor(android.graphics.Color.RED);
    for (int yy = 0; yy <= height / 15; yy++) {
        for (int xx = 0; xx <= width / 45; xx++) {
            c.drawText("ERROR", xx * 45, yy * 15, p);
        }//from www  . j  ava2s . c  o  m
    }

    return bitmap;
}

From source file:com.codetroopers.betterpickers.radialtimepicker.RadialTextsView.java

/**
 * Draw the 12 text values at the positions specified by the textGrid parameters.
 *//*from  w  w  w .  j av a  2 s  .  com*/
private void drawTexts(Canvas canvas, float textSize, Typeface typeface, String[] texts, float[] textGridWidths,
        float[] textGridHeights) {
    mPaint.setTextSize(textSize);
    mPaint.setTypeface(typeface);
    canvas.drawText(texts[0], textGridWidths[3], textGridHeights[0], mPaint);
    canvas.drawText(texts[1], textGridWidths[4], textGridHeights[1], mPaint);
    canvas.drawText(texts[2], textGridWidths[5], textGridHeights[2], mPaint);
    canvas.drawText(texts[3], textGridWidths[6], textGridHeights[3], mPaint);
    canvas.drawText(texts[4], textGridWidths[5], textGridHeights[4], mPaint);
    canvas.drawText(texts[5], textGridWidths[4], textGridHeights[5], mPaint);
    canvas.drawText(texts[6], textGridWidths[3], textGridHeights[6], mPaint);
    canvas.drawText(texts[7], textGridWidths[2], textGridHeights[5], mPaint);
    canvas.drawText(texts[8], textGridWidths[1], textGridHeights[4], mPaint);
    canvas.drawText(texts[9], textGridWidths[0], textGridHeights[3], mPaint);
    canvas.drawText(texts[10], textGridWidths[1], textGridHeights[2], mPaint);
    canvas.drawText(texts[11], textGridWidths[2], textGridHeights[1], mPaint);
}