Example usage for android.graphics Paint ANTI_ALIAS_FLAG

List of usage examples for android.graphics Paint ANTI_ALIAS_FLAG

Introduction

In this page you can find the example usage for android.graphics Paint ANTI_ALIAS_FLAG.

Prototype

int ANTI_ALIAS_FLAG

To view the source code for android.graphics Paint ANTI_ALIAS_FLAG.

Click Source Link

Document

Paint flag that enables antialiasing when drawing.

Usage

From source file:com.android.contacts.common.list.ShortcutIntentBuilder.java

/**
 * Generates a phone number shortcut icon. Adds an overlay describing the type of the phone
 * number, and if there is a photo also adds the call action icon.
 */// w w  w .j  a v  a  2 s . c  o m
private Bitmap generatePhoneNumberIcon(Drawable photo, int phoneType, String phoneLabel, int actionResId) {
    final Resources r = mContext.getResources();
    final float density = r.getDisplayMetrics().density;

    Bitmap phoneIcon = ((BitmapDrawable) r.getDrawableForDensity(actionResId, mIconDensity)).getBitmap();

    Bitmap icon = generateQuickContactIcon(photo);
    Canvas canvas = new Canvas(icon);

    // Copy in the photo
    Paint photoPaint = new Paint();
    photoPaint.setDither(true);
    photoPaint.setFilterBitmap(true);
    Rect dst = new Rect(0, 0, mIconSize, mIconSize);

    // Create an overlay for the phone number type
    CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel);

    if (overlay != null) {
        TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
        textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size));
        textPaint.setColor(r.getColor(R.color.textColorIconOverlay));
        textPaint.setShadowLayer(4f, 0, 2f, r.getColor(R.color.textColorIconOverlayShadow));

        final FontMetricsInt fmi = textPaint.getFontMetricsInt();

        // First fill in a darker background around the text to be drawn
        final Paint workPaint = new Paint();
        workPaint.setColor(mOverlayTextBackgroundColor);
        workPaint.setStyle(Paint.Style.FILL);
        final int textPadding = r.getDimensionPixelOffset(R.dimen.shortcut_overlay_text_background_padding);
        final int textBandHeight = (fmi.descent - fmi.ascent) + textPadding * 2;
        dst.set(0, mIconSize - textBandHeight, mIconSize, mIconSize);
        canvas.drawRect(dst, workPaint);

        overlay = TextUtils.ellipsize(overlay, textPaint, mIconSize, TruncateAt.END);
        final float textWidth = textPaint.measureText(overlay, 0, overlay.length());
        canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2,
                mIconSize - fmi.descent - textPadding, textPaint);
    }

    // Draw the phone action icon as an overlay
    Rect src = new Rect(0, 0, phoneIcon.getWidth(), phoneIcon.getHeight());
    int iconWidth = icon.getWidth();
    dst.set(iconWidth - ((int) (20 * density)), -1, iconWidth, ((int) (19 * density)));
    canvas.drawBitmap(phoneIcon, src, dst, photoPaint);

    canvas.setBitmap(null);

    return icon;
}

From source file:eu.iescities.pilot.rovereto.roveretoexplorer.map.MapManager.java

private static Bitmap writeOnMarker(Context mContext, int drawableId, String text) {
    float scale = mContext.getResources().getDisplayMetrics().density;

    Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), drawableId)
            .copy(Bitmap.Config.ARGB_8888, true);

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextAlign(Align.CENTER);/*from  w ww  .ja v  a  2 s .co m*/
    paint.setTextSize(scale * 14);
    paint.setAntiAlias(true);
    paint.setARGB(255, 255, 255, 255);

    Canvas canvas = new Canvas(bitmap);
    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    float x = bitmap.getWidth() / 2;
    float y = bitmap.getHeight() / 2;
    canvas.drawText(text, x, y, paint);

    return bitmap;
}

From source file:de.vanita5.twittnuker.view.ShapedImageView.java

private void updateShadowBitmap() {
    if (USE_OUTLINE)
        return;/*from  w  w  w  .j a va2  s . c  o m*/
    final int width = getWidth(), height = getHeight();
    if (width <= 0 || height <= 0)
        return;
    final int contentLeft = getPaddingLeft(), contentTop = getPaddingTop(),
            contentRight = width - getPaddingRight(), contentBottom = height - getPaddingBottom();
    final int contentWidth = contentRight - contentLeft, contentHeight = contentBottom - contentTop;
    final float radius = mShadowRadius, dy = radius * 1.5f / 2;
    final int size = Math.round(Math.min(contentWidth, contentHeight) + radius * 2);
    mShadowBitmap = Bitmap.createBitmap(size, Math.round(size + dy), Config.ARGB_8888);
    Canvas canvas = new Canvas(mShadowBitmap);
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.WHITE);
    paint.setShadowLayer(radius, 0, radius * 1.5f / 2, SHADOW_START_COLOR);
    final RectF rect = new RectF(radius, radius, size - radius, size - radius);
    canvas.drawOval(rect, paint);
    paint.setShadowLayer(0, 0, 0, 0);
    paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
    canvas.drawOval(rect, paint);
    invalidate();
}

From source file:eu.iescities.pilot.rovereto.roveretoexplorer.map.MapManager.java

private static Bitmap writeOnStoryMarker(Context mContext, int drawableId, String text) {
    float scale = mContext.getResources().getDisplayMetrics().density;

    Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), drawableId)
            .copy(Bitmap.Config.ARGB_8888, true);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextAlign(Align.CENTER);/*from   w  w  w .  j a va 2 s.co  m*/
    paint.setTextSize(scale * 14);
    paint.setAntiAlias(true);
    paint.setARGB(255, 255, 255, 255);

    Canvas canvas = new Canvas(bitmap);
    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    float x = bitmap.getWidth() / 2;
    float y = bitmap.getHeight() / 2 - ((paint.descent() + paint.ascent()) / 2);

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

    return bitmap;
}

From source file:com.mappn.gfan.ui.HomeTabActivity.java

private Bitmap drawBitmap(DisplayMetrics dm, Bitmap background, Bitmap corner) {
    Canvas canvas = new Canvas();
    final int height = background.getScaledHeight(dm);
    final int width = background.getScaledWidth(dm);
    Bitmap smallBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    canvas.setBitmap(smallBitmap);/*from  w  w  w  . ja  v  a 2 s . c o  m*/
    Paint textPainter = new Paint(Paint.ANTI_ALIAS_FLAG);
    canvas.drawBitmap(background, 0, 0, textPainter);
    textPainter.setXfermode(new PorterDuffXfermode(Mode.SRC_OVER));
    canvas.drawBitmap(corner, width - corner.getScaledWidth(dm), 0, textPainter);
    canvas.save();
    return smallBitmap;
}

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

public void onDraw(Canvas canvas) {
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(1);//  w  w  w.jav  a2  s  . c om

    tPaint = new Paint();
    tPaint.setStyle(Paint.Style.STROKE);
    tPaint.setTypeface(Typeface.DEFAULT_BOLD);
    tPaint.setAntiAlias(true);
    tPaint.setTextSize(dTextSize);
    //
    tips = (int) tPaint.measureText("0");
    try {
        if (actualDataLen == 0) {
            return;
        }
        if (zs)
            axisLabelWidth = (int) Math.max(tPaint.measureText("99999.99"), tPaint.measureText("11000"));
        else
            axisLabelWidth = (int) tPaint.measureText("11000");
        klineWidth = width - axisLabelWidth;
        //?spaceWidth???
        visualKLineCount = (int) ((klineWidth - spaceWidth) / (spaceWidth + shapeWidth));

        if (isSingleMoved == false && isTrackStatus == false) {
            if (actualDataLen > visualKLineCount) {
                actualPos = actualDataLen - visualKLineCount;
                count = visualKLineCount;
            } else {
                actualPos = 0;
                count = actualDataLen;
            }
        }

        //Log.i("@@@@@@@@isTrackStatus@@@@@@@@@", isTrackStatus+">>>>>>"+actualDataLen+">>>>>>"+isTrackNumber + ">>>>>>>>>" + actualPos);

        calcMaxMin(actualPos);

        //
        axisLabelHeight = Font.getFontHeight(dTextSize);
        klineX = axisLabelWidth;
        klineY = axisLabelHeight;

        klineHeight = (int) ((height - axisLabelHeight) * 0.6);
        volumeHeight = (int) ((height - axisLabelHeight) * 0.4);
        axisX = klineX;

        if (!isTrackStatus) {
            moveQuote(actualDataLen - 1);
        } else {
            //isTrackNumber = (isTrackNumber>actualDataLen-1)?actualDataLen-1:isTrackNumber;
            if (trackLineV == 0) {
                trackLineV = (int) (visualPos * (spaceWidth + shapeWidth) - shapeWidth / 2);
                isTrackNumber = actualPos + visualPos - 1;
            }
            if (isTrackNumber < 0) {
                isTrackNumber = 0;
            } else if (isTrackNumber > actualDataLen - 1) {
                isTrackNumber = actualDataLen - 1;
            }
            paint.setColor(GlobalColor.clrGrayLine);
            canvas.drawLine(klineX + trackLineV, axisLabelHeight, klineX + trackLineV, height - axisLabelHeight,
                    paint);
            moveQuote(isTrackNumber);
            drawQuoteWin(canvas, quoteData, isTrackNumber);
        }

        //
        tPaint.setTextAlign(Paint.Align.LEFT);
        tPaint.setColor(GlobalColor.colorM5);
        canvas.drawText(lblIndicatorName, (float) (klineX + tips), axisLabelHeight - 5, tPaint);

        float size = tPaint.measureText(lblIndicatorName) + tips * 2;
        tPaint.setColor(GlobalColor.colorM10);
        canvas.drawText(lblIndicatorT1, (float) (klineX + size), axisLabelHeight - 5, tPaint);

        size += tPaint.measureText(lblIndicatorT1) + tips;
        if (size <= (klineWidth - tPaint.measureText(lblIndicatorT2))) {
            //tPaint.setColor(GlobalColor.colorM20);
            tPaint.setARGB(255, 255, 0, 255);
            canvas.drawText(lblIndicatorT2, (float) (klineX + size), axisLabelHeight - 5, tPaint);
        }

        size += tPaint.measureText(lblIndicatorT2) + tips;
        if (size <= (klineWidth - tPaint.measureText(lblIndicatorT3))) {
            tPaint.setColor(GlobalColor.colorM60);
            canvas.drawText(lblIndicatorT3, (float) (klineX + size), axisLabelHeight - 5, tPaint);
        }

        //?
        tPaint.setColor(GlobalColor.colorLabelName);
        canvas.drawText(lblmainIndicatorT1, (float) (klineX + tips), klineY + klineHeight + axisLabelHeight - 5,
                tPaint);

        size = tPaint.measureText(lblmainIndicatorT1) + tips * 2;

        tPaint.setColor(GlobalColor.colorM5);
        canvas.drawText(lblmainIndicatorT2, (float) (klineX + size), klineY + klineHeight + axisLabelHeight - 5,
                tPaint);

        size += tPaint.measureText(lblmainIndicatorT2) + tips;
        if (size <= (klineWidth - tPaint.measureText(lblmainIndicatorT3))) {
            tPaint.setColor(GlobalColor.colorM10);
            canvas.drawText(lblmainIndicatorT3, (float) (klineX + size),
                    klineY + klineHeight + axisLabelHeight - 5, tPaint);
        }

        size += tPaint.measureText(lblmainIndicatorT3) + tips;
        if (size <= (klineWidth - tPaint.measureText(lblmainIndicatorT4))) {
            tPaint.setARGB(255, 255, 0, 255);
            canvas.drawText(lblmainIndicatorT4, (float) (klineX + size),
                    klineY + klineHeight + axisLabelHeight - 5, tPaint);
        }

        //???
        rowHeight = klineHeight / rowNum;
        scale = klineHeight / (highPrice - lowPrice);

        double ratio = (highPrice - lowPrice) / rowNum;

        paint.setColor(GlobalColor.clrLine);
        tPaint.setColor(GlobalColor.colorTicklabel);
        tPaint.setTextAlign(Paint.Align.RIGHT);
        for (int i = 0; i <= rowNum; i++) {
            if (i == rowNum || i == 0) {
                canvas.drawLine(klineX, klineY + rowHeight * i, width, klineY + rowHeight * i, paint);
            } else {
                Graphics.drawDashline(canvas, klineX, klineY + rowHeight * i, width, klineY + rowHeight * i,
                        paint);
            }
            if (i != rowNum && isTrackStatus == false) {
                double AxisLabelPrice = highPrice - ratio * i;
                String AxisLabelPriceText;
                AxisLabelPriceText = Utils.dataFormation(AxisLabelPrice, stockdigit);
                canvas.drawText(AxisLabelPriceText, klineX - tips / 4,
                        klineY + rowHeight * i + axisLabelHeight / 2, tPaint);
            }
        }

        //
        if (quoteData != null) {
            //axisX = 0;
            for (int i = actualPos; i < (actualPos + count); i++) {
                if (i == 0)
                    drawKLine(canvas, i - actualPos, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(2),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(3),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(4),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(4));
                else
                    drawKLine(canvas, i - actualPos, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(2),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(3),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(4),
                            quoteData.getJSONArray("K").getJSONArray(i - 1).getDouble(4));
            }
            if (mainIndicatorType.toUpperCase().equals("MA"))
                drawMA(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (mainIndicatorType.toUpperCase().equals("BOLL"))
                drawBoll(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);

            rowHeight = (volumeHeight - axisLabelHeight * 2) / rowNum;
            klineY = klineHeight + axisLabelHeight * 2;
            volumeHeight = rowNum * rowHeight;

            if (indicatorType.toUpperCase().equals("VOLUME"))
                drawVOLUME(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("MACD"))
                drawMACD(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("CCI"))
                drawCCI(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("BIAS"))
                drawBIAS(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("KDJ"))
                drawKDJ(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("RSI"))
                drawRSI(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("OBV"))
                drawOBV(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("PSY"))
                drawOther(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen, "PSY");
            else if (indicatorType.toUpperCase().equals("ROC"))
                drawROC(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen, "ROC");
            else if (indicatorType.toUpperCase().equals("VR"))
                drawOther(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen, "VR");
            else if (indicatorType.toUpperCase().equals("WR"))
                drawOther(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen, "WR");

            drawTimeAix(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                    highVolume, actualDataLen);
        }

        //?????
        paint.setColor(GlobalColor.clrLine);
        canvas.drawLine(klineX, 0, width, 0, paint);
        canvas.drawLine(klineX, 0, klineX, height - axisLabelHeight, paint);
        canvas.drawLine(width, 0, width, height - axisLabelHeight, paint);
        //canvas.drawLine(klineX, height - axisLabelHeight, width, height - axisLabelHeight, paint);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.android.contacts.ShortcutIntentBuilder.java

/**
 * Generates a phone number shortcut icon. Adds an overlay describing the type of the phone
 * number, and if there is a photo also adds the call action icon.
 *///from   www.j  av a2s. c o m
private Bitmap generatePhoneNumberIcon(Drawable photo, int phoneType, String phoneLabel, int actionResId) {
    final Resources r = mContext.getResources();
    final float density = r.getDisplayMetrics().density;

    final Drawable phoneDrawable = r.getDrawableForDensity(actionResId, mIconDensity);
    // These icons have the same height and width so either is fine for the size.
    final Bitmap phoneIcon = BitmapUtil.drawableToBitmap(phoneDrawable, phoneDrawable.getIntrinsicHeight());

    Bitmap icon = generateQuickContactIcon(photo);
    Canvas canvas = new Canvas(icon);

    // Copy in the photo
    Paint photoPaint = new Paint();
    photoPaint.setDither(true);
    photoPaint.setFilterBitmap(true);
    Rect dst = new Rect(0, 0, mIconSize, mIconSize);

    // Create an overlay for the phone number type if we're pre-O. O created shortcuts have the
    // app badge which overlaps the type overlay.
    CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel);
    if (!BuildCompat.isAtLeastO() && overlay != null) {
        TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
        textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size));
        textPaint.setColor(r.getColor(R.color.textColorIconOverlay));
        textPaint.setShadowLayer(4f, 0, 2f, r.getColor(R.color.textColorIconOverlayShadow));

        final FontMetricsInt fmi = textPaint.getFontMetricsInt();

        // First fill in a darker background around the text to be drawn
        final Paint workPaint = new Paint();
        workPaint.setColor(mOverlayTextBackgroundColor);
        workPaint.setStyle(Paint.Style.FILL);
        final int textPadding = r.getDimensionPixelOffset(R.dimen.shortcut_overlay_text_background_padding);
        final int textBandHeight = (fmi.descent - fmi.ascent) + textPadding * 2;
        dst.set(0, mIconSize - textBandHeight, mIconSize, mIconSize);
        canvas.drawRect(dst, workPaint);

        overlay = TextUtils.ellipsize(overlay, textPaint, mIconSize, TruncateAt.END);
        final float textWidth = textPaint.measureText(overlay, 0, overlay.length());
        canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2,
                mIconSize - fmi.descent - textPadding, textPaint);
    }

    // Draw the phone action icon as an overlay
    int iconWidth = icon.getWidth();
    if (BuildCompat.isAtLeastO()) {
        // On O we need to calculate where the phone icon goes slightly differently. The whole
        // canvas area is 108dp, a centered circle with a diameter of 66dp is the "safe zone".
        // So we start the drawing the phone icon at
        // 108dp - 21 dp (distance from right edge of safe zone to the edge of the canvas)
        // - 24 dp (size of the phone icon) on the x axis (left)
        // The y axis is simply 21dp for the distance to the safe zone (top).
        // See go/o-icons-eng for more details and a handy picture.
        final int left = (int) (mIconSize - (45 * density));
        final int top = (int) (21 * density);
        canvas.drawBitmap(phoneIcon, left, top, photoPaint);
    } else {
        dst.set(iconWidth - ((int) (20 * density)), -1, iconWidth, ((int) (19 * density)));
        canvas.drawBitmap(phoneIcon, null, dst, photoPaint);
    }

    canvas.setBitmap(null);
    return icon;
}

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

public void onDraw(Canvas canvas) {
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(1);/*from   w  ww.j a va2 s  .com*/

    tPaint = new Paint();
    tPaint.setStyle(Paint.Style.STROKE);
    tPaint.setTypeface(Typeface.DEFAULT_BOLD);
    tPaint.setAntiAlias(true);
    tPaint.setTextSize(dTextSize);
    //
    tips = (int) tPaint.measureText("0");
    try {
        if (actualDataLen == 0) {
            return;
        }
        if (zs)
            axisLabelWidth = (int) Math.max(tPaint.measureText("99999.99"), tPaint.measureText("11000"));
        else
            axisLabelWidth = (int) tPaint.measureText("11000");
        klineWidth = width - axisLabelWidth;
        //?spaceWidth???
        visualKLineCount = (int) ((klineWidth - spaceWidth) / (spaceWidth + shapeWidth));

        if (isSingleMoved == false && isTrackStatus == false) {
            if (actualDataLen > visualKLineCount) {
                actualPos = actualDataLen - visualKLineCount;
                count = visualKLineCount;
            } else {
                actualPos = 0;
                count = actualDataLen;
            }
        }

        calcMaxMin(actualPos);

        //
        axisLabelHeight = Font.getFontHeight(dTextSize);
        klineX = axisLabelWidth;
        klineY = axisLabelHeight;

        klineHeight = (int) ((height - axisLabelHeight) * 0.6);
        volumeHeight = (int) ((height - axisLabelHeight) * 0.4);
        axisX = klineX;

        if (!isTrackStatus) {
            moveQuote(actualDataLen - 1);
        } else {
            if (trackLineV == 0) {
                trackLineV = (int) (visualPos * (spaceWidth + shapeWidth) - shapeWidth / 2);
                isTrackNumber = actualPos + visualPos - 1;
            }
            if (isTrackNumber < 0) {
                isTrackNumber = 0;
            } else if (isTrackNumber > actualDataLen - 1) {
                isTrackNumber = actualDataLen - 1;
            }
            paint.setColor(GlobalColor.clrGrayLine);
            canvas.drawLine(klineX + trackLineV, axisLabelHeight, klineX + trackLineV, height - axisLabelHeight,
                    paint);
            moveQuote(isTrackNumber);
            drawQuoteWin(canvas, quoteData, isTrackNumber);
        }

        //
        tPaint.setTextAlign(Paint.Align.LEFT);
        tPaint.setColor(GlobalColor.colorM5);
        canvas.drawText(lblIndicatorName, (float) (klineX + tips), axisLabelHeight - 5, tPaint);

        float size = tPaint.measureText(lblIndicatorName) + tips * 2;
        tPaint.setColor(GlobalColor.colorM10);
        canvas.drawText(lblIndicatorT1, (float) (klineX + size), axisLabelHeight - 5, tPaint);

        size += tPaint.measureText(lblIndicatorT1) + tips;
        if (size <= (klineWidth - tPaint.measureText(lblIndicatorT2))) {
            //tPaint.setColor(GlobalColor.colorM20);
            tPaint.setARGB(255, 255, 0, 255);
            canvas.drawText(lblIndicatorT2, (float) (klineX + size), axisLabelHeight - 5, tPaint);
        }

        size += tPaint.measureText(lblIndicatorT2) + tips;
        if (size <= (klineWidth - tPaint.measureText(lblIndicatorT3))) {
            tPaint.setColor(GlobalColor.colorM60);
            canvas.drawText(lblIndicatorT3, (float) (klineX + size), axisLabelHeight - 5, tPaint);
        }

        //?
        tPaint.setColor(GlobalColor.colorLabelName);
        canvas.drawText(lblmainIndicatorT1, (float) (klineX + tips), klineY + klineHeight + axisLabelHeight - 5,
                tPaint);

        size = tPaint.measureText(lblmainIndicatorT1) + tips * 2;

        tPaint.setColor(GlobalColor.colorM5);
        canvas.drawText(lblmainIndicatorT2, (float) (klineX + size), klineY + klineHeight + axisLabelHeight - 5,
                tPaint);

        size += tPaint.measureText(lblmainIndicatorT2) + tips;
        if (size <= (klineWidth - tPaint.measureText(lblmainIndicatorT3))) {
            tPaint.setColor(GlobalColor.colorM10);
            canvas.drawText(lblmainIndicatorT3, (float) (klineX + size),
                    klineY + klineHeight + axisLabelHeight - 5, tPaint);
        }

        size += tPaint.measureText(lblmainIndicatorT3) + tips;
        if (size <= (klineWidth - tPaint.measureText(lblmainIndicatorT4))) {
            tPaint.setARGB(255, 255, 0, 255);
            canvas.drawText(lblmainIndicatorT4, (float) (klineX + size),
                    klineY + klineHeight + axisLabelHeight - 5, tPaint);
        }

        //???
        rowHeight = klineHeight / rowNum;
        scale = klineHeight / (highPrice - lowPrice);

        double ratio = (highPrice - lowPrice) / rowNum;

        paint.setColor(GlobalColor.clrLine);
        tPaint.setColor(GlobalColor.colorTicklabel);
        tPaint.setTextAlign(Paint.Align.RIGHT);
        for (int i = 0; i <= rowNum; i++) {
            if (i == rowNum || i == 0) {
                canvas.drawLine(klineX, klineY + rowHeight * i, width, klineY + rowHeight * i, paint);
            } else {
                Graphics.drawDashline(canvas, klineX, klineY + rowHeight * i, width, klineY + rowHeight * i,
                        paint);
            }
            if (i != rowNum && isTrackStatus == false) {
                double AxisLabelPrice = highPrice - ratio * i;
                String AxisLabelPriceText;
                AxisLabelPriceText = Utils.dataFormation(AxisLabelPrice, stockdigit);
                canvas.drawText(AxisLabelPriceText, klineX - tips / 4,
                        klineY + rowHeight * i + axisLabelHeight / 2, tPaint);
            }
        }

        //
        if (quoteData != null) {
            //axisX = 0;
            for (int i = actualPos; i < (actualPos + count); i++) {
                if (i == 0)
                    drawKLine(canvas, i - actualPos, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(2),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(3),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(4),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(4));
                else
                    drawKLine(canvas, i - actualPos, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(2),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(3),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(4),
                            quoteData.getJSONArray("K").getJSONArray(i - 1).getDouble(4));
            }
            if (mainIndicatorType.toUpperCase().equals("MA"))
                drawMA(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (mainIndicatorType.toUpperCase().equals("BOLL"))
                drawBoll(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);

            rowHeight = (volumeHeight - axisLabelHeight * 2) / rowNum;
            klineY = klineHeight + axisLabelHeight * 2;
            volumeHeight = rowNum * rowHeight;

            if (indicatorType.toUpperCase().equals("VOLUME"))
                drawVOLUME(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("MACD"))
                drawMACD(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("CCI"))
                drawCCI(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("BIAS"))
                drawBIAS(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("KDJ"))
                drawKDJ(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("RSI"))
                drawRSI(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("OBV"))
                drawOBV(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);
            else if (indicatorType.toUpperCase().equals("PSY"))
                drawOther(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen, "PSY");
            else if (indicatorType.toUpperCase().equals("ROC"))
                drawROC(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen, "ROC");
            else if (indicatorType.toUpperCase().equals("VR"))
                drawOther(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen, "VR");
            else if (indicatorType.toUpperCase().equals("WR"))
                drawOther(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen, "WR");

            drawTimeAix(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                    highVolume, actualDataLen);
        }

        //?????
        paint.setColor(GlobalColor.clrLine);
        canvas.drawLine(klineX, 0, width, 0, paint);
        canvas.drawLine(klineX, 0, klineX, height - axisLabelHeight, paint);
        canvas.drawLine(width, 0, width, height - axisLabelHeight, paint);
        //canvas.drawLine(klineX, height - axisLabelHeight, width, height - axisLabelHeight, paint);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:xyz.berial.textinputlayout.CollapsingTextHelper.java

private void ensureExpandedTexture() {
    if (mExpandedTitleTexture != null || mExpandedBounds.isEmpty() || TextUtils.isEmpty(mTextToDraw)) {
        return;/*ww  w.j  a v a2  s . c  o m*/
    }

    mTextPaint.setTextSize(mExpandedTextSize);
    mTextPaint.setColor(mExpandedTextColor);
    mTextureAscent = mTextPaint.ascent();
    mTextureDescent = mTextPaint.descent();

    final int w = Math.round(mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()));
    final int h = Math.round(mTextureDescent - mTextureAscent);

    if (w <= 0 && h <= 0) {
        return; // If the width or height are 0, return
    }

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

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

    if (mTexturePaint == null) {
        // Make sure we have a paint
        mTexturePaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
    }
}

From source file:com.mappn.gfan.ui.HomeTabActivity.java

private Bitmap drawText(DisplayMetrics dm, Resources res, Bitmap bm, int num) {
    final int height = bm.getScaledHeight(dm);
    final int width = bm.getScaledWidth(dm);
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    canvas.drawBitmap(bm, new Matrix(), new Paint());
    Paint textPainter = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPainter.setColor(res.getColor(R.color.tab_app_num));
    textPainter.setTextSize(dm.scaledDensity * 12);
    textPainter.setTypeface(Typeface.DEFAULT_BOLD);
    float textWidth = textPainter.measureText(String.valueOf(num)) / 2;
    canvas.drawText(String.valueOf(num), width / 2 - textWidth, height / 2 + (dm.scaledDensity * 6),
            textPainter);//from  w w  w .jav  a  2  s.  c o  m
    canvas.save();
    return newBitmap;
}