Java Code Examples for android.graphics.Path#reset()
The following examples show how to use
android.graphics.Path#reset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MarkerDrawable.java From Panoramic-Screenshot with GNU General Public License v3.0 | 6 votes |
private void computePath(Rect bounds) { final float currentScale = mCurrentScale; final Path path = mPath; final RectF rect = mRect; final Matrix matrix = mMatrix; path.reset(); int totalSize = Math.min(bounds.width(), bounds.height()); float initial = mClosedStateSize; float destination = totalSize; float currentSize = initial + (destination - initial) * currentScale; float halfSize = currentSize / 2f; float inverseScale = 1f - currentScale; float cornerSize = halfSize * inverseScale; float[] corners = new float[]{halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize, cornerSize}; rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize); path.addRoundRect(rect, corners, Path.Direction.CCW); matrix.reset(); matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize); matrix.postTranslate((bounds.width() - currentSize) / 2, 0); float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale; matrix.postTranslate(0, hDiff); path.transform(matrix); }
Example 2
Source File: PercentileView.java From NightWatch with GNU General Public License v3.0 | 6 votes |
private void drawPolygon(Canvas canvas, double[] lowerValues, double[] higherValues, Paint paint) { Path myPath = new Path(); myPath.reset(); double xStep = (canvas.getWidth() - dpOffset) * 1d / lowerValues.length; //lowerValues myPath.moveTo(dpOffset, getYfromBG(lowerValues[0], canvas)); for (int i = 1; i < lowerValues.length; i++) { myPath.lineTo((int) (i * xStep + dpOffset), getYfromBG(lowerValues[i], canvas)); } // 00:00 == 24:00 myPath.lineTo((int) (lowerValues.length * xStep + dpOffset), getYfromBG(lowerValues[0], canvas)); myPath.lineTo((int) (higherValues.length * xStep + dpOffset), getYfromBG(higherValues[0], canvas)); //higher Values for (int i = higherValues.length - 1; i >= 0; i--) { myPath.lineTo((int) (i * xStep + dpOffset), getYfromBG(higherValues[i], canvas)); } myPath.close(); canvas.drawPath(myPath, paint); }
Example 3
Source File: XRadarView.java From XRadarView with MIT License | 6 votes |
private void drawPolygon(Canvas canvas) { Path path = new Path(); float r = radius / layerCount; for (int i = layerCount; i >= 1; i--) { float curR = r * i; path.reset(); if (isCircle) { path.addCircle(centerX, centerY, curR, Path.Direction.CW); } else { for (int j = 0; j < count; j++) { if (j == 0) { path.moveTo(centerX, centerY - curR); } else { path.lineTo((float) (centerX + Math.cos(angle * j + Math.PI / 2) * curR), (float) (centerY - Math.sin(angle * j + Math.PI / 2) * curR)); } } path.close(); } canvas.drawPath(path, cobwebPaint); } }
Example 4
Source File: MainView.java From kAndroid with Apache License 2.0 | 6 votes |
private void drawLine(Canvas canvas) { //虚线 Path path = new Path(); path.reset(); path.moveTo(getX(0), getCurveY(mPoints.get(0).getCurve())); // for (int i = 1; i < mPoints.size(); i++) { // path.lineTo(getX(i), getCurveY(mPoints.get(i).getValue())); // canvas.drawPath(path, mImaginaryLinePaint); // } drawScrollLine(canvas, path); //小圆点线 mDotPaint.setColor(getColor(R.color.c67D9FF)); float r = mColumnWidth * 0.5f / 2; for (int i = 0; i < mPoints.size(); i++) { canvas.drawCircle(getX(i), getCurveY(mPoints.get(i).getCurve()), r, mDotPaint); } }
Example 5
Source File: MarkerDrawable.java From IdealMedia with Apache License 2.0 | 6 votes |
private void computePath(Rect bounds) { final float currentScale = mCurrentScale; final Path path = mPath; final RectF rect = mRect; final Matrix matrix = mMatrix; path.reset(); int totalSize = Math.min(bounds.width(), bounds.height()); float initial = mClosedStateSize; float destination = totalSize; float currentSize = initial + (destination - initial) * currentScale; float halfSize = currentSize / 2f; float inverseScale = 1f - currentScale; float cornerSize = halfSize * inverseScale; float[] corners = new float[]{halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize, cornerSize}; rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize); path.addRoundRect(rect, corners, Path.Direction.CCW); matrix.reset(); matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize); matrix.postTranslate((bounds.width() - currentSize) / 2, 0); float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale; matrix.postTranslate(0, hDiff); path.transform(matrix); }
Example 6
Source File: DrawingView.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
/** * Erases the signature. */ public void clear() { for (Path path : paths) { path.reset(); } // Repaints the entire view. invalidate(); }
Example 7
Source File: TextSelectionHint.java From Telegram with GNU General Public License v2.0 | 5 votes |
private void roundedRect(Path path, float left, float top, float right, float bottom, float rx, float ry, boolean tl, boolean tr) { path.reset(); if (rx < 0) rx = 0; if (ry < 0) ry = 0; float width = right - left; float height = bottom - top; if (rx > width / 2) rx = width / 2; if (ry > height / 2) ry = height / 2; float widthMinusCorners = (width - (2 * rx)); float heightMinusCorners = (height - (2 * ry)); path.moveTo(right, top + ry); if (tr) path.rQuadTo(0, -ry, -rx, -ry); else { path.rLineTo(0, -ry); path.rLineTo(-rx, 0); } path.rLineTo(-widthMinusCorners, 0); if (tl) path.rQuadTo(-rx, 0, -rx, ry); else { path.rLineTo(-rx, 0); path.rLineTo(0, ry); } path.rLineTo(0, heightMinusCorners); path.rLineTo(0, ry); path.rLineTo(rx, 0); path.rLineTo(widthMinusCorners, 0); path.rLineTo(rx, 0); path.rLineTo(0, -ry); path.rLineTo(0, -heightMinusCorners); path.close(); }
Example 8
Source File: LineChartRenderer.java From Ticket-Analysis with MIT License | 5 votes |
/** * Generates a path that is used for filled drawing. * * @param dataSet The dataset from which to read the entries. * @param startIndex The index from which to start reading the dataset * @param endIndex The index from which to stop reading the dataset * @param outputPath The path object that will be assigned the chart data. * @return */ private void generateFilledPath(final ILineDataSet dataSet, final int startIndex, final int endIndex, final Path outputPath) { final float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart); final float phaseY = mAnimator.getPhaseY(); final boolean isDrawSteppedEnabled = dataSet.getMode() == LineDataSet.Mode.STEPPED; final Path filled = outputPath; filled.reset(); final Entry entry = dataSet.getEntryForIndex(startIndex); filled.moveTo(entry.getX(), fillMin); filled.lineTo(entry.getX(), entry.getY() * phaseY); // create a new path Entry currentEntry = null; Entry previousEntry = null; for (int x = startIndex + 1; x <= endIndex; x++) { currentEntry = dataSet.getEntryForIndex(x); if (isDrawSteppedEnabled && previousEntry != null) { filled.lineTo(currentEntry.getX(), previousEntry.getY() * phaseY); } filled.lineTo(currentEntry.getX(), currentEntry.getY() * phaseY); previousEntry = currentEntry; } // close up if (currentEntry != null) { filled.lineTo(currentEntry.getX(), fillMin); } filled.close(); }
Example 9
Source File: BaseBallBuilder.java From ZLoading with MIT License | 5 votes |
protected final void drawBall(Canvas canvas, Path path, Paint paint) { path.reset(); path.moveTo(mBallPoints.get(0).getX(), mBallPoints.get(0).getY()); path.cubicTo(mBallPoints.get(1).getX(), mBallPoints.get(1).getY(), mBallPoints.get(2).getX(), mBallPoints.get(2).getY(), mBallPoints.get(3).getX(), mBallPoints.get(3).getY()); path.cubicTo(mBallPoints.get(4).getX(), mBallPoints.get(4).getY(), mBallPoints.get(5).getX(), mBallPoints.get(5).getY(), mBallPoints.get(6).getX(), mBallPoints.get(6).getY()); path.cubicTo(mBallPoints.get(7).getX(), mBallPoints.get(7).getY(), mBallPoints.get(8).getX(), mBallPoints.get(8).getY(), mBallPoints.get(9).getX(), mBallPoints.get(9).getY()); path.cubicTo(mBallPoints.get(10).getX(), mBallPoints.get(10).getY(), mBallPoints.get(11).getX(), mBallPoints.get(11).getY(), mBallPoints.get(0).getX(), mBallPoints.get(0).getY()); canvas.drawPath(path, paint); }
Example 10
Source File: XAxisRendererCurrentDay.java From shinny-futures-android with GNU General Public License v3.0 | 5 votes |
@Override public void renderGridLines(Canvas c) { if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled()) return; float[] position = new float[]{ 0f, 0f }; mGridPaint.setColor(mXAxis.getGridColor()); mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth()); mGridPaint.setPathEffect(mXAxis.getGridDashPathEffect()); Path gridLinePath = mRenderGridLinesPath; gridLinePath.reset(); int count = mXAxis.getXLabels().size(); if (!mChart.isScaleXEnabled()) { count -= 1; } //首尾标签不画 for (int i = 1; i < count; i++) { int ix = mXAxis.getXLabels().keyAt(i); position[0] = ix; mTrans.pointValuesToPixel(position); gridLinePath.moveTo(position[0], mViewPortHandler.contentBottom()); gridLinePath.lineTo(position[0], mViewPortHandler.contentTop()); // draw a path because lines don't support dashing on lower android versions c.drawPath(gridLinePath, mGridPaint); gridLinePath.reset(); } }
Example 11
Source File: MusicPathBuilder.java From ZLoading with MIT License | 5 votes |
private void resetDrawPath() { mOpenJump = false; for (Path path : mMusicDrawPaths) { path.reset(); path.lineTo(0, 0); } for (MusicParam musicParam : mMusicParams) { musicParam.clear(); } }
Example 12
Source File: PullableWrapper.java From Dashchan with Apache License 2.0 | 5 votes |
private void drawArc(Canvas canvas, Paint paint, RectF size, float start, float length) { if (length < 0.001f) { length = 0.001f; } Path path = this.path; path.reset(); if (length >= 1f) { path.arcTo(size, 0f, 180f, false); path.arcTo(size, 180f, 180f, false); } else { path.arcTo(size, start * 360f - 90f, length * 360f, false); } canvas.drawPath(path, paint); }
Example 13
Source File: XAxisRenderer.java From iMoney with Apache License 2.0 | 5 votes |
@Override public void renderGridLines(Canvas c) { if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled()) return; // pre alloc float[] position = new float[] { 0f, 0f }; mGridPaint.setColor(mXAxis.getGridColor()); mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth()); mGridPaint.setPathEffect(mXAxis.getGridDashPathEffect()); Path gridLinePath = new Path(); for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) { position[0] = i; mTrans.pointValuesToPixel(position); if (position[0] >= mViewPortHandler.offsetLeft() && position[0] <= mViewPortHandler.getChartWidth()) { gridLinePath.moveTo(position[0], mViewPortHandler.contentBottom()); gridLinePath.lineTo(position[0], mViewPortHandler.contentTop()); // draw a path because lines don't support dashing on lower android versions c.drawPath(gridLinePath, mGridPaint); } gridLinePath.reset(); } }
Example 14
Source File: XAxisRenderer.java From Stayfit with Apache License 2.0 | 5 votes |
@Override public void renderGridLines(Canvas c) { if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled()) return; // pre alloc float[] position = new float[] { 0f, 0f }; mGridPaint.setColor(mXAxis.getGridColor()); mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth()); mGridPaint.setPathEffect(mXAxis.getGridDashPathEffect()); Path gridLinePath = new Path(); for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) { position[0] = i; mTrans.pointValuesToPixel(position); if (position[0] >= mViewPortHandler.offsetLeft() && position[0] <= mViewPortHandler.getChartWidth()) { gridLinePath.moveTo(position[0], mViewPortHandler.contentBottom()); gridLinePath.lineTo(position[0], mViewPortHandler.contentTop()); // draw a path because lines don't support dashing on lower android versions c.drawPath(gridLinePath, mGridPaint); } gridLinePath.reset(); } }
Example 15
Source File: FreeHandView.java From Machine-Learning-Projects-for-Mobile-Applications with MIT License | 5 votes |
private void touchStart(float x, float y) { mPath = new Path(); FingerPath fp = new FingerPath(currentColor, emboss, blur, strokeWidth, mPath); paths.add(fp); mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; }
Example 16
Source File: VectorDrawable.java From Mover with Apache License 2.0 | 4 votes |
public void toPath(Path path) { path.reset(); if (mNodes != null) { PathParser.PathDataNode.nodesToPath(mNodes, path); } }
Example 17
Source File: VectorDrawableCompat.java From VectorChildFinder with Apache License 2.0 | 4 votes |
public void toPath(Path path) { path.reset(); if (mNodes != null) { PathParser.PathDataNode.nodesToPath(mNodes, path); } }
Example 18
Source File: YAxisRenderer.java From JNChartDemo with Apache License 2.0 | 4 votes |
/** * Draws the LimitLines associated with this axis to the screen. * * @param c */ @Override public void renderLimitLines(Canvas c) { List<LimitLine> limitLines = mYAxis.getLimitLines(); if (limitLines == null || limitLines.size() <= 0) return; float[] pts = new float[2]; Path limitLinePath = new Path(); for (int i = 0; i < limitLines.size(); i++) { LimitLine l = limitLines.get(i); if (!l.isEnabled()) continue; mLimitLinePaint.setStyle(Paint.Style.STROKE); mLimitLinePaint.setColor(l.getLineColor()); mLimitLinePaint.setStrokeWidth(l.getLineWidth()); mLimitLinePaint.setPathEffect(l.getDashPathEffect()); pts[1] = l.getLimit(); mTrans.pointValuesToPixel(pts); limitLinePath.moveTo(mViewPortHandler.contentLeft(), pts[1]); limitLinePath.lineTo(mViewPortHandler.contentRight(), pts[1]); c.drawPath(limitLinePath, mLimitLinePaint); limitLinePath.reset(); // c.drawLines(pts, mLimitLinePaint); String label = l.getLabel(); // if drawing the limit-value label is enabled if (label != null && !label.equals("")) { mLimitLinePaint.setStyle(l.getTextStyle()); mLimitLinePaint.setPathEffect(null); mLimitLinePaint.setColor(l.getTextColor()); mLimitLinePaint.setTypeface(l.getTypeface()); mLimitLinePaint.setStrokeWidth(0.5f); mLimitLinePaint.setTextSize(l.getTextSize()); final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label); float xOffset = Utils.convertDpToPixel(4f) + l.getXOffset(); float yOffset = l.getLineWidth() + labelLineHeight + l.getYOffset(); final LimitLine.LimitLabelPosition position = l.getLabelPosition(); if (position == LimitLine.LimitLabelPosition.RIGHT_TOP) { mLimitLinePaint.setTextAlign(Align.RIGHT); c.drawText(label, mViewPortHandler.contentRight() - xOffset, pts[1] - yOffset + labelLineHeight, mLimitLinePaint); } else if (position == LimitLine.LimitLabelPosition.RIGHT_BOTTOM) { mLimitLinePaint.setTextAlign(Align.RIGHT); c.drawText(label, mViewPortHandler.contentRight() - xOffset, pts[1] + yOffset, mLimitLinePaint); } else if (position == LimitLine.LimitLabelPosition.LEFT_TOP) { mLimitLinePaint.setTextAlign(Align.LEFT); c.drawText(label, mViewPortHandler.contentLeft() + xOffset, pts[1] - yOffset + labelLineHeight, mLimitLinePaint); } else { mLimitLinePaint.setTextAlign(Align.LEFT); c.drawText(label, mViewPortHandler.offsetLeft() + xOffset, pts[1] + yOffset, mLimitLinePaint); } } } }
Example 19
Source File: XAxisRendererHorizontalBarChart.java From android-kline with Apache License 2.0 | 4 votes |
/** * Draws the LimitLines associated with this axis to the screen. * This is the standard YAxis renderer using the XAxis limit lines. * * @param c */ @Override public void renderLimitLines(Canvas c) { List<LimitLine> limitLines = mXAxis.getLimitLines(); if (limitLines == null || limitLines.size() <= 0) return; float[] pts = mRenderLimitLinesBuffer; pts[0] = 0; pts[1] = 0; Path limitLinePath = mRenderLimitLinesPathBuffer; limitLinePath.reset(); for (int i = 0; i < limitLines.size(); i++) { LimitLine l = limitLines.get(i); if(!l.isEnabled()) continue; int clipRestoreCount = c.save(); mLimitLineClippingRect.set(mViewPortHandler.getContentRect()); mLimitLineClippingRect.inset(0.f, -l.getLineWidth()); c.clipRect(mLimitLineClippingRect); mLimitLinePaint.setStyle(Paint.Style.STROKE); mLimitLinePaint.setColor(l.getLineColor()); mLimitLinePaint.setStrokeWidth(l.getLineWidth()); mLimitLinePaint.setPathEffect(l.getDashPathEffect()); pts[1] = l.getLimit(); mTrans.pointValuesToPixel(pts); limitLinePath.moveTo(mViewPortHandler.contentLeft(), pts[1]); limitLinePath.lineTo(mViewPortHandler.contentRight(), pts[1]); c.drawPath(limitLinePath, mLimitLinePaint); limitLinePath.reset(); // c.drawLines(pts, mLimitLinePaint); String label = l.getLabel(); // if drawing the limit-value label is enabled if (label != null && !label.equals("")) { mLimitLinePaint.setStyle(l.getTextStyle()); mLimitLinePaint.setPathEffect(null); mLimitLinePaint.setColor(l.getTextColor()); mLimitLinePaint.setStrokeWidth(0.5f); mLimitLinePaint.setTextSize(l.getTextSize()); final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label); float xOffset = Utils.convertDpToPixel(4f) + l.getXOffset(); float yOffset = l.getLineWidth() + labelLineHeight + l.getYOffset(); final LimitLine.LimitLabelPosition position = l.getLabelPosition(); if (position == LimitLine.LimitLabelPosition.RIGHT_TOP) { mLimitLinePaint.setTextAlign(Align.RIGHT); c.drawText(label, mViewPortHandler.contentRight() - xOffset, pts[1] - yOffset + labelLineHeight, mLimitLinePaint); } else if (position == LimitLine.LimitLabelPosition.RIGHT_BOTTOM) { mLimitLinePaint.setTextAlign(Align.RIGHT); c.drawText(label, mViewPortHandler.contentRight() - xOffset, pts[1] + yOffset, mLimitLinePaint); } else if (position == LimitLine.LimitLabelPosition.LEFT_TOP) { mLimitLinePaint.setTextAlign(Align.LEFT); c.drawText(label, mViewPortHandler.contentLeft() + xOffset, pts[1] - yOffset + labelLineHeight, mLimitLinePaint); } else { mLimitLinePaint.setTextAlign(Align.LEFT); c.drawText(label, mViewPortHandler.offsetLeft() + xOffset, pts[1] + yOffset, mLimitLinePaint); } } c.restoreToCount(clipRestoreCount); } }
Example 20
Source File: YAxisRenderer.java From Ticket-Analysis with MIT License | 4 votes |
/** * Draws the LimitLines associated with this axis to the screen. * * @param c */ @Override public void renderLimitLines(Canvas c) { List<LimitLine> limitLines = mYAxis.getLimitLines(); if (limitLines == null || limitLines.size() <= 0) return; float[] pts = mRenderLimitLinesBuffer; pts[0] = 0; pts[1] = 0; Path limitLinePath = mRenderLimitLines; limitLinePath.reset(); for (int i = 0; i < limitLines.size(); i++) { LimitLine l = limitLines.get(i); if (!l.isEnabled()) continue; int clipRestoreCount = c.save(); mLimitLineClippingRect.set(mViewPortHandler.getContentRect()); mLimitLineClippingRect.inset(0.f, -l.getLineWidth()); c.clipRect(mLimitLineClippingRect); mLimitLinePaint.setStyle(Paint.Style.STROKE); mLimitLinePaint.setColor(l.getLineColor()); mLimitLinePaint.setStrokeWidth(l.getLineWidth()); mLimitLinePaint.setPathEffect(l.getDashPathEffect()); pts[1] = l.getLimit(); mTrans.pointValuesToPixel(pts); limitLinePath.moveTo(mViewPortHandler.contentLeft(), pts[1]); limitLinePath.lineTo(mViewPortHandler.contentRight(), pts[1]); c.drawPath(limitLinePath, mLimitLinePaint); limitLinePath.reset(); // c.drawLines(pts, mLimitLinePaint); String label = l.getLabel(); // if drawing the limit-value label is enabled if (label != null && !label.equals("")) { mLimitLinePaint.setStyle(l.getTextStyle()); mLimitLinePaint.setPathEffect(null); mLimitLinePaint.setColor(l.getTextColor()); mLimitLinePaint.setTypeface(l.getTypeface()); mLimitLinePaint.setStrokeWidth(0.5f); mLimitLinePaint.setTextSize(l.getTextSize()); final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label); float xOffset = Utils.convertDpToPixel(4f) + l.getXOffset(); float yOffset = l.getLineWidth() + labelLineHeight + l.getYOffset(); final LimitLine.LimitLabelPosition position = l.getLabelPosition(); if (position == LimitLine.LimitLabelPosition.RIGHT_TOP) { mLimitLinePaint.setTextAlign(Align.RIGHT); c.drawText(label, mViewPortHandler.contentRight() - xOffset, pts[1] - yOffset + labelLineHeight, mLimitLinePaint); } else if (position == LimitLine.LimitLabelPosition.RIGHT_BOTTOM) { mLimitLinePaint.setTextAlign(Align.RIGHT); c.drawText(label, mViewPortHandler.contentRight() - xOffset, pts[1] + yOffset, mLimitLinePaint); } else if (position == LimitLine.LimitLabelPosition.LEFT_TOP) { mLimitLinePaint.setTextAlign(Align.LEFT); c.drawText(label, mViewPortHandler.contentLeft() + xOffset, pts[1] - yOffset + labelLineHeight, mLimitLinePaint); } else { mLimitLinePaint.setTextAlign(Align.LEFT); c.drawText(label, mViewPortHandler.offsetLeft() + xOffset, pts[1] + yOffset, mLimitLinePaint); } } c.restoreToCount(clipRestoreCount); } }