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.cssweb.android.view.KlineViewSingle.java

public void drawKDJ(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {

    if (quoteData.isNull("KDJ") || quoteData.getJSONArray("KDJ").length() < 1) {
        isNetworkErrorDisplay();//from   www  .  j  a v  a2  s.  c om
        return;
    }

    //this.shapeWidth = shapeWidth;
    //this.spaceWidth = spaceWidth;

    double max = 0.001;
    double min = -0.001;

    int len = quoteData.getJSONArray("KDJ").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        double k = quoteData.getJSONArray("KDJ").getJSONArray(i).getDouble(1);
        double d = quoteData.getJSONArray("KDJ").getJSONArray(i).getDouble(2);
        double j = quoteData.getJSONArray("KDJ").getJSONArray(i).getDouble(3);

        if (k > max)
            max = k;
        if (d > max)
            max = d;
        if (j > max)
            max = j;

        if (k < 0) {
            if (k < min)
                min = k;
        }
        if (d < 0) {
            if (d < min)
                min = d;
        }
        if (j < 0) {
            if (j < min)
                min = j;
        }
    }
    max = Math.max(max, 100);
    min = Math.min(min, 0.0);
    double scale = this.volumeHeight / (Math.max(max, 100) + Math.abs(min));

    int startX = klineX;
    int startY = klineY;

    int axisY100 = (int) (startY + volumeHeight - (100 + Math.abs(min)) * scale);

    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY100, width, axisY100, paint);

    String axisLabel1 = "100.00";

    int axisY80 = (int) (startY + volumeHeight - (80 + Math.abs(min)) * scale);

    Graphics.drawDashline(canvas, startX, axisY80, width, axisY80, paint);

    String axisLabel2 = "80.00";

    int axisY50 = (int) (startY + volumeHeight - (50 + Math.abs(min)) * scale);

    Graphics.drawDashline(canvas, startX, axisY50, width, axisY50, paint);

    String axisLabel3 = "50.00";

    int axisY20 = (int) (startY + volumeHeight - (20 + Math.abs(min)) * scale);

    Graphics.drawDashline(canvas, startX, axisY20, width, axisY20, paint);

    String axisLabel4 = "20.00";

    int axisY0 = (int) (startY + volumeHeight - (0 + Math.abs(min)) * scale);

    Graphics.drawDashline(canvas, startX, axisY0, width, axisY0, paint);

    String axisLabel5 = "0.00";
    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY100 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY80 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY50 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY20 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel5, startX - tips / 4, axisY0 + axisLabelHeight / 2, tPaint);
    }
    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {

        double axisX = klineX;
        double difx = klineX;

        double deax = klineX;
        double jx = klineX;

        int kHeight = 0;
        int ky = 0;
        int dHeight = 0;
        int dy = 0;
        int jHeight = 0;
        int jy = 0;

        for (int i = begin; i < (begin + count); i++) {
            double k = quoteData.getJSONArray("KDJ").getJSONArray(i).getDouble(1);
            double d = quoteData.getJSONArray("KDJ").getJSONArray(i).getDouble(2);
            double j = quoteData.getJSONArray("KDJ").getJSONArray(i).getDouble(3);

            //klineX = 0;
            if ((i - begin) == 0)
                axisX = axisX + spaceWidth;
            else
                axisX = axisX + spaceWidth + shapeWidth;

            if ((i - begin) == 0) {
                difx = difx + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((k + Math.abs(min)) * scale);
                ky = startY + volumeHeight - kHeight;
            } else {
                double x1 = difx;
                double y1 = ky;

                difx = difx + spaceWidth + shapeWidth;
                kHeight = (int) ((k + Math.abs(min)) * scale);
                ky = startY + volumeHeight - kHeight;

                paint.setColor(GlobalColor.colorM5);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(difx), (int) ky, paint);
            }

            if ((i - begin) == 0) {
                deax = deax + spaceWidth + shapeWidth / 2;
                dHeight = (int) ((d + Math.abs(min)) * scale);
                dy = startY + volumeHeight - dHeight;
            } else {
                double x1 = deax;
                double y1 = dy;

                deax = deax + spaceWidth + shapeWidth;
                dHeight = (int) ((d + Math.abs(min)) * scale);
                dy = startY + volumeHeight - dHeight;

                paint.setColor(GlobalColor.colorM10);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(deax), (int) dy, paint);
            }

            if ((i - begin) == 0) {
                jx = jx + spaceWidth + shapeWidth / 2;
                jHeight = (int) ((j + Math.abs(min)) * scale);
                jy = startY + volumeHeight - jHeight;
            } else {
                double x1 = jx;
                double y1 = jy;

                jx = jx + spaceWidth + shapeWidth;
                jHeight = (int) ((j + Math.abs(min)) * scale);
                jy = startY + volumeHeight - jHeight;

                paint.setARGB(255, 255, 0, 255);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(jx), (int) jy, paint);
            }

            if (i == (begin + count - 1)) {
                //labelDif.text = "K:" + Utils.StockFormat(exchange+stockCode, k);
                //labelDea.text = "D:" + Utils.StockFormat(exchange+stockCode, d);
                //labelMacd.text = "J:" + Utils.StockFormat(exchange+stockCode, j);
            }
        } // end for
    } // end if
}

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);//  www .  ja va 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);

        //
        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: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);//from  ww  w.  jav  a 2 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:xiaofan.llongimageview.view.SubsamplingScaleImageView.java

/**
 * Draw method should not be called until the view has dimensions so the first calls are used as triggers to calculate
 * the scaling and tiling required. Once the view is setup, tiles are displayed as they are loaded.
 *//*  w w w . ja v a 2 s. c o  m*/
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    createPaints();

    // If image or view dimensions are not known yet, abort.
    if (sWidth == 0 || sHeight == 0 || decoder == null || getWidth() == 0 || getHeight() == 0) {
        return;
    }

    // On first render with no tile map ready, initialise it and kick off async base image loading.
    if (tileMap == null) {
        initialiseBaseLayer(getMaxBitmapDimensions(canvas));
        return;
    }

    // If waiting to translate to new center position, set translate now
    if (sPendingCenter != null && pendingScale != null) {
        scale = pendingScale;
        vTranslate.x = (getWidth() / 2) - (scale * sPendingCenter.x);
        vTranslate.y = (getHeight() / 2) - (scale * sPendingCenter.y);
        sPendingCenter = null;
        pendingScale = null;
        fitToBounds(true);
        refreshRequiredTiles(true);
    }

    // On first display of base image set up position, and in other cases make sure scale is correct.
    fitToBounds(false);

    // Everything is set up and coordinates are valid. Inform subclasses.
    if (!readySent) {
        readySent = true;
        new Thread(new Runnable() {
            public void run() {
                onImageReady();
            }
        }).start();
    }

    // If animating scale, calculate current scale and center with easing equations
    if (anim != null) {
        long scaleElapsed = System.currentTimeMillis() - anim.time;
        boolean finished = scaleElapsed > anim.duration;
        scaleElapsed = Math.min(scaleElapsed, anim.duration);
        scale = ease(anim.easing, scaleElapsed, anim.scaleStart, anim.scaleEnd - anim.scaleStart,
                anim.duration);

        // Apply required animation to the focal point
        float vFocusNowX = ease(anim.easing, scaleElapsed, anim.vFocusStart.x,
                anim.vFocusEnd.x - anim.vFocusStart.x, anim.duration);
        float vFocusNowY = ease(anim.easing, scaleElapsed, anim.vFocusStart.y,
                anim.vFocusEnd.y - anim.vFocusStart.y, anim.duration);
        // Find out where the focal point is at this scale and adjust its position to follow the animation path
        PointF vFocus = sourceToViewCoord(anim.sCenterEnd);
        vTranslate.x -= vFocus.x - vFocusNowX;
        vTranslate.y -= vFocus.y - vFocusNowY;

        // For translate anims, showing the image non-centered is never allowed, for scaling anims it is during the animation.
        fitToBounds(finished || (anim.scaleStart == anim.scaleEnd));
        refreshRequiredTiles(finished);
        if (finished) {
            anim = null;
        }
        invalidate();
    }

    // Optimum sample size for current scale
    int sampleSize = Math.min(fullImageSampleSize, calculateInSampleSize());

    // First check for missing tiles - if there are any we need the base layer underneath to avoid gaps
    boolean hasMissingTiles = false;
    for (Map.Entry<Integer, List<Tile>> tileMapEntry : tileMap.entrySet()) {
        if (tileMapEntry.getKey() == sampleSize) {
            for (Tile tile : tileMapEntry.getValue()) {
                if (tile.visible && (tile.loading || tile.bitmap == null)) {
                    hasMissingTiles = true;
                }
            }
        }
    }

    // Render all loaded tiles. LinkedHashMap used for bottom up rendering - lower res tiles underneath.
    for (Map.Entry<Integer, List<Tile>> tileMapEntry : tileMap.entrySet()) {
        if (tileMapEntry.getKey() == sampleSize || hasMissingTiles) {
            for (Tile tile : tileMapEntry.getValue()) {
                Rect vRect = convertRect(sourceToViewRect(tile.sRect));
                if (!tile.loading && tile.bitmap != null) {
                    canvas.drawBitmap(tile.bitmap, null, vRect, bitmapPaint);
                    if (debug) {
                        canvas.drawRect(vRect, debugPaint);
                    }
                } else if (tile.loading && debug) {
                    canvas.drawText("LOADING", vRect.left + 5, vRect.top + 35, debugPaint);
                }
                if (tile.visible && debug) {
                    canvas.drawText(
                            "ISS " + tile.sampleSize + " RECT " + tile.sRect.top + "," + tile.sRect.left + ","
                                    + tile.sRect.bottom + "," + tile.sRect.right,
                            vRect.left + 5, vRect.top + 15, debugPaint);
                }
            }
        }
    }

    if (debug) {
        canvas.drawText("Scale: " + String.format("%.2f", scale), 5, 15, debugPaint);
        canvas.drawText(
                "Translate: " + String.format("%.2f", vTranslate.x) + ":" + String.format("%.2f", vTranslate.y),
                5, 35, debugPaint);
        PointF center = getCenter();
        canvas.drawText(
                "Source center: " + String.format("%.2f", center.x) + ":" + String.format("%.2f", center.y), 5,
                55, debugPaint);

        if (anim != null) {
            PointF vCenterStart = sourceToViewCoord(anim.sCenterStart);
            PointF vCenterEndRequested = sourceToViewCoord(anim.sCenterEndRequested);
            PointF vCenterEnd = sourceToViewCoord(anim.sCenterEnd);
            canvas.drawCircle(vCenterStart.x, vCenterStart.y, 10, debugPaint);
            canvas.drawCircle(vCenterEndRequested.x, vCenterEndRequested.y, 20, debugPaint);
            canvas.drawCircle(vCenterEnd.x, vCenterEnd.y, 25, debugPaint);
            canvas.drawCircle(getWidth() / 2, getHeight() / 2, 30, debugPaint);
        }
    }
}

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

public void drawROC(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen,
        String indicator) throws JSONException {
    if (quoteData.isNull(indicator) || quoteData.getJSONArray(indicator).length() < 1) {
        isNetworkErrorDisplay();// w w w.j a  v a 2s .  com
        return;
    }
    this.shapeWidth = shapeWidth;
    this.spaceWidth = spaceWidth;

    double max = 0.001;
    double min = 9999999999f;
    double wr = 0, wr2 = 0;
    int len = quoteData.getJSONArray(indicator).length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        wr = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(1);
        wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(2);
        max = Arith.max(wr, wr2, max);
        min = Arith.min(wr, wr2, min);
    }
    max = max * 1.1;
    min = min - Math.abs(min) * 0.1;
    double scale = (double) (this.volumeHeight) / (max - min);

    int startX = klineX;
    int startY = klineY;

    double AxisLabelVolume = max;
    String lblvalue = "12345";
    int ratiolen = String.valueOf(Math.round(AxisLabelVolume)).length() - String.valueOf(lblvalue).length();

    String labelRatio = "";
    int scaleVol = 1;
    switch (ratiolen) {
    case 1:
        labelRatio = "x10";
        scaleVol = 10;
        break;
    case 2:
        labelRatio = "x100";
        scaleVol = 100;
        break;
    case 3:
        labelRatio = "x1000";
        scaleVol = 1000;
        break;
    case 4:
        labelRatio = "x10000";
        scaleVol = 10000;
        break;
    default:
        labelRatio = "";
        scaleVol = 1;
        break;
    }

    int axisY1 = (int) (startY + volumeHeight - (max - min) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY1, width, axisY1, paint);

    String axisLabel1 = Utils.dataFormation(max / scaleVol, 1);

    int axisY2 = (int) (startY + volumeHeight - (max - min) * 3 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY2, width, axisY2, paint);

    String axisLabel2 = Utils.dataFormation((min + (max - min) * 3 / 4) / scaleVol, 1);

    int axisY3 = (int) (startY + volumeHeight - (max - min) * 2 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY3, klineX + klineWidth, axisY3, paint);

    String axisLabel3 = Utils.dataFormation((min + (max - min) * 2 / 4) / scaleVol, 1);

    int axisY4 = (int) (startY + volumeHeight - (max - min) / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY4, klineX + klineWidth, axisY4, paint);

    String axisLabel4 = Utils.dataFormation((min + (max - min) * 1 / 4) / scaleVol, 1);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(labelRatio, startX - tips / 4, startY + volumeHeight + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY1 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY2 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY3 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY4 + axisLabelHeight / 2, tPaint);
    }

    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double currX = 0, currY1 = 0, currY2 = 0;//???
        double nextX = 0, nextY1 = 0, nextY2 = 0;//??

        int kHeight = 0;

        for (int i = begin; i < (begin + count) && i < len; i++) {
            wr = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(1);
            wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(2);

            if ((i - begin) == 0) {
                currX = startX;
                currX = nextX = currX + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((wr - min) * scale);
                currY1 = nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                currY2 = nextY2 = startY + volumeHeight - kHeight;
            } else {
                nextX = currX + spaceWidth + shapeWidth;
                kHeight = (int) ((wr - min) * scale);
                nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                nextY2 = startY + volumeHeight - kHeight;
            }
            paint.setColor(GlobalColor.colorM5);
            canvas.drawLine((float) currX, (float) currY1, (float) nextX, (float) nextY1, paint);

            paint.setColor(GlobalColor.colorM10);
            canvas.drawLine((float) currX, (float) currY2, (float) nextX, (float) nextY2, paint);

            currX = nextX;
            currY1 = nextY1;
            currY2 = nextY2;

            if (i == (begin + count - 1)) {

            }
        } // end for
    } // end if
}

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

public void drawOther(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen,
        String indicator) throws JSONException {
    if (quoteData.isNull(indicator) || quoteData.getJSONArray(indicator).length() < 1) {
        isNetworkErrorDisplay();/*from   w  w w  .j  a  v a  2s  . c  o m*/
        return;
    }
    this.shapeWidth = shapeWidth;
    this.spaceWidth = spaceWidth;

    double max = 0.001;
    double min = 9999999999f;
    double wr = 0, wr2 = 0;
    int len = quoteData.getJSONArray(indicator).length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        wr = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(1);
        wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(2);
        max = Arith.max(wr, wr2, max);
        min = Arith.min(wr, wr2, min);
    }
    max = max + (max - min) / 10;
    min = min - (max - min) / 10;
    double scale = (double) (this.volumeHeight) / (max - min);

    int startX = klineX;
    int startY = klineY;

    double AxisLabelVolume = max;
    String lblvalue = "12345";
    int ratiolen = String.valueOf(Math.round(AxisLabelVolume)).length() - String.valueOf(lblvalue).length();

    String labelRatio = "";
    int scaleVol = 1;
    switch (ratiolen) {
    case 1:
        labelRatio = "x10";
        scaleVol = 10;
        break;
    case 2:
        labelRatio = "x100";
        scaleVol = 100;
        break;
    case 3:
        labelRatio = "x1000";
        scaleVol = 1000;
        break;
    case 4:
        labelRatio = "x10000";
        scaleVol = 10000;
        break;
    default:
        labelRatio = "";
        scaleVol = 1;
        break;
    }

    int axisY1 = (int) (startY + volumeHeight - (max - min) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY1, width, axisY1, paint);

    String axisLabel1 = String.valueOf((int) max / scaleVol);

    int axisY2 = (int) (startY + volumeHeight - (max - min) * 3 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY2, width, axisY2, paint);

    String axisLabel2 = String.valueOf((int) (min + (max - min) * 3 / 4) / scaleVol);

    int axisY3 = (int) (startY + volumeHeight - (max - min) * 2 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY3, klineX + klineWidth, axisY3, paint);

    String axisLabel3 = String.valueOf((int) (min + (max - min) * 2 / 4) / scaleVol);

    int axisY4 = (int) (startY + volumeHeight - (max - min) / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY4, klineX + klineWidth, axisY4, paint);

    String axisLabel4 = String.valueOf((int) (min + (max - min) * 1 / 4) / scaleVol);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(labelRatio, startX - tips / 4, startY + volumeHeight + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY1 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY2 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY3 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY4 + axisLabelHeight / 2, tPaint);
    }

    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double currX = 0, currY1 = 0, currY2 = 0;//???
        double nextX = 0, nextY1 = 0, nextY2 = 0;//??

        int kHeight = 0;

        for (int i = begin; i < (begin + count) && i < len; i++) {
            wr = quoteData.getJSONArray(indicator).getJSONArray(i).getLong(1);
            wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getLong(2);

            if ((i - begin) == 0) {
                currX = startX;
                currX = nextX = currX + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((wr - min) * scale);
                currY1 = nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                currY2 = nextY2 = startY + volumeHeight - kHeight;
            } else {
                nextX = currX + spaceWidth + shapeWidth;
                kHeight = (int) ((wr - min) * scale);
                nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                nextY2 = startY + volumeHeight - kHeight;
            }
            paint.setColor(GlobalColor.colorM5);
            canvas.drawLine((float) currX, (float) currY1, (float) nextX, (float) nextY1, paint);

            paint.setColor(GlobalColor.colorM10);
            canvas.drawLine((float) currX, (float) currY2, (float) nextX, (float) nextY2, paint);

            currX = nextX;
            currY1 = nextY1;
            currY2 = nextY2;

            if (i == (begin + count - 1)) {

            }
        } // end for
    } // end if
}

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

public void drawROC(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen,
        String indicator) throws JSONException {
    this.shapeWidth = shapeWidth;
    this.spaceWidth = spaceWidth;
    if (quoteData.isNull(indicator) || quoteData.getJSONArray(indicator).length() < 1) {
        isNetworkErrorDisplay();/*from www .j a v a 2 s .  c  om*/
        return;
    }
    double max = 0.001;
    double min = 9999999999f;
    double wr = 0, wr2 = 0;
    int len = quoteData.getJSONArray(indicator).length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        wr = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(1);
        wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(2);
        max = Arith.max(wr, wr2, max);
        min = Arith.min(wr, wr2, min);
    }
    max = max * 1.1;
    min = min - Math.abs(min) * 0.1;
    double scale = (double) (this.volumeHeight) / (max - min);

    int startX = klineX;
    int startY = klineY;

    double AxisLabelVolume = max;
    String lblvalue = "12345";
    int ratiolen = String.valueOf(Math.round(AxisLabelVolume)).length() - String.valueOf(lblvalue).length();

    String labelRatio = "";
    int scaleVol = 1;
    switch (ratiolen) {
    case 1:
        labelRatio = "x10";
        scaleVol = 10;
        break;
    case 2:
        labelRatio = "x100";
        scaleVol = 100;
        break;
    case 3:
        labelRatio = "x1000";
        scaleVol = 1000;
        break;
    case 4:
        labelRatio = "x10000";
        scaleVol = 10000;
        break;
    default:
        labelRatio = "";
        scaleVol = 1;
        break;
    }

    int axisY1 = (int) (startY + volumeHeight - (max - min) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY1, width, axisY1, paint);

    String axisLabel1 = Utils.dataFormation(max / scaleVol, 1);

    int axisY2 = (int) (startY + volumeHeight - (max - min) * 3 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY2, width, axisY2, paint);

    String axisLabel2 = Utils.dataFormation((min + (max - min) * 3 / 4) / scaleVol, 1);

    int axisY3 = (int) (startY + volumeHeight - (max - min) * 2 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY3, klineX + klineWidth, axisY3, paint);

    String axisLabel3 = Utils.dataFormation((min + (max - min) * 2 / 4) / scaleVol, 1);

    int axisY4 = (int) (startY + volumeHeight - (max - min) / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY4, klineX + klineWidth, axisY4, paint);

    String axisLabel4 = Utils.dataFormation((min + (max - min) * 1 / 4) / scaleVol, 1);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(labelRatio, startX - tips / 4, startY + volumeHeight + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY1 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY2 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY3 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY4 + axisLabelHeight / 2, tPaint);
    }

    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double currX = 0, currY1 = 0, currY2 = 0;//???
        double nextX = 0, nextY1 = 0, nextY2 = 0;//??

        int kHeight = 0;

        for (int i = begin; i < (begin + count) && i < len; i++) {
            wr = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(1);
            wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(2);

            if ((i - begin) == 0) {
                currX = startX;
                currX = nextX = currX + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((wr - min) * scale);
                currY1 = nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                currY2 = nextY2 = startY + volumeHeight - kHeight;
            } else {
                nextX = currX + spaceWidth + shapeWidth;
                kHeight = (int) ((wr - min) * scale);
                nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                nextY2 = startY + volumeHeight - kHeight;
            }
            paint.setColor(GlobalColor.colorM5);
            canvas.drawLine((float) currX, (float) currY1, (float) nextX, (float) nextY1, paint);

            paint.setColor(GlobalColor.colorM10);
            canvas.drawLine((float) currX, (float) currY2, (float) nextX, (float) nextY2, paint);

            currX = nextX;
            currY1 = nextY1;
            currY2 = nextY2;

            if (i == (begin + count - 1)) {

            }
        } // end for
    } // end if
}

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

public void drawOther(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen,
        String indicator) throws JSONException {
    this.shapeWidth = shapeWidth;
    this.spaceWidth = spaceWidth;
    if (quoteData.isNull(indicator) || quoteData.getJSONArray(indicator).length() < 1) {
        isNetworkErrorDisplay();// w  w w  . j a  v a  2s . c om
        return;
    }
    double max = 0.001;
    double min = 9999999999f;
    double wr = 0, wr2 = 0;
    int len = quoteData.getJSONArray(indicator).length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        wr = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(1);
        wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(2);
        max = Arith.max(wr, wr2, max);
        min = Arith.min(wr, wr2, min);
    }
    max = max + (max - min) / 10;
    min = min - (max - min) / 10;
    double scale = (double) (this.volumeHeight) / (max - min);

    int startX = klineX;
    int startY = klineY;

    double AxisLabelVolume = max;
    String lblvalue = "12345";
    int ratiolen = String.valueOf(Math.round(AxisLabelVolume)).length() - String.valueOf(lblvalue).length();

    String labelRatio = "";
    int scaleVol = 1;
    switch (ratiolen) {
    case 1:
        labelRatio = "x10";
        scaleVol = 10;
        break;
    case 2:
        labelRatio = "x100";
        scaleVol = 100;
        break;
    case 3:
        labelRatio = "x1000";
        scaleVol = 1000;
        break;
    case 4:
        labelRatio = "x10000";
        scaleVol = 10000;
        break;
    default:
        labelRatio = "";
        scaleVol = 1;
        break;
    }

    int axisY1 = (int) (startY + volumeHeight - (max - min) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY1, width, axisY1, paint);

    String axisLabel1 = String.valueOf((int) max / scaleVol);

    int axisY2 = (int) (startY + volumeHeight - (max - min) * 3 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY2, width, axisY2, paint);

    String axisLabel2 = String.valueOf((int) (min + (max - min) * 3 / 4) / scaleVol);

    int axisY3 = (int) (startY + volumeHeight - (max - min) * 2 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY3, klineX + klineWidth, axisY3, paint);

    String axisLabel3 = String.valueOf((int) (min + (max - min) * 2 / 4) / scaleVol);

    int axisY4 = (int) (startY + volumeHeight - (max - min) / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY4, klineX + klineWidth, axisY4, paint);

    String axisLabel4 = String.valueOf((int) (min + (max - min) * 1 / 4) / scaleVol);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(labelRatio, startX - tips / 4, startY + volumeHeight + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY1 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY2 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY3 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY4 + axisLabelHeight / 2, tPaint);
    }

    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double currX = 0, currY1 = 0, currY2 = 0;//???
        double nextX = 0, nextY1 = 0, nextY2 = 0;//??

        int kHeight = 0;

        for (int i = begin; i < (begin + count) && i < len; i++) {
            wr = quoteData.getJSONArray(indicator).getJSONArray(i).getLong(1);
            wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getLong(2);

            if ((i - begin) == 0) {
                currX = startX;
                currX = nextX = currX + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((wr - min) * scale);
                currY1 = nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                currY2 = nextY2 = startY + volumeHeight - kHeight;
            } else {
                nextX = currX + spaceWidth + shapeWidth;
                kHeight = (int) ((wr - min) * scale);
                nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                nextY2 = startY + volumeHeight - kHeight;
            }
            paint.setColor(GlobalColor.colorM5);
            canvas.drawLine((float) currX, (float) currY1, (float) nextX, (float) nextY1, paint);

            paint.setColor(GlobalColor.colorM10);
            canvas.drawLine((float) currX, (float) currY2, (float) nextX, (float) nextY2, paint);

            currX = nextX;
            currY1 = nextY1;
            currY2 = nextY2;

            if (i == (begin + count - 1)) {

            }
        } // end for
    } // end if
}

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

public void drawOBV(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {
    //      this.shapeWidth = shapeWidth;
    //      this.spaceWidth = spaceWidth;
    if (quoteData.isNull("OBV") || quoteData.getJSONArray("OBV").length() < 1) {
        isNetworkErrorDisplay();/*from  w  w w .j  a v  a  2 s  . c  o  m*/
        return;
    }

    long max = 1;
    long min = 99999999999999l;
    long obv, maobv;
    int len = quoteData.getJSONArray("OBV").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        obv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(1);
        maobv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(2);
        max = Arith.max(obv, maobv, max);
        min = Arith.min(obv, maobv, min);
    }
    max = max + (max - min) / 10;
    min = min - (max - min) / 10;
    double scale = (double) (this.volumeHeight) / (max - min);

    int startX = klineX;
    int startY = klineY;

    double AxisLabelVolume = max;
    String lblvalue = "12345";
    int ratiolen = String.valueOf(Math.round(AxisLabelVolume)).length() - String.valueOf(lblvalue).length();

    String labelRatio = "";
    int scaleVol = 1;
    switch (ratiolen) {
    case 1:
        labelRatio = "x10";
        scaleVol = 10;
        break;
    case 2:
        labelRatio = "x100";
        scaleVol = 100;
        break;
    case 3:
        labelRatio = "x1000";
        scaleVol = 1000;
        break;
    case 4:
        labelRatio = "x10000";
        scaleVol = 10000;
        break;
    case 5:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    case 6:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    default:
        labelRatio = "x1";
        scaleVol = 1;
        break;
    }

    int axisY1 = (int) (startY + volumeHeight - (max - min) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY1, width, axisY1, paint);

    String axisLabel1 = String.valueOf((int) max / scaleVol);

    int axisY2 = (int) (startY + volumeHeight - (max - min) * 3 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY2, width, axisY2, paint);

    String axisLabel2 = String.valueOf((int) (min + (max - min) * 3 / 4) / scaleVol);

    int axisY3 = (int) (startY + volumeHeight - (max - min) * 2 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY3, width, axisY3, paint);

    String axisLabel3 = String.valueOf((int) (min + (max - min) * 2 / 4) / scaleVol);

    int axisY4 = (int) (startY + volumeHeight - (max - min) / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY4, width, axisY4, paint);

    String axisLabel4 = String.valueOf((int) (min + (max - min) * 1 / 4) / scaleVol);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(labelRatio, startX - tips / 4, startY + volumeHeight + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY1 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY2 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY3 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY4 + axisLabelHeight / 2, tPaint);
    }
    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double currX = 0, currY1 = 0, currY2 = 0;//???
        double nextX = 0, nextY1 = 0, nextY2 = 0;//??

        int kHeight = 0;

        for (int i = begin; i < (begin + count) && i < len; i++) {
            obv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(1);
            maobv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(2);

            startX = klineX;

            if ((i - begin) == 0) {
                currX = 0;
                currX = nextX = currX + startX + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((obv - min) * scale);
                currY1 = nextY1 = startY + volumeHeight - kHeight;
                kHeight = (int) ((maobv - min) * scale);
                currY2 = nextY2 = startY + volumeHeight - kHeight;
            } else {
                nextX = currX + spaceWidth + shapeWidth;
            }
            // obv
            kHeight = (int) ((obv - min) * scale);
            nextY1 = startY + volumeHeight - kHeight;
            paint.setColor(GlobalColor.colorM5);
            canvas.drawLine((int) currX, (int) currY1, (int) nextX, (int) nextY1, paint);

            // maobv
            kHeight = (int) ((maobv - min) * scale);
            nextY2 = startY + volumeHeight - kHeight;
            paint.setColor(GlobalColor.colorM10);
            canvas.drawLine((int) currX, (int) currY2, (int) nextX, (int) nextY2, paint);

            currX = nextX;
            currY1 = nextY1;
            currY2 = nextY2;

            if (i == (begin + count - 1)) {

            }
        } // end for
    } // end if
}

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

public void drawOBV(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {
    //      this.shapeWidth = shapeWidth;
    //      this.spaceWidth = spaceWidth;
    if (quoteData.isNull("OBV") || quoteData.getJSONArray("OBV").length() < 1) {
        isNetworkErrorDisplay();/*  w ww  .  j av a 2  s .c  o  m*/
        return;
    }
    long max = 1;
    long min = 99999999999999l;
    long obv, maobv;
    int len = quoteData.getJSONArray("OBV").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        obv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(1);
        maobv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(2);
        max = Arith.max(obv, maobv, max);
        min = Arith.min(obv, maobv, min);
    }
    max = max + (max - min) / 10;
    min = min - (max - min) / 10;
    double scale = (double) (this.volumeHeight) / (max - min);

    int startX = klineX;
    int startY = klineY;

    double AxisLabelVolume = max;
    String lblvalue = "12345";
    int ratiolen = String.valueOf(Math.round(AxisLabelVolume)).length() - String.valueOf(lblvalue).length();

    String labelRatio = "";
    int scaleVol = 1;
    switch (ratiolen) {
    case 1:
        labelRatio = "x10";
        scaleVol = 10;
        break;
    case 2:
        labelRatio = "x100";
        scaleVol = 100;
        break;
    case 3:
        labelRatio = "x1000";
        scaleVol = 1000;
        break;
    case 4:
        labelRatio = "x10000";
        scaleVol = 10000;
        break;
    case 5:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    case 6:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    default:
        labelRatio = "x1";
        scaleVol = 1;
        break;
    }

    int axisY1 = (int) (startY + volumeHeight - (max - min) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY1, width, axisY1, paint);

    String axisLabel1 = String.valueOf((int) max / scaleVol);

    int axisY2 = (int) (startY + volumeHeight - (max - min) * 3 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY2, width, axisY2, paint);

    String axisLabel2 = String.valueOf((int) (min + (max - min) * 3 / 4) / scaleVol);

    int axisY3 = (int) (startY + volumeHeight - (max - min) * 2 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY3, width, axisY3, paint);

    String axisLabel3 = String.valueOf((int) (min + (max - min) * 2 / 4) / scaleVol);

    int axisY4 = (int) (startY + volumeHeight - (max - min) / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY4, width, axisY4, paint);

    String axisLabel4 = String.valueOf((int) (min + (max - min) * 1 / 4) / scaleVol);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(labelRatio, startX - tips / 4, startY + volumeHeight + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY1 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY2 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY3 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY4 + axisLabelHeight / 2, tPaint);
    }
    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double currX = 0, currY1 = 0, currY2 = 0;//???
        double nextX = 0, nextY1 = 0, nextY2 = 0;//??

        int kHeight = 0;

        for (int i = begin; i < (begin + count) && i < len; i++) {
            obv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(1);
            maobv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(2);

            startX = klineX;

            if ((i - begin) == 0) {
                currX = 0;
                currX = nextX = currX + startX + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((obv - min) * scale);
                currY1 = nextY1 = startY + volumeHeight - kHeight;
                kHeight = (int) ((maobv - min) * scale);
                currY2 = nextY2 = startY + volumeHeight - kHeight;
            } else {
                nextX = currX + spaceWidth + shapeWidth;
            }
            // obv
            kHeight = (int) ((obv - min) * scale);
            nextY1 = startY + volumeHeight - kHeight;
            paint.setColor(GlobalColor.colorM5);
            canvas.drawLine((int) currX, (int) currY1, (int) nextX, (int) nextY1, paint);

            // maobv
            kHeight = (int) ((maobv - min) * scale);
            nextY2 = startY + volumeHeight - kHeight;
            paint.setColor(GlobalColor.colorM10);
            canvas.drawLine((int) currX, (int) currY2, (int) nextX, (int) nextY2, paint);

            currX = nextX;
            currY1 = nextY1;
            currY2 = nextY2;

            if (i == (begin + count - 1)) {

            }
        } // end for
    } // end if
}