Java Code Examples for android.graphics.Path#addCircle()
The following examples show how to use
android.graphics.Path#addCircle() .
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: GeneralUtils.java From AndroidPhotoFilters with Apache License 2.0 | 6 votes |
public static Bitmap generateCircularBitmap(Bitmap input) { final int width = input.getWidth(); final int height = input.getHeight(); final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Path path = new Path(); path.addCircle( (float) (width / 2) , (float) (height / 2) , (float) Math.min(width, (height / 2)) , Path.Direction.CCW ); final Canvas canvas = new Canvas(outputBitmap); canvas.clipPath(path); canvas.drawBitmap(input, 0, 0, null); return outputBitmap; }
Example 2
Source File: CircularSplashView.java From Depth with MIT License | 6 votes |
public Bitmap GetBitmapClippedCircle(Bitmap bitmap) { final int width = bitmap.getWidth(); final int height = bitmap.getHeight(); final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Path path = new Path(); path.addCircle( (float) (width / 2) , (float) (height / 2) , (float) Math.min(width, (height / 2)) , Path.Direction.CCW); final Canvas canvas = new Canvas(outputBitmap); canvas.clipPath(path); canvas.drawBitmap(bitmap, 0, 0, null); bitmap.recycle(); return outputBitmap; }
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: CircleProgress.java From android with MIT License | 6 votes |
private void drawAlert(Canvas canvas, int radius, float angle) { Paint textPaint = new Paint(); textPaint.setColor(mCircleWhite); textPaint.setAntiAlias(true); textPaint.setTextSize(getResources().getDimension(R.dimen.out_indicator_size)); Paint.FontMetricsInt fmi = textPaint.getFontMetricsInt(); float textRadius = radius - Math.abs(fmi.bottom + fmi.top) / 2; Path path = new Path(); path.addCircle(getCenterX(), getCenterY(), textRadius, Path.Direction.CW);//顺时针绘制(or CCW) float circlePathLength = ViewUtils.getCirclePathLength(textRadius, (CIRCLE_START_ANGLE + angle / 2)); circlePathLength -= ViewUtils.getTextWidth(textPaint, mProgressAlert) / 2; canvas.drawTextOnPath(String.valueOf(mProgressAlert), path, circlePathLength, 0, textPaint); }
Example 5
Source File: CircularSplashView.java From Depth with MIT License | 6 votes |
public Bitmap GetBitmapClippedCircle(Bitmap bitmap) { final int width = bitmap.getWidth(); final int height = bitmap.getHeight(); final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Path path = new Path(); path.addCircle( (float) (width / 2) , (float) (height / 2) , (float) Math.min(width, (height / 2)) , Path.Direction.CCW); final Canvas canvas = new Canvas(outputBitmap); canvas.clipPath(path); canvas.drawBitmap(bitmap, 0, 0, null); bitmap.recycle(); return outputBitmap; }
Example 6
Source File: CircularSplashView.java From Android-Plugin-Framework with MIT License | 6 votes |
public Bitmap GetBitmapClippedCircle(Bitmap bitmap) { final int width = bitmap.getWidth(); final int height = bitmap.getHeight(); final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Path path = new Path(); path.addCircle((float) (width / 2), (float) (height / 2), (float) Math.min(width, (height / 2)), Path.Direction.CCW); final Canvas canvas = new Canvas(outputBitmap); canvas.clipPath(path); canvas.drawBitmap(bitmap, 0, 0, null); bitmap.recycle(); return outputBitmap; }
Example 7
Source File: GeneralUtils.java From AndroidPhotoFilters with Apache License 2.0 | 6 votes |
public static Bitmap generateCircularBitmap(Bitmap input) { final int width = input.getWidth(); final int height = input.getHeight(); final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Path path = new Path(); path.addCircle( (float) (width / 2) , (float) (height / 2) , (float) Math.min(width, (height / 2)) , Path.Direction.CCW ); final Canvas canvas = new Canvas(outputBitmap); canvas.clipPath(path); canvas.drawBitmap(input, 0, 0, null); return outputBitmap; }
Example 8
Source File: RadarChartRenderer.java From NetKnight with Apache License 2.0 | 5 votes |
public void drawHighlightCircle(Canvas c, PointF point, float innerRadius, float outerRadius, int fillColor, int strokeColor, float strokeWidth) { c.save(); outerRadius = Utils.convertDpToPixel(outerRadius); innerRadius = Utils.convertDpToPixel(innerRadius); if (fillColor != ColorTemplate.COLOR_NONE) { Path p = new Path(); p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW); if (innerRadius > 0.f) { p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW); } mHighlightCirclePaint.setColor(fillColor); mHighlightCirclePaint.setStyle(Paint.Style.FILL); c.drawPath(p, mHighlightCirclePaint); } if (strokeColor != ColorTemplate.COLOR_NONE) { mHighlightCirclePaint.setColor(strokeColor); mHighlightCirclePaint.setStyle(Paint.Style.STROKE); mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth)); c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint); } c.restore(); }
Example 9
Source File: ShiftDrawable.java From focus-android with Mozilla Public License 2.0 | 5 votes |
private void updateBounds() { final Rect b = getBounds(); final int width = (int) ((float) b.width() * getLevel() / MAX_LEVEL); final float radius = b.height() / 2f; mVisibleRect.set(b.left, b.top, b.left + width, b.height()); // draw round to head of progressbar. I know it looks stupid, don't blame me now. mPath = new Path(); mPath.addRect(b.left, b.top, b.left + width - radius, b.height(), Path.Direction.CCW); mPath.addCircle(b.left + width - radius, radius, radius, Path.Direction.CCW); }
Example 10
Source File: RadarChartRenderer.java From StockChart-MPAndroidChart with MIT License | 5 votes |
public void drawHighlightCircle(Canvas c, MPPointF point, float innerRadius, float outerRadius, int fillColor, int strokeColor, float strokeWidth) { c.save(); outerRadius = Utils.convertDpToPixel(outerRadius); innerRadius = Utils.convertDpToPixel(innerRadius); if (fillColor != ColorTemplate.COLOR_NONE) { Path p = mDrawHighlightCirclePathBuffer; p.reset(); p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW); if (innerRadius > 0.f) { p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW); } mHighlightCirclePaint.setColor(fillColor); mHighlightCirclePaint.setStyle(Paint.Style.FILL); c.drawPath(p, mHighlightCirclePaint); } if (strokeColor != ColorTemplate.COLOR_NONE) { mHighlightCirclePaint.setColor(strokeColor); mHighlightCirclePaint.setStyle(Paint.Style.STROKE); mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth)); c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint); } c.restore(); }
Example 11
Source File: RadarChartRenderer.java From android-kline with Apache License 2.0 | 5 votes |
public void drawHighlightCircle(Canvas c, MPPointF point, float innerRadius, float outerRadius, int fillColor, int strokeColor, float strokeWidth) { c.save(); outerRadius = Utils.convertDpToPixel(outerRadius); innerRadius = Utils.convertDpToPixel(innerRadius); if (fillColor != ColorTemplate.COLOR_NONE) { Path p = mDrawHighlightCirclePathBuffer; p.reset(); p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW); if (innerRadius > 0.f) { p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW); } mHighlightCirclePaint.setColor(fillColor); mHighlightCirclePaint.setStyle(Paint.Style.FILL); c.drawPath(p, mHighlightCirclePaint); } if (strokeColor != ColorTemplate.COLOR_NONE) { mHighlightCirclePaint.setColor(strokeColor); mHighlightCirclePaint.setStyle(Paint.Style.STROKE); mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth)); c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint); } c.restore(); }
Example 12
Source File: LeadActivity.java From KotlinMVPRxJava2Dagger2GreenDaoRetrofitDemo with Apache License 2.0 | 5 votes |
@Override protected void initData() { Path path = new Path(); path.moveTo(0,0); path.addCircle(40,40,30, Path.Direction.CW); pathAnimView1.setSourcePath(PathParserUtils.getPathFromArrayFloatList(StoreHousePath.getPath("pathview"))); pathAnimView1.startAnim(); }
Example 13
Source File: RadarChartRenderer.java From JNChartDemo with Apache License 2.0 | 5 votes |
public void drawHighlightCircle(Canvas c, PointF point, float innerRadius, float outerRadius, int fillColor, int strokeColor, float strokeWidth) { c.save(); outerRadius = Utils.convertDpToPixel(outerRadius); innerRadius = Utils.convertDpToPixel(innerRadius); if (fillColor != ColorTemplate.COLOR_NONE) { Path p = new Path(); p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW); if (innerRadius > 0.f) { p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW); } mHighlightCirclePaint.setColor(fillColor); mHighlightCirclePaint.setStyle(Paint.Style.FILL); c.drawPath(p, mHighlightCirclePaint); } if (strokeColor != ColorTemplate.COLOR_NONE) { mHighlightCirclePaint.setColor(strokeColor); mHighlightCirclePaint.setStyle(Paint.Style.STROKE); mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth)); c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint); } c.restore(); }
Example 14
Source File: CircleColorView.java From Status with Apache License 2.0 | 5 votes |
@Override public void render(Canvas canvas) { int size = Math.min(canvas.getWidth(), canvas.getHeight()); Path path = new Path(); path.addCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, size / 2, Path.Direction.CW); canvas.clipPath(path); super.render(canvas); canvas.drawCircle(getWidth() / 2, getHeight() / 2, (size / 2) - (outlineSize / 2), outlinePaint); }
Example 15
Source File: RippleEffectDrawer.java From fab with Apache License 2.0 | 5 votes |
/** * Returns the clipped path, which clips the ripple circle so that it doesn't goes beyond * the <b>Action Button</b> circle * * @return clipped path, which clips the ripple circle */ private Path getCircleClipPath() { Path path = new Path(); path.addCircle(getActionButton().calculateCenterX(), getActionButton().calculateCenterY(), getActionButton().calculateCircleRadius(), Path.Direction.CW); return path; }
Example 16
Source File: CirclePath.java From ShapeView with Apache License 2.0 | 4 votes |
@Override public void setClipPath(Path path, int width, int height) { path.addCircle(width / 2f, height / 2f, Math.min(width / 2f, height / 2f), Path.Direction.CW); }
Example 17
Source File: OC_Sorting_S4.java From GLEXP-Team-onebillion with Apache License 2.0 | 4 votes |
public void setSceneXX(String scene) { if (totalObjectCount == 0) { deleteControls("obj.*"); if (collar != null) collar.hide(); } super.setSceneXX(scene); currentPaintPot = null; String potName = eventAttributes.get("targetpot"); if (potName != null) { correctPaintPot = objectDict.get(potName); Map<String,Object> targetAttrs = correctPaintPot.attributes(); correctColour = OBUtils.colorFromRGBString((String)targetAttrs.get("fillcolour")); correctObjArray = filterControls(String.format("%s.*",eventAttributes.get("targetitem"))); } targets = filterControls("objj.*"); if (totalObjectCount == 0) { totalObjectCount = targets.size(); for (OBControl obj : targets) { obj.setDoubleSided(true); obj.texturise(false,this); } } pots = filterControls("objpot.*"); if (collar == null) { float w = pots.get(0).width()+applyGraphicScale(4f); Path p = new Path(); p.addCircle(w/2, w/2, w/2, Path.Direction.CCW); collar = new OBPath(p); //collar.setLineWidth(applyGraphicScale(4f)); collar.sizeToBoundingBoxIncludingStroke(); collar.setFillColor(Color.GRAY); collar.setZPosition(pots.get(0).zPosition()-0.01f); attachControl(collar); collar.hide(); } }
Example 18
Source File: Utils.java From SpotifyTray-Android with MIT License | 4 votes |
/** * Takes an inputstream, loads a bitmap optimized of space and then crops it for the view. * @param iStream Inputstream to the image. * @param containerHeight Height of the image holder container. * @param containerWidth Width of the image holder container. * @return Cropped/masked bitmap. */ public static Bitmap loadMaskedBitmap(InputStream iStream, int containerHeight, int containerWidth){ // Load image data before loading the image itself. BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeStream(iStream,null,bmOptions); int photoH = bmOptions.outHeight; int photoW = bmOptions.outWidth; // Find a suitable scalefactor to load the smaller bitmap, and then set the options. int scaleFactor = Math.min(photoH/containerHeight, photoW/containerHeight); bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; bmOptions.inPurgeable = true; // Load the square region out of the bitmap. Bitmap bmap=null; BitmapRegionDecoder decoder; try { iStream.reset(); decoder = BitmapRegionDecoder.newInstance(iStream, false); bmap = decoder.decodeRegion(new Rect(0, 0, Math.min(photoH, photoW), Math.min(photoH, photoW)),bmOptions); } catch (IOException e) { e.printStackTrace(); } // Calculate new width of the bitmap based on the width of the container int bitmapNewWidth = (bmap.getWidth()*containerWidth)/containerHeight; // Produce clipping mask on the canvas and draw the bitmap Bitmap targetBitmap = Bitmap.createBitmap(bitmapNewWidth, bmap.getHeight(), bmap.getConfig()); Canvas canvas = new Canvas(targetBitmap); Path path = new Path(); path.addCircle(bmap.getWidth() / 2, bmap.getHeight() / 2, bmap.getWidth() / 2, Path.Direction.CCW); canvas.clipPath(path); canvas.drawBitmap(bmap, 0, 0, null); // Retrieve the clipped bitmap and return return targetBitmap; }
Example 19
Source File: LobsterPicker.java From Lobsterpicker with Apache License 2.0 | 4 votes |
private void init(Context context, AttributeSet attrs, int defStyle) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LobsterPicker, defStyle, 0); final Resources b = context.getResources(); int thickness = a.getDimensionPixelSize( R.styleable.LobsterPicker_color_wheel_thickness, b.getDimensionPixelSize(R.dimen.color_wheel_thickness)); radius = a.getDimensionPixelSize( R.styleable.LobsterPicker_color_wheel_radius, b.getDimensionPixelSize(R.dimen.color_wheel_radius)); pointerRadius = a.getDimensionPixelSize( R.styleable.LobsterPicker_color_wheel_pointer_radius, b.getDimensionPixelSize(R.dimen.color_wheel_pointer_radius)); historyRadius = a.getDimensionPixelSize( R.styleable.LobsterPicker_color_history_radius, b.getDimensionPixelSize(R.dimen.color_history_radius)); colorHistoryEnabled = a.getBoolean( R.styleable.LobsterPicker_color_history_enabled, false); int pointerShadowRadius = a.getDimensionPixelSize( R.styleable.LobsterPicker_color_wheel_pointer_shadow_radius, b.getDimensionPixelSize(R.dimen.color_wheel_pointer_shadow_radius)); int pointerShadowColor = a.getColor(R.styleable.LobsterPicker_color_wheel_pointer_shadow, b.getColor(R.color.lobsterpicker_pointer_shadow)); int schemeRes = a.getResourceId(R.styleable.LobsterPicker_color_wheel_scheme, R.drawable.default_pallete); a.recycle(); decorators = new ArrayList<>(); listeners = new ArrayList<>(); decorators.add(updateDecorator); wheelPaint = new Paint(Paint.ANTI_ALIAS_FLAG); wheelPaint.setStyle(Paint.Style.STROKE); wheelPaint.setStrokeWidth(thickness); pointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); pointerPaint.setStyle(Paint.Style.FILL); historyPaint = new Paint(Paint.ANTI_ALIAS_FLAG); historyPaint.setStyle(Paint.Style.FILL); Paint pointerShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG); pointerShadowPaint.setStyle(Paint.Style.FILL); pointerShadowPaint.setColor(pointerShadowColor); //Predraw the pointers shadow pointerShadow = Bitmap.createBitmap(pointerShadowRadius * 2, pointerShadowRadius * 2, Bitmap.Config.ARGB_8888); Canvas pointerShadowCanvas = new Canvas(pointerShadow); pointerShadowCanvas.drawCircle(pointerShadowRadius, pointerShadowRadius, pointerShadowRadius, pointerShadowPaint); //Outer wheel ring largeRadiusPath = new Path(); largeRadiusPath.addCircle(0, 0, radius + thickness / 2, Path.Direction.CW); largeRadiusPath.close(); //inner wheel ring smallRadiusPath = new Path(); smallRadiusPath.addCircle(0, 0, radius - thickness / 2, Path.Direction.CW); smallRadiusPath.close(); //Default color adapter adapter = new BitmapColorAdapter(context, schemeRes); updateColorAdapter(); invalidate(); }
Example 20
Source File: ARTShapeShadowNode.java From art with MIT License | 4 votes |
/** * Creates a {@link Path} from an array of instructions constructed by JS * (see ARTSerializablePath.js). Each instruction starts with a type (see PATH_TYPE_*) followed * by arguments for that instruction. For example, to create a line the instruction will be * 2 (PATH_LINE_TO), x, y. This will draw a line from the last draw point (or 0,0) to x,y. * * @param data the array of instructions * @return the {@link Path} that can be drawn to a canvas */ private Path createPath(float[] data) { Path path = new Path(); path.moveTo(0, 0); int i = 0; while (i < data.length) { int type = (int) data[i++]; switch (type) { case PATH_TYPE_MOVETO: path.moveTo(data[i++] * mScale, data[i++] * mScale); break; case PATH_TYPE_CLOSE: path.close(); break; case PATH_TYPE_LINETO: path.lineTo(data[i++] * mScale, data[i++] * mScale); break; case PATH_TYPE_CURVETO: path.cubicTo( data[i++] * mScale, data[i++] * mScale, data[i++] * mScale, data[i++] * mScale, data[i++] * mScale, data[i++] * mScale); break; case PATH_TYPE_ARC: { float x = data[i++] * mScale; float y = data[i++] * mScale; float r = data[i++] * mScale; float start = (float) Math.toDegrees(data[i++]); float end = (float) Math.toDegrees(data[i++]); boolean counterClockwise = !(data[i++] == 1f); float sweep = end - start; if (Math.abs(sweep) >= 360) { path.addCircle(x, y, r, counterClockwise ? Path.Direction.CCW : Path.Direction.CW); } else { sweep = modulus(sweep, 360); if (counterClockwise && sweep < 360) { // Counter-clockwise sweeps are negative sweep = -1 * (360 - sweep); } RectF oval = new RectF(x - r, y - r, x + r, y + r); path.arcTo(oval, start, sweep); } break; } default: throw new JSApplicationIllegalArgumentException( "Unrecognized drawing instruction " + type); } } return path; }