Example usage for android.graphics Canvas drawLine

List of usage examples for android.graphics Canvas drawLine

Introduction

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

Prototype

public void drawLine(float startX, float startY, float stopX, float stopY, @NonNull Paint paint) 

Source Link

Document

Draw a line segment with the specified start and stop x,y coordinates, using the specified paint.

Usage

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

/**
 * Draws a range crosshair./*from   w w w.  j av a2 s  .  c om*/
 * 
 * @param g2
 *            the graphics target.
 * @param dataArea
 *            the data area.
 * @param orientation
 *            the plot orientation.
 * @param value
 *            the crosshair value.
 * @param axis
 *            the axis against which the value is measured.
 * @param stroke
 *            the stroke used to draw the crosshair line.
 * @param paint
 *            the paint used to draw the crosshair line.
 * 
 * @since 1.0.4
 */
protected void drawRangeCrosshair(Canvas g2, Rectangle2D dataArea, PlotOrientation orientation, double value,
        ValueAxis axis, Float stroke, Paint paint) {

    if (axis.getRange().contains(value)) {
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            double xx = axis.valueToJava2D(value, dataArea, RectangleEdge.BOTTOM);
            line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY());
        } else {
            double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
            line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy);
        }
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(stroke);
        g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(),
                paint);
    }

}

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

public void drawBIAS(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("BIAS") || quoteData.getJSONArray("BIAS").length() < 1) {
        isNetworkErrorDisplay();// ww  w  .j  a v  a  2  s. c  o m
        return;
    }
    double max = 0.001;
    double min = -0.001;

    int len = quoteData.getJSONArray("BIAS").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        double bias1 = quoteData.getJSONArray("BIAS").getJSONArray(i).getDouble(1);
        double bias2 = quoteData.getJSONArray("BIAS").getJSONArray(i).getDouble(2);
        double bias3 = quoteData.getJSONArray("BIAS").getJSONArray(i).getDouble(3);

        if (bias1 > max)
            max = bias1;
        if (bias2 > max)
            max = bias2;
        if (bias3 > max)
            max = bias3;

        if (bias1 < 0) {
            if (bias1 < min)
                min = bias1;
        }
        if (bias2 < 0) {
            if (bias2 < min)
                min = bias2;
        }
        if (bias3 < 0) {
            if (bias3 < min)
                min = bias3;
        }
    }

    max = max + (max - min) * 0.1;
    min = min - (max - min) * 0.1;

    //double scale = this.volumeHeight / (max + Math.abs(min)) / 1.2;
    double scale = this.volumeHeight / (max - min);
    double lbl1value = max - (max - min) / 3;
    double lbl2value = max - (max - min) * 2 / 3;

    int startX = klineX;
    int startY = klineY;

    int axisY10 = (int) (startY + volumeHeight - (max - min) * scale);

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

    int axisY0 = (int) (startY + volumeHeight - (lbl1value - min) * scale);
    Graphics.drawDashline(canvas, startX, axisY0, width, axisY0, paint);

    int axisYM10 = (int) (startY + volumeHeight - (lbl2value - min) * scale);
    Graphics.drawDashline(canvas, startX, axisYM10, width, axisYM10, paint);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(Utils.dataFormation(max, stockdigit), startX - tips / 4, axisY10 + axisLabelHeight / 2,
                tPaint);
        canvas.drawText(Utils.dataFormation(lbl1value, stockdigit), startX - tips / 4,
                axisY0 + axisLabelHeight / 2, tPaint);
        canvas.drawText(Utils.dataFormation(lbl2value, stockdigit), startX - tips / 4,
                axisYM10 + axisLabelHeight / 2, tPaint);
    }
    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double axisX = 0;

        double bias1x = 0;
        double bias1y = 0;

        double bias2x = 0;
        double bias2y = 0;

        double bias3x = 0;
        double bias3y = 0;

        for (int i = begin; i < (begin + count); i++) {
            double bias1 = quoteData.getJSONArray("BIAS").getJSONArray(i).getDouble(1);
            double bias2 = quoteData.getJSONArray("BIAS").getJSONArray(i).getDouble(2);
            double bias3 = quoteData.getJSONArray("BIAS").getJSONArray(i).getDouble(3);

            double bias1Height = 0;
            double bias2Height = 0;
            double bias3Height = 0;

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

            if ((i - begin) == 0) {
                bias1x = bias1x + startX + spaceWidth + shapeWidth / 2;
                bias1Height = (bias1 + Math.abs(min)) * scale;
                bias1y = startY + volumeHeight - bias1Height;
            } else {
                double x1 = bias1x;
                double y1 = bias1y;

                bias1x = bias1x + spaceWidth + shapeWidth;
                bias1Height = (bias1 + Math.abs(min)) * scale;
                bias1y = startY + volumeHeight - bias1Height;

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

            if ((i - begin) == 0) {
                bias2x = bias2x + startX + spaceWidth + shapeWidth / 2;
                bias2Height = (bias2 + Math.abs(min)) * scale;
                bias2y = startY + volumeHeight - bias2Height;
            } else {
                double x1 = bias2x;
                double y1 = bias2y;

                bias2x = bias2x + spaceWidth + shapeWidth;
                bias2Height = (bias2 + Math.abs(min)) * scale;
                bias2y = startY + volumeHeight - bias2Height;

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

            if ((i - begin) == 0) {
                bias3x = bias3x + startX + spaceWidth + shapeWidth / 2;
                bias3Height = (bias3 + Math.abs(min)) * scale;
                bias3y = startY + volumeHeight - bias3Height;
            } else {
                double x1 = bias3x;
                double y1 = bias3y;

                bias3x = bias3x + spaceWidth + shapeWidth;

                bias3Height = (bias3 + Math.abs(min)) * scale;
                bias3y = startY + volumeHeight - bias3Height;

                //paint.setColor(GlobalColor.colorM20);
                paint.setARGB(255, 255, 0, 255);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias3x), (int) bias3y, paint);
            }

            if (i == (begin + count - 1)) {
                //labelDif.text = "BIAS6:" + Utils.StockFormat(exchange+stockCode, bias1);
                //labelDea.text = "BIAS12:" + Utils.StockFormat(exchange+stockCode, bias2);
                //labelMacd.text = "BIAS24:" + Utils.StockFormat(exchange+stockCode, bias3);
            }
        } // end for
    } // end if
}

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

private void drawMACD(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {
    if (quoteData == null || quoteData.isNull("MACD")) {
        isNetworkErrorDisplay();/*from w w w  .  jav  a  2  s.c o m*/
        return;
    }
    double max = 0.001;
    double min = -0.001;
    int len = quoteData.getJSONArray("MACD").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        double dif = quoteData.getJSONArray("MACD").getJSONArray(i).getDouble(1);
        double dea = quoteData.getJSONArray("MACD").getJSONArray(i).getDouble(2);
        double macd = quoteData.getJSONArray("MACD").getJSONArray(i).getDouble(3);

        if (dif > max)
            max = dif;
        if (dea > max)
            max = dea;
        if (macd > max)
            max = macd;

        if (dif < 0) {
            if (dif < min)
                min = dif;
        }
        if (dea < 0) {
            if (dea < min)
                min = dea;
        }
        if (macd < 0) {
            if (macd < min)
                min = macd;
        }
    }

    max = max + (max - min) * 0.1;
    min = min - (max - min) * 0.1;
    if (max <= 0) {
        max = -min / 5;
    }
    max = Math.max(max, 0);

    double scale = this.volumeHeight / (max - min);
    double lbl1value = max - (max - min) / 3;
    double lbl2value = max - (max - min) * 2 / 3;

    if (Math.abs(lbl1value) < Math.abs(lbl2value)) {
        lbl1value = 0;
    } else {
        lbl2value = 0;
    }
    int startX = klineX;
    int startY = klineY;

    int axisY10 = (int) (startY + volumeHeight - (max - min) * scale);

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

    int axisY0 = (int) (startY + volumeHeight - (lbl1value - min) * scale);
    Graphics.drawDashline(canvas, startX, axisY0, width, axisY0, paint);

    int axisYM10 = (int) (startY + volumeHeight - (lbl2value - min) * scale);
    Graphics.drawDashline(canvas, startX, axisYM10, width, axisYM10, paint);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(Utils.dataFormation(max, stockdigit), startX - tips / 4, axisY10 + axisLabelHeight / 2,
                tPaint);
        canvas.drawText(Utils.dataFormation(lbl1value, stockdigit), startX - tips / 4,
                axisY0 + axisLabelHeight / 2, tPaint);
        canvas.drawText(Utils.dataFormation(lbl2value, stockdigit), startX - tips / 4,
                axisYM10 + axisLabelHeight / 2, tPaint);
    }
    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double axisX = klineX;

        double dif = 0, dea = 0, macd = 0, difx1 = 0, difx2 = 0, deax1 = 0, deax2 = 0;
        int dify1 = 0, dify2 = 0, deay1 = 0, deay2 = 0;
        for (int i = begin; i < (begin + count) && i < len; i++) {
            dif = quoteData.getJSONArray("MACD").getJSONArray(i).getDouble(1);
            dea = quoteData.getJSONArray("MACD").getJSONArray(i).getDouble(2);
            macd = quoteData.getJSONArray("MACD").getJSONArray(i).getDouble(3);

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

            if ((i - begin) == 0) {
                difx2 = difx2 + klineX + spaceWidth + shapeWidth / 2;
                dify2 = (int) (startY + volumeHeight - (dif - min) * scale);
            } else {
                difx1 = difx2;
                dify1 = dify2;
                difx2 = difx2 + spaceWidth + shapeWidth;
                dify2 = (int) (startY + volumeHeight - (dif - min) * scale);

                paint.setColor(GlobalColor.colorM5);
                canvas.drawLine((float) difx1, (float) dify1, (float) difx2, (float) dify2, paint);
            }

            if ((i - begin) == 0) {
                deax2 = deax2 + klineX + spaceWidth + shapeWidth / 2;
                deay2 = (int) (startY + volumeHeight - (dea - min) * scale);
            } else {
                deax1 = deax2;
                deay1 = deay2;
                deax2 = deax2 + spaceWidth + shapeWidth;
                deay2 = (int) (startY + volumeHeight - (dea - min) * scale);

                paint.setColor(GlobalColor.colorM10);
                canvas.drawLine((float) deax1, (float) deay1, (float) deax2, (float) deay2, paint);
            }

            if (macd >= 0) {
                paint.setColor(GlobalColor.colorKdown);
                canvas.drawLine((int) (axisX + shapeWidth / 2),
                        (int) (startY + volumeHeight - (0 - min) * scale), (int) (axisX + shapeWidth / 2),
                        (int) (startY + volumeHeight - (macd - min) * scale), paint);
            } else {
                paint.setARGB(255, 84, 255, 255);
                canvas.drawLine((int) (axisX + shapeWidth / 2),
                        (int) (startY + volumeHeight - (0 - min) * scale), (int) (axisX + shapeWidth / 2),
                        (int) (startY + volumeHeight - (macd - min) * scale), paint);
            }

            if (i == (begin + count - 1)) {
                //
            }
        } // end for
    } // end if
}

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

public void drawRSI(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("RSI") || quoteData.getJSONArray("RSI").length() < 1) {
        isNetworkErrorDisplay();/*from  www. j av  a 2s .  co m*/
        return;
    }

    double max = 100.0;
    double min = 0.0;

    int len = quoteData.getJSONArray("RSI").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        double k = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(1);
        double d = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(2);
        double j = quoteData.getJSONArray("RSI").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;
        }
    }
    double scale = this.volumeHeight / (max + 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 = "";
    if (zs)
        axisLabel1 = "100.00";
    else
        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);

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

    if (quoteData != null) {
        double axisX = klineX;

        double bias1x = klineX;
        double bias1y = 0;

        double bias2x = klineX;
        double bias2y = 0;

        double bias3x = klineX;
        double bias3y = 0;

        for (int i = begin; i < (begin + count); i++) {
            double rsi1 = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(1);
            double rsi2 = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(2);
            double rsi3 = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(3);

            double bias1Height = 0;
            double bias2Height = 0;
            double bias3Height = 0;

            bias1Height = scale * rsi1;
            bias2Height = scale * rsi2;
            bias3Height = scale * rsi3;

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

            if ((i - begin) == 0) {
                bias1x = bias1x + spaceWidth + shapeWidth / 2;
                bias1y = height - axisLabelHeight - bias1Height;
            } else {
                double x1 = bias1x;
                double y1 = bias1y;

                bias1x = bias1x + spaceWidth + shapeWidth;

                bias1y = height - axisLabelHeight - bias1Height;

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

            if ((i - begin) == 0) {
                bias2x = bias2x + spaceWidth + shapeWidth / 2;
                bias2y = height - axisLabelHeight - bias2Height;
            } else {
                double x1 = bias2x;
                double y1 = bias2y;
                bias2x = bias2x + spaceWidth + shapeWidth;
                bias2y = height - axisLabelHeight - bias2Height;
                paint.setColor(GlobalColor.colorM10);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias2x), (int) bias2y, paint);
            }

            if ((i - begin) == 0) {
                bias3x = bias3x + spaceWidth + shapeWidth / 2;
                bias3y = height - axisLabelHeight - bias3Height;
            } else {
                double x1 = bias3x;
                double y1 = bias3y;
                bias3x = bias3x + spaceWidth + shapeWidth;
                bias3y = height - axisLabelHeight - bias3Height;
                paint.setARGB(255, 255, 0, 255);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias3x), (int) bias3y, paint);
            }

            if (i == (begin + count - 1)) {
                //labelDif.text = "RSI6:" + Utils.StockFormat(exchange+stockCode, rsi1);
                //labelDea.text = "RSI12:" + Utils.StockFormat(exchange+stockCode, rsi2);
                //labelMacd.text = "RSI24:" + Utils.StockFormat(exchange+stockCode, rsi3);
            }
        } // end for
    } // end if
}

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

public void drawRSI(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("RSI") || quoteData.getJSONArray("RSI").length() < 1) {
        isNetworkErrorDisplay();//from   w w w  .j  a va  2 s. c o  m
        return;
    }

    double max = 100.0;
    double min = 0.0;

    int len = quoteData.getJSONArray("RSI").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        double k = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(1);
        double d = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(2);
        double j = quoteData.getJSONArray("RSI").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;
        }
    }
    double scale = this.volumeHeight / (max + 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 = "";
    if (zs)
        axisLabel1 = "100.00";
    else
        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);

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

    if (quoteData != null) {
        double axisX = klineX;

        double bias1x = klineX;
        double bias1y = 0;

        double bias2x = klineX;
        double bias2y = 0;

        double bias3x = klineX;
        double bias3y = 0;

        for (int i = begin; i < (begin + count); i++) {
            double rsi1 = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(1);
            double rsi2 = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(2);
            double rsi3 = quoteData.getJSONArray("RSI").getJSONArray(i).getDouble(3);

            double bias1Height = 0;
            double bias2Height = 0;
            double bias3Height = 0;

            bias1Height = scale * rsi1;
            bias2Height = scale * rsi2;
            bias3Height = scale * rsi3;

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

            if ((i - begin) == 0) {
                bias1x = bias1x + spaceWidth + shapeWidth / 2;
                bias1y = height - axisLabelHeight - bias1Height;
            } else {
                double x1 = bias1x;
                double y1 = bias1y;

                bias1x = bias1x + spaceWidth + shapeWidth;

                bias1y = height - axisLabelHeight - bias1Height;

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

            if ((i - begin) == 0) {
                bias2x = bias2x + spaceWidth + shapeWidth / 2;
                bias2y = height - axisLabelHeight - bias2Height;
            } else {
                double x1 = bias2x;
                double y1 = bias2y;
                bias2x = bias2x + spaceWidth + shapeWidth;
                bias2y = height - axisLabelHeight - bias2Height;
                paint.setColor(GlobalColor.colorM10);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias2x), (int) bias2y, paint);
            }

            if ((i - begin) == 0) {
                bias3x = bias3x + spaceWidth + shapeWidth / 2;
                bias3y = height - axisLabelHeight - bias3Height;
            } else {
                double x1 = bias3x;
                double y1 = bias3y;
                bias3x = bias3x + spaceWidth + shapeWidth;
                bias3y = height - axisLabelHeight - bias3Height;
                paint.setARGB(255, 255, 0, 255);
                canvas.drawLine((int) Math.round(x1), (int) y1, (int) Math.round(bias3x), (int) bias3y, paint);
            }

            if (i == (begin + count - 1)) {
                //labelDif.text = "RSI6:" + Utils.StockFormat(exchange+stockCode, rsi1);
                //labelDea.text = "RSI12:" + Utils.StockFormat(exchange+stockCode, rsi2);
                //labelMacd.text = "RSI24:" + Utils.StockFormat(exchange+stockCode, rsi3);
            }
        } // end for
    } // end if
}

From source file:com.cssweb.android.view.KlineView.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();/*w  w  w.j  a v  a2 s .  c o  m*/
        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 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  w w w  .  jav a 2  s.  c  o  m
        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.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 ww .  j av  a2s  .c om*/

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