public void setWindSpeedDirection(int direction) { // ----Point for the triangle indicator------- Point a = new Point(x, y - (int) ((height / 2) - textSize)); Point b = new Point(x - (height / 17), y); Point c = new Point(x + (height / 17), y); Path path = new Path(); path.moveTo(a.x, a.y); path.lineTo(b.x, b.y); path.lineTo(c.x, c.y); path.lineTo(a.x, a.y); path.close(); // Red Brush for the painting Paint redBrush = new Paint(Paint.ANTI_ALIAS_FLAG); redBrush.setColor(Color.RED); redBrush.setStrokeWidth(3f); if (currentDegrees != direction) { // matrix.postRotate(currentDegrees++,x,y); mCanvas.rotate(currentDegrees++, x, y); } else { finishAnimation = true; mCanvas.rotate(direction, x, y); } mCanvas.drawPath(path, redBrush); mCanvas.restore(); }
@Override public boolean onTouchEvent(MotionEvent me) { synchronized (mThread.getSurfaceHolder()) { if (!mIsScratchable) { return true; } switch (me.getAction()) { case MotionEvent.ACTION_DOWN: path = new Path(); path.moveTo(me.getX(), me.getY()); startX = me.getX(); startY = me.getY(); mPathList.add(path); break; case MotionEvent.ACTION_MOVE: if (mScratchStart) { path.lineTo(me.getX(), me.getY()); } else { if (isScratch(startX, me.getX(), startY, me.getY())) { mScratchStart = true; path.lineTo(me.getX(), me.getY()); } } break; case MotionEvent.ACTION_UP: mScratchStart = false; break; } return true; } }
/** * 绘制图网络线 * * @param canvas 画布 * @param lineData 数据集类 * @param arrayDataX x坐标 * @param arrayDataY y坐标 */ private void drawDataPath( Canvas canvas, RadarData lineData, Float[] arrayDataX, Float[] arrayDataY) { float startX = 0.0f, startY = 0.0f; float initX = 0.0f, initY = 0.0f; Path pathArea = new Path(); for (int p = 0; p < arrayDataX.length; p++) { if (0 == p) { initX = startX = arrayDataX[p]; initY = startY = arrayDataY[p]; pathArea.moveTo(initX, initY); } else { pathArea.lineTo(arrayDataX[p], arrayDataY[p]); startX = arrayDataX[p]; startY = arrayDataY[p]; } // 绘制点及对应的标签 renderDotAndLabel(canvas, lineData, arrayDataX[p], arrayDataY[p], p); } // 收尾 pathArea.lineTo(initX, initY); pathArea.close(); lineData.getPlotLine().getLinePaint().setAlpha(mAreaAlpha); // lineData.getPlotLine().getLinePaint().setStyle(Style.STROKE); canvas.drawPath(pathArea, lineData.getPlotLine().getLinePaint()); }
/** * Draws a needle that is centered at the top or bottom of the compass. * * @param canvas the {@link Canvas} upon which to draw. * @param bottom true to draw the bottom needle, or false to draw the top needle. */ private void drawNeedle(Canvas canvas, boolean bottom) { float centerX = getWidth() / 2.0f; float origin; float sign; // Flip the vertical coordinates if we're drawing the bottom needle. if (bottom) { origin = getHeight(); sign = -1; } else { origin = 0; sign = 1; } float needleHalfWidth = NEEDLE_WIDTH / 2; mPath.reset(); mPath.moveTo(centerX - needleHalfWidth, origin); mPath.lineTo(centerX - needleHalfWidth, origin + sign * (NEEDLE_HEIGHT - 4)); mPath.lineTo(centerX, origin + sign * NEEDLE_HEIGHT); mPath.lineTo(centerX + needleHalfWidth, origin + sign * (NEEDLE_HEIGHT - 4)); mPath.lineTo(centerX + needleHalfWidth, origin); mPath.close(); canvas.drawPath(mPath, mPaint); }
@Override public Path draw() { int squareWidth = pathHeight / 4; int middleSquare = squareWidth / 2; Point[] squarePoints = new Point[4]; initializePoints(squarePoints); squarePoints[0].set(center.x - middleSquare, center.y - middleSquare); squarePoints[1].set(center.x + middleSquare, squarePoints[0].y); squarePoints[2].set(squarePoints[1].x, center.y + middleSquare); squarePoints[3].set(squarePoints[0].x, squarePoints[2].y); Point[] starPoints = new Point[4]; initializePoints(starPoints); starPoints[0].set(maxBallSize, center.y); starPoints[1].set(center.x, maxBallSize); starPoints[2].set(pathWidth - maxBallSize, center.y); starPoints[3].set(center.x, pathHeight - maxBallSize); Path starPath = new Path(); starPath.moveTo(starPoints[0].x, starPoints[0].y); starPath.lineTo(squarePoints[0].x, squarePoints[0].y); for (int i = 1; i < 4; i++) { starPath.lineTo(starPoints[i].x, starPoints[i].y); starPath.lineTo(squarePoints[i].x, squarePoints[i].y); } starPath.close(); return starPath; }
private void drawSpring(Canvas canvas, int springDelta) { mPath.reset(); mPath.moveTo(0, 0); mPath.lineTo(0, PULL_HEIGHT); mPath.quadTo(mWidth / 2, PULL_HEIGHT - springDelta, mWidth, PULL_HEIGHT); mPath.lineTo(mWidth, 0); canvas.drawPath(mPath, mBackPaint); int curH = PULL_HEIGHT - springDelta / 2; if (curH > PULL_HEIGHT - PULL_DELTA / 2) { int leftX = (int) (mWidth / 2 - 2 * mRadius + getSprRatio() * mRadius); mPath.reset(); mPath.moveTo(leftX, curH); mPath.quadTo(mWidth / 2, curH - mRadius * getSprRatio() * 2, mWidth - leftX, curH); canvas.drawPath(mPath, mBallPaint); } else { canvas.drawArc( new RectF(mWidth / 2 - mRadius, curH - mRadius, mWidth / 2 + mRadius, curH + mRadius), 180, 180, true, mBallPaint); } }
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (mTabCount == 0) { return; } // under line Paint paint = new Paint(); paint.setColor(mUnderLineColor); RectF rectF = new RectF(0, getHeight() - mUnderLineHeight, getWidth(), getHeight()); canvas.drawRect(rectF, paint); // indicator line mPath.rewind(); float leftX = mIndicatorMarginTab + mLineMarginX; float rightX = leftX + mTabWidth - 2 * mIndicatorMarginTab; mPath.moveTo(leftX, mIndicatorTopY); mPath.lineTo(rightX, mIndicatorTopY); mPath.lineTo(rightX, mIndicatorBottomY); mPath.lineTo(leftX, mIndicatorBottomY); mPath.close(); canvas.drawPath(mPath, mPaintLine); }
/** * 描述:TODO. * * @param canvas the canvas * @param points the points * @param paint the paint * @param circular the circular * @see com.ab.view.chart.AbstractChart#drawPath(android.graphics.Canvas, float[], * android.graphics.Paint, boolean) */ @Override protected void drawPath(Canvas canvas, float[] points, Paint paint, boolean circular) { Path p = new Path(); float x = points[0]; float y = points[1]; p.moveTo(x, y); int length = points.length; if (circular) { length -= 4; } for (int i = 0; i < length; i += 2) { int nextIndex = i + 2 < length ? i + 2 : i; int nextNextIndex = i + 4 < length ? i + 4 : nextIndex; calc(points, p1, i, nextIndex, secondMultiplier); p2.setX(points[nextIndex]); p2.setY(points[nextIndex + 1]); calc(points, p3, nextIndex, nextNextIndex, firstMultiplier); // From last point, approaching x1/y1 and x2/y2 and ends up at x3/y3 p.cubicTo(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY()); } if (circular) { for (int i = length; i < length + 4; i += 2) { p.lineTo(points[i], points[i + 1]); } p.lineTo(points[0], points[1]); } canvas.drawPath(p, paint); }
@SuppressWarnings("NewApi") public Path computePath(int radius, int l, int t, int r, int b) { final Point o = computeOrigin(l, t, r, b); final int ol = o.x - radius; final int ot = o.y - radius; final int or = o.x + radius; final int ob = o.y + radius; Path path = new Path(); path.moveTo(o.x, o.y); switch (startAngle) { case 0: path.lineTo(or, o.y); break; case 90: path.lineTo(o.x, ob); break; case 180: path.lineTo(ol, o.y); break; case 270: path.lineTo(o.x, ot); break; default: throw new UnsupportedOperationException(); } if (Utils.LOLLIPOP_OR_LATER) { path.arcTo(ol, ot, or, ob, startAngle, sweepAngle, true); } else { path.arcTo(new RectF(ol, ot, or, ob), startAngle, sweepAngle, true); } path.lineTo(o.x, o.y); return path; }
public void onDraw(Canvas canvas) { // 검정색 배경으로 지운다. 빈 화면이면 지우기만 하고 리턴 canvas.drawColor(Color.BLACK); if (status == BLANK) { return; } // 도형 목록을 순회하면서 도형 정보대로 출력한다. int idx; for (idx = 0; idx < arShape.size(); idx++) { Paint Pnt = new Paint(); Pnt.setAntiAlias(true); Pnt.setColor(arShape.get(idx).color); Rect rt = arShape.get(idx).rt; switch (arShape.get(idx).what) { case Shape.RECT: canvas.drawRect(rt, Pnt); break; case Shape.CIRCLE: canvas.drawCircle( rt.left + rt.width() / 2, rt.top + rt.height() / 2, rt.width() / 2, Pnt); break; case Shape.TRIANGLE: Path path = new Path(); path.moveTo(rt.left + rt.width() / 2, rt.top); path.lineTo(rt.left, rt.bottom); path.lineTo(rt.right, rt.bottom); canvas.drawPath(path, Pnt); break; } } }
private void updatePath() { float radius = getWidth() / 20; float arrowHeight = getHeight() / 4; Rect rect = new Rect(2, 2, this.getWidth() - 4, this.getHeight() - 4); mPath = new Path(); mPath.moveTo(rect.left + radius, rect.top); mPath.lineTo(rect.right, rect.top); mPath.lineTo(rect.right, rect.bottom - arrowHeight); mPath.lineTo(rect.exactCenterX(), rect.bottom); mPath.lineTo(rect.left, rect.bottom - arrowHeight); mPath.lineTo(rect.left, rect.top); mPath.close(); int color = this.getContext().getResources().getColor(R.color.tag_unselected_outline); if (mIsActive) color = this.getContext().getResources().getColor(R.color.tag_selected_outline); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setColor(color); mPaint.setStyle(Paint.Style.FILL); mPaint.setStrokeWidth(0); mPaint.setStrokeJoin(Paint.Join.ROUND); // set the join to round you // want mPaint.setStrokeCap(Paint.Cap.ROUND); // set the paint cap to round too mPaint.setPathEffect(new CornerPathEffect(radius)); // set the path // effect when they color = this.getContext().getResources().getColor(R.color.tag_unselected); if (mIsActive) color = this.getContext().getResources().getColor(R.color.tag_selected); mShader = new LinearGradient(0, 0, 0, getHeight(), color, color, Shader.TileMode.CLAMP); }
/** * The graphical representation of a path. * * @param canvas the canvas to paint to * @param points the points that are contained in the path to paint * @param paint the paint to be used for painting * @param circular if the path ends with the start point */ protected void drawPath(Canvas canvas, float[] points, Paint paint, boolean circular) { Path path = new Path(); int height = canvas.getHeight(); int width = canvas.getWidth(); float[] tempDrawPoints; if (points.length < 4) { return; } tempDrawPoints = calculateDrawPoints(points[0], points[1], points[2], points[3], height, width); path.moveTo(tempDrawPoints[0], tempDrawPoints[1]); path.lineTo(tempDrawPoints[2], tempDrawPoints[3]); for (int i = 4; i < points.length; i += 2) { if ((points[i - 1] < 0 && points[i + 1] < 0) || (points[i - 1] > height && points[i + 1] > height)) { continue; } tempDrawPoints = calculateDrawPoints( points[i - 2], points[i - 1], points[i], points[i + 1], height, width); if (!circular) { path.moveTo(tempDrawPoints[0], tempDrawPoints[1]); } path.lineTo(tempDrawPoints[2], tempDrawPoints[3]); } if (circular) { path.lineTo(points[0], points[1]); } canvas.drawPath(path, paint); }
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); centerX = w / 2; centerY = h / 2; // Make reference line long enough to cross the bounds diagonally after being rotated. referenceLine.reset(); float radius = (float) Math.hypot(centerX, centerY); float delta = radius - centerX; referenceLine.moveTo(-delta, centerY); referenceLine.lineTo(getWidth() + delta, centerY); delta = radius - centerY; referenceLine.moveTo(centerX, -delta); referenceLine.lineTo(centerX, getHeight() + delta); // Set grids inside photo display bounds. grids.reset(); delta = displayBounds.width() / 4.0f; for (float x = displayBounds.left + delta; x < displayBounds.right; x += delta) { grids.moveTo(x, displayBounds.top); grids.lineTo(x, displayBounds.bottom); } delta = displayBounds.height() / 4.0f; for (float y = displayBounds.top + delta; y < displayBounds.bottom; y += delta) { grids.moveTo(displayBounds.left, y); grids.lineTo(displayBounds.right, y); } }
private void drawTriangle(Canvas c, float startAngle, float sweepAngle, Rect bounds) { if (mShowArrow) { if (mArrow == null) { mArrow = new Path(); mArrow.setFillType(Path.FillType.EVEN_ODD); } else { mArrow.reset(); } // Adjust the position of the triangle so that it is inset as // much as the arc, but also centered on the arc. float inset = (int) mStrokeInset / 2 * mArrowScale; float x = (float) (mRingCenterRadius * Math.cos(0) + bounds.exactCenterX()); float y = (float) (mRingCenterRadius * Math.sin(0) + bounds.exactCenterY()); // Update the path each time. This works around an issue in SKIA // where concatenating a rotation matrix to a scale matrix // ignored a starting negative rotation. This appears to have // been fixed as of API 21. mArrow.moveTo(0, 0); mArrow.lineTo(mArrowWidth * mArrowScale, 0); mArrow.lineTo((mArrowWidth * mArrowScale / 2), (mArrowHeight * mArrowScale)); mArrow.offset(x - inset, y); mArrow.close(); // draw a triangle mArrowPaint.setColor(mColors[mColorIndex]); c.rotate( startAngle + sweepAngle - ARROW_OFFSET_ANGLE, bounds.exactCenterX(), bounds.exactCenterY()); c.drawPath(mArrow, mArrowPaint); } }
@Override protected void drawCallout(Canvas canvas, NMapView mapView, boolean shadow, long when) { adjustTextBounds(mapView); stepAnimations(canvas, mapView, when); // Draw inner info window canvas.drawRoundRect(mTempRectF, CALLOUT_ROUND_RADIUS_X, CALLOUT_ROUND_RADIUS_Y, mInnerPaint); // Draw border for info window canvas.drawRoundRect(mTempRectF, CALLOUT_ROUND_RADIUS_X, CALLOUT_ROUND_RADIUS_Y, mBorderPaint); // Draw bottom tag if (CALLOUT_TAG_WIDTH > 0 && CALLOUT_TAG_HEIGHT > 0) { float x = mTempRectF.centerX(); float y = mTempRectF.bottom; Path path = mPath; path.reset(); path.moveTo(x - CALLOUT_TAG_WIDTH, y); path.lineTo(x, y + CALLOUT_TAG_HEIGHT); path.lineTo(x + CALLOUT_TAG_WIDTH, y); path.close(); canvas.drawPath(path, mInnerPaint); canvas.drawPath(path, mBorderPaint); } // Draw title canvas.drawText(mOverlayItem.getTitle(), mOffsetX, mOffsetY, mTextPaint); }
private void drawBG(Canvas canvas) { Path path = new Path(); int currentPointY = 0; switch (mStatus) { case NONE: currentPointY = mMaxArcHeight; break; case STATUS_SMOOTH_UP: case STATUS_UP: currentPointY = getHeight() - (int) ((getHeight() - mMaxArcHeight) * Math.min( 1, (mArcHeight - mMaxArcHeight / 4) * 2.0 / mMaxArcHeight * 1.3)); break; case STATUS_DOWN: currentPointY = mMaxArcHeight; break; } path.moveTo(0, currentPointY); path.quadTo(getWidth() / 2, currentPointY - mArcHeight, getWidth(), currentPointY); path.lineTo(getWidth(), getHeight()); path.lineTo(0, getHeight()); path.lineTo(0, currentPointY); canvas.drawPath(path, mPaint); }
@Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int width = getMeasuredWidth(); int height = getMeasuredHeight(); int curve = (int) (height * 1.125f); mPath.reset(); if (mSide == CurveTowards.LEFT) { mPath.moveTo(0, height); mPath.cubicTo(curve * 0.75f, height, curve * 0.25f, 0, curve, 0); mPath.lineTo(0, 0); mPath.lineTo(0, height); } else if (mSide == CurveTowards.RIGHT) { mPath.moveTo(width, height); mPath.cubicTo( (width - (curve * 0.75f)), height, (width - (curve * 0.25f)), 0, (width - curve), 0); mPath.lineTo(width, 0); mPath.lineTo(width, height); } }
private void drawPointerArrow(Canvas canvas) { int centerX = getWidth() / 2; int centerY = getHeight() / 2; double tipAngle = (colorHSV[2] - 0.5f) * Math.PI; double leftAngle = tipAngle + Math.PI / 96; double rightAngle = tipAngle - Math.PI / 96; double tipAngleX = Math.cos(tipAngle) * outerWheelRadius; double tipAngleY = Math.sin(tipAngle) * outerWheelRadius; double leftAngleX = Math.cos(leftAngle) * (outerWheelRadius + arrowPointerSize); double leftAngleY = Math.sin(leftAngle) * (outerWheelRadius + arrowPointerSize); double rightAngleX = Math.cos(rightAngle) * (outerWheelRadius + arrowPointerSize); double rightAngleY = Math.sin(rightAngle) * (outerWheelRadius + arrowPointerSize); arrowPointerPath.reset(); arrowPointerPath.moveTo((float) tipAngleX + centerX, (float) tipAngleY + centerY); arrowPointerPath.lineTo((float) leftAngleX + centerX, (float) leftAngleY + centerY); arrowPointerPath.lineTo((float) rightAngleX + centerX, (float) rightAngleY + centerY); arrowPointerPath.lineTo((float) tipAngleX + centerX, (float) tipAngleY + centerY); valuePointerArrowPaint.setColor(Color.HSVToColor(colorHSV)); valuePointerArrowPaint.setStyle(Style.FILL); canvas.drawPath(arrowPointerPath, valuePointerArrowPaint); valuePointerArrowPaint.setStyle(Style.STROKE); valuePointerArrowPaint.setStrokeJoin(Join.ROUND); valuePointerArrowPaint.setColor(Color.BLACK); canvas.drawPath(arrowPointerPath, valuePointerArrowPaint); }
private static Path createLightPath(int width, int height) { final Path path = new Path(); path.moveTo(0, height); path.lineTo(0, 0); path.lineTo(width, 0); return path; }
@Override public void draw(Canvas canvas) { canvas.drawRoundRect(mRectF, mRadius, mRadius, mBorderPaint); Path path = new Path(); path.moveTo(mRectF.right - 2 * mOffsetY - mOffsetX, mRectF.bottom); path.lineTo(mRectF.right - (2 * mOffsetY + mRadius) / 2 - mOffsetX, mRectF.bottom + mOffsetY); path.lineTo(mRectF.right - mRadius - mOffsetX, mRectF.bottom); float x = 0; float y = mRectF.centerY(); String text = "One Piece"; float[] characterWidths = new float[text.length()]; int characterNum = mTextPaint.getTextWidths(text, characterWidths); float textWidth = 0f; for (int i = 0; i < characterNum; i++) { textWidth += characterWidths[i]; } canvas.save(); canvas.translate(mRectF.width() / 2 - textWidth / 2, 0); canvas.drawText("one piece", x, y, mTextPaint); canvas.restore(); canvas.drawPath(path, mBorderPaint); }
static void drawYajirusi(Canvas c, int cc, Vec2 xxx, Vec2 vvx) { Paint pp = new Paint(); pp.setColor(cc); Path p = new Path(); float rr = vvx.Norm(); float width = rr * 0.05f; Vec2 xx = vvx.Prod(width / rr); xx.Rot1(); Vec2 soko1 = xxx.Diff(xx); Vec2 soko2 = xxx.Sum(xx); Vec2 noki3 = soko2.Sum(vvx.Prod(0.8f)); Vec2 noki2 = soko1.Sum(vvx.Prod(0.8f)); Vec2 noki1 = noki2.Diff(xx); Vec2 noki4 = noki3.Sum(xx); Vec2 teppen = xxx.Sum(vvx); p.moveTo(soko1.X(), soko1.Y()); p.lineTo(soko2.X(), soko2.Y()); p.lineTo(noki3.X(), noki3.Y()); p.lineTo(noki4.X(), noki4.Y()); p.lineTo(teppen.X(), teppen.Y()); p.lineTo(noki1.X(), noki1.Y()); p.lineTo(noki2.X(), noki2.Y()); p.lineTo(soko1.X(), soko1.Y()); c.drawPath(p, pp); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); mPath.moveTo(-1 / 4F * vWidth, waveY); mPath.quadTo(ctrX, ctrY, vWidth + 1 / 4f, waveY); mPath.lineTo(vWidth + 1 / 4f, vHeight); mPath.lineTo(-1 / 4F * vWidth, vHeight); mPath.close(); canvas.drawPath(mPath, mPaint); if (ctrX >= vWidth + 0.25f * vWidth) { isInc = false; } else if (ctrX <= -0.25f * vWidth) { isInc = true; } ctrX = isInc ? ctrX + 20 : ctrX - 20; if (ctrY <= vHeight) { ctrY += 2; waveY += 2; } mPath.reset(); invalidate(); }
private void getTrackPath(float x, float y, float radius) { float halfStroke = mTrackSize / 2f; mTrackPath.reset(); if (mTrackCap != Paint.Cap.ROUND) { mTempRect.set(x - radius + 1f, y - radius + 1f, x + radius - 1f, y + radius - 1f); float angle = (float) (Math.asin(halfStroke / (radius - 1f)) / Math.PI * 180); if (x - radius > mDrawRect.left) { mTrackPath.moveTo(mDrawRect.left, y - halfStroke); mTrackPath.arcTo(mTempRect, 180 + angle, -angle * 2); mTrackPath.lineTo(mDrawRect.left, y + halfStroke); mTrackPath.close(); } if (x + radius < mDrawRect.right) { mTrackPath.moveTo(mDrawRect.right, y - halfStroke); mTrackPath.arcTo(mTempRect, -angle, angle * 2); mTrackPath.lineTo(mDrawRect.right, y + halfStroke); mTrackPath.close(); } } else { float angle = (float) (Math.asin(halfStroke / (radius - 1f)) / Math.PI * 180); if (x - radius > mDrawRect.left) { float angle2 = (float) (Math.acos(Math.max(0f, (mDrawRect.left + halfStroke - x + radius) / halfStroke)) / Math.PI * 180); mTempRect.set(mDrawRect.left, y - halfStroke, mDrawRect.left + mTrackSize, y + halfStroke); mTrackPath.arcTo(mTempRect, 180 - angle2, angle2 * 2); mTempRect.set(x - radius + 1f, y - radius + 1f, x + radius - 1f, y + radius - 1f); mTrackPath.arcTo(mTempRect, 180 + angle, -angle * 2); mTrackPath.close(); } if (x + radius < mDrawRect.right) { float angle2 = (float) Math.acos(Math.max(0f, (x + radius - mDrawRect.right + halfStroke) / halfStroke)); mTrackPath.moveTo( (float) (mDrawRect.right - halfStroke + Math.cos(angle2) * halfStroke), (float) (y + Math.sin(angle2) * halfStroke)); angle2 = (float) (angle2 / Math.PI * 180); mTempRect.set( mDrawRect.right - mTrackSize, y - halfStroke, mDrawRect.right, y + halfStroke); mTrackPath.arcTo(mTempRect, angle2, -angle2 * 2); mTempRect.set(x - radius + 1f, y - radius + 1f, x + radius - 1f, y + radius - 1f); mTrackPath.arcTo(mTempRect, -angle, angle * 2); mTrackPath.close(); } } }
/** * draw lines * * <p>ラインを書く * * <p>绘制线条 * * @param canvas */ protected void drawAreas(Canvas canvas) { // distance between two points float lineLength = ((super.getWidth() - super.getAxisMarginLeft()) / displayNumber) - 1; // start point‘s X float startX; float lastY = 0; float lastX = 0; LineEntity<DateValueEntity> line1 = (LineEntity<DateValueEntity>) bandData.get(0); LineEntity<DateValueEntity> line2 = (LineEntity<DateValueEntity>) bandData.get(1); if (line1.isDisplay() && line2.isDisplay()) { Paint mPaint = new Paint(); mPaint.setColor(line1.getLineColor()); mPaint.setAlpha(70); mPaint.setAntiAlias(true); List<DateValueEntity> line1Data = line1.getLineData(); List<DateValueEntity> line2Data = line2.getLineData(); // set start point’s X startX = super.getAxisMarginLeft() + lineLength / 2f; Path areaPath = new Path(); if (line1Data != null && line2Data != null) { for (int j = displayFrom; j < displayFrom + displayNumber; j++) { float value1 = line1Data.get(j).getValue(); float value2 = line2Data.get(j).getValue(); // calculate Y float valueY1 = (float) ((1f - (value1 - this.getMinValue()) / (this.getMaxValue() - this.getMinValue())) * (super.getHeight() - super.getAxisMarginBottom())); float valueY2 = (float) ((1f - (value2 - this.getMinValue()) / (this.getMaxValue() - this.getMinValue())) * (super.getHeight() - super.getAxisMarginBottom())); // 绘制线条路径 if (j == displayFrom) { areaPath.moveTo(startX, valueY1); areaPath.lineTo(startX, valueY2); areaPath.moveTo(startX, valueY1); } else { areaPath.lineTo(startX, valueY1); areaPath.lineTo(startX, valueY2); areaPath.lineTo(lastX, lastY); areaPath.close(); areaPath.moveTo(startX, valueY1); } lastX = startX; lastY = valueY2; startX = startX + 1 + lineLength; } areaPath.close(); canvas.drawPath(areaPath, mPaint); } } }
private void drawPolygon( BinaryMapDataObject obj, RenderingRuleSearchRequest render, Canvas canvas, RenderingContext rc, TagValuePair pair) { if (render == null || pair == null) { return; } float xText = 0; float yText = 0; int zoom = rc.zoom; Path path = null; // rc.main.color = Color.rgb(245, 245, 245); render.setInitialTagValueZoom(pair.tag, pair.value, zoom, obj); boolean rendered = render.search(RenderingRulesStorage.POLYGON_RULES); if (!rendered || !updatePaint(render, paint, 0, true, rc)) { return; } rc.visible++; int len = obj.getPointsLength(); for (int i = 0; i < obj.getPointsLength(); i++) { PointF p = calcPoint(obj, i, rc); xText += p.x; yText += p.y; if (path == null) { path = new Path(); path.moveTo(p.x, p.y); } else { path.lineTo(p.x, p.y); } } int[][] polygonInnerCoordinates = obj.getPolygonInnerCoordinates(); if (polygonInnerCoordinates != null && path != null) { path.setFillType(FillType.EVEN_ODD); for (int j = 0; j < polygonInnerCoordinates.length; j++) { for (int i = 0; i < polygonInnerCoordinates[j].length; i += 2) { PointF p = calcPoint(polygonInnerCoordinates[j][i], polygonInnerCoordinates[j][i + 1], rc); if (i == 0) { path.moveTo(p.x, p.y); } else { path.lineTo(p.x, p.y); } } } } if (path != null && len > 0) { canvas.drawPath(path, paint); if (updatePaint(render, paint, 1, false, rc)) { canvas.drawPath(path, paint); } textRenderer.renderText(obj, render, rc, pair, xText / len, yText / len, null, null); } }
private void drawCircle(Canvas canvas, BatteryTracker tracker, float textX, RectF drawRect) { boolean unknownStatus = tracker.status == BatteryManager.BATTERY_STATUS_UNKNOWN; int animOffset = tracker.shouldIndicateCharging() ? mAnimOffset : 0; int level = tracker.level; Paint paint; if (unknownStatus) { paint = mBackPaint; level = 100; // Draw all the circle; } else { paint = mFrontPaint; paint.setColor(getColorForLevel(level)); if (tracker.status == BatteryManager.BATTERY_STATUS_FULL) { level = 100; } } // draw thin gray ring first canvas.drawArc(drawRect, 270, 360, false, mBackPaint); // draw colored arc representing charge level canvas.drawArc(drawRect, 270 + animOffset, 3.6f * level, false, paint); // if chosen by options, draw percentage text in the middle // always skip percentage when 100, so layout doesnt break if (unknownStatus) { mTextPaint.setColor(paint.getColor()); canvas.drawText("?", textX, mTextY, mTextPaint); } else if (tracker.shouldIndicateCharging() && (!mShowPercent || level == 100)) { // draw the bolt final float bl = (int) (drawRect.left + drawRect.width() / 3.2f); final float bt = (int) (drawRect.top + drawRect.height() / 4f); final float br = (int) (drawRect.right - drawRect.width() / 5.2f); final float bb = (int) (drawRect.bottom - drawRect.height() / 8f); if (mBoltFrame.left != bl || mBoltFrame.top != bt || mBoltFrame.right != br || mBoltFrame.bottom != bb) { mBoltFrame.set(bl, bt, br, bb); mBoltPath.reset(); mBoltPath.moveTo( mBoltFrame.left + mBoltPoints[0] * mBoltFrame.width(), mBoltFrame.top + mBoltPoints[1] * mBoltFrame.height()); for (int i = 2; i < mBoltPoints.length; i += 2) { mBoltPath.lineTo( mBoltFrame.left + mBoltPoints[i] * mBoltFrame.width(), mBoltFrame.top + mBoltPoints[i + 1] * mBoltFrame.height()); } mBoltPath.lineTo( mBoltFrame.left + mBoltPoints[0] * mBoltFrame.width(), mBoltFrame.top + mBoltPoints[1] * mBoltFrame.height()); } canvas.drawPath(mBoltPath, mBoltPaint); } else if (level < 100 && mShowPercent) { mTextPaint.setColor(paint.getColor()); canvas.drawText(Integer.toString(level), textX, mTextY, mTextPaint); } }
public static void play( Canvas paramCanvas, Paint paramPaint, int paramInt1, int paramInt2, int paramInt3) { Path localPath = new Path(); localPath.moveTo(paramInt3, paramInt3); localPath.lineTo(paramInt1 - paramInt3, paramInt3 + (paramInt2 - paramInt3 * 2.0F) / 2.0F); localPath.lineTo(paramInt3, paramInt2 - paramInt3); localPath.lineTo(paramInt3, paramInt3); paramCanvas.drawPath(localPath, paramPaint); }
protected final int h(int paramInt, Object... paramVarArgs) { switch (paramInt) { } for (; ; ) { return 0; return 46; return 46; Canvas localCanvas = (Canvas) paramVarArgs[0]; paramVarArgs = (Looper) paramVarArgs[1]; c.e(paramVarArgs); c.d(paramVarArgs); Object localObject = c.h(paramVarArgs); ((Paint) localObject).setFlags(385); ((Paint) localObject).setStyle(Paint.Style.FILL); Paint localPaint1 = c.h(paramVarArgs); localPaint1.setFlags(385); localPaint1.setStyle(Paint.Style.STROKE); ((Paint) localObject).setColor(-16777216); localPaint1.setStrokeWidth(1.0F); localPaint1.setStrokeCap(Paint.Cap.BUTT); localPaint1.setStrokeJoin(Paint.Join.MITER); localPaint1.setStrokeMiter(4.0F); localPaint1.setPathEffect(null); Paint localPaint2 = c.a(localPaint1, paramVarArgs); localPaint2.set(localPaint1); localPaint2.setStrokeWidth(1.0F); localCanvas.save(); localPaint1 = c.a((Paint) localObject, paramVarArgs); localPaint1.set((Paint) localObject); localPaint1.setColor(-8744017); localObject = c.i(paramVarArgs); ((Path) localObject).moveTo(30.430653F, 34.178318F); ((Path) localObject).cubicTo(27.249908F, 36.57749F, 23.291077F, 38.0F, 19.0F, 38.0F); ((Path) localObject).cubicTo(8.50659F, 38.0F, 0.0F, 29.49341F, 0.0F, 19.0F); ((Path) localObject).cubicTo(0.0F, 8.50659F, 8.50659F, 0.0F, 19.0F, 0.0F); ((Path) localObject).cubicTo(29.49341F, 0.0F, 38.0F, 8.50659F, 38.0F, 19.0F); ((Path) localObject) .cubicTo(38.0F, 23.291077F, 36.57749F, 27.249908F, 34.178318F, 30.430653F); ((Path) localObject).lineTo(45.619164F, 41.8715F); ((Path) localObject).lineTo(41.8715F, 45.619164F); ((Path) localObject).lineTo(30.430653F, 34.178318F); ((Path) localObject).close(); ((Path) localObject).moveTo(27.062714F, 30.44662F); ((Path) localObject).cubicTo(24.783264F, 32.055153F, 22.001972F, 33.0F, 19.0F, 33.0F); ((Path) localObject).cubicTo(11.268014F, 33.0F, 5.0F, 26.731987F, 5.0F, 19.0F); ((Path) localObject).cubicTo(5.0F, 11.268014F, 11.268014F, 5.0F, 19.0F, 5.0F); ((Path) localObject).cubicTo(26.731987F, 5.0F, 33.0F, 11.268014F, 33.0F, 19.0F); ((Path) localObject) .cubicTo(33.0F, 22.001972F, 32.055153F, 24.783264F, 30.44662F, 27.062714F); ((Path) localObject).lineTo(27.062714F, 30.44662F); ((Path) localObject).close(); WeChatSVGRenderC2Java.setFillType((Path) localObject, 2); localCanvas.drawPath((Path) localObject, localPaint1); localCanvas.restore(); c.g(paramVarArgs); } }
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); sizePath.reset(); sizePath.moveTo(borderSize, borderSize); sizePath.lineTo(getWidth() - borderSize, getHeight() / 2); sizePath.lineTo(borderSize, getHeight() - borderSize); }
@Override public Path draw() { Path path = new Path(); path.moveTo(maxBallSize, pathHeight - maxBallSize); path.lineTo(center.x, maxBallSize); path.lineTo(pathWidth - maxBallSize, pathHeight - maxBallSize); path.lineTo(maxBallSize, pathHeight - maxBallSize); return path; }