List of usage examples for android.graphics Canvas drawLine
public void drawLine(float startX, float startY, float stopX, float stopY, @NonNull Paint paint)
From source file:com.cssweb.android.view.PriceView.java
public void drawIndex(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);//from w w w .ja v a 2 s. c o m tPaint.setColor(GlobalColor.clrLine); tPaint.setStyle(Paint.Style.STROKE); tPaint.setStrokeWidth(1); this.x = 0; this.y = 0; startX = x + tips / 2; endX = width - tips / 2; canvas.drawRect(startX, DY + DY / 4, endX, height - DY / 4, tPaint); canvas.drawLine(startX, DY * 7 + DY / 2, endX, DY * 7 + DY / 2, tPaint); canvas.drawLine(startX, DY * 18 + DY / 4, endX, DY * 18 + DY / 4, tPaint); if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); double zrsp = jo.getDouble("zrsp"); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY * 2); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("???", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY * 1.5f); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(width, -DY * 15.5f); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("a"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("b"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("govbond"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("fund"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("warrant"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("bond"), true), x - tips, y, paint); double zjcj = jo.getDouble("zjcj"); setColor(paint, zjcj, zrsp); canvas.translate(0, DY * 1.5f); canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double jrkp = jo.getDouble("jrkp"); setColor(paint, jrkp, zrsp); canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorLabelName); canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint); double zhangd = jo.getDouble("zd"); if (zhangd < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangd > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY); String zhangdie = Utils.dataFormation(zhangd, stockdigit); if (zhangdie.equals("-")) canvas.drawText("", x - tips, y, paint); else canvas.drawText(zhangdie, x - tips, y, paint); double zhangf = jo.getDouble("zf"); if (zhangf < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangf > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY); String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit); if (zhangfu.equals("-")) canvas.drawText("", x - tips, y, paint); else canvas.drawText(zhangfu + "%", x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("amp") * 100, 1) + "%", x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjsl"), true), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint); canvas.translate(0, DY); double zg = jo.getDouble("zgcj"); setColor(paint, zg, zrsp); canvas.drawText(Utils.dataFormation(zg, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double zd = jo.getDouble("zdcj"); setColor(paint, zd, zrsp); canvas.drawText(Utils.dataFormation(zd, stockdigit), x - tips, y, paint); canvas.translate(-width, DY * 1.7f); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(width / 2, 0); canvas.drawText(String.valueOf(jo.getInt("zj")), x, y, paint); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(width / 2, 0); canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.tiange.hz.wheelview.widget.WheelView.java
/** * Draws rect for current value/*from ww w .j a va2s .com*/ * @param canvas the canvas for drawing */ private void drawCenterRect(Canvas canvas) { int center = getHeight() / 2; int offset = (int) (getItemHeight() / 2 * 1.2); if (centerDrawable != null) { centerDrawable.setBounds(0, center - offset, getWidth(), center + offset); centerDrawable.draw(canvas); } //dip2px if (wheelForegroundColor != Color.TRANSPARENT) { Paint paint = new Paint(); paint.setColor(wheelForegroundColor); paint.setStyle(Paint.Style.FILL); canvas.drawRect(new Rect(0, center - offset, getWidth(), center + offset), paint); } if (wheelForeDividerColor != Color.TRANSPARENT) { //wheelForeDividerWidth== Paint paint = new Paint(); paint.setColor(wheelForeDividerColor); canvas.drawLine(0, center - offset, getWidth(), center - offset, paint); canvas.drawLine(0, center + offset, getWidth(), center + offset, paint); } }
From source file:com.cssweb.android.view.PriceView.java
public void drawPrice(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; tPaint.setColor(GlobalColor.clrLine); tPaint.setStyle(Paint.Style.STROKE); tPaint.setStrokeWidth(1);/*from w ww . ja v a 2 s . co m*/ this.x = 0; this.y = 0; startX = x + tips / 2; endX = width - tips / 2; canvas.drawRect(startX, DY / 4, endX, height - DY / 4, tPaint); canvas.drawLine(startX, DY + DY / 4, endX, DY + DY / 4, tPaint); canvas.drawLine(startX, DY * 6 + DY / 4, endX, DY * 6 + DY / 4, tPaint); canvas.drawLine(startX, DY * 11 + DY / 4, endX, DY * 11 + DY / 4, tPaint); canvas.drawLine(startX, DY * 16 + DY / 4, endX, DY * 16 + DY / 4, tPaint); if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); String str = ""; double zrsp = jo.getDouble("zrsp"); canvas.translate(0, DY); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, 0); if (jo.getDouble("wb") < 0) paint.setColor(GlobalColor.colorPriceDown); else if (jo.getDouble("wb") > 0) paint.setColor(GlobalColor.colorpriceUp); else paint.setColor(GlobalColor.colorPriceEqual); if (jo.getInt("tp") == 1) canvas.drawText("", x, y, paint); else canvas.drawText(Utils.dataFormation(jo.getDouble("wb") * 100, 1) + "%", x, y, paint); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, 0); if (jo.getDouble("wc") < 0) { paint.setColor(GlobalColor.colorPriceDown); canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x - tips, y, paint); } else if (jo.getDouble("wc") > 0) { paint.setColor(GlobalColor.colorpriceUp); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x - tips, y, paint); } else { paint.setColor(GlobalColor.colorPriceEqual); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), false), x - tips, y, paint); } canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY * 4); for (int i = 5; i >= 1; i--) { double temp2 = jo.getDouble("sjw" + i); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp")); //paint.setTextAlign(Paint.Align.CENTER); canvas.drawText(str, x, y, paint); if (i != 1) canvas.translate(0, DY); } paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2, -DY * 4); for (int i = 5; i >= 1; i--) { paint.setTextAlign(Paint.Align.RIGHT); canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl" + i), false), x - tips, y, paint); if (i != 1) canvas.translate(0, DY); } canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(width / 2, -DY * 4); paint.setTextAlign(Paint.Align.RIGHT); for (int i = 1; i <= 5; i++) { double temp2 = jo.getDouble("bjw" + i); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp")); canvas.drawText(str, x, y, paint); if (i != 5) canvas.translate(0, DY); } paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2, -DY * 4); for (int i = 1; i <= 5; i++) { paint.setTextAlign(Paint.Align.RIGHT); canvas.drawText(Utils.getAmountFormat(jo.getInt("bsl" + i), false), x - tips, y, paint); if (i != 5) canvas.translate(0, DY); } canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); int syjd = jo.getInt("syjd"); switch (syjd) { case 1: canvas.drawText("()", x + tips, y, paint); break; case 2: canvas.drawText("()", x + tips, y, paint); break; case 3: canvas.drawText("()", x + tips, y, paint); break; case 4: canvas.drawText("()", x + tips, y, paint); break; default: canvas.drawText("()", x + tips, y, paint); break; } canvas.translate(width / 2, -DY * 7); paint.setTextAlign(Paint.Align.RIGHT); double zjcj = jo.getDouble("zjcj"); setColor(paint, zjcj, zrsp); canvas.drawText(Utils.dataFormation(zjcj, stockdigit, jo.getInt("tp")), x, y, paint); canvas.translate(0, DY); double zhangd = jo.getDouble("zd"); if (zhangd < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangd > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } String zhangdie = Utils.dataFormation(zhangd, stockdigit, jo.getInt("tp")); if (zhangdie.equals("-")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangdie, x, y, paint); double zhangf = jo.getDouble("zf"); if (zhangf < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangf > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY); String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit, jo.getInt("tp")); if (zhangfu.equals("-") || zhangfu.equals("")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangfu + "%", x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("hs") * 100, 1) + "%", x, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jz"), 1), x, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("mgsy"), 2), x, y, paint); canvas.translate(0, -DY * 7); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); if (NameRule.isBond(type)) canvas.drawText("", x + tips, y, paint); else canvas.drawText("PE()", x + tips, y, paint); canvas.translate(width / 2, -DY * 7); paint.setTextAlign(Paint.Align.RIGHT); double jrkp = jo.getDouble("jrkp"); setColor(paint, jrkp, zrsp); canvas.drawText(Utils.dataFormation(jrkp, stockdigit, jo.getInt("tp")), x - tips, y, paint); canvas.translate(0, DY); double zg = jo.getDouble("zgcj"); setColor(paint, zg, zrsp); canvas.drawText(Utils.dataFormation(zg, stockdigit, jo.getInt("tp")), x - tips, y, paint); canvas.translate(0, DY); double zd = jo.getDouble("zdcj"); setColor(paint, zd, zrsp); canvas.drawText(Utils.dataFormation(zd, stockdigit, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("gb"), true), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("ltsl") * 100, true), x - tips, y, paint); canvas.translate(0, DY); if (NameRule.isBond(type)) { canvas.drawText(Utils.dataFormation(jo.getDouble("fullprice"), 1), x - tips, y, paint); } else { canvas.drawText(Utils.dataFormation(jo.getDouble("sy"), 1), x - tips, y, paint); } } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:org.lucasr.dspec.DesignSpec.java
private void drawKeylines(Canvas canvas) { if (!mKeylinesVisible) { return;/* w w w. ja v a 2s . co m*/ } final int width = getIntrinsicWidth(); final int height = getIntrinsicHeight(); final int count = mKeylines.size(); for (int i = 0; i < count; i++) { final Keyline keyline = mKeylines.get(i); final float position; switch (keyline.from) { case LEFT: case TOP: position = keyline.position; break; case RIGHT: position = width - keyline.position; break; case BOTTOM: position = height - keyline.position; break; case VERTICAL_CENTER: position = (height / 2) + keyline.position; break; case HORIZONTAL_CENTER: position = (width / 2) + keyline.position; break; default: throw new IllegalStateException("Invalid keyline offset"); } switch (keyline.from) { case LEFT: case RIGHT: case HORIZONTAL_CENTER: canvas.drawLine(position, 0, position, height, mKeylinesPaint); break; case TOP: case BOTTOM: case VERTICAL_CENTER: canvas.drawLine(0, position, width, position, mKeylinesPaint); break; } } }
From source file:com.cssweb.android.view.PriceView.java
public void drawHKPrice(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; tPaint.setColor(GlobalColor.clrLine); tPaint.setStyle(Paint.Style.STROKE); tPaint.setStrokeWidth(1);/*www. j av a 2s. c o m*/ this.x = 0; this.y = 0; startX = x + tips / 2; endX = width - tips / 2; canvas.drawRect(startX, DY / 4, endX, height - DY / 4, tPaint); // canvas.drawLine(startX, DY+DY/4, endX, DY+DY/4, tPaint); canvas.drawLine(startX, DY * 5 + DY / 4, endX, DY * 5 + DY / 4, tPaint); canvas.drawLine(startX, DY * 10 + DY / 4, endX, DY * 10 + DY / 4, tPaint); canvas.drawLine(startX, DY * 16 + DY / 4, endX, DY * 16 + DY / 4, tPaint); if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); String str = ""; double zrsp = jo.getDouble("zrsp"); canvas.translate(0, DY); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true); paint.setTextSize(mTextSize); // paint.setTextAlign(Paint.Align.LEFT); // paint.setColor(GlobalColor.colorLabelName); // canvas.drawText("", x+tips, y, paint); // // paint.setTextAlign(Paint.Align.RIGHT); // canvas.translate(width/2, 0); // if(jo.getDouble("wb")<0) // paint.setColor(GlobalColor.colorPriceDown); // else if(jo.getDouble("wb")>0) // paint.setColor(GlobalColor.colorpriceUp); // else // paint.setColor(GlobalColor.colorPriceEqual); // canvas.drawText(Utils.dataFormation(jo.getDouble("wb")*100, 1)+"%", x, y, paint); // // paint.setTextAlign(Paint.Align.LEFT); // paint.setColor(GlobalColor.colorLabelName); // canvas.drawText("", x+tips, y, paint); // // paint.setTextAlign(Paint.Align.RIGHT); // canvas.translate(width/2, 0); // if(jo.getDouble("wc")<0) { // paint.setColor(GlobalColor.colorPriceDown); // canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x-tips, y, paint); // } // else if(jo.getDouble("wc")>0) { // paint.setColor(GlobalColor.colorpriceUp); // canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint); // } // else { // paint.setColor(GlobalColor.colorPriceEqual); // canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint); // } // // canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY * 4); for (int i = 5; i >= 1; i--) { double temp2 = jo.getDouble("sjw" + i); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp")); canvas.drawText(str, x, y, paint); if (i != 1) canvas.translate(0, DY); } paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2, -DY * 4); for (int i = 5; i >= 1; i--) { paint.setTextAlign(Paint.Align.RIGHT); canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl" + i), false), x - tips, y, paint); if (i != 1) canvas.translate(0, DY); } canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(width / 2, -DY * 4); paint.setTextAlign(Paint.Align.RIGHT); for (int i = 1; i <= 5; i++) { double temp2 = jo.getDouble("bjw" + i); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp")); canvas.drawText(str, x, y, paint); if (i != 5) canvas.translate(0, DY); } paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2, -DY * 4); for (int i = 1; i <= 5; i++) { paint.setTextAlign(Paint.Align.RIGHT); canvas.drawText(Utils.getAmountFormat(jo.getInt("bsl" + i), false), x - tips, y, paint); if (i != 5) canvas.translate(0, DY); } canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(width / 2, -DY * 6); paint.setTextAlign(Paint.Align.RIGHT); double zjcj = jo.getDouble("zjcj"); setColor(paint, zjcj, zrsp); canvas.drawText(Utils.dataFormation(zjcj, stockdigit, jo.getInt("tp")), x, y, paint); canvas.translate(0, DY); double zhangd = jo.getDouble("zd"); if (zhangd < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangd > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } String zhangdie = Utils.dataFormation(zhangd, stockdigit, jo.getInt("tp")); if (zhangdie.equals("-") || zhangdie.equals("")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangdie, x, y, paint); double zhangf = jo.getDouble("zf"); if (zhangf < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangf > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY); String zhangfu = Utils.dataFormation(zhangf * 100, 1, jo.getInt("tp")); if (zhangfu.equals("-") || zhangfu.equals("")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangfu + "%", x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("msgs"), true), x, y, paint); canvas.translate(0, -DY * 5); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); // canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(width / 2, -DY * 5); paint.setTextAlign(Paint.Align.RIGHT); double jrkp = jo.getDouble("jrkp"); setColor(paint, jrkp, zrsp); canvas.drawText(Utils.dataFormation(jrkp, stockdigit, jo.getInt("tp")), x - tips, y, paint); canvas.translate(0, DY); double zg = jo.getDouble("zgcj"); setColor(paint, zg, zrsp); canvas.drawText(Utils.dataFormation(zg, stockdigit, jo.getInt("tp")), x - tips, y, paint); canvas.translate(0, DY); double zd = jo.getDouble("zdcj"); setColor(paint, zd, zrsp); canvas.drawText(Utils.dataFormation(zd, stockdigit, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); // canvas.translate(0, DY); // canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.alimuzaffar.lib.widgets.PinEntryEditText.java
@Override protected void onDraw(Canvas canvas) { //super.onDraw(canvas); CharSequence text = getFullText(); int textLength = text.length(); float[] textWidths = new float[textLength]; getPaint().getTextWidths(text, 0, textLength, textWidths); for (int i = 0; i < mNumChars; i++) { //If a background for the pin characters is specified, it should be behind the characters. if (mPinBackground != null) { updateDrawableState(i < textLength, i == textLength); mPinBackground.setBounds((int) mLineCoords[i].left, (int) mLineCoords[i].top, (int) mLineCoords[i].right, (int) mLineCoords[i].bottom); mPinBackground.draw(canvas); }/*from ww w .j a v a2s. c om*/ if (textLength > i) { float middle = mLineCoords[i].left + mCharSize / 2; if (!mAnimate || i != textLength - 1) { canvas.drawText(text, i, i + 1, middle - textWidths[i] / 2, mCharBottom[i], mCharPaint); } else { canvas.drawText(text, i, i + 1, middle - textWidths[i] / 2, mCharBottom[i], mLastCharPaint); } } //The lines should be in front of the text (because that's how I want it). if (mPinBackground == null) { updateColorForLines(i <= textLength); canvas.drawLine(mLineCoords[i].left, mLineCoords[i].top, mLineCoords[i].right, mLineCoords[i].bottom, mLinesPaint); } } }
From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java
private void drawScale(Canvas canvas, Boolean Colors, int Count, int Max) { RectF faceRect = new RectF(); faceRect.set(10, 10, 190, 190);/*from w ww . ja va 2s . com*/ Paint scalePaint = new Paint(); scalePaint.setStyle(Paint.Style.STROKE); scalePaint.setColor(getResources().getColor(R.color.WarningGreen)); scalePaint.setStrokeWidth(1); scalePaint.setAntiAlias(true); scalePaint.setTextSize(12); scalePaint.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/chivo.ttf")); scalePaint.setTextAlign(Paint.Align.CENTER); float scalePosition = 10; RectF scaleRect = new RectF(); scaleRect.set(faceRect.left + scalePosition, faceRect.top + scalePosition, faceRect.right - scalePosition, faceRect.bottom - scalePosition); if (!Colors) scalePaint.setColor(Color.WHITE); scalePaint.setStrokeWidth(2); canvas.save(Canvas.MATRIX_SAVE_FLAG); for (int i = 0; i < Max; ++i) { if (Colors) { if (i > 20) scalePaint.setColor(getResources().getColor(R.color.WarningYellow)); if (i > 40) scalePaint.setColor(getResources().getColor(R.color.WarningOrange)); if (i > 60) scalePaint.setColor(getResources().getColor(R.color.WarningRed)); } canvas.drawLine(100, 20, 100, 18, scalePaint); int divisor = 5; if (Max > 100) divisor = 25; if (i % divisor == 0) { canvas.drawText(Integer.toString(i), 100, 16, scalePaint); } canvas.rotate((360.0f / Max), 100, 100); } canvas.restore(); }
From source file:com.dean.phonesafe.ui.SlideSwitch.java
@Override protected void onDraw(Canvas canvas) { if (shape == SHAPE_RECT) { paint.setColor(Color.GRAY); canvas.drawRect(backRect, paint); paint.setColor(color_theme);/*from www .j av a2 s . c o m*/ paint.setAlpha(alpha); canvas.drawRect(backRect, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight() - RIM_SIZE); paint.setColor(Color.WHITE); canvas.drawRect(frontRect, paint); } else { // draw circle int radius; radius = backRect.height() / 2 - RIM_SIZE; paint.setColor(Color.GRAY); backCircleRect.set(backRect); canvas.drawRoundRect(backCircleRect, radius, radius, paint); paint.setColor(color_theme); paint.setAlpha(alpha); canvas.drawRoundRect(backCircleRect, radius, radius, paint); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + backRect.height() - 2 * RIM_SIZE, backRect.height() - RIM_SIZE); frontCircleRect.set(frontRect); paint.setColor(Color.WHITE); canvas.drawRoundRect(frontCircleRect, radius, radius, paint); } //?? //? paint.setStrokeWidth(2); paint.setAlpha(alpha); paint.setStyle(Paint.Style.STROKE); float gap = backRect.width() - frontRect.width(); float left = frontRect.left - gap + frontRect.width() / 2; canvas.drawLine(left, backRect.height() / 4, left, backRect.height() / 4 * 3, paint); //?? paint.setAlpha(255 - alpha); left = frontRect.left + gap + frontRect.width() / 2; canvas.drawCircle(left, backRect.height() / 2, frontRect.width() / 5, paint); // paint.setStyle(Paint.Style.FILL); }
From source file:com.base.app.widget.indicatorview.TabPageIndicator.java
@Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); if (isInEditMode() || count == 0) { return;//from w w w. ja v a2 s . c o m } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = mTabLayout.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates between current and next tab if (currentPositionOffset > 0f && currentPosition < count - 1) { View nextTab = mTabLayout.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, mTabLayout.getWidth(), height, rectPaint); // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < count - 1; i++) { View tab = mTabLayout.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } }
From source file:com.orange.ocara.ui.view.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from w w w . j a v a2s . c o m } final int height = getHeight(); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, getWidth(), height, rectPaint); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } float tabsLeft = tabsContainer.getLeft(); canvas.drawRect(lineLeft + tabsLeft, height - indicatorHeight, lineRight + tabsLeft, height, rectPaint); // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } }