List of usage examples for android.graphics Canvas drawArc
public void drawArc(@NonNull RectF oval, float startAngle, float sweepAngle, boolean useCenter, @NonNull Paint paint)
Draw the specified arc, which will be scaled to fit inside the specified oval.
From source file:com.myhexaville.iconanimations.gooey_fab.GooeyFabCompatImpl.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); RectF gooeyPart = new RectF(0, mCenterY - getArcAbsolute(), mWidth, mCenterY + getArcAbsolute()); RectF backgroundCircle = new RectF(0, mCenterY - getFabWidth() / 2, mWidth, mCenterY + getFabWidth() / 2); canvas.drawArc(gooeyPart, 0, mIsLargeFab ? -180 : 180, false, mPaint); canvas.drawArc(backgroundCircle, 0, 360, false, mPaint); }
From source file:com.cuelogic.android.WheelIndicatorView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.translate(traslationX, traslationY); if (circleBackgroundPaint != null) canvas.drawCircle(wheelBoundsRectF.centerX(), wheelBoundsRectF.centerY(), wheelBoundsRectF.width() / 2 - itemsLineWidth, circleBackgroundPaint); canvas.drawArc(wheelBoundsRectF, ANGLE_INIT_OFFSET, 360, false, innerBackgroundCirclePaint); drawIndicatorItems("First", canvas); // itemArcPaint.setColor(Color.parseColor("#FF9000")); // canvas.drawArc((float)wheelBoundsRectF.centerX(), wheelBoundsRectF.centerY(), // wheelBoundsRectF.width() / 2 - itemsLineWidth,false, itemArcPaint); drawIndicatorArc(canvas);/*from w w w. j a va 2 s.c o m*/ drawIndicatorItems("Second", canvas); }
From source file:com.todddavies.components.progressbar.ProgressWheel.java
protected void onDraw(Canvas canvas) { super.onDraw(canvas); //Draw the inner circle canvas.drawArc(circleBounds, 360, 360, false, circlePaint); //Draw the rim canvas.drawArc(circleBounds, 360, 360, false, rimPaint); canvas.drawArc(circleOuterContour, 360, 360, false, contourPaint); canvas.drawArc(circleInnerContour, 360, 360, false, contourPaint); //Draw the bar if (isSpinning) { canvas.drawArc(circleBounds, m_Degree - 90, barLength, false, barPaint); } else {/*from w ww . j a v a 2 s .c om*/ canvas.drawArc(circleBounds, -90, m_Degree, false, barPaint); } //Draw the text (attempts to center it horizontally and vertically) float textHeight = textPaint.descent() - textPaint.ascent(); float verticalTextOffset = (textHeight / 2) - textPaint.descent(); for (String s : splitText) { float horizontalTextOffset = textPaint.measureText(s) / 2; canvas.drawText(s, this.getWidth() / 2 - horizontalTextOffset, this.getHeight() / 2 + verticalTextOffset, textPaint); } }
From source file:com.android.tabletcustomui.views.LeftCircleContainer.java
private void addCircle(int position, final int value, float diff, double ratio) { final int radius = value / 2; final RectF mOval = new RectF(); mOval.set(0 + diff, 0 + diff, value - diff, value - diff); final Paint mPaintClip = new Paint(); mPaintClip.setStyle(Paint.Style.FILL); mPaintClip.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.OVERLAY)); mPaintClip.setAntiAlias(true);// ww w.j a v a2s . c om final PointF pointF = new PointF(mOval.centerX(), mOval.centerY()); final Path clipPath = new Path(); clipPath.addCircle(pointF.x, pointF.y, (float) (radius * ratio), Path.Direction.CW); View circleView; if (position == 0) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 330, 10, true, mPaintClip); canvas.drawArc(mOval, 342, 20, true, mPaintClip); canvas.drawArc(mOval, 4, 10, true, mPaintClip); canvas.drawArc(mOval, 240, 10, true, mPaintClip); canvas.drawArc(mOval, 252, 20, true, mPaintClip); canvas.drawArc(mOval, 275, 10, true, mPaintClip); canvas.drawArc(mOval, 150, 10, true, mPaintClip); canvas.drawArc(mOval, 162, 20, true, mPaintClip); canvas.drawArc(mOval, 185, 10, true, mPaintClip); canvas.drawArc(mOval, 60, 10, true, mPaintClip); canvas.drawArc(mOval, 72, 20, true, mPaintClip); canvas.drawArc(mOval, 95, 10, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 1) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawCircle(pointF.x, pointF.y, radius, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 2) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 55, 190, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 3) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 240, 190, true, mPaintClip); canvas.drawArc(mOval, 80, 150, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 4) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 335, 150, true, mPaintClip); canvas.drawArc(mOval, 140, 180, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 5) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_grey)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 330, 150, true, mPaintClip); canvas.drawArc(mOval, 140, 150, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 6) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_purple_color)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 290, 5, true, mPaintClip); canvas.drawArc(mOval, 297, 20, true, mPaintClip); canvas.drawArc(mOval, 319, 20, true, mPaintClip); canvas.drawArc(mOval, 60, 15, true, mPaintClip); canvas.drawArc(mOval, 77, 8, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 7) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 160, 10, true, mPaintClip); canvas.drawArc(mOval, 172, 30, true, mPaintClip); canvas.drawArc(mOval, 204, 30, true, mPaintClip); canvas.drawArc(mOval, 236, 10, true, mPaintClip); canvas.drawArc(mOval, 20, 20, true, mPaintClip); canvas.drawArc(mOval, 42, 8, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateAntiClockWise(circleView); } }
From source file:org.telegram.ui.Cells.FeaturedStickerSetInfoCell.java
public FeaturedStickerSetInfoCell(Context context, int left) { super(context); if (botProgressPaint == null) { botProgressPaint = new Paint(Paint.ANTI_ALIAS_FLAG); botProgressPaint.setColor(0xffffffff); botProgressPaint.setStrokeCap(Paint.Cap.ROUND); botProgressPaint.setStyle(Paint.Style.STROKE); }/*from w w w.j a v a2s . co m*/ botProgressPaint.setStrokeWidth(AndroidUtilities.dp(2)); nameTextView = new TextView(context); // TODO nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text) /*0xff333333*/); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17); nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); nameTextView.setEllipsize(TextUtils.TruncateAt.END); nameTextView.setSingleLine(true); addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, left, 8, 100, 0)); infoTextView = new TextView(context); infoTextView.setTextColor(0xff8a8a8a); infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); infoTextView.setEllipsize(TextUtils.TruncateAt.END); infoTextView.setSingleLine(true); addView(infoTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, left, 30, 100, 0)); addButton = new TextView(context) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (drawProgress || !drawProgress && progressAlpha != 0) { botProgressPaint.setAlpha(Math.min(255, (int) (progressAlpha * 255))); int x = getMeasuredWidth() - AndroidUtilities.dp(11); rect.set(x, AndroidUtilities.dp(3), x + AndroidUtilities.dp(8), AndroidUtilities.dp(8 + 3)); canvas.drawArc(rect, angle, 220, false, botProgressPaint); invalidate((int) rect.left - AndroidUtilities.dp(2), (int) rect.top - AndroidUtilities.dp(2), (int) rect.right + AndroidUtilities.dp(2), (int) rect.bottom + AndroidUtilities.dp(2)); long newTime = System.currentTimeMillis(); if (Math.abs(lastUpdateTime - System.currentTimeMillis()) < 1000) { long delta = (newTime - lastUpdateTime); float dt = 360 * delta / 2000.0f; angle += dt; angle -= 360 * (angle / 360); if (drawProgress) { if (progressAlpha < 1.0f) { progressAlpha += delta / 200.0f; if (progressAlpha > 1.0f) { progressAlpha = 1.0f; } } } else { if (progressAlpha > 0.0f) { progressAlpha -= delta / 200.0f; if (progressAlpha < 0.0f) { progressAlpha = 0.0f; } } } } lastUpdateTime = newTime; invalidate(); } } }; addButton.setPadding(AndroidUtilities.dp(17), 0, AndroidUtilities.dp(17), 0); addButton.setGravity(Gravity.CENTER); addButton.setTextColor(0xffffffff); addButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); addButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); addView(addButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 28, Gravity.TOP | Gravity.RIGHT, 0, 16, 14, 0)); }
From source file:com.example.waitou.rxjava.LoadingView.java
/** * draw the ring/*from www . j av a2 s.c om*/ * * @param canvas to draw the Ring * @param bounds the ring's rect */ private void drawRing(Canvas canvas, Rect bounds) { final RectF arcBounds = mTempBounds; final Ring ring = mRing; arcBounds.set(bounds); arcBounds.inset(ring.strokeInset, ring.strokeInset); canvas.drawArc(arcBounds, ring.start, ring.sweep, false, mPaint); }
From source file:com.yanzhenjie.album.widget.loading.LevelLoadingRenderer.java
@Override protected void draw(Canvas canvas) { int saveCount = canvas.save(); mTempBounds.set(mBounds);//www .j a v a 2 s . co m mTempBounds.inset(mStrokeInset, mStrokeInset); canvas.rotate(mGroupRotation, mTempBounds.centerX(), mTempBounds.centerY()); for (int i = 0; i < 3; i++) { if (mLevelSwipeDegrees[i] != 0) { mPaint.setColor(mLevelColors[i]); canvas.drawArc(mTempBounds, mEndDegrees, mLevelSwipeDegrees[i], false, mPaint); } } canvas.restoreToCount(saveCount); }
From source file:zxyilian.com.myapplication.ui.ProgressWheel.java
protected void onDraw(Canvas canvas) { super.onDraw(canvas); //Draw the inner circle canvas.drawArc(innerCircleBounds, 360, 360, false, circlePaint); //Draw the rim canvas.drawArc(circleBounds, 360, 360, false, rimPaint); canvas.drawArc(circleOuterContour, 360, 360, false, contourPaint); //canvas.drawArc(circleInnerContour, 360, 360, false, contourPaint); //Draw the bar if (isSpinning) { /* double cx = 0; double cy = 0;//from w w w.ja v a2 s.c o m int width = getMeasuredWidth(); int height = getMeasuredHeight(); float r = (innerCircleBounds.right-innerCircleBounds.left)/2; if (anInt > 0 && anInt < 90) { cx = (float) (width + (r * Math.sin(anInt * Math.PI / 180))); cy = (float) (height - (r * Math.cos(anInt * Math.PI / 180))); } else if (anInt > 90 && anInt < 180) {// 90-180 anInt = 180 - anInt; cx = (float) (width + (r * Math.sin(anInt * Math.PI / 180))); cy = (float) (height + (r * Math.cos(anInt * Math.PI / 180))); } else if (anInt > 180 && anInt < 270) {//180-270 anInt = 270 - anInt; cx = (float) (width - (r * Math.cos(anInt * Math.PI / 180))); cy = (float) (height + (r * Math.sin(anInt * Math.PI / 180))); } else if (anInt > 270 && anInt < 360) {//270-360 anInt = 360 - anInt; cx = (float) (width - (r * Math.sin(anInt * Math.PI / 180))); cy = (float) (height - (r * Math.cos(anInt * Math.PI / 180))); } canvas.drawCircle( (float) cx,(float) cy,5,mCicle);*/ //canvas.drawRect(circleBounds,barPaint); canvas.drawArc(circleBounds, progress - 90, barLength, false, barPaint); } else { canvas.drawArc(circleBounds, -90, progress, false, barPaint); } //Draw the text (attempts to center it horizontally and vertically) float textHeight = textPaint.descent() - textPaint.ascent(); float verticalTextOffset = (textHeight / 2) - textPaint.descent(); for (String line : splitText) { float horizontalTextOffset = textPaint.measureText(line) / 2; canvas.drawText(line, this.getWidth() / 2 - horizontalTextOffset, this.getHeight() / 2 + verticalTextOffset, textPaint); } if (isSpinning) { scheduleRedraw(); } }
From source file:de.mrapp.android.util.BitmapUtil.java
/** * Clips the corners of a bitmap in order to transform it into a round shape. Additionally, the * bitmap is resized to a specific size and a border will be added. Bitmaps, whose width and * height are not equal, will be clipped to a square beforehand. * * @param bitmap//from w ww. ja va 2 s . c o m * The bitmap, which should be clipped, as an instance of the class {@link Bitmap}. The * bitmap may not be null * @param size * The size, the bitmap should be resized to, as an {@link Integer} value in pixels. The * size must be at least 1 * @param borderWidth * The width of the border as an {@link Integer} value in pixels. The width must be at * least 0 * @param borderColor * The color of the border as an {@link Integer} value * @return The clipped bitmap as an instance of the class {@link Bitmap} */ public static Bitmap clipCircle(@NonNull final Bitmap bitmap, final int size, final int borderWidth, @ColorInt final int borderColor) { ensureAtLeast(borderWidth, 0, "The border width must be at least 0"); Bitmap clippedBitmap = clipCircle(bitmap, size); Bitmap result = Bitmap.createBitmap(clippedBitmap.getWidth(), clippedBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); float offset = borderWidth / 2.0f; Rect src = new Rect(0, 0, clippedBitmap.getWidth(), clippedBitmap.getHeight()); RectF dst = new RectF(offset, offset, result.getWidth() - offset, result.getHeight() - offset); canvas.drawBitmap(clippedBitmap, src, dst, null); if (borderWidth > 0 && Color.alpha(borderColor) != 0) { Paint paint = new Paint(); paint.setFilterBitmap(false); paint.setAntiAlias(true); paint.setStrokeCap(Paint.Cap.ROUND); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(borderWidth); paint.setColor(borderColor); offset = borderWidth / 2.0f; RectF bounds = new RectF(offset, offset, result.getWidth() - offset, result.getWidth() - offset); canvas.drawArc(bounds, 0, COMPLETE_ARC_ANGLE, false, paint); } return result; }
From source file:com.example.brendan.learningandroid2.SeekArc.java
@Override protected void onDraw(Canvas canvas) { if (!mClockwise) { canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY()); }//from w w w . j av a 2 s.c o m // Draw the arcs final int arcStart = mStartAngle + mAngleOffset + mRotation; final int arcSweep = mSweepAngle; canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint); canvas.drawArc(mArcRect, arcStart, mProgressSweep, false, mProgressPaint); // Draw the thumb nail canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos); // mThumb.draw(canvas); }