Example usage for org.json JSONObject getJSONArray

List of usage examples for org.json JSONObject getJSONArray

Introduction

In this page you can find the example usage for org.json JSONObject getJSONArray.

Prototype

public JSONArray getJSONArray(String key) throws JSONException 

Source Link

Document

Get the JSONArray value associated with a key.

Usage

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

public void drawCCI(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("CCI") || quoteData.getJSONArray("CCI").length() < 1) {
        isNetworkErrorDisplay();//from w  ww . j  a  v  a 2s.  com
        return;
    }

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

    double max = 0.001;
    double min = -0.001;
    for (int i = begin; i < (begin + count); i++) {
        double cci = quoteData.getJSONArray("CCI").getJSONArray(i).getDouble(1);
        max = Math.max(cci, max);
        min = Math.min(cci, min);
    }

    double scale = this.volumeHeight / (Math.max(100, max) + Math.max(Math.abs(min), 100));

    int axisY100 = (int) (klineY + volumeHeight - (100 + Math.abs(min)) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, klineX, axisY100, width, axisY100, paint);

    int axisY0 = (int) (klineY + volumeHeight - (0 + Math.abs(min)) * scale);
    Graphics.drawDashline(canvas, klineX, axisY0, width, axisY0, paint);

    int axisYM100 = (int) (klineY + volumeHeight - (Math.abs(min) - 100) * scale);
    Graphics.drawDashline(canvas, klineX, axisYM100, width, axisYM100, paint);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText("100.00", klineX - tips / 4, axisY100 + axisLabelHeight / 2, tPaint);
        canvas.drawText("0.00", klineX - tips / 4, axisY0 + axisLabelHeight / 2, tPaint);
        canvas.drawText("-100.00", klineX - tips / 4, axisYM100 + axisLabelHeight / 2, tPaint);
    }
    canvas.drawLine(klineX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

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

        //double deax = 0;
        //double jx = 0;

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

        paint.setColor(GlobalColor.colorM5);
        for (int i = begin; i < (begin + count); i++) {
            double cci = quoteData.getJSONArray("CCI").getJSONArray(i).getDouble(1);

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

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

                canvas.drawLine((int) x1, y1, (int) difx, ky, paint);
            }

            if (i == (begin + count - 1)) {
                //labelDif.text = "CCI:" + Utils.StockFormat(exchange+stockCode, cci);
            }
        } // end for
    } // end if
}

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();//from   ww w.j av  a2s  . 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

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

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

private void drawTimeAix(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {
    String quoteTime = "";
    double apX = klineX;

    int n = 0;//  w  ww .j  a  v  a2 s  .  co m
    tPaint.setColor(GlobalColor.colorLabelName);
    tPaint.setTextAlign(Paint.Align.LEFT);
    for (int i = begin; i < (begin + count); i++, n++) {
        quoteTime = quoteData.getJSONArray("K").getJSONArray(i).getString(0);
        if (i == begin) {// ??
            canvas.drawText(quoteTime, (float) apX, height - axisLabelHeight / 4, tPaint);
        } else { // ???
            if (i == begin + count - 1)
                canvas.drawText(quoteTime, (float) (width - tPaint.measureText(quoteTime)),
                        height - axisLabelHeight / 4, tPaint);
        }
    }
}

From source file:nl.spellenclubeindhoven.dominionshuffle.Application.java

public void loadResult() {
    try {/*from   w w  w  .ja  va 2 s.  c  o  m*/
        JSONObject jsonResult = new JSONObject(DataReader.readStringFromFile(this, "result.json"));

        JSONArray jsonCards = jsonResult.getJSONArray("cards");
        LinkedList<Card> cards = new LinkedList<Card>();

        for (int i = 0; i < jsonCards.length(); i++) {
            Card card = dataReader.getData().getCard(jsonCards.getString(i));
            if (card == null)
                return;
            cards.add(card);
        }

        Card baneCard = null;
        Card obeliskCard = null;
        if (jsonResult.has("baneCard")) {
            baneCard = dataReader.getData().getCard(jsonResult.getString("baneCard"));
        }
        if (jsonResult.has("obeliskCard")) {
            obeliskCard = dataReader.getData().getCard(jsonResult.getString("obeliskCard"));
        }

        result = new Result();
        result.setCards(cards);
        result.setBaneCard(baneCard);
        result.setObeliskCard(obeliskCard);
    } catch (JSONException ignore) {
        ignore.printStackTrace();
    }
}

From source file:net.mandaria.radioreddit.apis.RadioRedditAPI.java

public static RadioSong GetCurrentSongInformation(Context context, RadioRedditApplication application) {
    RadioSong radiosong = new RadioSong();
    radiosong.ErrorMessage = "";

    try {/*ww  w .j  av  a2s . c  o  m*/
        String status_url = context.getString(R.string.radio_reddit_base_url) + application.CurrentStream.Status
                + context.getString(R.string.radio_reddit_status);

        String outputStatus = "";
        boolean errorGettingStatus = false;

        try {
            outputStatus = HTTPUtil.get(context, status_url);
        } catch (Exception ex) {
            ex.printStackTrace();
            errorGettingStatus = true;
            // For now, not used. It is acceptable to error out and not alert the user
            // radiosong.ErrorMessage = context.getString(R.string.error_RadioRedditServerIsDownNotification);
        }

        if (!errorGettingStatus && outputStatus.length() > 0) {
            JSONTokener status_tokener = new JSONTokener(outputStatus);
            JSONObject status_json = new JSONObject(status_tokener);

            radiosong.Playlist = status_json.getString("playlist");

            JSONObject songs = status_json.getJSONObject("songs");
            JSONArray songs_array = songs.getJSONArray("song");

            // get the first song in the array
            JSONObject song = songs_array.getJSONObject(0);
            radiosong.ID = song.getInt("id");
            radiosong.Title = song.getString("title");
            radiosong.Artist = song.getString("artist");
            radiosong.Redditor = song.getString("redditor");
            radiosong.Genre = song.getString("genre");
            radiosong.CumulativeScore = song.getString("score");

            if (radiosong.CumulativeScore.equals("{}"))
                radiosong.CumulativeScore = null;

            radiosong.Reddit_title = song.getString("reddit_title");
            radiosong.Reddit_url = song.getString("reddit_url");
            if (song.has("preview_url"))
                radiosong.Preview_url = song.getString("preview_url");
            if (song.has("download_url"))
                radiosong.Download_url = song.getString("download_url");
            if (song.has("bandcamp_link"))
                radiosong.Bandcamp_link = song.getString("bandcamp_link");
            if (song.has("bandcamp_art"))
                radiosong.Bandcamp_art = song.getString("bandcamp_art");
            if (song.has("itunes_link"))
                radiosong.Itunes_link = song.getString("itunes_link");
            if (song.has("itunes_art"))
                radiosong.Itunes_art = song.getString("itunes_art");
            if (song.has("itunes_price"))
                radiosong.Itunes_price = song.getString("itunes_price");

            // get vote score 
            String reddit_info_url = context.getString(R.string.reddit_link_by)
                    + URLEncoder.encode(radiosong.Reddit_url);

            String outputRedditInfo = "";
            boolean errorGettingRedditInfo = false;

            try {
                outputRedditInfo = HTTPUtil.get(context, reddit_info_url);
            } catch (Exception ex) {
                ex.printStackTrace();
                errorGettingRedditInfo = true;
                // For now, not used. It is acceptable to error out and not alert the user
                // radiosong.ErrorMessage = "Unable to connect to reddit";//context.getString(R.string.error_RadioRedditServerIsDownNotification);
            }

            if (!errorGettingRedditInfo && outputRedditInfo.length() > 0) {
                // Log.e("radio_reddit_test", "Length: " + outputRedditInfo.length());
                // Log.e("radio_reddit_test", "Value: " + outputRedditInfo); // TODO: sometimes the value contains "error: 404", need to check for that. (We can probably safely ignore this for now)
                JSONTokener reddit_info_tokener = new JSONTokener(outputRedditInfo);
                JSONObject reddit_info_json = new JSONObject(reddit_info_tokener);

                JSONObject data = reddit_info_json.getJSONObject("data");

                // default value of score
                String score = context.getString(R.string.vote_to_submit_song);
                String likes = "null";
                String name = "";

                JSONArray children_array = data.getJSONArray("children");

                // Song hasn't been submitted yet
                if (children_array.length() > 0) {
                    JSONObject children = children_array.getJSONObject(0);

                    JSONObject children_data = children.getJSONObject("data");
                    score = children_data.getString("score");

                    likes = children_data.getString("likes");
                    name = children_data.getString("name");
                }

                radiosong.Score = score;
                radiosong.Likes = likes;
                radiosong.Name = name;
            } else {
                radiosong.Score = "?";
                radiosong.Likes = "null";
                radiosong.Name = "";
            }

            return radiosong;
        }
        return null;
    } catch (Exception ex) {
        // We fail to get the current song information...
        CustomExceptionHandler ceh = new CustomExceptionHandler(context);
        ceh.sendEmail(ex);

        ex.printStackTrace();
        radiosong.ErrorMessage = ex.toString();
        return radiosong;
    }
}