Example usage for android.graphics Paint Paint

List of usage examples for android.graphics Paint Paint

Introduction

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

Prototype

public Paint(Paint paint) 

Source Link

Document

Create a new paint, initialized with the attributes in the specified paint parameter.

Usage

From source file:android.support.wear.widget.drawer.PageIndicatorView.java

public PageIndicatorView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.PageIndicatorView, defStyleAttr,
            R.style.WsPageIndicatorViewStyle);

    mDotSpacing = a.getDimensionPixelOffset(R.styleable.PageIndicatorView_wsPageIndicatorDotSpacing, 0);
    mDotRadius = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotRadius, 0);
    mDotRadiusSelected = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotRadiusSelected, 0);
    mDotColor = a.getColor(R.styleable.PageIndicatorView_wsPageIndicatorDotColor, 0);
    mDotColorSelected = a.getColor(R.styleable.PageIndicatorView_wsPageIndicatorDotColorSelected, 0);
    mDotFadeOutDelay = a.getInt(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeOutDelay, 0);
    mDotFadeOutDuration = a.getInt(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeOutDuration, 0);
    mDotFadeInDuration = a.getInt(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeInDuration, 0);
    mDotFadeWhenIdle = a.getBoolean(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeWhenIdle, false);
    mDotShadowDx = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowDx, 0);
    mDotShadowDy = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowDy, 0);
    mDotShadowRadius = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowRadius, 0);
    mDotShadowColor = a.getColor(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowColor, 0);
    a.recycle();// w  w w  . j  av  a  2s .  co  m

    mDotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaint.setColor(mDotColor);
    mDotPaint.setStyle(Style.FILL);

    mDotPaintSelected = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaintSelected.setColor(mDotColorSelected);
    mDotPaintSelected.setStyle(Style.FILL);
    mDotPaintShadow = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaintShadowSelected = new Paint(Paint.ANTI_ALIAS_FLAG);

    mCurrentViewPagerState = ViewPager.SCROLL_STATE_IDLE;
    if (isInEditMode()) {
        // When displayed in layout preview:
        // Simulate 5 positions, currently on the 3rd position.
        mNumberOfPositions = 5;
        mSelectedPosition = 2;
        mDotFadeWhenIdle = false;
    }

    if (mDotFadeWhenIdle) {
        mVisible = false;
        animate().alpha(0f).setStartDelay(2000).setDuration(mDotFadeOutDuration).start();
    } else {
        animate().cancel();
        setAlpha(1.0f);
    }
    updateShadows();
}

From source file:net.droidsolutions.droidcharts.core.plot.Marker.java

/**
 * Constructs a new marker./*  w w w. java2 s. c o m*/
 * 
 * @param paint
 *            the paint (<code>null</code> not permitted).
 * @param stroke
 *            the stroke (<code>null</code> not permitted).
 * @param outlinePaint
 *            the outline paint (<code>null</code> permitted).
 * @param outlineStroke
 *            the outline stroke (<code>null</code> permitted).
 * @param alpha
 *            the alpha transparency (must be in the range 0.0f to 1.0f).
 * 
 * @throws IllegalArgumentException
 *             if <code>paint</code> or <code>stroke</code> is
 *             <code>null</code>, or <code>alpha</code> is not in the
 *             specified range.
 */
protected Marker(int paint, float stroke, int outlinePaint, float outlineStroke, int alpha) {

    Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setColor(paint);
    this.paint = p;
    this.stroke = stroke;
    p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setColor(outlinePaint);
    this.outlinePaint = p;
    this.outlineStroke = outlineStroke;
    this.alpha = alpha;

    this.labelFont = new Font("SansSerif", Typeface.NORMAL, 9);
    p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setColor(Color.BLACK);
    this.labelPaint = p;
    this.labelAnchor = RectangleAnchor.TOP_LEFT;
    this.labelOffset = new RectangleInsets(3.0, 3.0, 3.0, 3.0);
    this.labelOffsetType = LengthAdjustmentType.CONTRACT;
    this.labelTextAnchor = TextAnchor.CENTER;

}

From source file:android.support.v17.leanback.app.ErrorSupportFragment.java

private static FontMetricsInt getFontMetricsInt(TextView textView) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(textView.getTextSize());
    paint.setTypeface(textView.getTypeface());
    return paint.getFontMetricsInt();
}

From source file:Main.java

/**
 * This is only used when the launcher shortcut is created.
 *
 * @param bitmap The artist, album, genre, or playlist image that's going to
 *               be cropped./* w w  w.  j  ava2s.c  om*/
 * @param size   The new size.
 * @return A {@link Bitmap} that has been resized and cropped for a launcher
 * shortcut.
 */
public static final Bitmap resizeAndCropCenter(final Bitmap bitmap, final int size) {
    final int w = bitmap.getWidth();
    final int h = bitmap.getHeight();
    if (w == size && h == size) {
        return bitmap;
    }

    final float mScale = (float) size / Math.min(w, h);

    final Bitmap mTarget = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    final int mWidth = Math.round(mScale * bitmap.getWidth());
    final int mHeight = Math.round(mScale * bitmap.getHeight());
    final Canvas mCanvas = new Canvas(mTarget);
    mCanvas.translate((size - mWidth) / 2f, (size - mHeight) / 2f);
    mCanvas.scale(mScale, mScale);
    final Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
    mCanvas.drawBitmap(bitmap, 0, 0, paint);
    return mTarget;
}

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

private void drawWin(Canvas canvas) {
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(1);//  w ww .  j  a v  a2 s . c  o  m

    mpaint = new Paint();
    mpaint.setTypeface(Typeface.DEFAULT_BOLD);
    mpaint.setAntiAlias(true);
    mpaint.setTextAlign(Paint.Align.LEFT);
    mpaint.setStyle(Paint.Style.STROKE);
    mpaint.setTextSize(dTextSize);

    /**
     * ?
     */
    closeLeft = Utils.dataFormation(high, stockdigit);
    closeRight = "00.00%";

    LSpace = (int) (Math.max(mpaint.measureText(closeLeft), mpaint.measureText(closeRight)));
    //???
    //RSpace = (int)(paint.measureText(closeRight) + 10);
    RSpace = 0;

    axisLabelHeight = Font.getFontHeight(dTextSize);

    graphicsQuoteWidth = width - LSpace - RSpace;
    SPACE = graphicsQuoteWidth / MINUTES;
    topTitleHeight = axisLabelHeight;
    graphicsQuoteHeight = height - axisLabelHeight - topTitleHeight;
    price_row_num = 2;//(int)graphicsQuoteHeight/3/25;
    volume_row_num = price_row_num;
    price_row_height = graphicsQuoteHeight / price_row_num / 3;
    volume_row_height = price_row_height;

    calc_zf();

    title1 = ":";
    title7 = ":";
    title8 = "";
    title2 = "";

    mpaint.setColor(GlobalColor.colorLabelName);

    canvas.drawText(title7 + title8, LSpace, axisLabelHeight - 5, mpaint);
    canvas.drawText(title1, LSpace + mpaint.measureText(":00:0000"), axisLabelHeight - 5, mpaint);
    canvas.drawText(title2, LSpace + mpaint.measureText(":00:0000:"), axisLabelHeight - 5, mpaint);

    if (isZs()) {
        if (close == 0)
            close = 1000;
    } else {
        if (close == 0)
            close = 1;
    }

    low = Math.min(low, close);
    //upPrice = close * (1+max_zf);
    //downPrice = close * (1-max_zf);

    paint.setColor(GlobalColor.clrLine);
    canvas.drawLine(LSpace + graphicsQuoteWidth, topTitleHeight, LSpace + graphicsQuoteWidth,
            graphicsQuoteHeight + topTitleHeight, paint);

    // 
    upQuoteX = LSpace;
    upQuoteY = topTitleHeight;
    upQuoteWidth = (int) graphicsQuoteWidth;
    upQuoteHeight = price_row_num * price_row_height;
    for (int i = 0; i < price_row_num; i++) {
        if (i == 0) {
            canvas.drawLine(upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth,
                    upQuoteY + price_row_height * i, paint);
        } else
            Graphics.drawDashline(canvas, upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth,
                    upQuoteY + price_row_height * i, paint);
    }

    for (int i = 0; i < DIVIDE_COUNT; i++) {
        if (i == 0) {
            canvas.drawLine(upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY,
                    upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint);
        } else
            Graphics.drawDashline(canvas, upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY,
                    upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint);
    }

    // 
    downQuoteX = LSpace;
    downQuoteY = topTitleHeight + upQuoteHeight;
    downQuoteWidth = (int) graphicsQuoteWidth;

    downQuoteHeight = upQuoteHeight;

    paint.setColor(GlobalColor.clrLine);
    for (int i = 0; i < price_row_num; i++) {
        if (i == 0) {
            canvas.drawLine(downQuoteX, downQuoteY + price_row_height * i, downQuoteX + downQuoteWidth,
                    downQuoteY + price_row_height * i, paint);
        } else
            Graphics.drawDashline(canvas, downQuoteX, downQuoteY + price_row_height * i,
                    downQuoteX + downQuoteWidth, downQuoteY + price_row_height * i, paint);
    }

    for (int i = 0; i < DIVIDE_COUNT; i++) {
        if (i == 0) {
            canvas.drawLine(downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY,
                    downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight + 1, paint);
        } else
            Graphics.drawDashline(canvas, downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY,
                    downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight, paint);
    }

    // ??
    volumeX = LSpace;
    volumeY = topTitleHeight + upQuoteHeight + downQuoteHeight;
    volumeWidth = (int) graphicsQuoteWidth;
    volumeHeight = graphicsQuoteHeight - upQuoteHeight - downQuoteHeight;

    volume_row_height = volumeHeight / volume_row_num;

    paint.setColor(GlobalColor.clrLine);
    for (int i = 0; i <= volume_row_num; i++) {
        if (i == 0) {
            canvas.drawLine(volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth,
                    volumeY + volume_row_height * i, paint);
        } else {
            if (i != volume_row_num)
                Graphics.drawDashline(canvas, volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth,
                        volumeY + volume_row_height * i, paint);
        }
    }

    for (int i = 0; i < DIVIDE_COUNT; i++) {
        if (i == 0) {
            canvas.drawLine(volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY,
                    volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint);
        } else
            Graphics.drawDashline(canvas, volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY,
                    volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint);
    }
    // 
    canvas.drawLine(LSpace, graphicsQuoteHeight + topTitleHeight, LSpace + graphicsQuoteWidth,
            graphicsQuoteHeight + topTitleHeight, paint);
}

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

public void onDraw(Canvas canvas) {
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(1);//from w w  w .j a v  a  2 s  .  co  m

    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);

        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);
        }

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

        klineHeight = height - axisLabelHeight * 2;
        axisX = klineX;

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

        float size = tPaint.measureText(lblIndicatorName) + tips;
        tPaint.setColor(GlobalColor.colorM10);
        canvas.drawText(lblIndicatorT1, (float) (klineX + shapeWidth + 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 + shapeWidth + size), axisLabelHeight - 5, tPaint);
        }

        size += tPaint.measureText(lblIndicatorT2) + tips;
        if (size <= (klineWidth - tPaint.measureText(lblIndicatorT3))) {
            tPaint.setColor(GlobalColor.colorM60);
            canvas.drawText(lblIndicatorT3, (float) (klineX + shapeWidth + size), 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;
                if (zs) {
                    AxisLabelPriceText = Utils.dataFormation(Math.round(AxisLabelPrice), 0);
                } else {
                    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);

            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);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.ruesga.rview.misc.BitmapUtils.java

public static Bitmap createScaledBitmap(Bitmap unscaledBitmap, int dstWidth, int dstHeight,
        ScalingLogic scalingLogic) {/*from w  w w.j a v  a2  s. co  m*/
    if (unscaledBitmap.getWidth() == dstWidth && unscaledBitmap.getHeight() == dstHeight) {
        return unscaledBitmap;
    }
    Rect srcRect = calculateSrcRect(unscaledBitmap.getWidth(), unscaledBitmap.getHeight(), dstWidth, dstHeight,
            scalingLogic);
    Rect dstRect = calculateDstRect(unscaledBitmap.getWidth(), unscaledBitmap.getHeight(), dstWidth, dstHeight,
            scalingLogic);
    Bitmap scaledBitmap = Bitmap.createBitmap(dstRect.width(), dstRect.height(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(scaledBitmap);
    canvas.drawBitmap(unscaledBitmap, srcRect, dstRect, new Paint(Paint.FILTER_BITMAP_FLAG));
    return scaledBitmap;
}

From source file:com.chrynan.guitarchords.view.GuitarChordView.java

private void initPaint() {
    bridgeNutPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    bridgeNutColor = DEFAULT_COLOR;//from  w w w  .  j a  v a  2s. com
    bridgeNutPaint.setColor(bridgeNutColor);
    bridgeNutPaint.setStyle(Paint.Style.STROKE);
    bridgeNutPaint.setStrokeCap(Paint.Cap.BUTT);
    fretMarkerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    fretMarkerColor = DEFAULT_COLOR;
    fretMarkerPaint.setColor(fretMarkerColor);
    fretMarkerPaint.setStyle(Paint.Style.STROKE);
    fretMarkerPaint.setStrokeCap(Paint.Cap.ROUND);
    stringPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    stringColor = DEFAULT_COLOR;
    stringPaint.setColor(stringColor);
    stringPaint.setStyle(Paint.Style.STROKE);
    stringPaint.setStrokeCap(Paint.Cap.BUTT);
    fretNumberPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    fretNumberColor = DEFAULT_COLOR;
    fretNumberPaint.setColor(fretNumberColor);
    fretNumberPaint.setTextAlign(Paint.Align.CENTER);
    stringMarkerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    stringMarkerColor = DEFAULT_COLOR;
    stringMarkerPaint.setColor(stringMarkerColor);
    stringMarkerPaint.setTextAlign(Paint.Align.CENTER);
    notePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    noteColor = DEFAULT_COLOR;
    notePaint.setColor(noteColor);
    noteNumberPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    noteNumberColor = WHITE;
    noteNumberPaint.setColor(noteNumberColor);
    noteNumberPaint.setTextAlign(Paint.Align.CENTER);
    barLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    barLineColor = DEFAULT_COLOR;
    barLinePaint.setColor(barLineColor);
    barLinePaint.setStyle(Paint.Style.STROKE);
}

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

private void drawChart(Canvas canvas) throws JSONException {
    Log.i("@@@@@@@@@draw tick@@@@@@@@@@", quoteArray + ">>>>>>>>>");
    //Log.i("@@@@@@@@@@@@@@@@@@@", quoteArray.length()+">>>>>>>>>");
    if (quoteArray == null || quoteArray.isNull(0))
        return;//from  w  w  w  .  j a v  a 2  s  .  c o m

    canvas.drawColor(GlobalColor.clearSCREEN);

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(1);

    mpaint = new Paint();
    mpaint.setTypeface(Typeface.DEFAULT_BOLD);
    mpaint.setAntiAlias(true);
    mpaint.setTextAlign(Paint.Align.LEFT);
    mpaint.setStyle(Paint.Style.STROKE);
    mpaint.setTextSize(dTextSize);

    /**
     * ?
     */
    closeLeft = Utils.dataFormation(high, stockdigit);
    closeRight = "00.00%";
    LSpace = (int) (Math.max(mpaint.measureText(closeLeft),
            mpaint.measureText(String.valueOf(Math.round(highvolume)))));
    //???
    //RSpace = (int)(paint.measureText(closeRight) + 10);
    RSpace = 0;

    axisLabelHeight = Font.getFontHeight(dTextSize);

    graphicsQuoteWidth = width - LSpace - RSpace;
    SPACE = graphicsQuoteWidth / MINUTES;
    topTitleHeight = axisLabelHeight;
    graphicsQuoteHeight = height - axisLabelHeight - topTitleHeight;
    price_row_num = 2;//(int)graphicsQuoteHeight/3/25;
    volume_row_num = price_row_num;
    price_row_height = graphicsQuoteHeight / price_row_num / 3;
    volume_row_height = price_row_height;

    calc_zf();

    title1 = ":";
    title7 = ":";
    title8 = quoteArray.getJSONArray(isTrackNumber).getString(3);
    title2 = Utils.dataFormation(quoteArray.getJSONArray(isTrackNumber).getDouble(0), stockdigit);

    mpaint.setColor(GlobalColor.colorLabelName);

    canvas.drawText(title7 + title8.substring(11, 16), LSpace, axisLabelHeight - 5, mpaint);
    canvas.drawText(title1, LSpace + mpaint.measureText(":00:0000"), axisLabelHeight - 5, mpaint);
    if (quoteArray.getJSONArray(isTrackNumber).getDouble(0) == 0) {
        mpaint.setColor(GlobalColor.colorPriceEqual);
    } else if (quoteArray.getJSONArray(isTrackNumber).getDouble(0) > close) {
        mpaint.setColor(GlobalColor.colorpriceUp);
    } else if (quoteArray.getJSONArray(isTrackNumber).getDouble(0) < close) {
        mpaint.setColor(GlobalColor.colorPriceDown);
    } else {
        mpaint.setColor(GlobalColor.colorPriceEqual);
    }
    canvas.drawText(title2, LSpace + mpaint.measureText(":00:0000:"), axisLabelHeight - 5, mpaint);

    if (!this.isZs()) {
        if ("cf".equals(exchange) || "dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)
                || "hk".equals(exchange)) {
        } else {
            mpaint.setColor(GlobalColor.colorLabelName);
            title9 = "?:";
            canvas.drawText(title9, LSpace + mpaint.measureText(":00:000000:" + title2),
                    axisLabelHeight - 5, mpaint);
            double avePrice = 0;
            double cjje = quoteArray.getJSONArray(isTrackNumber).getDouble(2);
            int scaleCount = 1;
            scaleCount = Utils.getCoefficient(exchange, stockcode);
            double cjsl = quoteArray.getJSONArray(isTrackNumber).getDouble(1) * scaleCount;
            if (cjsl > 0) {
                avePrice = cjje / cjsl;
            } else {
                avePrice = jrkp;
            }
            if (avePrice == 0) {
                mpaint.setColor(GlobalColor.colorPriceEqual);
            } else if (avePrice > close) {
                mpaint.setColor(GlobalColor.colorpriceUp);
            } else if (avePrice < close) {
                mpaint.setColor(GlobalColor.colorPriceDown);
            } else {
                mpaint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.drawText(Utils.dataFormation(avePrice, stockdigit),
                    LSpace + mpaint.measureText(":00:000000:" + title2 + "?:"),
                    axisLabelHeight - 5, mpaint);
        }
    }

    if (isZs()) {
        if (close == 0)
            close = 1000;
    } else {
        if (close == 0)
            close = 1;
    }

    low = Math.min(low, close);
    //upPrice = close * (1+max_zf);
    //downPrice = close * (1-max_zf);

    paint.setColor(GlobalColor.clrLine);
    canvas.drawLine(LSpace + graphicsQuoteWidth, topTitleHeight, LSpace + graphicsQuoteWidth,
            graphicsQuoteHeight + topTitleHeight, paint);

    // 
    upQuoteX = LSpace;
    upQuoteY = topTitleHeight;
    upQuoteWidth = (int) graphicsQuoteWidth;
    upQuoteHeight = price_row_num * price_row_height;
    for (int i = 0; i < price_row_num; i++) {
        if (i == 0) {
            canvas.drawLine(upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth,
                    upQuoteY + price_row_height * i, paint);
        } else
            Graphics.drawDashline(canvas, upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth,
                    upQuoteY + price_row_height * i, paint);
    }

    for (int i = 0; i < DIVIDE_COUNT; i++) {
        if (i == 0) {
            canvas.drawLine(upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY,
                    upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint);
        } else
            Graphics.drawDashline(canvas, upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY,
                    upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint);
    }
    //scale = close * max_zf / price_row_num;
    scale = Arith.div(close * max_zf, price_row_num, stockdigit + 1);

    mpaint.setTextAlign(Paint.Align.RIGHT);
    mpaint.setColor(GlobalColor.colorPriceEqual);
    canvas.drawText(Utils.dataFormation(close, stockdigit), upQuoteX,
            upQuoteY + upQuoteHeight + axisLabelHeight / 2, mpaint);

    mpaint.setColor(GlobalColor.colorpriceUp);
    for (int i = 1; i <= price_row_num; i++) {
        AxisLabelPrice = close + scale * i;
        canvas.drawText(Utils.dataFormation(AxisLabelPrice, stockdigit), upQuoteX,
                upQuoteY + upQuoteHeight - price_row_height * i + axisLabelHeight / 2, mpaint);
    }

    // 
    downQuoteX = LSpace;
    downQuoteY = topTitleHeight + upQuoteHeight;
    downQuoteWidth = (int) graphicsQuoteWidth;

    downQuoteHeight = upQuoteHeight;

    paint.setColor(GlobalColor.clrLine);
    for (int i = 0; i < price_row_num; i++) {
        if (i == 0) {
            canvas.drawLine(downQuoteX, downQuoteY + price_row_height * i, downQuoteX + downQuoteWidth,
                    downQuoteY + price_row_height * i, paint);
        } else
            Graphics.drawDashline(canvas, downQuoteX, downQuoteY + price_row_height * i,
                    downQuoteX + downQuoteWidth, downQuoteY + price_row_height * i, paint);
    }

    for (int i = 0; i < DIVIDE_COUNT; i++) {
        if (i == 0) {
            canvas.drawLine(downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY,
                    downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight + 1, paint);
        } else
            Graphics.drawDashline(canvas, downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY,
                    downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight, paint);
    }

    mpaint.setColor(GlobalColor.colorPriceDown);
    for (int i = 1; i < price_row_num; i++) {
        AxisLabelPrice = close - scale * i;
        canvas.drawText(Utils.dataFormation(AxisLabelPrice, stockdigit), upQuoteX,
                upQuoteY + upQuoteHeight + price_row_height * i + axisLabelHeight / 2, mpaint);
    }

    //  
    // added by hujun for 20110511???
    if (actualDataLen > 0 && !this.isOpenFund()) {
        if ("cf".equals(exchange) || "dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)) {
            scale = upQuoteHeight / (close * max_zf);
            paint.setColor(GlobalColor.colorFZLine);
            int quotelen = quoteArray.length();
            double x1 = 0;
            double y1 = 0;
            double x2 = 0;
            double y2 = 0;
            double temp = 0;

            x1 = upQuoteX;
            double lastnewp = 0;
            double nownewp = 0;
            nownewp = quoteArray.getJSONArray(0).getDouble(0);
            if (nownewp == 0)
                nownewp = close;
            if (nownewp >= close) {
                temp = (nownewp - close) * scale;
                y1 = topTitleHeight + upQuoteHeight - temp;
            } else {
                temp = (close - nownewp) * scale;
                y1 = topTitleHeight + upQuoteHeight + temp;
            }
            lastnewp = nownewp;
            for (int i = 1; i < quotelen; i++) {
                x2 = upQuoteX + SPACE * i;
                nownewp = quoteArray.getJSONArray(i).getDouble(0);
                if (nownewp == 0)
                    nownewp = lastnewp;
                if (nownewp >= close) {
                    temp = (nownewp - close) * scale;
                    y2 = topTitleHeight + upQuoteHeight - temp;
                } else {
                    temp = (close - nownewp) * scale;
                    y2 = topTitleHeight + upQuoteHeight + temp;
                }
                lastnewp = nownewp;

                canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);

                x1 = x2;
                y1 = y2;
            } // end for

            paint.setColor(GlobalColor.colorFZAvePriceLine);
            x1 = upQuoteX;
            double cjje = quoteArray.getJSONArray(0).getDouble(0);
            double avePrice = cjje;
            double lastavg = 0;
            if (avePrice > high) {
                avePrice = high;
            }
            if (avePrice < low) {
                avePrice = low;
            }
            if (avePrice >= close) {
                temp = (avePrice - close) * scale;
                y1 = topTitleHeight + upQuoteHeight - temp;
            } else {
                temp = (close - avePrice) * scale;
                y1 = topTitleHeight + upQuoteHeight + temp;
            }
            lastavg = avePrice;
            double xl = quoteArray.getJSONArray(0).getDouble(1);
            double mathpjj = quoteArray.getJSONArray(0).getDouble(0) * xl;
            for (int i = 1; i < quotelen; i++) {
                x2 = upQuoteX + SPACE * i;
                mathpjj += quoteArray.getJSONArray(i).getDouble(0) * (quoteArray.getJSONArray(i).getDouble(1)
                        - quoteArray.getJSONArray(i - 1).getDouble(1));
                if (mathpjj == 0) {
                    if (lastavg == 0) {
                        avePrice = close;
                    } else {
                        avePrice = lastavg;
                    }
                } else {
                    avePrice = mathpjj / quoteArray.getJSONArray(i).getDouble(1);
                }
                lastavg = avePrice;
                if (avePrice > high) {
                    avePrice = high;
                }
                if (avePrice < low) {
                    avePrice = low;
                }
                if (avePrice >= close) {
                    temp = (avePrice - close) * scale;
                    y2 = topTitleHeight + upQuoteHeight - temp;
                } else {
                    temp = (close - avePrice) * scale;
                    y2 = topTitleHeight + upQuoteHeight + temp;
                }
                canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);

                x1 = x2;
                y1 = y2;
            } // end for
        } else {
            scale = upQuoteHeight / (close * max_zf);
            paint.setColor(GlobalColor.colorFZLine);
            int quotelen = quoteArray.length();
            double x1 = 0;
            double y1 = 0;
            double x2 = 0;
            double y2 = 0;
            double temp = 0;

            x1 = upQuoteX;
            double lastnewp = 0;
            double nownewp = 0;
            nownewp = quoteArray.getJSONArray(0).getDouble(0);
            if (nownewp == 0)
                nownewp = close;
            if (nownewp >= close) {
                temp = (nownewp - close) * scale;
                y1 = topTitleHeight + upQuoteHeight - temp;
            } else {
                temp = (close - nownewp) * scale;
                y1 = topTitleHeight + upQuoteHeight + temp;
            }
            lastnewp = nownewp;
            for (int i = 1; i < quotelen; i++) {
                x2 = upQuoteX + SPACE * i;
                nownewp = quoteArray.getJSONArray(i).getDouble(0);
                if (nownewp == 0)
                    nownewp = lastnewp;
                if (nownewp >= close) {
                    temp = (nownewp - close) * scale;
                    y2 = topTitleHeight + upQuoteHeight - temp;
                } else {
                    temp = (close - nownewp) * scale;
                    y2 = topTitleHeight + upQuoteHeight + temp;
                }
                lastnewp = nownewp;

                canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);

                x1 = x2;
                y1 = y2;
            } // end for

            if (this.isZs()) {
                // ?   ??
                if ("sz".equals(exchange) || "sh".equals(exchange)) {
                    if (("000001".equals(stockcode) || "399001".equals(stockcode))
                            && !quoteData.isNull("data2")) {
                        paint.setColor(GlobalColor.colorFZAvePriceLine);
                        x1 = upQuoteX;
                        double avePrice = quoteData.getJSONArray("data2").getJSONArray(0).getDouble(0);
                        if (avePrice > high) {
                            avePrice = high;
                        }
                        if (avePrice < low) {
                            avePrice = low;
                        }
                        if (avePrice >= close) {
                            temp = (avePrice - close) * scale;
                            y1 = topTitleHeight + upQuoteHeight - temp;
                        } else {
                            temp = (close - avePrice) * scale;
                            y1 = topTitleHeight + upQuoteHeight + temp;
                        }
                        int len = quoteData.getJSONArray("data2").length();
                        for (int i = 1; i < len; i++) {
                            if ("15:00".equals(quoteData.getJSONArray("data2").getJSONArray(i).getString(1)
                                    .substring(11, 16))) {

                            } else {
                                x2 = upQuoteX + SPACE * i;
                                avePrice = quoteData.getJSONArray("data2").getJSONArray(i).getDouble(0);
                                if (avePrice > high) {
                                    avePrice = high;
                                }
                                if (avePrice < low) {
                                    avePrice = low;
                                }
                                if (avePrice >= close) {
                                    temp = (avePrice - close) * scale;
                                    y2 = topTitleHeight + upQuoteHeight - temp;
                                } else {
                                    temp = (close - avePrice) * scale;
                                    y2 = topTitleHeight + upQuoteHeight + temp;
                                }
                                canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);

                                x1 = x2;
                                y1 = y2;
                            }
                        } // end for
                    } else {
                        paint.setColor(GlobalColor.colorFZAvePriceLine);
                        x1 = upQuoteX;
                        double cjje = quoteArray.getJSONArray(0).getDouble(0);
                        double avePrice = cjje;
                        double lastavg = 0;
                        if (avePrice > high) {
                            avePrice = high;
                        }
                        if (avePrice < low) {
                            avePrice = low;
                        }
                        if (avePrice >= close) {
                            temp = (avePrice - close) * scale;
                            y1 = topTitleHeight + upQuoteHeight - temp;
                        } else {
                            temp = (close - avePrice) * scale;
                            y1 = topTitleHeight + upQuoteHeight + temp;
                        }
                        lastavg = avePrice;
                        double xl = quoteArray.getJSONArray(0).getDouble(1);
                        double mathpjj = quoteArray.getJSONArray(0).getDouble(0) * xl;
                        for (int i = 1; i < quotelen; i++) {
                            x2 = upQuoteX + SPACE * i;
                            mathpjj += quoteArray.getJSONArray(i).getDouble(0)
                                    * (quoteArray.getJSONArray(i).getDouble(1)
                                            - quoteArray.getJSONArray(i - 1).getDouble(1));
                            if (mathpjj == 0) {
                                if (lastavg == 0) {
                                    avePrice = close;
                                } else {
                                    avePrice = lastavg;
                                }
                            } else {
                                avePrice = mathpjj / quoteArray.getJSONArray(i).getDouble(1);
                            }
                            lastavg = avePrice;
                            if (avePrice > high) {
                                avePrice = high;
                            }
                            if (avePrice < low) {
                                avePrice = low;
                            }
                            if (avePrice >= close) {
                                temp = (avePrice - close) * scale;
                                y2 = topTitleHeight + upQuoteHeight - temp;
                            } else {
                                temp = (close - avePrice) * scale;
                                y2 = topTitleHeight + upQuoteHeight + temp;
                            }
                            canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);

                            x1 = x2;
                            y1 = y2;
                        } // end for
                    }
                }
            } else {
                paint.setColor(GlobalColor.colorFZAvePriceLine);
                x1 = upQuoteX;
                double cjje = quoteArray.getJSONArray(0).getDouble(2);
                int scaleCount = 1;
                scaleCount = Utils.getCoefficient(exchange, stockcode);
                double cjsl = quoteArray.getJSONArray(0).getDouble(1) * scaleCount;
                double avePrice = cjje / cjsl;
                double lastavg = 0;
                if (cjsl == 0)
                    avePrice = close;
                if (avePrice > high) {
                    avePrice = high;
                }
                if (avePrice < low) {
                    avePrice = low;
                }
                if (avePrice >= close) {
                    temp = (avePrice - close) * scale;
                    y1 = topTitleHeight + upQuoteHeight - temp;
                } else {
                    temp = (close - avePrice) * scale;
                    y1 = topTitleHeight + upQuoteHeight + temp;
                }
                lastavg = avePrice;
                for (int i = 1; i < quotelen; i++) {
                    x2 = upQuoteX + SPACE * i;
                    cjje = quoteArray.getJSONArray(i).getDouble(2);
                    cjsl = quoteArray.getJSONArray(i).getDouble(1) * scaleCount; // ?
                    if (cjsl == 0) {
                        if (lastavg == 0) {
                            avePrice = close;
                        } else {
                            avePrice = lastavg;
                        }
                    } else {
                        avePrice = cjje / cjsl;
                    }
                    lastavg = avePrice;
                    if (avePrice > high) {
                        avePrice = high;
                    }
                    if (avePrice < low) {
                        avePrice = low;
                    }
                    if (avePrice >= close) {
                        temp = (avePrice - close) * scale;
                        y2 = topTitleHeight + upQuoteHeight - temp;
                    } else {
                        temp = (close - avePrice) * scale;
                        y2 = topTitleHeight + upQuoteHeight + temp;
                    }
                    canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);

                    x1 = x2;
                    y1 = y2;
                } // end for
            }
        }
    }

    // ??
    volumeX = LSpace;
    volumeY = topTitleHeight + upQuoteHeight + downQuoteHeight;
    volumeWidth = (int) graphicsQuoteWidth;
    volumeHeight = graphicsQuoteHeight - upQuoteHeight - downQuoteHeight;

    volume_row_height = volumeHeight / volume_row_num;

    paint.setColor(GlobalColor.clrLine);
    for (int i = 0; i <= volume_row_num; i++) {
        if (i == 0) {
            canvas.drawLine(volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth,
                    volumeY + volume_row_height * i, paint);
        } else {
            if (i != volume_row_num)
                Graphics.drawDashline(canvas, volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth,
                        volumeY + volume_row_height * i, paint);
        }
    }

    for (int i = 0; i < DIVIDE_COUNT; i++) {
        if (i == 0) {
            canvas.drawLine(volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY,
                    volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint);
        } else
            Graphics.drawDashline(canvas, volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY,
                    volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint);
    }

    if (this.isZs()) {
        //highVolume =  TickUtil.gethighAmount(quoteData.getJSONArray("data"));
        highVolume = highamount;
    } else {
        //highVolume =  TickUtil.gethighVolume(quoteData.getJSONArray("data"));
        highVolume = highvolume;
    }

    if (highVolume == 0) {
        if (this.isZs()) {
            // ?
            highVolume = volume_row_num * 4 * 100; // ???48highVolume=32
        } else {
            highVolume = volume_row_num * 4 * 100; // ???48highVolume=32
        }
    }
    if (highVolume < volume_row_num + 1)
        highVolume = volume_row_num + 1;
    scale = highVolume / volume_row_num;
    int volumeLabelY = volumeY + Font.getFontHeight(dTextSize) / 2;

    mpaint.setColor(GlobalColor.clr_tick_volume);
    for (int i = 0; i <= volume_row_num; i++) {
        if (i != volume_row_num) {
            AxisLabelVolume = highVolume - scale * i;
            if (this.isZs())
                AxisLabelVolume = Math.round(AxisLabelVolume / 10000);
            else
                AxisLabelVolume = Math.round(AxisLabelVolume);

            canvas.drawText(String.valueOf((int) AxisLabelVolume), upQuoteX,
                    volumeLabelY + volume_row_height * i, mpaint);
        }
    }

    // ??
    if (actualDataLen > 0) {
        scale = volumeHeight / highVolume;
        paint.setColor(GlobalColor.colorVolumeLine);
        double prevVol = 0;
        double temp = 0;
        for (int i = 0; i < actualDataLen; i++) {
            if (this.isZs())
                temp = (quoteArray.getJSONArray(i).getDouble(2) - prevVol) * scale;
            else
                temp = (quoteArray.getJSONArray(i).getDouble(1) - prevVol) * scale;
            float x1 = volumeX + SPACE * i;
            float y1 = (float) (volumeY + volumeHeight - temp);

            float x2 = x1;
            float y2 = volumeY + volumeHeight;
            canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint);
            if (this.isZs())
                prevVol = quoteArray.getJSONArray(i).getDouble(2);
            else
                prevVol = quoteArray.getJSONArray(i).getDouble(1);
        }
    }

    drawTimeX(canvas);

    // 
    paint.setColor(GlobalColor.clrLine);
    canvas.drawLine(LSpace, graphicsQuoteHeight + topTitleHeight, LSpace + graphicsQuoteWidth,
            graphicsQuoteHeight + topTitleHeight, paint);

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

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 ww  w . j  a v  a2  s .  c om*/
    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;
}