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.ickphum.android.isoview.IsoCanvas.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.translate(-mOriginX, -mOriginY); for (int x = 0; x < 100; x++) { for (int y = 0; y < 100; y++) { canvas.save();/*from www .j a v a 2 s . c o m*/ canvas.translate(-x * 7, -y * 7); canvas.drawPath(mPaths[0], mPaints[0]); //canvas.drawRect(0.0f, 0.0f, 5.0f, 5.0f, mPaints[0]); canvas.restore(); } } canvas.drawLine(mContentRect.left, mContentRect.top, mContentRect.right, mContentRect.bottom, mBackgroundLinePaint); canvas.drawLine(mContentRect.left, mContentRect.bottom, mContentRect.right, mContentRect.top, mBackgroundLinePaint); for (int x = -1000; x < 1000; x += 200) { for (int y = -1000; y < 1000; y += 200) { canvas.drawText(x + "," + y, x, y, mBackgroundLinePaint); } } }
From source file:org.lucasr.dspec.DesignSpec.java
private void drawBaselineGrid(Canvas canvas) { if (!mBaselineGridVisible) { return;/*from w w w.jav a 2 s . c om*/ } final int width = getIntrinsicWidth(); final int height = getIntrinsicHeight(); float x = mBaselineGridCellSize; while (x < width) { canvas.drawLine(x, 0, x, height, mBaselineGridPaint); x += mBaselineGridCellSize; } float y = mBaselineGridCellSize; while (y < height) { canvas.drawLine(0, y, width, y, mBaselineGridPaint); y += mBaselineGridCellSize; } }
From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java
public void drawSun(Canvas canvas) { sunPaint.reset();/* ww w .j a v a2s . c om*/ sunPaint.setColor(Color.YELLOW); sunPaint.setStyle(Paint.Style.FILL_AND_STROKE); // Horizontal sunPosition = new Horizontal(225, 45); if (sunPosition.getElevation() > -10) { canvas.rotate((float) sunPosition.getAzimuth() - 360, px, py); sunPaint.setPathEffect(dashPath); int ry = (int) (((90 - sunPosition.getElevation()) / 90) * Radius); canvas.drawCircle(px, py - ry, r, sunPaint); dashedPaint.setColor(Color.YELLOW); canvas.drawLine(px, py - Radius, px, py + Radius, dashedPaint); sunPaint.setPathEffect(null); canvas.restore(); } }
From source file:com.wanikani.androidnotifier.graph.HistogramPlot.java
@Override protected void onDraw(Canvas canvas) { float left, right, tagLabelBaseline; int d, lo, hi, ascent; Samples bar;/* w w w. jav a 2s.c om*/ canvas.drawLine(meas.plotArea.left, meas.plotArea.bottom, meas.plotArea.right, meas.plotArea.bottom, pas.axisPaint); lo = vp.leftmostBar() - 1; /* We want broken bars too :) */ hi = vp.rightmostBar() + 1; ascent = (int) pas.labelPaint.getFontMetrics().ascent; tagLabelBaseline = meas.plotArea.bottom - ascent + meas.headroom / 2; for (d = lo; d <= hi; d++) { if (d < 0) continue; if (d >= bars.size()) break; left = vp.getRelPosition(d); right = left + vp.meas.dipPerBar; bar = bars.get(d); drawBar(canvas, bar, left, right); canvas.drawText(bar.tag, (left + right) / 2, tagLabelBaseline, pas.labelPaint); } if (meas.yaxisGrid > 0) { for (d = meas.yaxisGrid; vp.getY(d) >= meas.plotArea.top; d += meas.yaxisGrid) { canvas.drawLine(meas.plotArea.left, vp.getY(d), meas.plotArea.right, vp.getY(d), pas.gridPaint); } } }
From source file:org.stockchart.series.StockSeries.java
protected void drawPoint(Canvas c, SeriesPaintInfo pinfo, float x1, float x2, StockPoint p) { this.fPaint.reset(); double openPrice = p.getOpen(); double closePrice = p.getClose(); boolean isFall = (closePrice < openPrice); float open = pinfo.getY(p.getOpen()); float close = pinfo.getY(p.getClose()); float high = pinfo.getY(p.getHigh()); float low = pinfo.getY(p.getLow()); float midX = (x1 + x2) / 2; Appearance a = isFall ? fFallAppearance : getRiseAppearance(); if (getViewType() == ViewType.CANDLESTICK) { fBodyRect.set(x1, open, x2, close); fBodyRect.sort();/*from w ww . j a v a2s. c om*/ // high-low line a.applyOutline(fPaint); c.drawLine(midX, high, midX, low, fPaint); // body fill a.applyFill(fPaint, fBodyRect); c.drawRect(fBodyRect, fPaint); // body outline a.applyOutline(fPaint); c.drawRect(fBodyRect, fPaint); } else if (getViewType() == ViewType.BAR) { a.applyOutline(fPaint); c.drawLine(midX, high, midX, low, fPaint); c.drawLine(x1, open, midX, open, fPaint); c.drawLine(midX, close, x2, close, fPaint); } }
From source file:com.google.android.apps.santatracker.doodles.shared.physics.Polygon.java
public void draw(Canvas canvas) { if (!(SwimmingFragment.editorMode)) { return;// w ww .j a v a 2s. c o m } for (int i = 0; i < vertices.size(); i++) { Vector2D start = vertices.get(i); Vector2D end; if (i < vertices.size() - 1) { end = vertices.get(i + 1); } else { end = vertices.get(0); } Vector2D midpoint = Util.getMidpoint(start, end); Vector2D normal = Vector2D.get(end).subtract(start).toNormal(); canvas.drawCircle(start.x, start.y, VERTEX_RADIUS, vertexPaint); canvas.drawLine(start.x, start.y, end.x, end.y, linePaint); canvas.drawCircle(midpoint.x, midpoint.y, VERTEX_RADIUS / 2, midpointPaint); canvas.drawLine(midpoint.x, midpoint.y, midpoint.x + normal.x * 20, midpoint.y + normal.y * 20, linePaint); midpoint.release(); normal.release(); } }
From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java
public void drawTrueNorthArrow(Canvas canvas, float drawnAngle) { trueNorthArrowPaint.reset();/*from w w w . j av a2 s .c om*/ trueNorthArrowPaint.setColor(Color.RED); trueNorthArrowPaint.setStyle(Paint.Style.FILL); trueNorthArrowPaint.setAlpha(100); int r = Radius / 12; // Construct a wedge-shaped path mPath.reset(); mPath.moveTo(px, py - px); mPath.lineTo(px - r, py); mPath.lineTo(px, py + r); mPath.lineTo(px + r, py); mPath.addCircle(px, py, r, Path.Direction.CCW); mPath.close(); canvas.drawPath(mPath, trueNorthArrowPaint); dashedPaint.setColor(Color.RED); canvas.drawLine(px, py - px, px, py + Radius, dashedPaint); canvas.drawCircle(px, py, 5, dashedPaint); canvas.restore(); }
From source file:com.layer_net.stepindicator.StepIndicator.java
@Override protected void onDraw(Canvas canvas) { if (stepsCount <= 1) { setVisibility(GONE);/*from w w w. j a v a 2s . com*/ return; } super.onDraw(canvas); int pointX = startX; int pointOffset; /** draw Line */ for (int i = 0; i < stepsCount - 1; i++) { if (i < currentStepPosition) { paint.setColor(stepColor); canvas.drawLine(pointX, centerY, pointX + stepDistance, centerY, paint); } else if (i == currentStepPosition) { paint.setColor(backgroundColor); canvas.drawLine(pointX, centerY, pointX + stepDistance, centerY, paint); } else { paint.setColor(backgroundColor); canvas.drawLine(pointX, centerY, pointX + stepDistance, centerY, paint); } pointX = pointX + stepDistance; } /**draw progress Line */ if (offsetPixel != 0 && pagerScrollState == 1) { pointOffset = startX + (currentStepPosition * stepDistance); int drawOffset = pointOffset + offsetPixel; if (drawOffset >= startX && drawOffset <= endX) { if (offsetPixel < 0) { paint.setColor(backgroundColor); } else { paint.setColor(stepColor); } canvas.drawLine(pointOffset, centerY, drawOffset, centerY, paint); } } /**draw Circle */ pointX = startX; for (int i = 0; i < stepsCount; i++) { if (i < currentStepPosition) { //draw previous step paint.setColor(stepColor); canvas.drawCircle(pointX, centerY, radius, paint); //draw transition if (i == currentStepPosition - 1 && offsetPixel < 0 && pagerScrollState == 1) { pStoke.setAlpha(255); pStoke.setStrokeWidth(strokeWidth - Math.round(strokeWidth * offset)); canvas.drawCircle(pointX, centerY, radius, pStoke); } pText.setColor(secondaryTextColor); } else if (i == currentStepPosition) { //draw current step if (offsetPixel == 0 || pagerScrollState == 0) { //set stroke default paint.setColor(currentColor); pStoke.setStrokeWidth(Math.round(strokeWidth)); pStoke.setAlpha(255); } else if (offsetPixel < 0) { pStoke.setStrokeWidth(Math.round(strokeWidth * offset)); pStoke.setAlpha(Math.round(offset * 255f)); paint.setColor(getColorToBG(offset)); } else { //set stroke transition paint.setColor(getColorToProgess(offset)); pStoke.setStrokeWidth(strokeWidth - Math.round(strokeWidth * offset)); pStoke.setAlpha(255 - Math.round(offset * 255f)); } canvas.drawCircle(pointX, centerY, radius, paint); canvas.drawCircle(pointX, centerY, radius, pStoke); pText.setColor(textColor); } else { //draw next step paint.setColor(backgroundColor); canvas.drawCircle(pointX, centerY, radius, paint); pText.setColor(secondaryTextColor); //draw transition if (i == currentStepPosition + 1 && offsetPixel > 0 && pagerScrollState == 1) { pStoke.setStrokeWidth(Math.round(strokeWidth * offset)); pStoke.setAlpha(Math.round(offset * 255f)); canvas.drawCircle(pointX, centerY, radius, pStoke); } } drawTextCentred(canvas, pText, String.valueOf(i + 1), pointX, centerY); pointX = pointX + stepDistance; } }
From source file:com.chenl.widgets.flippablestackview.indicator.OrientedPagerSlidingTabLayout.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//ww w . j a v a 2 s .c om } if (underlineHeight > 0) { final int height = getHeight(); // 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); } // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); } if (indicatorHeight > 0) { final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(mCurrentPosition); 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 && mCurrentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(mCurrentPosition + 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); } }
From source file:com.ez.gallery.ucrop.view.widget.HorizontalProgressWheelView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.getClipBounds(mCanvasClipBounds); int linesCount = mCanvasClipBounds.width() / (mProgressLineWidth + mProgressLineMargin); float deltaX = (mTotalScrollDistance) % (float) (mProgressLineMargin + mProgressLineWidth); mProgressLinePaint.setColor(getResources().getColor(R.color.ucrop_color_progress_wheel_line)); for (int i = 0; i < linesCount; i++) { if (i < (linesCount / 4)) { mProgressLinePaint.setAlpha((int) (255 * (i / (float) (linesCount / 4)))); } else if (i > (linesCount * 3 / 4)) { mProgressLinePaint.setAlpha((int) (255 * ((linesCount - i) / (float) (linesCount / 4)))); } else {// w w w. j a v a 2 s .c o m mProgressLinePaint.setAlpha(255); } canvas.drawLine(-deltaX + mCanvasClipBounds.left + i * (mProgressLineWidth + mProgressLineMargin), mCanvasClipBounds.centerY() - mProgressLineHeight / 4.0f, -deltaX + mCanvasClipBounds.left + i * (mProgressLineWidth + mProgressLineMargin), mCanvasClipBounds.centerY() + mProgressLineHeight / 4.0f, mProgressLinePaint); } mProgressLinePaint.setColor(mMiddleLineColor); canvas.drawLine(mCanvasClipBounds.centerX(), mCanvasClipBounds.centerY() - mProgressLineHeight / 2.0f, mCanvasClipBounds.centerX(), mCanvasClipBounds.centerY() + mProgressLineHeight / 2.0f, mProgressLinePaint); }