List of usage examples for android.graphics Canvas drawText
public void drawText(@NonNull String text, float x, float y, @NonNull Paint paint)
From source file:com.cssweb.android.view.KlineView.java
public void drawQuoteWin(Canvas canvas, JSONObject quoteData, int idx) throws JSONException { Paint mPaint = new Paint(); mPaint.setTextAlign(Paint.Align.LEFT); mPaint.setStyle(Paint.Style.STROKE); mPaint.setTypeface(Typeface.DEFAULT_BOLD); mPaint.setAntiAlias(true);//from w w w. j a va 2 s. c om mPaint.setColor(GlobalColor.colorKlinePopub); mPaint.setTextSize(sTextSize); canvas.drawText(":", 0, axisLabelHeight, mPaint); canvas.drawText(":", 0, axisLabelHeight * 3, mPaint); canvas.drawText(":", 0, axisLabelHeight * 5, mPaint); canvas.drawText(":", 0, axisLabelHeight * 7, mPaint); canvas.drawText(":", 0, axisLabelHeight * 9, mPaint); canvas.drawText(":", 0, axisLabelHeight * 11, mPaint); canvas.drawText("??:", 0, axisLabelHeight * 13, mPaint); canvas.drawText("??:", 0, axisLabelHeight * 15, mPaint); mPaint.setTextAlign(Paint.Align.RIGHT); String qt = quoteData.getJSONArray("K").getJSONArray(idx).getString(0); double jrkp = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(1); double zg = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(2); double zd = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(3); double sp = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(4); double preclose; if ("cf".equals(exchange) || "dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)) { switch (idx) { case 0: preclose = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(7); break; default: preclose = quoteData.getJSONArray("K").getJSONArray(idx - 1).getDouble(7); break; } if (quoteData.getJSONArray("K").length() == 1) { preclose = quoteData.getJSONArray("K").getJSONArray(0).getDouble(7); } } else { switch (idx) { case 0: preclose = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(4); break; default: preclose = quoteData.getJSONArray("K").getJSONArray(idx - 1).getDouble(4); break; } if (quoteData.getJSONArray("K").length() == 1) { preclose = quoteData.getDouble("zrsp");//quoteData.getJSONArray("K").getJSONArray(0).getDouble(4); } } mPaint.setColor(getcolor(jrkp, preclose)); canvas.drawText(Utils.dataFormation(jrkp, stockdigit), klineX, axisLabelHeight * 2, mPaint); mPaint.setColor(getcolor(zg, preclose)); canvas.drawText(Utils.dataFormation(zg, stockdigit), klineX, axisLabelHeight * 4, mPaint); mPaint.setColor(getcolor(zd, preclose)); canvas.drawText(Utils.dataFormation(zd, stockdigit), klineX, axisLabelHeight * 6, mPaint); mPaint.setColor(getcolor(sp, preclose)); canvas.drawText(Utils.dataFormation(sp, stockdigit), klineX, axisLabelHeight * 8, mPaint); double zhangdie = sp - preclose; if (zhangdie > 0) mPaint.setColor(GlobalColor.colorpriceUp); else if (zhangdie < 0) mPaint.setColor(GlobalColor.colorPriceDown); else mPaint.setColor(GlobalColor.colorPriceEqual); canvas.drawText(Utils.dataFormation(zhangdie, stockdigit), klineX, axisLabelHeight * 10, mPaint); // if(quoteData.getString("period").equals("min5") || // quoteData.getString("period").equals("min15") || // quoteData.getString("period").equals("min30") || // quoteData.getString("period").equals("min60")){ // qt = qt.substring(4,6)+'/'+qt.substring(6,8)+' '+qt.substring(8); // }else{ // qt = qt.substring(2,4)+qt.substring(4,6)+qt.substring(6,8); // } qt = qt.substring(2, 4) + qt.substring(4, 6) + qt.substring(6, 8); mPaint.setColor(GlobalColor.colorLabelName); canvas.drawText(qt, klineX, axisLabelHeight * 12, mPaint); mPaint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(quoteData.getJSONArray("K").getJSONArray(idx).getDouble(5), false), klineX, axisLabelHeight * 14, mPaint); mPaint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(quoteData.getJSONArray("K").getJSONArray(idx).getDouble(6), false), klineX, axisLabelHeight * 16, mPaint); }
From source file:com.tbse.mywearapplication.WatchFaceDrawer.java
void onDraw(Context context, IWatchFaceConfig config, Canvas canvas, Rect bounds) { final Calendar calendar = config.getCalendar(); final boolean isAmbient = config.isAmbient(); final boolean isRound = config.isRound(); final boolean useLightTheme = !isAmbient && config.isLightTheme(); mBackgroundPaint.setColor(ContextCompat.getColor(context, useLightTheme ? R.color.watchface_background_light : R.color.watchface_background)); ///////////////////////////////////////////////////////////////////// // Draw your watch face here, using the provided canvas and bounds // ///////////////////////////////////////////////////////////////////// final int width = bounds.width(); final int height = bounds.height(); // Find the center. Ignore the window insets so that, on round // watches with a "chin", the watch face is centered on the entire // screen, not just the usable portion. final float centerX = width / 2f; final float centerY = height / 2f; // Draw the background. if (mIsMobilePreview) { if (isRound) { canvas.drawCircle(centerX, centerY, centerX, mPreviewBorderPaint); } else {/*ww w . j a v a 2 s.c o m*/ final float radius = mPreviewSquareRadius; final RectF rectF = new RectF(0, 0, canvas.getWidth(), canvas.getHeight()); canvas.drawRoundRect(rectF, radius, radius, mPreviewBorderPaint); } final float translateXY = width * 0.05f; canvas.translate(translateXY, translateXY); canvas.scale(0.9f, 0.9f); if (isRound) { canvas.drawCircle(centerX, centerY, centerX, mBackgroundPaint); } else { canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint); } } else { canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint); } // Draw weather icon if (image != null) { Matrix matrix = new Matrix(); matrix.setTranslate(50, 90); matrix.preScale(0.2f, 0.2f); canvas.drawBitmap(image, matrix, null); } final float secRot = calendar.get(Calendar.SECOND) / 30f * (float) Math.PI; final int minutes = calendar.get(Calendar.MINUTE); final float minRot = minutes / 30f * (float) Math.PI; final float hrRot = ((calendar.get(Calendar.HOUR) + (minutes / 60f)) / 6f) * (float) Math.PI; final float secLength = centerX - mSecondOuterOffset; final float minLength = centerX - mMinuteOuterOffset; final float hrLength = centerX - mHourOuterOffset; if (!isAmbient) { final float secX = (float) Math.sin(secRot) * secLength; final float secY = (float) -Math.cos(secRot) * secLength; canvas.drawLine(centerX, centerY, centerX + secX, centerY + secY, mSecondHandPaint); } final float minX = (float) Math.sin(minRot) * minLength; final float minY = (float) -Math.cos(minRot) * minLength; canvas.drawLine(centerX, centerY, centerX + minX, centerY + minY, mMinuteHandPaint); final float hrX = (float) Math.sin(hrRot) * hrLength; final float hrY = (float) -Math.cos(hrRot) * hrLength; canvas.drawLine(centerX, centerY, centerX + hrX, centerY + hrY, mHourHandPaint); // Draw weather text canvas.drawText(day, 50, 50, isAmbient ? ambientTextPaint : textPaint); canvas.drawText(low, 50, 65, isAmbient ? ambientTextPaint : textPaint); canvas.drawText(high, 80, 65, isAmbient ? ambientTextPaint : textPaint); canvas.drawText(weatherDescription, 50, 80, isAmbient ? ambientTextPaint : textPaint); }
From source file:de.treichels.hott.ui.android.html.AndroidCurveImageGenerator.java
private Bitmap getBitmap(final Curve curve, final float scale, final boolean description) { final boolean pitchCurve = curve.getPoint()[0].getPosition() == 0; final float scale1 = scale * 0.75f; // smaller images on the android // platform/*from ww w .ja v a 2 s. c o m*/ final Bitmap image = Bitmap.createBitmap((int) (10 + 200 * scale1), (int) (10 + 250 * scale1), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(image); final Paint backgroundPaint = new Paint(); backgroundPaint.setColor(Color.WHITE); backgroundPaint.setStyle(Style.FILL); final Paint forgroundPaint = new Paint(); forgroundPaint.setColor(Color.BLACK); forgroundPaint.setStyle(Style.STROKE); forgroundPaint.setStrokeWidth(1.0f); forgroundPaint.setStrokeCap(Cap.BUTT); forgroundPaint.setStrokeJoin(Join.ROUND); forgroundPaint.setStrokeMiter(0.0f); final Paint curvePaint = new Paint(forgroundPaint); curvePaint.setFlags(Paint.ANTI_ALIAS_FLAG); curvePaint.setStrokeWidth(2.0f); final Paint pointPaint = new Paint(curvePaint); pointPaint.setStrokeWidth(5.0f); pointPaint.setStyle(Style.FILL_AND_STROKE); final Paint helpLinePaint = new Paint(forgroundPaint); helpLinePaint.setColor(Color.GRAY); helpLinePaint.setPathEffect(new DashPathEffect(new float[] { 5.0f, 5.0f }, 2.5f)); final Paint textPaint = new Paint(forgroundPaint); textPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); textPaint.setTextSize(12.0f); textPaint.setTextAlign(Align.CENTER); textPaint.setStyle(Style.FILL); canvas.drawRect(0, 0, 10 + 200 * scale1, 10 + 250 * scale1, backgroundPaint); canvas.drawRect(5, 5, 5 + 200 * scale1, 5 + 250 * scale1, forgroundPaint); canvas.drawLine(5, 5 + 25 * scale1, 5 + 200 * scale1, 5 + 25 * scale1, helpLinePaint); canvas.drawLine(5, 5 + 225 * scale1, 5 + 200 * scale1, 5 + 225 * scale1, helpLinePaint); if (!pitchCurve) { canvas.drawLine(5, 5 + 125 * scale1, 5 + 200 * scale1, 5 + 125 * scale1, helpLinePaint); canvas.drawLine(5 + 100 * scale1, 5, 5 + 100 * scale1, 5 + 250 * scale1, helpLinePaint); } if (curve.getPoint() != null) { int numPoints = 0; for (final CurvePoint p : curve.getPoint()) { if (p.isEnabled()) { numPoints++; } } final double[] xVals = new double[numPoints]; final double[] yVals = new double[numPoints]; int i = 0; for (final CurvePoint p : curve.getPoint()) { if (p.isEnabled()) { if (i == 0) { xVals[i] = pitchCurve ? 0 : -100; } else if (i == numPoints - 1) { xVals[i] = 100; } else { xVals[i] = p.getPosition(); } yVals[i] = p.getValue(); if (description) { float x0; float y0; if (pitchCurve) { x0 = (float) (5 + xVals[i] * 2 * scale1); y0 = (float) (5 + (225 - yVals[i] * 2) * scale1); } else { x0 = (float) (5 + (100 + xVals[i]) * scale1); y0 = (float) (5 + (125 - yVals[i]) * scale1); } canvas.drawPoint(x0, y0, pointPaint); if (y0 < 5 + 125 * scale1) { canvas.drawRect(x0 - 4, y0 + 5, x0 + 3, y0 + 18, backgroundPaint); canvas.drawText(Integer.toString(p.getNumber() + 1), x0 - 1, y0 + 16, textPaint); } else { canvas.drawRect(x0 - 4, y0 - 5, x0 + 3, y0 - 18, backgroundPaint); canvas.drawText(Integer.toString(p.getNumber() + 1), x0 - 1, y0 - 7, textPaint); } } i++; } } if (numPoints > 2 && curve.isSmoothing()) { final SplineInterpolator s = new SplineInterpolator(); final PolynomialSplineFunction function = s.interpolate(xVals, yVals); float x0 = 5; float y0; if (pitchCurve) { y0 = (float) (5 + (225 - yVals[0] * 2) * scale1); } else { y0 = (float) (5 + (125 - yVals[0]) * scale1); } while (x0 < 4 + 200 * scale1) { final float x1 = x0 + 1; float y1; if (pitchCurve) { y1 = (float) (5 + (225 - function.value((x1 - 5) / scale1 / 2) * 2) * scale1); } else { y1 = (float) (5 + (125 - function.value((x1 - 5) / scale1 - 100)) * scale1); } canvas.drawLine(x0, y0, x1, y1, curvePaint); x0 = x1; y0 = y1; } } else { for (i = 0; i < numPoints - 1; i++) { float x0, y0, x1, y1; if (pitchCurve) { x0 = (float) (5 + xVals[i] * 2 * scale1); y0 = (float) (5 + (225 - yVals[i] * 2) * scale1); x1 = (float) (5 + xVals[i + 1] * 2 * scale1); y1 = (float) (5 + (225 - yVals[i + 1] * 2) * scale1); } else { x0 = (float) (5 + (100 + xVals[i]) * scale1); y0 = (float) (5 + (125 - yVals[i]) * scale1); x1 = (float) (5 + (100 + xVals[i + 1]) * scale1); y1 = (float) (5 + (125 - yVals[i + 1]) * scale1); } canvas.drawLine(x0, y0, x1, y1, curvePaint); } } } return image; }
From source file:info.bartowski.easteregg.MLand.java
@Override public void onDraw(Canvas c) { super.onDraw(c); if (SHOW_TOUCHES) { for (Player p : mPlayers) { if (p.mTouchX > 0) { mTouchPaint.setColor(0x80FFFFFF & p.color); mPlayerTracePaint.setColor(0x80FFFFFF & p.color); float x1 = p.mTouchX; float y1 = p.mTouchY; c.drawCircle(x1, y1, 100, mTouchPaint); float x2 = p.getX() + p.getPivotX(); float y2 = p.getY() + p.getPivotY(); float angle = PI_2 - (float) Math.atan2(x2 - x1, y2 - y1); x1 += 100 * Math.cos(angle); y1 += 100 * Math.sin(angle); c.drawLine(x1, y1, x2, y2, mPlayerTracePaint); }//from www . j av a2 s . c o m } } if (!DEBUG_DRAW) return; final Paint pt = new Paint(); pt.setColor(0xFFFFFFFF); for (Player p : mPlayers) { final int L = p.corners.length; final int N = L / 2; for (int i = 0; i < N; i++) { final int x = (int) p.corners[i * 2]; final int y = (int) p.corners[i * 2 + 1]; c.drawCircle(x, y, 4, pt); c.drawLine(x, y, p.corners[(i * 2 + 2) % L], p.corners[(i * 2 + 3) % L], pt); } } pt.setStyle(Paint.Style.STROKE); pt.setStrokeWidth(getResources().getDisplayMetrics().density); final int M = getChildCount(); pt.setColor(0x8000FF00); for (int i = 0; i < M; i++) { final View v = getChildAt(i); if (v instanceof Player) continue; if (!(v instanceof GameView)) continue; if (v instanceof Pop) { final Pop pop = (Pop) v; c.drawCircle(pop.cx, pop.cy, pop.r, pt); } else { final Rect r = new Rect(); v.getHitRect(r); c.drawRect(r, pt); } } pt.setColor(Color.BLACK); final StringBuilder sb = new StringBuilder("obstacles: "); for (Obstacle ob : mObstaclesInPlay) { sb.append(ob.hitRect.toShortString()); sb.append(" "); } pt.setTextSize(20f); c.drawText(sb.toString(), 20, 100, pt); }
From source file:com.cssweb.android.view.KlineMini.java
public void onDraw(Canvas canvas) { paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(1);/*from w ww.j a v a 2s . c o m*/ tPaint = new Paint(); tPaint.setStyle(Paint.Style.STROKE); tPaint.setTypeface(Typeface.DEFAULT_BOLD); tPaint.setAntiAlias(true); tPaint.setTextSize(dTextSize); // tips = (int) tPaint.measureText("0"); try { if (actualDataLen == 0) { return; } if (zs) axisLabelWidth = (int) Math.max(tPaint.measureText("99999.99"), tPaint.measureText("11000")); else axisLabelWidth = (int) tPaint.measureText("11000"); klineWidth = width - axisLabelWidth; //?spaceWidth??? visualKLineCount = (int) ((klineWidth - spaceWidth) / (spaceWidth + shapeWidth)); if (isSingleMoved == false && isTrackStatus == false) { if (actualDataLen > visualKLineCount) { actualPos = actualDataLen - visualKLineCount; count = visualKLineCount; } else { actualPos = 0; count = actualDataLen; } } calcMaxMin(actualPos); if (!isTrackStatus) { moveQuote(actualDataLen - 1); } else { if (trackLineV == 0) { trackLineV = (int) (visualPos * (spaceWidth + shapeWidth) - shapeWidth / 2); isTrackNumber = actualPos + visualPos - 1; } if (isTrackNumber < 0) { isTrackNumber = 0; } else if (isTrackNumber > actualDataLen - 1) { isTrackNumber = actualDataLen - 1; } paint.setColor(GlobalColor.clrGrayLine); canvas.drawLine(klineX + trackLineV, axisLabelHeight, klineX + trackLineV, height - axisLabelHeight, paint); moveQuote(isTrackNumber); drawQuoteWin(canvas, quoteData, isTrackNumber); } // axisLabelHeight = Font.getFontHeight(dTextSize); klineX = axisLabelWidth; klineY = axisLabelHeight; klineHeight = height - axisLabelHeight * 2; axisX = klineX; // tPaint.setTextAlign(Paint.Align.LEFT); tPaint.setColor(GlobalColor.colorM5); canvas.drawText(lblIndicatorName, (float) (klineX + shapeWidth), axisLabelHeight - 5, tPaint); float size = tPaint.measureText(lblIndicatorName) + tips; tPaint.setColor(GlobalColor.colorM10); canvas.drawText(lblIndicatorT1, (float) (klineX + shapeWidth + size), axisLabelHeight - 5, tPaint); size += tPaint.measureText(lblIndicatorT1) + tips; if (size <= (klineWidth - tPaint.measureText(lblIndicatorT2))) { //tPaint.setColor(GlobalColor.colorM20); tPaint.setARGB(255, 255, 0, 255); canvas.drawText(lblIndicatorT2, (float) (klineX + shapeWidth + size), axisLabelHeight - 5, tPaint); } size += tPaint.measureText(lblIndicatorT2) + tips; if (size <= (klineWidth - tPaint.measureText(lblIndicatorT3))) { tPaint.setColor(GlobalColor.colorM60); canvas.drawText(lblIndicatorT3, (float) (klineX + shapeWidth + size), axisLabelHeight - 5, tPaint); } //??? rowHeight = klineHeight / rowNum; scale = klineHeight / (highPrice - lowPrice); double ratio = (highPrice - lowPrice) / rowNum; paint.setColor(GlobalColor.clrLine); tPaint.setColor(GlobalColor.colorTicklabel); tPaint.setTextAlign(Paint.Align.RIGHT); for (int i = 0; i <= rowNum; i++) { if (i == rowNum || i == 0) { canvas.drawLine(klineX, klineY + rowHeight * i, width, klineY + rowHeight * i, paint); } else { Graphics.drawDashline(canvas, klineX, klineY + rowHeight * i, width, klineY + rowHeight * i, paint); } if (i != rowNum && isTrackStatus == false) { double AxisLabelPrice = highPrice - ratio * i; String AxisLabelPriceText; if (zs) { AxisLabelPriceText = Utils.dataFormation(Math.round(AxisLabelPrice), 0); } else { AxisLabelPriceText = Utils.dataFormation(AxisLabelPrice, stockdigit); } canvas.drawText(AxisLabelPriceText, klineX - tips / 4, klineY + rowHeight * i + axisLabelHeight / 2, tPaint); } } // if (quoteData != null) { //axisX = 0; for (int i = actualPos; i < (actualPos + count); i++) { if (i == 0) drawKLine(canvas, i - actualPos, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1), quoteData.getJSONArray("K").getJSONArray(i).getDouble(2), quoteData.getJSONArray("K").getJSONArray(i).getDouble(3), quoteData.getJSONArray("K").getJSONArray(i).getDouble(4), quoteData.getJSONArray("K").getJSONArray(i).getDouble(4)); else drawKLine(canvas, i - actualPos, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1), quoteData.getJSONArray("K").getJSONArray(i).getDouble(2), quoteData.getJSONArray("K").getJSONArray(i).getDouble(3), quoteData.getJSONArray("K").getJSONArray(i).getDouble(4), quoteData.getJSONArray("K").getJSONArray(i - 1).getDouble(4)); } if (mainIndicatorType.toUpperCase().equals("MA")) drawMA(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen); drawTimeAix(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen); } //????? paint.setColor(GlobalColor.clrLine); canvas.drawLine(klineX, 0, width, 0, paint); canvas.drawLine(klineX, 0, klineX, height - axisLabelHeight, paint); canvas.drawLine(width, 0, width, height - axisLabelHeight, paint); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.hxsn.witwork.ui.ViewfinderView.java
@Override public void onDraw(Canvas canvas) { // ??????CameraManager? if (CameraManager.get() == null) { return;//from w w w. j a v a 2 s. c o m } Rect frame = CameraManager.get().getFramingRect(); if (frame == null) { return; } // ? if (!isFirst) { isFirst = true; slideTop = frame.top; slideBottom = frame.bottom; } // ?? int width = canvas.getWidth(); int height = canvas.getHeight(); paint.setColor(resultBitmap != null ? resultColor : maskColor); // ????????????? // ????????? canvas.drawRect(0, 0, width, frame.top + 15, paint); canvas.drawRect(0, frame.top + 15, frame.left + 15, frame.bottom - 14, paint); canvas.drawRect(frame.right - 14, frame.top + 15, width, frame.bottom - 14, paint); canvas.drawRect(0, frame.bottom - 14, width, height, paint); if (resultBitmap != null) { // Draw the opaque result bitmap over the scanning rectangle paint.setAlpha(OPAQUE); canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint); } else { // ??8 paint.setColor(Color.rgb(139, 193, 17)); canvas.drawRect(frame.left, frame.top, frame.left + ScreenRate, frame.top + CORNER_WIDTH, paint); canvas.drawRect(frame.left, frame.top, frame.left + CORNER_WIDTH, frame.top + ScreenRate, paint); canvas.drawRect(frame.right - ScreenRate, frame.top, frame.right, frame.top + CORNER_WIDTH, paint); canvas.drawRect(frame.right - CORNER_WIDTH, frame.top, frame.right, frame.top + ScreenRate, paint); canvas.drawRect(frame.left, frame.bottom - CORNER_WIDTH, frame.left + ScreenRate, frame.bottom, paint); canvas.drawRect(frame.left, frame.bottom - ScreenRate, frame.left + CORNER_WIDTH, frame.bottom, paint); canvas.drawRect(frame.right - ScreenRate, frame.bottom - CORNER_WIDTH, frame.right, frame.bottom, paint); canvas.drawRect(frame.right - CORNER_WIDTH, frame.bottom - ScreenRate, frame.right, frame.bottom, paint); // ,??SPEEN_DISTANCE slideTop += SPEEN_DISTANCE; if (slideTop >= frame.bottom) { slideTop = frame.top; } // canvas.drawRect(frame.left + MIDDLE_LINE_PADDING, slideTop - // MIDDLE_LINE_WIDTH/2, frame.right - MIDDLE_LINE_PADDING,slideTop + // MIDDLE_LINE_WIDTH/2, paint); Rect lineRect = new Rect(); lineRect.left = frame.left; lineRect.right = frame.right; lineRect.top = slideTop; lineRect.bottom = slideTop + 18; canvas.drawBitmap(((BitmapDrawable) (getResources().getDrawable(R.drawable.fgx))).getBitmap(), null, lineRect, paint); // ??? paint.setColor(Color.WHITE); paint.setTextSize(TEXT_SIZE * density); // paint.setAlpha(0x40); // paint.setTypeface(Typeface.create("System", Typeface.BOLD)); canvas.drawText("?/??????", frame.left, (float) (frame.bottom + (float) TEXT_PADDING_TOP * density), paint); canvas.drawText("??" + num + "", frame.left, (float) (frame.bottom + (float) TEXT_PADDING_TOP * density + 50), paint); int max = 7; if (name.size() < max) { max = name.size(); for (int i = 0; i < max; i++) { canvas.drawText(name.get(i), frame.left, (float) (frame.bottom + (float) TEXT_PADDING_TOP * density + 100 + 50 * i), paint); } } else { for (int i = 6; i >= 0; i--) { canvas.drawText(name.get((name.size() - 1) - (6 - i)), frame.left, (float) (frame.bottom + (float) TEXT_PADDING_TOP * density + 100 + 50 * i), paint); } } paint.setStyle(Style.STROKE); canvas.drawRect(frame.left + 15, frame.top + 15, frame.right - 15, frame.bottom - 15, paint); setViewY(frame.bottom); paint.setStyle(Style.FILL); Collection<ResultPoint> currentPossible = possibleResultPoints; Collection<ResultPoint> currentLast = lastPossibleResultPoints; if (currentPossible.isEmpty()) { lastPossibleResultPoints = null; } else { possibleResultPoints = new HashSet<ResultPoint>(5); lastPossibleResultPoints = currentPossible; paint.setAlpha(OPAQUE); paint.setColor(resultPointColor); for (ResultPoint point : currentPossible) { canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, paint); } } if (currentLast != null) { paint.setAlpha(OPAQUE / 2); paint.setColor(resultPointColor); for (ResultPoint point : currentLast) { canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 3.0f, paint); } } // ???? postInvalidate(); // postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, // frame.right, frame.bottom); } }
From source file:com.cssweb.android.view.TrendView.java
private void drawChart(Canvas canvas) throws JSONException { Log.i("@@@@@@@@@draw tick@@@@@@@@@@", quoteArray + ">>>>>>>>>"); //Log.i("@@@@@@@@@@@@@@@@@@@", quoteArray.length()+">>>>>>>>>"); if (quoteArray == null || quoteArray.isNull(0)) return;/*from ww w .j a v a 2 s . c o m*/ canvas.drawColor(GlobalColor.clearSCREEN); paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(1); mpaint = new Paint(); mpaint.setTypeface(Typeface.DEFAULT_BOLD); mpaint.setAntiAlias(true); mpaint.setTextAlign(Paint.Align.LEFT); mpaint.setStyle(Paint.Style.STROKE); mpaint.setTextSize(dTextSize); /** * ? */ closeLeft = Utils.dataFormation(high, stockdigit); closeRight = "00.00%"; LSpace = (int) (Math.max(mpaint.measureText(closeLeft), mpaint.measureText(String.valueOf(Math.round(highvolume))))); //??? //RSpace = (int)(paint.measureText(closeRight) + 10); RSpace = 0; axisLabelHeight = Font.getFontHeight(dTextSize); graphicsQuoteWidth = width - LSpace - RSpace; SPACE = graphicsQuoteWidth / MINUTES; topTitleHeight = axisLabelHeight; graphicsQuoteHeight = height - axisLabelHeight - topTitleHeight; price_row_num = 2;//(int)graphicsQuoteHeight/3/25; volume_row_num = price_row_num; price_row_height = graphicsQuoteHeight / price_row_num / 3; volume_row_height = price_row_height; calc_zf(); title1 = ":"; title7 = ":"; title8 = quoteArray.getJSONArray(isTrackNumber).getString(3); title2 = Utils.dataFormation(quoteArray.getJSONArray(isTrackNumber).getDouble(0), stockdigit); mpaint.setColor(GlobalColor.colorLabelName); canvas.drawText(title7 + title8.substring(11, 16), LSpace, axisLabelHeight - 5, mpaint); canvas.drawText(title1, LSpace + mpaint.measureText(":00:0000"), axisLabelHeight - 5, mpaint); if (quoteArray.getJSONArray(isTrackNumber).getDouble(0) == 0) { mpaint.setColor(GlobalColor.colorPriceEqual); } else if (quoteArray.getJSONArray(isTrackNumber).getDouble(0) > close) { mpaint.setColor(GlobalColor.colorpriceUp); } else if (quoteArray.getJSONArray(isTrackNumber).getDouble(0) < close) { mpaint.setColor(GlobalColor.colorPriceDown); } else { mpaint.setColor(GlobalColor.colorPriceEqual); } canvas.drawText(title2, LSpace + mpaint.measureText(":00:0000:"), axisLabelHeight - 5, mpaint); if (!this.isZs()) { if ("cf".equals(exchange) || "dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange) || "hk".equals(exchange)) { } else { mpaint.setColor(GlobalColor.colorLabelName); title9 = "?:"; canvas.drawText(title9, LSpace + mpaint.measureText(":00:000000:" + title2), axisLabelHeight - 5, mpaint); double avePrice = 0; double cjje = quoteArray.getJSONArray(isTrackNumber).getDouble(2); int scaleCount = 1; scaleCount = Utils.getCoefficient(exchange, stockcode); double cjsl = quoteArray.getJSONArray(isTrackNumber).getDouble(1) * scaleCount; if (cjsl > 0) { avePrice = cjje / cjsl; } else { avePrice = jrkp; } if (avePrice == 0) { mpaint.setColor(GlobalColor.colorPriceEqual); } else if (avePrice > close) { mpaint.setColor(GlobalColor.colorpriceUp); } else if (avePrice < close) { mpaint.setColor(GlobalColor.colorPriceDown); } else { mpaint.setColor(GlobalColor.colorPriceEqual); } canvas.drawText(Utils.dataFormation(avePrice, stockdigit), LSpace + mpaint.measureText(":00:000000:" + title2 + "?:"), axisLabelHeight - 5, mpaint); } } if (isZs()) { if (close == 0) close = 1000; } else { if (close == 0) close = 1; } low = Math.min(low, close); //upPrice = close * (1+max_zf); //downPrice = close * (1-max_zf); paint.setColor(GlobalColor.clrLine); canvas.drawLine(LSpace + graphicsQuoteWidth, topTitleHeight, LSpace + graphicsQuoteWidth, graphicsQuoteHeight + topTitleHeight, paint); // upQuoteX = LSpace; upQuoteY = topTitleHeight; upQuoteWidth = (int) graphicsQuoteWidth; upQuoteHeight = price_row_num * price_row_height; for (int i = 0; i < price_row_num; i++) { if (i == 0) { canvas.drawLine(upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth, upQuoteY + price_row_height * i, paint); } else Graphics.drawDashline(canvas, upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth, upQuoteY + price_row_height * i, paint); } for (int i = 0; i < DIVIDE_COUNT; i++) { if (i == 0) { canvas.drawLine(upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY, upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint); } else Graphics.drawDashline(canvas, upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY, upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint); } //scale = close * max_zf / price_row_num; scale = Arith.div(close * max_zf, price_row_num, stockdigit + 1); mpaint.setTextAlign(Paint.Align.RIGHT); mpaint.setColor(GlobalColor.colorPriceEqual); canvas.drawText(Utils.dataFormation(close, stockdigit), upQuoteX, upQuoteY + upQuoteHeight + axisLabelHeight / 2, mpaint); mpaint.setColor(GlobalColor.colorpriceUp); for (int i = 1; i <= price_row_num; i++) { AxisLabelPrice = close + scale * i; canvas.drawText(Utils.dataFormation(AxisLabelPrice, stockdigit), upQuoteX, upQuoteY + upQuoteHeight - price_row_height * i + axisLabelHeight / 2, mpaint); } // downQuoteX = LSpace; downQuoteY = topTitleHeight + upQuoteHeight; downQuoteWidth = (int) graphicsQuoteWidth; downQuoteHeight = upQuoteHeight; paint.setColor(GlobalColor.clrLine); for (int i = 0; i < price_row_num; i++) { if (i == 0) { canvas.drawLine(downQuoteX, downQuoteY + price_row_height * i, downQuoteX + downQuoteWidth, downQuoteY + price_row_height * i, paint); } else Graphics.drawDashline(canvas, downQuoteX, downQuoteY + price_row_height * i, downQuoteX + downQuoteWidth, downQuoteY + price_row_height * i, paint); } for (int i = 0; i < DIVIDE_COUNT; i++) { if (i == 0) { canvas.drawLine(downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY, downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight + 1, paint); } else Graphics.drawDashline(canvas, downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY, downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight, paint); } mpaint.setColor(GlobalColor.colorPriceDown); for (int i = 1; i < price_row_num; i++) { AxisLabelPrice = close - scale * i; canvas.drawText(Utils.dataFormation(AxisLabelPrice, stockdigit), upQuoteX, upQuoteY + upQuoteHeight + price_row_height * i + axisLabelHeight / 2, mpaint); } // // added by hujun for 20110511??? if (actualDataLen > 0 && !this.isOpenFund()) { if ("cf".equals(exchange) || "dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)) { scale = upQuoteHeight / (close * max_zf); paint.setColor(GlobalColor.colorFZLine); int quotelen = quoteArray.length(); double x1 = 0; double y1 = 0; double x2 = 0; double y2 = 0; double temp = 0; x1 = upQuoteX; double lastnewp = 0; double nownewp = 0; nownewp = quoteArray.getJSONArray(0).getDouble(0); if (nownewp == 0) nownewp = close; if (nownewp >= close) { temp = (nownewp - close) * scale; y1 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - nownewp) * scale; y1 = topTitleHeight + upQuoteHeight + temp; } lastnewp = nownewp; for (int i = 1; i < quotelen; i++) { x2 = upQuoteX + SPACE * i; nownewp = quoteArray.getJSONArray(i).getDouble(0); if (nownewp == 0) nownewp = lastnewp; if (nownewp >= close) { temp = (nownewp - close) * scale; y2 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - nownewp) * scale; y2 = topTitleHeight + upQuoteHeight + temp; } lastnewp = nownewp; canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); x1 = x2; y1 = y2; } // end for paint.setColor(GlobalColor.colorFZAvePriceLine); x1 = upQuoteX; double cjje = quoteArray.getJSONArray(0).getDouble(0); double avePrice = cjje; double lastavg = 0; if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y1 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y1 = topTitleHeight + upQuoteHeight + temp; } lastavg = avePrice; double xl = quoteArray.getJSONArray(0).getDouble(1); double mathpjj = quoteArray.getJSONArray(0).getDouble(0) * xl; for (int i = 1; i < quotelen; i++) { x2 = upQuoteX + SPACE * i; mathpjj += quoteArray.getJSONArray(i).getDouble(0) * (quoteArray.getJSONArray(i).getDouble(1) - quoteArray.getJSONArray(i - 1).getDouble(1)); if (mathpjj == 0) { if (lastavg == 0) { avePrice = close; } else { avePrice = lastavg; } } else { avePrice = mathpjj / quoteArray.getJSONArray(i).getDouble(1); } lastavg = avePrice; if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y2 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y2 = topTitleHeight + upQuoteHeight + temp; } canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); x1 = x2; y1 = y2; } // end for } else { scale = upQuoteHeight / (close * max_zf); paint.setColor(GlobalColor.colorFZLine); int quotelen = quoteArray.length(); double x1 = 0; double y1 = 0; double x2 = 0; double y2 = 0; double temp = 0; x1 = upQuoteX; double lastnewp = 0; double nownewp = 0; nownewp = quoteArray.getJSONArray(0).getDouble(0); if (nownewp == 0) nownewp = close; if (nownewp >= close) { temp = (nownewp - close) * scale; y1 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - nownewp) * scale; y1 = topTitleHeight + upQuoteHeight + temp; } lastnewp = nownewp; for (int i = 1; i < quotelen; i++) { x2 = upQuoteX + SPACE * i; nownewp = quoteArray.getJSONArray(i).getDouble(0); if (nownewp == 0) nownewp = lastnewp; if (nownewp >= close) { temp = (nownewp - close) * scale; y2 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - nownewp) * scale; y2 = topTitleHeight + upQuoteHeight + temp; } lastnewp = nownewp; canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); x1 = x2; y1 = y2; } // end for if (this.isZs()) { // ? ?? if ("sz".equals(exchange) || "sh".equals(exchange)) { if (("000001".equals(stockcode) || "399001".equals(stockcode)) && !quoteData.isNull("data2")) { paint.setColor(GlobalColor.colorFZAvePriceLine); x1 = upQuoteX; double avePrice = quoteData.getJSONArray("data2").getJSONArray(0).getDouble(0); if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y1 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y1 = topTitleHeight + upQuoteHeight + temp; } int len = quoteData.getJSONArray("data2").length(); for (int i = 1; i < len; i++) { if ("15:00".equals(quoteData.getJSONArray("data2").getJSONArray(i).getString(1) .substring(11, 16))) { } else { x2 = upQuoteX + SPACE * i; avePrice = quoteData.getJSONArray("data2").getJSONArray(i).getDouble(0); if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y2 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y2 = topTitleHeight + upQuoteHeight + temp; } canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); x1 = x2; y1 = y2; } } // end for } else { paint.setColor(GlobalColor.colorFZAvePriceLine); x1 = upQuoteX; double cjje = quoteArray.getJSONArray(0).getDouble(0); double avePrice = cjje; double lastavg = 0; if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y1 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y1 = topTitleHeight + upQuoteHeight + temp; } lastavg = avePrice; double xl = quoteArray.getJSONArray(0).getDouble(1); double mathpjj = quoteArray.getJSONArray(0).getDouble(0) * xl; for (int i = 1; i < quotelen; i++) { x2 = upQuoteX + SPACE * i; mathpjj += quoteArray.getJSONArray(i).getDouble(0) * (quoteArray.getJSONArray(i).getDouble(1) - quoteArray.getJSONArray(i - 1).getDouble(1)); if (mathpjj == 0) { if (lastavg == 0) { avePrice = close; } else { avePrice = lastavg; } } else { avePrice = mathpjj / quoteArray.getJSONArray(i).getDouble(1); } lastavg = avePrice; if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y2 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y2 = topTitleHeight + upQuoteHeight + temp; } canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); x1 = x2; y1 = y2; } // end for } } } else { paint.setColor(GlobalColor.colorFZAvePriceLine); x1 = upQuoteX; double cjje = quoteArray.getJSONArray(0).getDouble(2); int scaleCount = 1; scaleCount = Utils.getCoefficient(exchange, stockcode); double cjsl = quoteArray.getJSONArray(0).getDouble(1) * scaleCount; double avePrice = cjje / cjsl; double lastavg = 0; if (cjsl == 0) avePrice = close; if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y1 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y1 = topTitleHeight + upQuoteHeight + temp; } lastavg = avePrice; for (int i = 1; i < quotelen; i++) { x2 = upQuoteX + SPACE * i; cjje = quoteArray.getJSONArray(i).getDouble(2); cjsl = quoteArray.getJSONArray(i).getDouble(1) * scaleCount; // ? if (cjsl == 0) { if (lastavg == 0) { avePrice = close; } else { avePrice = lastavg; } } else { avePrice = cjje / cjsl; } lastavg = avePrice; if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y2 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y2 = topTitleHeight + upQuoteHeight + temp; } canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); x1 = x2; y1 = y2; } // end for } } } // ?? volumeX = LSpace; volumeY = topTitleHeight + upQuoteHeight + downQuoteHeight; volumeWidth = (int) graphicsQuoteWidth; volumeHeight = graphicsQuoteHeight - upQuoteHeight - downQuoteHeight; volume_row_height = volumeHeight / volume_row_num; paint.setColor(GlobalColor.clrLine); for (int i = 0; i <= volume_row_num; i++) { if (i == 0) { canvas.drawLine(volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth, volumeY + volume_row_height * i, paint); } else { if (i != volume_row_num) Graphics.drawDashline(canvas, volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth, volumeY + volume_row_height * i, paint); } } for (int i = 0; i < DIVIDE_COUNT; i++) { if (i == 0) { canvas.drawLine(volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY, volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint); } else Graphics.drawDashline(canvas, volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY, volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint); } if (this.isZs()) { //highVolume = TickUtil.gethighAmount(quoteData.getJSONArray("data")); highVolume = highamount; } else { //highVolume = TickUtil.gethighVolume(quoteData.getJSONArray("data")); highVolume = highvolume; } if (highVolume == 0) { if (this.isZs()) { // ? highVolume = volume_row_num * 4 * 100; // ???48highVolume=32 } else { highVolume = volume_row_num * 4 * 100; // ???48highVolume=32 } } if (highVolume < volume_row_num + 1) highVolume = volume_row_num + 1; scale = highVolume / volume_row_num; int volumeLabelY = volumeY + Font.getFontHeight(dTextSize) / 2; mpaint.setColor(GlobalColor.clr_tick_volume); for (int i = 0; i <= volume_row_num; i++) { if (i != volume_row_num) { AxisLabelVolume = highVolume - scale * i; if (this.isZs()) AxisLabelVolume = Math.round(AxisLabelVolume / 10000); else AxisLabelVolume = Math.round(AxisLabelVolume); canvas.drawText(String.valueOf((int) AxisLabelVolume), upQuoteX, volumeLabelY + volume_row_height * i, mpaint); } } // ?? if (actualDataLen > 0) { scale = volumeHeight / highVolume; paint.setColor(GlobalColor.colorVolumeLine); double prevVol = 0; double temp = 0; for (int i = 0; i < actualDataLen; i++) { if (this.isZs()) temp = (quoteArray.getJSONArray(i).getDouble(2) - prevVol) * scale; else temp = (quoteArray.getJSONArray(i).getDouble(1) - prevVol) * scale; float x1 = volumeX + SPACE * i; float y1 = (float) (volumeY + volumeHeight - temp); float x2 = x1; float y2 = volumeY + volumeHeight; canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); if (this.isZs()) prevVol = quoteArray.getJSONArray(i).getDouble(2); else prevVol = quoteArray.getJSONArray(i).getDouble(1); } } drawTimeX(canvas); // paint.setColor(GlobalColor.clrLine); canvas.drawLine(LSpace, graphicsQuoteHeight + topTitleHeight, LSpace + graphicsQuoteWidth, graphicsQuoteHeight + topTitleHeight, paint); if (isTrackStatus) { canvas.save(); //?? paint.setColor(GlobalColor.colorLine); canvas.drawLine(trackLineV, topTitleHeight, trackLineV, graphicsQuoteHeight + topTitleHeight, paint); canvas.restore(); } }
From source file:com.example.SmartBoard.DrawingView.java
public void onDrawCircle(Canvas canvas) { Paint paint = drawPaint;/*from w ww. ja va 2 s. co m*/ if (points[3] == null) //point4 null when user did not touch and move on screen. return; int left, top, right, bottom; left = points[0].x; top = points[0].y; right = points[0].x; bottom = points[0].y; for (int i = 1; i < points.length; i++) { left = left > points[i].x ? points[i].x : left; top = top > points[i].y ? points[i].y : top; right = right < points[i].x ? points[i].x : right; bottom = bottom < points[i].y ? points[i].y : bottom; } float cx = (left + right) / 2f; float cy = (top + bottom) / 2f; float radius = (float) Math.hypot(top - bottom, right - left) / 2f; //draw stroke paint.setStyle(Paint.Style.STROKE); // paint.setColor(Color.parseColor("#AADB1255")); paint.setStrokeWidth(5); if (finished) { JSONObject objectProperties = new JSONObject(); String key = UUID.randomUUID().toString(); try { objectProperties.put("id", key); objectProperties.put("type", "Circle"); objectProperties.put("color", drawPaint.getColor()); objectProperties.put("size", 5); objectProperties.put("clientId", client.getClientId()); objectProperties.put("radius", radius); objectProperties.put("x", cx); objectProperties.put("y", cy); } catch (JSONException e) { } objectDrawables.put(key, objectProperties); // drawCanvas.drawCircle(cx, cy, radius, paint); // drawCanvas.save(); // mqtt.publishRectangle(objectProperties); mqtt.publishCircle(objectProperties); //reset to start drawing again points = new Point[4]; colorballs.clear(); return; } canvas.drawCircle(cx, cy, radius, paint); // draw the balls on the canvas // paint.setColor(Color.BLUE); paint.setTextSize(18); paint.setStrokeWidth(0); // paint.setColor(Color.BLUE); for (int i = 0; i < colorballs.size(); i++) { ColorBall ball = colorballs.get(i); canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), paint); canvas.drawText("" + (i + 1), ball.getX(), ball.getY(), paint); } }
From source file:com.android.mail.ui.FolderDisplayer.java
public static void drawFolder(Canvas canvas, float x, float y, int width, int height, String name, int fgColor, int bgColor, FolderDisplayer.FolderDrawableResources res, BidiFormatter formatter, Paint paint) { canvas.save();// ww w . java2 s. c o m canvas.translate(x, y + res.folderVerticalOffset); // Draw the box. paint.setColor(bgColor); paint.setStyle(Paint.Style.FILL); final RectF rect = new RectF(0, 0, width, height); canvas.drawRoundRect(rect, res.folderRoundedCornerRadius, res.folderRoundedCornerRadius, paint); // Draw the text based on the language locale and layout direction. paint.setColor(fgColor); paint.setStyle(Paint.Style.FILL); // Compute the text/gradient indices final int textLength = (int) paint.measureText(name); final int gradientX0; final int gradientX1; final int textX; /*************************************************************************************************** * width - the actual folder chip rectangle. * * textLength - the length of the folder's full name (can be longer than * * the actual chip, which is what overflow gradient is for). * * innerPadding - the padding between the text and the chip edge. * * overflowPadding - the padding between start of overflow and the chip edge. * * * * * * text is in a RTL language * * * * index-0 * * |<---------------------------- width ---------------------------->| * * |<-------------------------textLength------------------>| | * * | |<----- overflowPadding ----->| | * * | |<- innerPadding ->|<-------->|<--------->|<- horizontalPadding ->| * * textX gX1 gX0 * * * * * * text is in a LTR language. * * * * index-0 * * |<------------------------------ width ------------------------------->| * * | |<-------------------------textLength-------------------->| * * | |<-------- overflowPadding ------->| * * |<- horizontalPadding ->|<--------->|<-------->|<- horizontalPadding ->| * * textX gX0 gX1 * * * **************************************************************************************************/ if (formatter.isRtl(name)) { gradientX0 = res.overflowGradientPadding; gradientX1 = res.folderHorizontalPadding; textX = width - res.folderHorizontalPadding - textLength; } else { gradientX0 = width - res.overflowGradientPadding; gradientX1 = width - res.folderHorizontalPadding; textX = res.folderHorizontalPadding; } // Draw the text and the possible overflow gradient // Overflow happens when the text is longer than the chip width minus side paddings. if (textLength > width - 2 * res.folderHorizontalPadding) { final Shader shader = new LinearGradient(gradientX0, 0, gradientX1, 0, fgColor, Utils.getTransparentColor(fgColor), Shader.TileMode.CLAMP); paint.setShader(shader); } final int textY = height / 2 - (int) (paint.descent() + paint.ascent()) / 2; canvas.drawText(name, textX, textY, paint); paint.setShader(null); canvas.restore(); }
From source file:com.appunite.list.FastScroller.java
public void draw(Canvas canvas) { if (mState == STATE_NONE) { // No need to draw anything return;//w w w . j ava 2 s. co m } final int y = mThumbY; final int viewWidth = mList.getWidth(); final FastScroller.ScrollFade scrollFade = mScrollFade; int alpha = -1; if (mState == STATE_EXIT) { alpha = scrollFade.getAlpha(); if (alpha < ScrollFade.ALPHA_MAX / 2) { mThumbDrawable.setAlpha(alpha * 2); } int left = 0; switch (mPosition) { case View.SCROLLBAR_POSITION_RIGHT: left = viewWidth - (mThumbW * alpha) / ScrollFade.ALPHA_MAX; break; case View.SCROLLBAR_POSITION_LEFT: left = -mThumbW + (mThumbW * alpha) / ScrollFade.ALPHA_MAX; break; } mThumbDrawable.setBounds(left, 0, left + mThumbW, mThumbH); mChangedBounds = true; } if (mTrackDrawable != null) { final Rect thumbBounds = mThumbDrawable.getBounds(); final int left = thumbBounds.left; final int halfThumbHeight = (thumbBounds.bottom - thumbBounds.top) / 2; final int trackWidth = mTrackDrawable.getIntrinsicWidth(); final int trackLeft = (left + mThumbW / 2) - trackWidth / 2; mTrackDrawable.setBounds(trackLeft, halfThumbHeight, trackLeft + trackWidth, mList.getHeight() - halfThumbHeight); mTrackDrawable.draw(canvas); } canvas.translate(0, y); mThumbDrawable.draw(canvas); canvas.translate(0, -y); // If user is dragging the scroll bar, draw the alphabet overlay if (mState == STATE_DRAGGING && mDrawOverlay) { if (mOverlayPosition == OVERLAY_AT_THUMB) { int left = 0; switch (mPosition) { default: case View.SCROLLBAR_POSITION_RIGHT: left = Math.max(0, mThumbDrawable.getBounds().left - mThumbW - mOverlaySize); break; case View.SCROLLBAR_POSITION_LEFT: left = Math.min(mThumbDrawable.getBounds().right + mThumbW, mList.getWidth() - mOverlaySize); break; } int top = Math.max(0, Math.min(y + (mThumbH - mOverlaySize) / 2, mList.getHeight() - mOverlaySize)); final RectF pos = mOverlayPos; pos.left = left; pos.right = pos.left + mOverlaySize; pos.top = top; pos.bottom = pos.top + mOverlaySize; if (mOverlayDrawable != null) { mOverlayDrawable.setBounds((int) pos.left, (int) pos.top, (int) pos.right, (int) pos.bottom); } } mOverlayDrawable.draw(canvas); final Paint paint = mPaint; float descent = paint.descent(); final RectF rectF = mOverlayPos; final Rect tmpRect = mTmpRect; mOverlayDrawable.getPadding(tmpRect); final int hOff = (tmpRect.right - tmpRect.left) / 2; final int vOff = (tmpRect.bottom - tmpRect.top) / 2; canvas.drawText(mSectionText, (int) (rectF.left + rectF.right) / 2 - hOff, (int) (rectF.bottom + rectF.top) / 2 + mOverlaySize / 4 - descent - vOff, paint); } else if (mState == STATE_EXIT) { if (alpha == 0) { // Done with exit setState(STATE_NONE); } else if (mTrackDrawable != null) { mList.invalidate(viewWidth - mThumbW, 0, viewWidth, mList.getHeight()); } else { mList.invalidate(viewWidth - mThumbW, y, viewWidth, y + mThumbH); } } }