List of usage examples for org.json JSONObject isNull
public boolean isNull(String key)
From source file:com.commontime.plugin.LocationManager.java
private Region parseBeaconRegion(JSONObject json) throws JSONException, UnsupportedOperationException { String identifier = json.getString("identifier"); //For Android, uuid can be null when scanning for all beacons (I think) String uuid = json.has("uuid") && !json.isNull("uuid") ? json.getString("uuid") : null; String major = json.has("major") && !json.isNull("major") ? json.getString("major") : null; String minor = json.has("minor") && !json.isNull("minor") ? json.getString("minor") : null; if (major == null && minor != null) throw new UnsupportedOperationException("Unsupported combination of 'major' and 'minor' parameters."); Identifier id1 = uuid != null ? Identifier.parse(uuid) : null; Identifier id2 = major != null ? Identifier.parse(major) : null; Identifier id3 = minor != null ? Identifier.parse(minor) : null; return new Region(identifier, id1, id2, id3); }
From source file:com.cssweb.android.view.KlineView.java
public void initData(JSONObject quoteData) throws JSONException { if (!quoteData.isNull("K")) { this.quoteData = quoteData; this.actualDataLen = quoteData.getJSONArray("K").length(); if (quoteData.isNull("joTMP") && actualDataLen > 1) {//temp?? this.actualDataLen = quoteData.getJSONArray("K").length() - 1; } else {//from www . j av a2 s.c o m makeTodayData(); } } }
From source file:com.cssweb.android.view.KlineView.java
private void drawMA(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("MA")) { isNetworkErrorDisplay();//from ww w . ja v a 2 s . c om return; } int startX = klineX; int startY = klineY; double ma5Height = 0; double ma5x = 0; double ma5y = 0; double ma5 = 0; paint.setColor(GlobalColor.colorM5); for (int i = begin; i < (begin + count); i++) { //klineX = 0; ma5 = quoteData.getJSONArray("MA").getJSONArray(i).getDouble(1); if ((i - begin) == 0) { ma5x = startX + spaceWidth + shapeWidth / 2; ma5Height = (int) ((ma5 - lowPrice) * scale); ma5y = axisLabelHeight + klineHeight - ma5Height; } else { if (quoteData.getJSONArray("MA").getJSONArray(i - 1).getDouble(1) == 0) { ma5x = ma5x + spaceWidth + shapeWidth; ma5Height = (ma5 - lowPrice) * scale; ma5y = startY + klineHeight - ma5Height; } else { canvas.drawLine((float) ma5x, (float) ma5y, (float) (ma5x + spaceWidth + shapeWidth), (float) (axisLabelHeight + klineHeight - (ma5 - lowPrice) * scale), paint); ma5x = ma5x + spaceWidth + shapeWidth; ma5Height = (ma5 - lowPrice) * scale; ma5y = startY + klineHeight - ma5Height; } } } // end for double ma10x = 0; double ma10y = 0; double ma10Height = 0; double ma10 = 0; paint.setColor(GlobalColor.colorM10); for (int i = begin; i < (begin + count); i++) { //klineX = 0; ma10 = quoteData.getJSONArray("MA").getJSONArray(i).getDouble(2); if ((i - begin) == 0) { ma10x = startX + spaceWidth + shapeWidth / 2; ma10Height = (ma10 - lowPrice) * scale; ma10y = startY + klineHeight - ma10Height; } else { if (quoteData.getJSONArray("MA").getJSONArray(i - 1).getDouble(2) == 0) { ma10x = ma10x + spaceWidth + shapeWidth; ma10Height = (ma10 - lowPrice) * scale; ma10y = startY + klineHeight - ma10Height; } else { canvas.drawLine((float) ma10x, (float) ma10y, (float) (ma10x + spaceWidth + shapeWidth), (float) (axisLabelHeight + klineHeight - (ma10 - lowPrice) * scale), paint); ma10x = ma10x + spaceWidth + shapeWidth; ma10Height = (ma10 - lowPrice) * scale; ma10y = startY + klineHeight - ma10Height; } } } // end for double ma20x = 0; double ma20y = 0; double ma20Height = 0; double ma20 = 0; //paint.setColor(GlobalColor.colorM20); paint.setARGB(255, 255, 0, 255); for (int i = begin; i < (begin + count); i++) { //klineX = 0; ma20 = quoteData.getJSONArray("MA").getJSONArray(i).getDouble(3); if ((i - begin) == 0) { ma20x = startX + spaceWidth + shapeWidth / 2; ma20Height = (ma20 - lowPrice) * scale; ma20y = startY + klineHeight - ma20Height; } else { if (quoteData.getJSONArray("MA").getJSONArray(i - 1).getDouble(3) == 0) { ma20x = ma20x + spaceWidth + shapeWidth; ma20Height = (ma20 - lowPrice) * scale; ma20y = startY + klineHeight - ma20Height; } else { canvas.drawLine((float) ma20x, (float) ma20y, (float) (ma20x + spaceWidth + shapeWidth), (float) (axisLabelHeight + klineHeight - (ma20 - lowPrice) * scale), paint); ma20x = ma20x + spaceWidth + shapeWidth; ma20Height = (ma20 - lowPrice) * scale; ma20y = startY + klineHeight - ma20Height; } } } // end for double ma60x = 0; double ma60y = 0; double ma60Height = 0; double ma60 = 0; paint.setColor(GlobalColor.colorM60); for (int i = begin; i < (begin + count); i++) { //klineX = 0; ma60 = quoteData.getJSONArray("MA").getJSONArray(i).getDouble(4); if ((i - begin) == 0) { ma60x = startX + spaceWidth + shapeWidth / 2; ma60Height = (ma60 - lowPrice) * scale; ma60y = startY + klineHeight - ma60Height; } else { if (quoteData.getJSONArray("MA").getJSONArray(i - 1).getDouble(4) == 0) { ma60x = ma60x + spaceWidth + shapeWidth; ma60Height = (ma60 - lowPrice) * scale; ma60y = startY + klineHeight - ma60Height; } else { canvas.drawLine((float) ma60x, (float) ma60y, (float) (ma60x + spaceWidth + shapeWidth), (float) (axisLabelHeight + klineHeight - (ma60 - lowPrice) * scale), paint); ma60x = ma60x + spaceWidth + shapeWidth; ma60Height = (ma60 - lowPrice) * scale; ma60y = startY + klineHeight - ma60Height; } } } // end for }
From source file:com.cssweb.android.view.KlineView.java
private void drawBoll(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("BOLL")) { isNetworkErrorDisplay();//w w w . j a v a 2s . com return; } int startX = klineX; int startY = klineY; //double axisX = 0; double upperx = 0; double uppery = 0; double upperHeight = 0; double upper = 0; double lowerx = 0; double lowery = 0; double lowerHeight = 0; double lower = 0; double midx = 0; double midy = 0; double midHeight = 0; double mid = 0; int len = quoteData.getJSONArray("BOLL").length(); for (int i = begin; i < (begin + count) && i < len; i++) { //klineX = 0; if (quoteData.getJSONArray("BOLL").length() < i - 1) break; upper = quoteData.getJSONArray("BOLL").getJSONArray(i).getDouble(2); lower = quoteData.getJSONArray("BOLL").getJSONArray(i).getDouble(3); mid = quoteData.getJSONArray("BOLL").getJSONArray(i).getDouble(1); if ((i - begin) == 0) { upperx = startX + spaceWidth + shapeWidth / 2; upperHeight = (upper - lowPrice) * scale; uppery = startY + klineHeight - upperHeight; } else { if (quoteData.getJSONArray("BOLL").getJSONArray(i - 1).getDouble(2) == 0) { upperx = upperx + spaceWidth + shapeWidth; upperHeight = (upper - lowPrice) * scale; uppery = startY + klineHeight - upperHeight; } else { double x1 = upperx; double y1 = uppery; upperx = upperx + spaceWidth + shapeWidth; upperHeight = (upper - lowPrice) * scale; uppery = startY + klineHeight - upperHeight; paint.setColor(GlobalColor.colorM10); canvas.drawLine((float) x1, (float) y1, (float) upperx, (float) uppery, paint); } } if ((i - begin) == 0) { lowerx = startX + spaceWidth + shapeWidth / 2; lowerHeight = (lower - lowPrice) * scale; lowery = startY + klineHeight - lowerHeight; } else { if (quoteData.getJSONArray("BOLL").getJSONArray(i - 1).getDouble(3) == 0) { lowerx = lowerx + spaceWidth + shapeWidth; lowerHeight = (lower - lowPrice) * scale; lowery = startY + klineHeight - lowerHeight; } else { double x1 = lowerx; double y1 = lowery; lowerx = lowerx + spaceWidth + shapeWidth; lowerHeight = (lower - lowPrice) * scale; lowery = startY + klineHeight - lowerHeight; //paint.setColor(GlobalColor.colorM20); paint.setARGB(255, 255, 0, 255); canvas.drawLine((float) x1, (float) y1, (float) lowerx, (float) lowery, paint); } } if ((i - begin) == 0) { midx = startX + spaceWidth + shapeWidth / 2; midHeight = (mid - lowPrice) * scale; midy = startY + klineHeight - midHeight; } else { if (quoteData.getJSONArray("BOLL").getJSONArray(i - 1).getDouble(1) == 0) { midx = midx + spaceWidth + shapeWidth; midHeight = (mid - lowPrice) * scale; midy = startY + klineHeight - midHeight; } else { double x1 = midx; double y1 = midy; midx = midx + spaceWidth + shapeWidth; midHeight = (mid - lowPrice) * scale; midy = startY + klineHeight - midHeight; paint.setColor(GlobalColor.colorM5); canvas.drawLine((float) x1, (float) y1, (float) midx, (float) midy, paint); } } } }
From source file:com.cssweb.android.view.KlineView.java
public void drawVOLUME(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("MA")) { isNetworkErrorDisplay();/* w ww . ja va 2s . c om*/ return; } axisX = klineX; for (int i = begin; i < (begin + count); i++) { highVolume = Arith.max(highVolume, quoteData.getJSONArray("MA").getJSONArray(i).getDouble(5), quoteData.getJSONArray("MA").getJSONArray(i).getDouble(6)); } if (highVolume > 0) { scale = volumeHeight / highVolume; } else { scale = 999999; } double ratio = highVolume / rowNum; ratio = Math.round(ratio); String lblvalue = "12345", labelRatio = ""; String lbhighVolume = String.valueOf(Math.round(highVolume)); int ratiolen = lbhighVolume.length() - lblvalue.length(); double 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 = "x1"; scaleVol = 10000; break; case 5: labelRatio = "x1"; scaleVol = 1000000; break; case 6: labelRatio = "x1"; scaleVol = 1000000; break; default: labelRatio = "x1"; scaleVol = 1; break; } double AxisLabelVolume = 0; paint.setColor(GlobalColor.clrLine); tPaint.setTextAlign(Paint.Align.RIGHT); for (int i = 0; i <= rowNum; i++) { if (i == rowNum || i == 0) { canvas.drawLine(klineX, klineY + rowHeight * i, width, klineY + rowHeight * i, paint); } else { Graphics.drawDashline(canvas, klineX, klineY + rowHeight * i, width, klineY + rowHeight * i, paint); } if (i != rowNum && isTrackStatus == false) { AxisLabelVolume = Math.round(highVolume - ratio * i); if (i == 0) { tPaint.setColor(GlobalColor.colorTicklabel); canvas.drawText(Utils.dataFormation(Math.round(AxisLabelVolume / scaleVol), 0), klineX - tips / 4, klineY + rowHeight * i + axisLabelHeight / 2, tPaint); } else { tPaint.setColor(GlobalColor.colorTicklabel); canvas.drawText(Utils.dataFormation(Math.round(AxisLabelVolume / scaleVol), 0), klineX - tips / 4, klineY + rowHeight * i + axisLabelHeight / 2, tPaint); } } } if (isTrackStatus == false) { tPaint.setColor(GlobalColor.colorTicklabel); canvas.drawText(labelRatio, klineX - tips / 4, height - axisLabelHeight, tPaint); } // K if (quoteData != null) { for (int i = begin; i < (begin + count); i++) { if (i == 0) { drawVolumeKLine(canvas, i - begin, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1), quoteData.getJSONArray("K").getJSONArray(i).getDouble(4), quoteData.getJSONArray("K").getJSONArray(i).getDouble(5)); } else { drawVolumeKLine(canvas, i - begin, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1), quoteData.getJSONArray("K").getJSONArray(i).getDouble(4), quoteData.getJSONArray("K").getJSONArray(i).getDouble(5)); } if (i == (begin + count - 1)) { // Util.drawString(g2, labelVolume, "VOLUME:", css); } } drawVolumeMACD(canvas, quoteData, begin, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume); } }
From source file:com.cssweb.android.view.KlineView.java
private void drawVolumeMACD(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth, double spaceWidth, double highPrice, double lowPrice, double highVolume) throws JSONException { if (quoteData == null || quoteData.isNull("MA") || highVolume == 0) { //isNetworkErrorDisplay(); return;//from www .ja va2 s. co m } double avgPrice, x1 = 0, x2 = 0; int y1 = 0, y2 = 0; paint.setColor(GlobalColor.colorM5); for (int i = begin; i < begin + count; i++) { if (quoteData.getJSONArray("MA").length() < i) break; avgPrice = quoteData.getJSONArray("MA").getJSONArray(i).getDouble(5); y2 = (int) (avgPrice * scale); y2 = klineY + volumeHeight - y2; if (i < 4) { if (x2 == 0) { x2 = klineX + spaceWidth + shapeWidth / 2; x2 += (spaceWidth + shapeWidth) * (4 - i); } continue; } if (i == 4 && begin != 4) { x1 = x2; y1 = y2; continue; } if (i == begin) x2 = klineX + spaceWidth + shapeWidth / 2; else x2 = spaceWidth + shapeWidth + x2; if (i == begin) { x1 = x2; y1 = y2; } else { canvas.drawLine((int) Math.round(x1), y1, (int) Math.round(x2), y2, paint); x1 = x2; y1 = y2; } if (i == (begin + count - 1)) { // Util.drawString(g2, labelMaVol5, "MA5:"+avgPrice, cssMa5); } } paint.setColor(GlobalColor.colorM10); x2 = 0; for (int i = begin; i < begin + count; i++) { if (quoteData.getJSONArray("MA").length() < i) break; avgPrice = quoteData.getJSONArray("MA").getJSONArray(i).getDouble(6); y2 = (int) (avgPrice * scale); y2 = klineY + volumeHeight - y2; if (i < 9) { if (x2 == 0) { x2 = klineX + spaceWidth + shapeWidth / 2; x2 += (spaceWidth + shapeWidth) * (9 - i); } continue; } if (i == 9 && begin != 9) { x1 = x2; y1 = y2; continue; } if (i == begin) x2 = klineX + spaceWidth + shapeWidth / 2; else x2 = spaceWidth + shapeWidth + x2; if (i == begin) { x1 = x2; y1 = y2; } else { canvas.drawLine((int) Math.round(x1), y1, (int) Math.round(x2), y2, paint); x1 = x2; y1 = y2; } if (i == (begin + count - 1)) { // Util.drawString(g2, labelMaVol10, "MA10:"+avgPrice, cssMa10); } } // end for }
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 . ja v 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 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();// w w w . j a va 2s.c om 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 w w w . j a v a 2 s . co 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();//from w w w . j a v a 2 s.co 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 }