List of usage examples for android.graphics Canvas drawCircle
public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint)
From source file:de.vanita5.twittnuker.view.ShapedImageView.java
private void drawBorder(@NonNull final Canvas canvas) { final RectF transitionSrc = mTransitionSource, transitionDst = mTransitionDestination; if (transitionSrc != null && transitionDst != null) { final float progress = 1 - (mDestination.width() - transitionDst.width()) / (transitionSrc.width() - transitionDst.width()); mBorderPaint.setStrokeWidth(mStrokeWidth * progress); mBorderPaint.setAlpha(Math.round(mBorderAlpha * progress)); ViewCompat.setTranslationZ(this, -ViewCompat.getElevation(this) * (1 - progress)); } else {//from ww w .j av a2 s.co m mBorderPaint.setStrokeWidth(mStrokeWidth); mBorderPaint.setAlpha(mBorderAlpha); ViewCompat.setTranslationZ(this, 0); } if (getStyle() == SHAPE_CIRCLE) { canvas.drawCircle(mDestination.centerX(), mDestination.centerY(), mDestination.width() / 2f - mBorderPaint.getStrokeWidth() / 2, mBorderPaint); } else { final float radius = getCalculatedCornerRadius(); canvas.drawRoundRect(mDestination, radius, radius, mBorderPaint); } }
From source file:com.hippo.widget.lockpattern.LockPatternView.java
/** * @param partOfPattern Whether this circle is part of the pattern. */// w w w .ja v a2s . c o m private void drawCircle(Canvas canvas, float centerX, float centerY, float size, boolean partOfPattern, float alpha) { mPaint.setColor(getCurrentColor(partOfPattern)); mPaint.setAlpha((int) (alpha * 255)); canvas.drawCircle(centerX, centerY, size / 2, mPaint); }
From source file:com.tct.mail.browse.MessageHeaderView.java
/** * Frames the input bitmap in a circle./*w w w .ja va 2 s.c o m*/ */ private static Bitmap frameBitmapInCircle(Bitmap input) { if (input == null) { return null; } // Crop the image if not squared. int inputWidth = input.getWidth(); int inputHeight = input.getHeight(); int targetX, targetY, targetSize; if (inputWidth >= inputHeight) { targetX = inputWidth / 2 - inputHeight / 2; targetY = 0; targetSize = inputHeight; } else { targetX = 0; targetY = inputHeight / 2 - inputWidth / 2; targetSize = inputWidth; } // Create an output bitmap and a canvas to draw on it. Bitmap output = Bitmap.createBitmap(targetSize, targetSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); // Create a black paint to draw the mask. Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.BLACK); // Draw a circle. canvas.drawCircle(targetSize / 2, targetSize / 2, targetSize / 2, paint); // Replace the black parts of the mask with the input image. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(input, targetX /* left */, targetY /* top */, paint); return output; }
From source file:org.jraf.android.cinetoday.mobile.ui.CirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { if (mViewPager == null) return;//from ww w . j a v a2 s . c o m int count = mViewPager.getAdapter().getCount(); if (count == 0) return; for (int i = 0; i < count; i++) { float x = i * (mCircleRadiusPx * 2 + mCircleMarginPx) + mCircleRadiusPx + mCircleMarginPx / 2; float y = mCircleRadiusPx; float radius; if (i == mPosition) { radius = mCircleRadiusPx - mCircleRadiusPx * SHRINK_FACTOR * mPositionOffset; } else if (i == mPosition + 1) { radius = mCircleRadiusPx - mCircleRadiusPx * SHRINK_FACTOR * (1f - mPositionOffset); } else { radius = mCircleRadiusPx - mCircleRadiusPx * SHRINK_FACTOR; } if (i == count - 1) { // Draw a '+' RectF dst = new RectF(); dst.left = x - radius; dst.right = x + radius; dst.top = y - radius; dst.bottom = y + radius; canvas.drawBitmap(mAddBitmap, null, dst, mPaint); } else { // Draw a circle canvas.drawCircle(x, y, radius, mPaint); } } }
From source file:com.diedrico.diedricoapp.PicMenuActivity.java
License:asdf
private PicAnalyzer.AsyncResponse analyzerFinished() { //We receive the important points and lines, we have to paint them return new PicAnalyzer.AsyncResponse() { @Override/*from w ww. j av a 2 s. com*/ public void processFinish(List<PointVector> points, List<LineVector> lines, List<Double> planos) { //Set that the analyzer finished analyzerFinished = Boolean.TRUE; //Save the points in another var, if the user select that there are errors in the scan, he can select the points and lines manually allPoints = points; allLines = lines; //First we have to delete the short lines, we get the top module and then we discard the short ones Collections.sort(lines, new Comparator<LineVector>() { @Override public int compare(LineVector line1, LineVector line2) { return (line1.getModuleTwoDimensionalVector() - line2.getModuleTwoDimensionalVector() >= 0) ? -1 : 1; } }); landLine = lines.get(0); //This is the landLine double minModule = lines.get(0).getModuleTwoDimensionalVector() / 6; for (LineVector linevector : new ArrayList<>(lines)) { if (linevector.getModuleTwoDimensionalVector() < minModule) { lines.remove(linevector); } } pointDiedrico = new ArrayList<>(); lineDiedrico = new ArrayList<>(); ////Delete the wrong lines, the ones that don't have x's view and y's view respectively (cota and alejamiento). Then we differ between if it is a line(in diedrico) or a plane for (int j = 1; j < lines.size(); j++) { //Start in 1 because in 0 the line is the landLine LineVector line1 = lines.get(j); for (int k = 1; k < lines.size(); k++) { LineVector line2 = lines.get(k); if (line1.equals(line2)) { if (k == lines.size() - 1) { //The last line of the list lines.remove(k); j--; break; } continue; } if (line1.getLineYA() > lines.get(0).getYEquation(line1.getLineXA()) && line2.getLineYA() < lines.get(0).getYEquation(line1.getLineXA()) || line2.getLineYA() > lines.get(0).getYEquation(line1.getLineXA()) && line1.getLineYA() < lines.get(0).getYEquation(line1.getLineXA())) { if (line1.getLineXA() > line2.getLineXA() - 50 && line1.getLineXA() < line2.getLineXA() + 50) { //Has found a result, then we delete the points from the list, and put them in pointDiedricoList and we continue if (line1.getLineYA() > landLine.getLineYA()) {//We store the cota and alejamiento, the cota is the line over the landline lineDiedrico.add(new LineDiedrico(line1, line2)); } else { lineDiedrico.add(new LineDiedrico(line2, line1)); } lines.remove(k); lines.remove(j); j--; break; } } if (k == lines.size() - 1) { //The line doesn't have a couple lines.remove(j); j--; } } } //Also, boofcv finds a lot of useless points near the lines, so we have to delete them Iterator<LineVector> lineVectorIterator = lines.iterator(); while (lineVectorIterator.hasNext()) { LineVector lineVector = lineVectorIterator.next(); points = Stream.of(points) .filter((PointVector point) -> point .getPointY() < lineVector.getYEquation(point.getPointX()) - 15 || point.getPointY() > lineVector.getYEquation(point.getPointX()) + 15) .toList(); } //Then we have to delete the groups of points and take only one of them for (int j = 0; j < points.size(); j++) { PointVector point1 = points.get(j); for (int k = 0; k < points.size(); k++) { PointVector point2 = points.get(k); if (point1.equals(point2)) { continue; } if (point1.getPointX() > point2.getPointX() - 20 && point1.getPointX() < point2.getPointX() + 20 && point1.getPointY() > point2.getPointY() - 20 && point1.getPointY() < point2.getPointY() + 20) { //Has found a result, then we delete the points from the list points.remove(k); k--; } } } //Delete the wrong point, the ones that don't have x's view and y's view respectively (cota and alejamiento). The correct points will be in pointDiedrico for (int j = 0; j < points.size(); j++) { PointVector point1 = points.get(j); for (int k = 0; k < points.size(); k++) { PointVector point2 = points.get(k); if (point1.equals(point2)) { if (k == points.size() - 1) { //The last point of the list points.remove(k); j--; break; } continue; } if (point1.getPointY() > lines.get(0).getYEquation(point1.getPointX()) && point2.getPointY() < lines.get(0).getYEquation(point2.getPointX()) || point2.getPointY() > lines.get(0).getYEquation(point2.getPointX()) && point1.getPointY() < lines.get(0).getYEquation(point1.getPointX())) { if (point1.getPointX() > point2.getPointX() - 15 && point1.getPointX() < point2.getPointX() + 15) { //Has found a result, then we delete the points from the list, and put them in pointDiedricoList and we continue if (point1.getPointY() > lines.get(0).getYEquation(point1.getPointX())) { //We store the cota and alejamiento, the cota is the point over the landline pointDiedrico.add(new PointDiedrico(point1, point2)); } else { pointDiedrico.add(new PointDiedrico(point2, point1)); } points.remove(k); points.remove(j); j--; break; } } if (k == points.size() - 1) { //The point doesn't have a couple points.remove(j); j--; } } } int indexColors = 0; //Counter for the color array int[] colors = context.getResources().getIntArray(R.array.rainbow); Paint paintMax; paintMax = new Paint(); paintMax.setStyle(Paint.Style.FILL); Canvas canvas = new Canvas(thresholdingBitmap); for (int i = 0; i < pointDiedrico.size(); i++) { paintMax.setColor(colors[indexColors++]); if (indexColors >= colors.length) indexColors = 0; canvas.drawCircle(pointDiedrico.get(i).getX().getPointX(), pointDiedrico.get(i).getX().getPointY(), 3, paintMax); canvas.drawCircle(pointDiedrico.get(i).getY().getPointX(), pointDiedrico.get(i).getY().getPointY(), 3, paintMax); } //Paint the landLine with color blue paintMax.setColor(Color.BLUE); canvas.drawLine(lines.get(0).getLineXA(), lines.get(0).getLineYA(), lines.get(0).getLineXB(), lines.get(0).getLineYB(), paintMax); //Paint the interesting lines for (int i = 0; i < lineDiedrico.size(); i++) { paintMax.setColor(colors[indexColors++]); if (indexColors >= colors.length) indexColors = 0; canvas.drawLine(lineDiedrico.get(i).getX().getLineXA(), lineDiedrico.get(i).getX().getLineYA(), lineDiedrico.get(i).getX().getLineXB(), lineDiedrico.get(i).getX().getLineYB(), paintMax); canvas.drawLine(lineDiedrico.get(i).getY().getLineXA(), lineDiedrico.get(i).getY().getLineYA(), lineDiedrico.get(i).getY().getLineXB(), lineDiedrico.get(i).getY().getLineYB(), paintMax); } imageView.setImageBitmap(thresholdingBitmap); } }; }
From source file:com.yk.notification.util.BitmapUtil.java
/** * //from ww w .j av a 2 s. c om * @param bitmap * @return */ public static Bitmap createRoundImageWithBorder(Context context, Bitmap bitmap) { // int bitmapWidth = bitmap.getWidth(); // int bitmapHeight = bitmap.getHeight(); // pixel int borderWidthHalf = 20; //?? int bitmapSquareWidth = Math.min(bitmapWidth, bitmapHeight); //? int newBitmapSquareWidth = bitmapSquareWidth + borderWidthHalf; Bitmap roundedBitmap = Bitmap.createBitmap(newBitmapSquareWidth, newBitmapSquareWidth, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(roundedBitmap); int x = borderWidthHalf + bitmapSquareWidth - bitmapWidth; int y = borderWidthHalf + bitmapSquareWidth - bitmapHeight; //???,?X,Y?2 ?? canvas.drawBitmap(bitmap, x / 2, y / 2, null); Paint borderPaint = new Paint(); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(borderWidthHalf); borderPaint.setColor(Color.WHITE); // canvas.drawCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, newBitmapSquareWidth / 2, borderPaint); RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), roundedBitmap); roundedBitmapDrawable.setGravity(Gravity.CENTER); roundedBitmapDrawable.setCircular(true); return getBitmapFromDrawable(roundedBitmapDrawable); }
From source file:info.bartowski.easteregg.LLand.java
@Override public void onDraw(Canvas c) { super.onDraw(c); if (!DEBUG_DRAW) return;// w ww.j a va 2 s . co m final Paint pt = new Paint(); pt.setColor(0xFFFFFFFF); final int L = mDroid.corners.length; final int N = L / 2; for (int i = 0; i < N; i++) { final int x = (int) mDroid.corners[i * 2]; final int y = (int) mDroid.corners[i * 2 + 1]; c.drawCircle(x, y, 4, pt); c.drawLine(x, y, mDroid.corners[(i * 2 + 2) % L], mDroid.corners[(i * 2 + 3) % L], pt); } pt.setStyle(Paint.Style.STROKE); pt.setStrokeWidth(getResources().getDisplayMetrics().density); final int M = getChildCount(); pt.setColor(0x8000FF00); for (int i = 0; i < M; i++) { final View v = getChildAt(i); if (v == mDroid) continue; if (!(v instanceof GameView)) continue; if (v instanceof Pop) { final Pop p = (Pop) v; c.drawCircle(p.cx, p.cy, p.r, pt); } else { final Rect r = new Rect(); v.getHitRect(r); c.drawRect(r, pt); } } pt.setColor(Color.BLACK); final StringBuilder sb = new StringBuilder("obstacles: "); for (Obstacle ob : mObstaclesInPlay) { sb.append(ob.hitRect.toShortString()); sb.append(" "); } pt.setTextSize(20f); c.drawText(sb.toString(), 20, 100, pt); }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw a spade//from ww w.j a va 2 s . c o m * @param canvas canvas to draw on * @param width width of the spade * @param height height of the spade */ public void drawSpade(final Canvas canvas, final float width, final float height) { final Paint paint = getBlackPaint(); final float width_half = width / 2; final float width_quarter = width / 4; final float width_fifth = width / 5; final float width_25th = width / 25; final float height_3_5th = height / 5 * 3; final Path path = new Path(); path.moveTo(width_half, 0); path.lineTo(width - width_25th, height_3_5th); path.lineTo(width_25th, height_3_5th); path.lineTo(width_half, 0); path.close(); canvas.drawPath(path, paint); canvas.drawCircle(width_quarter, height_3_5th, width_fifth, paint); canvas.drawCircle(width_quarter * 3, height_3_5th, width_fifth, paint); drawPedestal(canvas, width, height); }
From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java
private void drawCircleBackground(Canvas canvas) { canvas.drawCircle(mXCenter, mYCenter, mCircleRadius, mPaintBackground); }
From source file:com.mukesh.OtpView.java
private void drawCircle(Canvas canvas, int i) { Paint paint = getPaintByIndex(i); float cx = itemCenterPoint.x; float cy = itemCenterPoint.y; if (rtlTextDirection) { int reversedItemPosition = otpViewItemCount - i; int reversedCharPosition = reversedItemPosition - getHint().length(); if (reversedCharPosition <= 0) { canvas.drawCircle(cx, cy, paint.getTextSize() / 2, paint); }/*from ww w . j a va 2 s. c om*/ } else { canvas.drawCircle(cx, cy, paint.getTextSize() / 2, paint); } }