List of usage examples for android.graphics Path Path
public Path()
From source file:de.telekom.pde.codelibrary.ui.layout.PDESwipeRefreshLayout.java
private void drawTrigger(Canvas canvas, int cx, int cy) { float innerRadius; float outerRadius; Path circlePath;// www. ja v a 2s .c om if (mTriggerPercentage < 0.05f) return; innerRadius = 0.7f * PDEBuildingUnits.BU(); outerRadius = 0.9f * PDEBuildingUnits.BU(); canvas.drawCircle(cx, cy, PDEBuildingUnits.BU(), mPaint); circlePath = new Path(); circlePath.moveTo(cx, cy - innerRadius); circlePath.lineTo(cx, cy - outerRadius); circlePath.arcTo(new RectF(cx - outerRadius, cy - outerRadius, cx + outerRadius, cy + outerRadius), -90.0f, mTriggerPercentage * 360.0f); circlePath.lineTo((float) (cx + Math.sin(degreesToRadians(mTriggerPercentage * 360.0f)) * innerRadius), (float) (cy - Math.cos(degreesToRadians(mTriggerPercentage * 360.0f)) * innerRadius)); circlePath.arcTo(new RectF(cx - innerRadius, cy - innerRadius, cx + innerRadius, cy + innerRadius), -90.0f + mTriggerPercentage * 360.0f, -mTriggerPercentage * 360.0f); canvas.drawPath(circlePath, mWhitePaint); }
From source file:com.codegarden.nativenavigation.JuceActivity.java
public final int[] renderGlyph(char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) { Path p = new Path(); paint.getTextPath(String.valueOf(glyph), 0, 1, 0.0f, 0.0f, p); RectF boundsF = new RectF(); p.computeBounds(boundsF, true);/*from w w w. j av a 2 s . c o m*/ matrix.mapRect(boundsF); boundsF.roundOut(bounds); bounds.left--; bounds.right++; final int w = bounds.width(); final int h = Math.max(1, bounds.height()); Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bm); matrix.postTranslate(-bounds.left, -bounds.top); c.setMatrix(matrix); c.drawPath(p, paint); final int sizeNeeded = w * h; if (cachedRenderArray.length < sizeNeeded) cachedRenderArray = new int[sizeNeeded]; bm.getPixels(cachedRenderArray, 0, w, 0, 0, w, h); bm.recycle(); return cachedRenderArray; }
From source file:com.waz.zclient.views.images.CircularSeekBar.java
/** * Initialize the {@code Path} objects with the appropriate values. *//*from w ww .jav a 2 s . com*/ private void initPaths() { circlePath = new Path(); circlePath.addArc(circleRectF, startAngle, totalCircleDegrees); circleProgressPath = new Path(); circleProgressPath.addArc(circleRectF, startAngle, progressDegrees); }
From source file:com.wanikani.androidnotifier.graph.TYPlot.java
/** * Draws a segment containins samples//w w w . j a va 2 s . c o m * @param canvas the canvas * @param series the series * @param interval the interval * @param base a float array initially set to zero, and updated by this method * @param samples the samples */ protected void drawPlot(Canvas canvas, Pager.Series series, Pager.Interval interval, float base[], float samples[]) { Path path; Paint p; int i, n; p = pas.series.get(series); n = interval.stop - interval.start + 1; if (p == null || samples.length == 0 || n <= 0) return; path = new Path(); path.moveTo(vp.getRelPosition(interval.start + n), vp.getY(base[n - 1])); for (i = n - 1; i >= 0; i--) { path.lineTo(vp.getRelPosition(interval.start + i), vp.getY(base[i])); base[i] += samples[i]; } for (i = 0; i < n; i++) path.lineTo(vp.getRelPosition(interval.start + i), vp.getY(base[i])); path.lineTo(vp.getRelPosition(interval.start + n), vp.getY(base[n - 1])); path.close(); canvas.drawPath(path, p); }
From source file:cw.kop.autobackground.settings.WearSettingsFragment.java
private void drawAnalog() { if (!AppSettings.getTimeType().equals(AppSettings.ANALOG)) { return;/*from w w w . ja v a2 s. c om*/ } canvas = surfaceView.getHolder().lockCanvas(); if (canvas == null) { return; } setPaints(); if (imageBitmap != null) { canvas.drawBitmap(imageBitmap, 0, 0, bitmapPaint); } // Time time = new Time(); // time.setToNow(); // time.set(time.toMillis(false) + AppSettings.getTimeOffset()); // // float hour = time.hour + time.minute / 60f; // float minute = time.minute + time.second / 60f; // float second = time.second; float centerX = watchContainer.getWidth() * 0.222f; float centerY = watchContainer.getHeight() * 0.222f; float radius = centerX; // Draw tick marks for (int i = 0; i < 12; i++) { canvas.drawLine((float) (centerX + (radius * tickRadius / 100f) * Math.cos(Math.toRadians(i * 30f))), (float) (centerY + (radius * tickRadius / 100f) * Math.sin(Math.toRadians(i * 30f))), (float) (centerX + (radius) * Math.cos(Math.toRadians(i * 30f))), (float) (centerY + (radius) * Math.sin(Math.toRadians(i * 30f))), tickPaint); } // Draw clock hands // Draw shadows first to prevent outline overlapping other hands Path hourShadowPath = new Path(); hourShadowPath.moveTo((float) (centerX + hourWidth / 1.5f * Math.cos(Math.toRadians(90f))), (float) (centerY + hourWidth / 1.5f * Math.sin(Math.toRadians(90f)))); hourShadowPath.quadTo((float) (centerX - (hourWidth / 1.5f) * Math.cos(Math.toRadians(0f))), (float) (centerY - (hourWidth / 1.5f) * Math.sin(Math.toRadians(0f))), (float) (centerX + hourWidth / 1.5f * Math.cos(Math.toRadians(270f))), (float) (centerY + hourWidth / 1.5f * Math.sin(Math.toRadians(270f)))); hourShadowPath.lineTo( (float) (centerX + (radius * hourRadius / 100f + 2.0f) * Math.cos(Math.toRadians(0f))), (float) (centerY + (radius * hourRadius / 100f + 2.0f) * Math.sin(Math.toRadians(0f)))); hourShadowPath.close(); canvas.drawPath(hourShadowPath, hourShadowPaint); Path minuteShadowPath = new Path(); minuteShadowPath.moveTo((float) (centerX + minuteWidth / 1.5f * Math.cos(Math.toRadians(0f))), (float) (centerY + minuteWidth / 1.5f * Math.sin(Math.toRadians(0f)))); minuteShadowPath.quadTo((float) (centerX - (minuteWidth / 1.5f) * Math.cos(Math.toRadians(-180f))), (float) (centerY - (minuteWidth / 1.5f) * Math.sin(Math.toRadians(-180f))), (float) (centerX + minuteWidth / 1.5f * Math.cos(Math.toRadians(90f))), (float) (centerY + minuteWidth / 1.5f * Math.sin(Math.toRadians(90f)))); minuteShadowPath.lineTo( (float) (centerX + (radius * minuteRadius / 100f + 2.0f) * Math.cos(Math.toRadians(-90f))), (float) (centerY + (radius * minuteRadius / 100f + 2.0f) * Math.sin(Math.toRadians(-90f)))); minuteShadowPath.close(); canvas.drawPath(minuteShadowPath, minuteShadowPaint); Path secondShadowPath = new Path(); secondShadowPath.moveTo((float) (centerX + secondWidth / 1.5f * Math.cos(Math.toRadians(225f))), (float) (centerY + secondWidth / 1.5f * Math.sin(Math.toRadians(225f)))); secondShadowPath.quadTo((float) (centerX - (secondWidth / 1.5f) * Math.cos(Math.toRadians(45f))), (float) (centerY - (secondWidth / 1.5f) * Math.sin(Math.toRadians(45f))), (float) (centerX + secondWidth / 1.5f * Math.cos(Math.toRadians(315f))), (float) (centerY + secondWidth / 1.5f * Math.sin(Math.toRadians(315f)))); secondShadowPath.lineTo( (float) (centerX + (radius * secondRadius / 100f + 2f) * Math.cos(Math.toRadians(135f))), (float) (centerY + (radius * secondRadius / 100f + 2.0f) * Math.sin(Math.toRadians(135f)))); secondShadowPath.close(); canvas.drawPath(secondShadowPath, secondShadowPaint); // Now draw actual hands Path hourPath = new Path(); hourPath.moveTo((float) (centerX + hourWidth / 2f * Math.cos(Math.toRadians(90f))), (float) (centerY + hourWidth / 2f * Math.sin(Math.toRadians(90f)))); hourPath.quadTo((float) (centerX - (hourWidth / 2f) * Math.cos(Math.toRadians(0f))), (float) (centerY - (hourWidth / 2f) * Math.sin(Math.toRadians(0f))), (float) (centerX + hourWidth / 2f * Math.cos(Math.toRadians(270f))), (float) (centerY + hourWidth / 2f * Math.sin(Math.toRadians(270f)))); hourPath.lineTo((float) (centerX + (radius * hourRadius / 100f) * Math.cos(Math.toRadians(0f))), (float) (centerY + (radius * hourRadius / 100f) * Math.sin(Math.toRadians(0f)))); hourPath.close(); canvas.drawPath(hourPath, hourPaint); Path minutePath = new Path(); minutePath.moveTo((float) (centerX + minuteWidth / 2f * Math.cos(Math.toRadians(0f))), (float) (centerY + minuteWidth / 2f * Math.sin(Math.toRadians(0f)))); minutePath.quadTo((float) (centerX - (minuteWidth / 2f) * Math.cos(Math.toRadians(-180f))), (float) (centerY - (minuteWidth / 2f) * Math.sin(Math.toRadians(-180f))), (float) (centerX + minuteWidth / 2f * Math.cos(Math.toRadians(90f))), (float) (centerY + minuteWidth / 2f * Math.sin(Math.toRadians(90f)))); minutePath.lineTo((float) (centerX + (radius * minuteRadius / 100f) * Math.cos(Math.toRadians(-90f))), (float) (centerY + (radius * minuteRadius / 100f) * Math.sin(Math.toRadians(-90f)))); minutePath.close(); canvas.drawPath(minutePath, minutePaint); Path secondPath = new Path(); secondPath.moveTo((float) (centerX + secondWidth / 2f * Math.cos(Math.toRadians(225f))), (float) (centerY + secondWidth / 2f * Math.sin(Math.toRadians(225f)))); secondPath.quadTo((float) (centerX - (secondWidth / 2f) * Math.cos(Math.toRadians(45f))), (float) (centerY - (secondWidth / 2f) * Math.sin(Math.toRadians(45f))), (float) (centerX + secondWidth / 2f * Math.cos(Math.toRadians(315f))), (float) (centerY + secondWidth / 2f * Math.sin(Math.toRadians(315f)))); secondPath.lineTo((float) (centerX + (radius * secondRadius / 100f) * Math.cos(Math.toRadians(135f))), (float) (centerY + (radius * secondRadius / 100f) * Math.sin(Math.toRadians(135f)))); secondPath.close(); canvas.drawPath(secondPath, secondPaint); surfaceView.getHolder().unlockCanvasAndPost(canvas); }
From source file:com.juce.JuceAppActivity.java
public final int[] renderGlyph (char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) { Path p = new Path(); paint.getTextPath (String.valueOf (glyph), 0, 1, 0.0f, 0.0f, p); RectF boundsF = new RectF(); p.computeBounds (boundsF, true);//from w w w . ja va 2s .c o m matrix.mapRect (boundsF); boundsF.roundOut (bounds); bounds.left--; bounds.right++; final int w = bounds.width(); final int h = Math.max (1, bounds.height()); Bitmap bm = Bitmap.createBitmap (w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas (bm); matrix.postTranslate (-bounds.left, -bounds.top); c.setMatrix (matrix); c.drawPath (p, paint); final int sizeNeeded = w * h; if (cachedRenderArray.length < sizeNeeded) cachedRenderArray = new int [sizeNeeded]; bm.getPixels (cachedRenderArray, 0, w, 0, 0, w, h); bm.recycle(); return cachedRenderArray; }
From source file:org.navitproject.navit.NavitGraphics.java
protected void draw_polyline(Paint paint, int[] c) { paint.setStrokeWidth(c[0]);//from w w w.j a va2s . com paint.setARGB(c[1], c[2], c[3], c[4]); paint.setStyle(Paint.Style.STROKE); //paint.setAntiAlias(true); //paint.setStrokeWidth(0); int ndashes = c[5]; float[] intervals = new float[ndashes + (ndashes % 2)]; for (int i = 0; i < ndashes; i++) { intervals[i] = c[6 + i]; } if ((ndashes % 2) == 1) { intervals[ndashes] = intervals[ndashes - 1]; } if (ndashes > 0) { paint.setPathEffect(new android.graphics.DashPathEffect(intervals, 0.0f)); } Path path = new Path(); path.moveTo(c[6 + ndashes], c[7 + ndashes]); for (int i = 8 + ndashes; i < c.length; i += 2) { path.lineTo(c[i], c[i + 1]); } //global_path.close(); draw_canvas.drawPath(path, paint); paint.setPathEffect(null); }
From source file:org.navitproject.navit.NavitGraphics.java
protected void draw_polygon(Paint paint, int[] c) { paint.setStrokeWidth(c[0]);// ww w . j av a2 s . com paint.setARGB(c[1], c[2], c[3], c[4]); paint.setStyle(Paint.Style.FILL); //paint.setAntiAlias(true); //paint.setStrokeWidth(0); Path path = new Path(); path.moveTo(c[5], c[6]); for (int i = 7; i < c.length; i += 2) { path.lineTo(c[i], c[i + 1]); } //global_path.close(); draw_canvas.drawPath(path, paint); }
From source file:org.navitproject.navit.NavitGraphics.java
protected void draw_text(Paint paint, int x, int y, String text, int size, int dx, int dy, int bgcolor) { int oldcolor = paint.getColor(); Path path = null;//ww w . ja v a2 s .c o m paint.setTextSize(size / 15); paint.setStyle(Paint.Style.FILL); if (dx != 0x10000 || dy != 0) { path = new Path(); path.moveTo(x, y); path.rLineTo(dx, dy); paint.setTextAlign(android.graphics.Paint.Align.LEFT); } if (bgcolor != 0) { paint.setStrokeWidth(3); paint.setColor(bgcolor); paint.setStyle(Paint.Style.STROKE); if (path == null) { draw_canvas.drawText(text, x, y, paint); } else { draw_canvas.drawTextOnPath(text, path, 0, 0, paint); } paint.setStyle(Paint.Style.FILL); paint.setColor(oldcolor); } if (path == null) { draw_canvas.drawText(text, x, y, paint); } else { draw_canvas.drawTextOnPath(text, path, 0, 0, paint); } paint.clearShadowLayer(); }
From source file:net.droidsolutions.droidcharts.core.renderer.category.LineAndShapeRenderer.java
private Path convertAwtPathToAndroid(PathIterator pi) { Path path = new Path(); float[] coords = new float[6]; while (!pi.isDone()) { int windingRule = pi.getWindingRule(); if (windingRule == PathIterator.WIND_EVEN_ODD) { path.setFillType(Path.FillType.EVEN_ODD); } else {/*from www. ja v a 2 s.c o m*/ path.setFillType(Path.FillType.INVERSE_EVEN_ODD); } int pathType = pi.currentSegment(coords); switch (pathType) { case PathIterator.SEG_CLOSE: path.close(); break; case PathIterator.SEG_CUBICTO: path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case PathIterator.SEG_LINETO: path.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_MOVETO: path.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_QUADTO: path.quadTo(coords[0], coords[1], coords[2], coords[3]); break; } pi.next(); } return path; }