List of usage examples for android.graphics Canvas drawCircle
public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint)
From source file:com.jaredrummler.android.colorpicker.ColorPanelView.java
@Override protected void onDraw(Canvas canvas) { borderPaint.setColor(borderColor);/*w w w. j a v a 2s. com*/ colorPaint.setColor(color); if (shape == ColorShape.SQUARE) { if (borderWidthPx > 0) { canvas.drawRect(drawingRect, borderPaint); } if (alphaPattern != null) { alphaPattern.draw(canvas); } canvas.drawRect(colorRect, colorPaint); } else if (shape == ColorShape.CIRCLE) { final int outerRadius = getMeasuredWidth() / 2; if (borderWidthPx > 0) { canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, outerRadius, borderPaint); } if (Color.alpha(color) < 255) { canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, outerRadius - borderWidthPx, alphaPaint); } if (showOldColor) { canvas.drawArc(centerRect, 90, 180, true, originalPaint); canvas.drawArc(centerRect, 270, 180, true, colorPaint); } else { canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, outerRadius - borderWidthPx, colorPaint); } } }
From source file:com.metinkale.prayerapp.vakit.PrefsView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); canvas.scale(0.8f, 0.8f, canvas.getWidth() / 2, canvas.getHeight() / 2); Object o = getValue();/*from w ww .ja va2s .c o m*/ boolean active = ((o instanceof Boolean) && o.equals(true)) || ((o instanceof Integer) && !o.equals(0)) || ((o instanceof String) && !((String) o).startsWith("silent")); if (mPref == Pref.Vibration2) { active = !o.equals(-1); } mPaint.setColor(active ? 0xff03A9F4 : 0xffe0e0e0); int w = getHeight(); canvas.drawCircle(w / 2, w / 2, w / 2, mPaint); int p = w / 7; mDrawable.setBounds(p, p, w - p, w - p); mDrawable.setColorFilter(active ? sCFActive : sCFInactive); mDrawable.draw(canvas); if ((mPref == Pref.Time) || (mPref == Pref.SabahTime) || (mPref == Pref.Silenter)) { int s = (Integer) getValue(); if (s != 0) { mPaint.setColor(getResources().getColor(R.color.colorPrimaryDark)); canvas.drawCircle(getWidth() * 0.78f, getHeight() * 0.78f, getWidth() / 4, mPaint); mPaint.setColor(Color.WHITE); mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(w / 5); mPaint.setTypeface(Typeface.DEFAULT_BOLD); canvas.drawText(s + "", w * 0.78f, w * 0.87f, mPaint); } } else if (mPref == Pref.Vibration2) { int s = (Integer) getValue(); String txt = ""; if (s == 0) { txt = "8"; } else if (s == 1) { txt = "1"; } mPaint.setColor(Color.BLACK); mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(w / 2); mPaint.setTypeface(Typeface.DEFAULT_BOLD); if (s == 0) { canvas.rotate(90, canvas.getWidth() / 2, canvas.getHeight() / 2); canvas.drawText(txt, w / 2, (w * 2) / 3, mPaint); canvas.rotate(-90, canvas.getWidth() / 2, canvas.getHeight() / 2); } else { canvas.drawText(txt, w / 2, w * 2 / 3, mPaint); } } }
From source file:com.jakewharton.android.viewpagerindicator.CirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final int count = mViewPager.getAdapter().getCount(); final float threeRadius = mRadius * 3; final float topOffset = getPaddingTop() + mRadius; final int paddingLeft = getPaddingLeft(); float leftOffset = paddingLeft + mRadius; if (mCentered) { leftOffset += ((getWidth() - paddingLeft - getPaddingRight()) / 2.0f) - ((count * threeRadius) / 2.0f); }/* www . ja v a 2 s.c o m*/ //Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { canvas.drawCircle(leftOffset + (iLoop * threeRadius), topOffset, mRadius, mPaintStroke); } //Draw the filled circle according to the current scroll float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius; if (!mSnap && (mPageWidth != 0)) { cx += (mCurrentOffset * 1.0f / mPageWidth) * threeRadius; } canvas.drawCircle(leftOffset + cx, topOffset, mRadius, mPaintFill); }
From source file:com.yanzhenjie.durban.view.OverlayView.java
/** * This method draws dimmed area around the crop bounds. * * @param canvas - valid canvas object/* ww w . ja v a 2 s. c o m*/ */ protected void drawDimmedLayer(@NonNull Canvas canvas) { canvas.save(); if (mCircleDimmedLayer) canvas.clipPath(mCircularPath, Region.Op.DIFFERENCE); else canvas.clipRect(mCropViewRect, Region.Op.DIFFERENCE); canvas.drawColor(mDimmedColor); canvas.restore(); if (mCircleDimmedLayer) { // Draw 1px stroke to fix antialias canvas.drawCircle(mCropViewRect.centerX(), mCropViewRect.centerY(), Math.min(mCropViewRect.width(), mCropViewRect.height()) / 2.f, mDimmedStrokePaint); } }
From source file:com.github.segoh.viewpagerindicator.ViewPagerIndicator.java
@Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas); if (mViewPager == null || mViewPager.getAdapter() == null) { return;// www . j a v a 2 s . co m } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } // Draw circles for each page final float widthCircleWithSpacing = mRadius * 4; final float offsetFromTop = getMeasuredHeight() / 2f; final float offsetFromLeft = getPaddingLeft() + mRadius; for (int i = 0; i < count; ++i) { final float centerLeft = offsetFromLeft + (i * widthCircleWithSpacing); canvas.drawCircle(centerLeft, offsetFromTop, mRadius, mPaintPage); } // Draw circle for current page final float offsetForCircle = mCurrentPage * widthCircleWithSpacing; canvas.drawCircle(offsetFromLeft + offsetForCircle, offsetFromTop, mRadius, mPaintCurrentPage); }
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 . j a v a2 s. com 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.kmagic.solitaire.DrawMaster.java
/** * Draw a club/*ww w . j a v a 2 s . c om*/ * @param canvas canvas to draw on * @param width width of the club * @param height height of the club */ public void drawClub(final Canvas canvas, final float width, final float height) { final Paint paint = getBlackPaint(); final float width_half = width / 2; final float width_fifth = width / 5; final float height_5th = height / 5; canvas.drawCircle(width_half, height_5th, width_fifth, paint); canvas.drawCircle(width_fifth, height / 2, width_fifth, paint); canvas.drawCircle(width - width_fifth, height / 2, width_fifth, paint); drawPedestal(canvas, width, height); }
From source file:com.taobao.weex.ui.view.WXBaseCircleIndicator.java
@Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); float firstX = getWidth() / 2 + getPaddingLeft() - getCount() / 2.0f * (radius + circlePadding);// + radius; float firstY = getHeight() / 2 + getPaddingTop();// + radius; //draw stroked circles for (int i = 0; i < getCount(); i++) { float dx = firstX + circlePadding * i + radius * 2 * i; float dy = firstY; if (mPaintStroke.getStrokeWidth() > 0) { canvas.drawCircle(dx, dy, radius, mPaintStroke); }//from ww w . j a va 2 s . c o m if (mPaintPage.getAlpha() > 0) { canvas.drawCircle(dx, dy, radius, mPaintPage); } } //Draw the filled circle float dx = firstX + realCurrentItem * circlePadding + radius * 2 * realCurrentItem; float dy = firstY; canvas.drawCircle(dx, dy, radius, mPaintFill); }
From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java
public void drawTrueNorthArrow(Canvas canvas, float drawnAngle) { trueNorthArrowPaint.reset();//from ww w . j a va2s . c o m 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.concavenp.artistrymuse.fragments.BaseFragment.java
private BitmapImageViewTarget createBitmapImageViewTarget(final ImageView imageView) { return new BitmapImageViewTarget(imageView) { @Override/* w w w.j ava 2s .c om*/ protected void setResource(Bitmap bitmap) { int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight(); int borderWidthHalf = 5; int bitmapSquareWidth = Math.min(bitmapWidth, bitmapHeight); int newBitmapSquare = bitmapSquareWidth + borderWidthHalf; Bitmap roundedBitmap = Bitmap.createBitmap(newBitmapSquare, newBitmapSquare, Bitmap.Config.ARGB_8888); // Initialize a new Canvas to draw empty bitmap Canvas canvas = new Canvas(roundedBitmap); // Calculation to draw bitmap at the circular bitmap center position int x = borderWidthHalf + bitmapSquareWidth - bitmapWidth; int y = borderWidthHalf + bitmapSquareWidth - bitmapHeight; canvas.drawBitmap(bitmap, x, y, null); // Initializing a new Paint instance to draw circular border Paint borderPaint = new Paint(); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(borderWidthHalf * 2); borderPaint.setColor(ResourcesCompat.getColor(getResources(), R.color.myApp_accent_700, null)); canvas.drawCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, newBitmapSquare / 2, borderPaint); RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), roundedBitmap); circularBitmapDrawable.setCircular(true); imageView.setImageDrawable(circularBitmapDrawable); } }; }