Java Code Examples for android.graphics.Canvas#drawArc()
The following examples show how to use
android.graphics.Canvas#drawArc() .
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: MaterialProgressDrawable.java From NewFastFrame with Apache License 2.0 | 6 votes |
/** * Draw the progress spinner */ public void draw(Canvas c, Rect bounds) { final RectF arcBounds = mTempBounds; arcBounds.set(bounds); arcBounds.inset(mStrokeInset, mStrokeInset); final float startAngle = (mStartTrim + mRotation) * 360; final float endAngle = (mEndTrim + mRotation) * 360; float sweepAngle = endAngle - startAngle; mPaint.setColor(mCurrentColor); c.drawArc(arcBounds, startAngle, sweepAngle, false, mPaint); drawTriangle(c, startAngle, sweepAngle, bounds); if (mAlpha < 255) { mCirclePaint.setColor(mBackgroundColor); mCirclePaint.setAlpha(255 - mAlpha); c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2, mCirclePaint); } }
Example 2
Source File: RecordButton.java From phoenix with Apache License 2.0 | 6 votes |
protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawCircle(centerX, centerY, translucentCircleRadius, translucentPaint); //center white-p40 circle canvas.drawCircle(centerX, centerY, innerCircleRadiusToDraw, centerCirclePaint); //static out-most white circle canvas.drawArc(outMostCircleRect, startAngle270, 360.0F, false, outMostWhiteCirclePaint); //progress bar canvas.drawArc(outMostCircleRect, startAngle270, percentInDegree, false, processBarPaint); canvas.drawCircle(centerX, centerY, outBlackCircleRadius, outBlackCirclePaint); canvas.drawCircle(centerX, centerY, outMostBlackCircleRadius, outMostBlackCirclePaint); }
Example 3
Source File: MaterialProgressDrawable.java From BookReader with Apache License 2.0 | 6 votes |
/** * Draw the progress spinner */ public void draw(Canvas c, Rect bounds) { final RectF arcBounds = mTempBounds; arcBounds.set(bounds); arcBounds.inset(mStrokeInset, mStrokeInset); final float startAngle = (mStartTrim + mRotation) * 360; final float endAngle = (mEndTrim + mRotation) * 360; float sweepAngle = endAngle - startAngle; mPaint.setColor(mCurrentColor); c.drawArc(arcBounds, startAngle, sweepAngle, false, mPaint); drawTriangle(c, startAngle, sweepAngle, bounds); if (mAlpha < 255) { mCirclePaint.setColor(mBackgroundColor); mCirclePaint.setAlpha(255 - mAlpha); c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2, mCirclePaint); } }
Example 4
Source File: AroundCircleView.java From AroundCircleView with Apache License 2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { if (getDrawable() == null) { return; } canvas.drawCircle(getWidth() / 2, getHeight() / 2, mDrawableRadius, mBitmapPaint); // 里面的图片 if (mBorderWidth != 0) { //周边底部颜色 一般为白色 canvas.drawArc(mBorderRect, -90, 360, false, mBorderPaint_bg); //设置了周边弧度的宽度 每次重新绘制都要画上边上的弧度 canvas.drawArc(mBorderRect, -90, newAngle, false, mBorderPaint); } }
Example 5
Source File: MdStyleProgress.java From Android with MIT License | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.save(); canvas.translate(getPaddingLeft(),getPaddingTop()); if(mStatus == Status.Loading){ if (startAngle == minAngle) { endAngle += 6; } if (endAngle >= 300 || startAngle > minAngle) { startAngle += 6; if(endAngle > 20) { endAngle -= 6; } } if (startAngle > minAngle + 300) { minAngle = startAngle; endAngle = 20; } canvas.rotate(curAngle += rotateDelta,mRadius,mRadius);//rotating canvas.drawArc(new RectF(0,0,mRadius*2,mRadius*2),startAngle,endAngle,false,progressPaint); invalidate(); }else if(mStatus == Status.LoadSuccess){ canvas.drawArc(new RectF(0,0,mRadius*2,mRadius*2),startAngle + endAngle,statusCricle,false,progressPaint); canvas.drawLine(mRadius/2,mRadius*95/100f,mRadius/2+lineValueLeft,mRadius*95/100f+lineValueLeft,progressPaint); canvas.drawLine(mRadius*17/20f,mRadius+mRadius*3/10f,mRadius*17/20f+lineValueRight*13/12f,mRadius+mRadius*3/10f-lineValueRight,progressPaint); }else { canvas.drawArc(new RectF(0,0,mRadius*2,mRadius*2),startAngle + endAngle,statusCricle,false,progressPaint); canvas.drawLine(mRadius+mRadius/2-failAdd,mRadius/2+failAdd,mRadius*3/2-failAdd-failLineFirst,mRadius/2+failAdd+failLineFirst,progressPaint); canvas.drawLine(mRadius/2+failAdd,mRadius/2+failAdd,mRadius/2+failLineSecond+failAdd,mRadius/2+failLineSecond+failAdd,progressPaint); } canvas.restore(); }
Example 6
Source File: SecretMediaViewer.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@SuppressLint("DrawAllocation") @Override protected void onDraw(Canvas canvas) { if (currentMessageObject == null || currentMessageObject.messageOwner.destroyTime == 0) { return; } canvas.drawCircle(getMeasuredWidth() - AndroidUtilities.dp(16 + 19), getMeasuredHeight() / 2, AndroidUtilities.dp(16), circlePaint); float progress; if (useVideoProgress) { if (videoPlayer != null) { long duration = videoPlayer.getDuration(); long position = videoPlayer.getCurrentPosition(); if (duration != C.TIME_UNSET && position != C.TIME_UNSET) { progress = 1.0f - (position / (float) duration); } else { progress = 1; } } else { progress = 1; } } else { long msTime = System.currentTimeMillis() + ConnectionsManager.getInstance(currentAccount).getTimeDifference() * 1000; progress = Math.max(0, destroyTime - msTime) / (destroyTtl * 1000.0f); } int x = getMeasuredWidth() - AndroidUtilities.dp(32 - 11 + 19); int y = (getMeasuredHeight() - AndroidUtilities.dp(14)) / 2 - AndroidUtilities.dp(0.5f); drawable.setBounds(x, y, x + AndroidUtilities.dp(10), y + AndroidUtilities.dp(14)); drawable.draw(canvas); float radProgress = -360 * progress; canvas.drawArc(deleteProgressRect, -90, radProgress, false, afterDeleteProgressPaint); timerParticles.draw(canvas, particlePaint, deleteProgressRect, radProgress, 1.0f); invalidate(); }
Example 7
Source File: CircularProgressDrawable.java From FileManager with Apache License 2.0 | 5 votes |
@Override public void draw(Canvas canvas) { float startAngle = mCurrentGlobalAngle - mCurrentGlobalAngleOffset; float sweepAngle = mCurrentSweepAngle; if (mModeAppearing) { sweepAngle += MIN_SWEEP_ANGLE; } else { startAngle = startAngle + sweepAngle; sweepAngle = 360 - sweepAngle - MIN_SWEEP_ANGLE; } canvas.drawArc(fBounds, startAngle, sweepAngle, false, mPaint); }
Example 8
Source File: RoundProgress.java From Tok-Android with GNU General Public License v3.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int centerX = getWidth() / 2; int radius = (int) (centerX - roundWidth / 2); // step1 paint.setStrokeWidth(roundWidth); paint.setColor(roundColor); paint.setAntiAlias(true); switch (style) { case STROKE: paint.setStyle(Paint.Style.STROKE); break; case FILL: paint.setStyle(Paint.Style.FILL_AND_STROKE); break; } canvas.drawCircle(centerX, centerX, radius, paint); // step2 paint.setStrokeWidth(progressWidth); paint.setColor(progressColor); RectF oval = new RectF(centerX - radius, centerX - radius, centerX + radius, centerX + radius); float sweepAngle = 360 * curProgress / max; // 根据进度画圆弧 switch (style) { case STROKE: canvas.drawArc(oval, startAngle, sweepAngle, false, paint); break; case FILL: canvas.drawArc(oval, startAngle, sweepAngle, true, paint); break; } }
Example 9
Source File: ContactChipSpan.java From material with Apache License 2.0 | 5 votes |
@Override public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { canvas.save(); canvas.translate(x, top); float halfHeight = mHeight / 2f; mPaint.setShader(null); mPaint.setColor(mBackgroundColor); mRect.set(1, 0, mHeight + 1, mHeight); canvas.drawArc(mRect, 90, 180, true, mPaint); mRect.set(mWidth - mHeight, 0, mWidth, mHeight); canvas.drawArc(mRect, 270, 180, true, mPaint); mRect.set(halfHeight, 0, mWidth - halfHeight, mHeight); canvas.drawRect(mRect, mPaint); if(mBitmap != null){ mPaint.setShader(mBitmapShader); canvas.drawCircle(halfHeight, halfHeight, halfHeight, mPaint); } if(mContactName != null && mBoringLayout != null) { canvas.translate(mHeight + mPaddingLeft, (mHeight - mBoringLayout.getHeight()) / 2f); mBoringLayout.draw(canvas); } canvas.restore(); }
Example 10
Source File: EasyProgress.java From android-common-utils with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mCancled) return; canvas.drawArc(arcRectf, mStartAngle + mIncrementAngele, mSweepAngle, false, arcPaint); if (mAnimatorSet == null || !mAnimatorSet.isRunning()) { startAnimation(); } }
Example 11
Source File: ProgressWeekView.java From CalendarView with Apache License 2.0 | 5 votes |
@Override protected void onDrawScheme(Canvas canvas, Calendar calendar, int x) { int cx = x + mItemWidth / 2; int cy = mItemHeight / 2; int angle = getAngle(Integer.parseInt(calendar.getScheme())); RectF progressRectF = new RectF(cx - mRadius, cy - mRadius, cx + mRadius, cy + mRadius); canvas.drawArc(progressRectF, -90, angle, false, mProgressPaint); RectF noneRectF = new RectF(cx - mRadius, cy - mRadius, cx + mRadius, cy + mRadius); canvas.drawArc(noneRectF, angle - 90, 360 - angle, false, mNoneProgressPaint); }
Example 12
Source File: ProgressBarCircularIndeterminate.java From MaterialDesignLibrary with Apache License 2.0 | 5 votes |
/** * Draw second animation of view * @param canvas */ private void drawSecondAnimation(Canvas canvas){ if(arcO == limite) arcD+=6; if(arcD >= 290 || arcO > limite){ arcO+=6; arcD-=6; } if(arcO > limite + 290){ limite = arcO; arcO = limite; arcD = 1; } rotateAngle += 4; canvas.rotate(rotateAngle,getWidth()/2, getHeight()/2); Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); Canvas temp = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(backgroundColor); // temp.drawARGB(0, 0, 0, 255); temp.drawArc(new RectF(0, 0, getWidth(), getHeight()), arcO, arcD, true, paint); Paint transparentPaint = new Paint(); transparentPaint.setAntiAlias(true); transparentPaint.setColor(getResources().getColor(android.R.color.transparent)); transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); temp.drawCircle(getWidth()/2, getHeight()/2, (getWidth()/2)-Utils.dpToPx(4, getResources()), transparentPaint); canvas.drawBitmap(bitmap, 0, 0, new Paint()); }
Example 13
Source File: CircularAnimatedDrawable.java From ProgressButton with Apache License 2.0 | 5 votes |
@Override public void draw(Canvas canvas) { canvas.drawArc(fBounds, 270, mCurrentSweepAngle, false, mPaint); cancelButtonSpokeLength = (int) fBounds.width() / 3; canvas.drawLine(fBounds.left + cancelButtonSpokeLength, fBounds.bottom - cancelButtonSpokeLength, fBounds.right - cancelButtonSpokeLength, fBounds.top + cancelButtonSpokeLength, mCancelPaint); canvas.drawLine(fBounds.left + cancelButtonSpokeLength, fBounds.top + cancelButtonSpokeLength, fBounds.right - cancelButtonSpokeLength, fBounds.bottom - cancelButtonSpokeLength, mCancelPaint); }
Example 14
Source File: DeviceSeekArc.java From arcusandroid with Apache License 2.0 | 4 votes |
private void drawGradient(@NonNull Canvas canvas) { if (mHiliteGradient != null && isEnabled()) { canvas.save(); // Manual gradient positions float startPosition = mHiliteGradient.startPosition; float endPosition = mHiliteGradient.endPosition; // Dynamic gradient start position if (mHiliteGradient.startMarker) { startPosition = getDrawnMarkerPosition(); } else if (mHiliteGradient.startThumb == THUMB_LOW) { startPosition = mProgressLow; } else if (mHiliteGradient.startThumb == THUMB_HIGH) { startPosition = mProgressHigh; } // Dynamic gradient end position if (mHiliteGradient.endMarker) { endPosition = getDrawnMarkerPosition(); } else if (mHiliteGradient.endThumb == THUMB_LOW) { endPosition = mProgressLow; } else if (mHiliteGradient.endThumb == THUMB_HIGH) { endPosition = mProgressHigh; } // Fix inverted positions to prevent weird gradient renderings if (endPosition < startPosition) { float swap = endPosition; startPosition = endPosition; endPosition = swap; } // Calculate arc relativeAngle at which gradient starts and ends float startAngle = ((startPosition / mMax) * mSweepAngle) + mStartAngle; float endAngle = ((endPosition / mMax) * mSweepAngle) + mStartAngle; Paint hilitePaint = mHiliteGradient.getHiliteStrokePaint(startAngle, endAngle, mArcRect, mProgressWidth); canvas.drawArc(mArcRect, startAngle - 90 + mRotation, endAngle - startAngle, false, hilitePaint); canvas.restore(); } }
Example 15
Source File: CircleProgressView.java From CircleProgressView with MIT License | 4 votes |
private void draProgressArc(Canvas canvas) { canvas.drawArc(mArcRectF, -90, 360, false, mArcBgPaint); canvas.drawArc(mArcRectF, -90, angle, false, mArcPaint); }
Example 16
Source File: PercentageCircleView.java From moVirt with Apache License 2.0 | 4 votes |
private void drawBackground(Canvas canvas) { backgroundPaint.setColor(adjustColor(backgroundColor)); canvas.drawArc(backgroundRectF, startAngle, MAX_ANGLE, false, backgroundPaint); }
Example 17
Source File: PowerProgressBar.java From FileManager with Apache License 2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); //画出圆环 canvas.drawCircle(mCenter, mCenter, mRoundRadius, mRoundPaint); //画出填充的弧 if (mIsClockwise) { canvas.drawArc(mOval, mStartAngle, (float) (3.6 * getProgress()), false, mRoundFillPaint); } else { canvas.drawArc(mOval, mStartAngle, -(float) (3.6 * getProgress()), false, mRoundFillPaint); } //画出圆环中间的字体 float topTextWidth = mCenterTopTextPaint.measureText(mCenterTopText); float centerTextWidth = mCenterTextPaint.measureText(mCenterText); float bottomTextWidth = mCenterBottomTextPaint.measureText(mCenterBottomText); if (getProgress() <= 100) { canvas.drawText((int) getProgress() + "%" , mCenter - topTextWidth / 2 , mCenter + mCenterTopTextSize / 2 - mRoundRadius / 3 , mCenterTopTextPaint); } else { canvas.drawText(100 + "%" , mCenter - topTextWidth / 2 , mCenter + mCenterTopTextSize / 2 - mRoundRadius / 3 , mCenterTopTextPaint); } canvas.drawText(mCenterText , mCenter - centerTextWidth / 2 , mCenter + mCenterTopTextSize / 2 , mCenterTextPaint); canvas.drawText(mCenterBottomText , mCenter - bottomTextWidth / 2 , mCenter + mCenterTopTextSize / 2 + mRoundRadius / 3 , mCenterBottomTextPaint); invalidate(); }
Example 18
Source File: CircleWatchface.java From NightWatch with GNU General Public License v3.0 | 4 votes |
public void addArch(Canvas canvas, float start, float offset, int color, float size) { Paint paint = new Paint(); paint.setColor(color); RectF rectTemp = new RectF(PADDING + offset - CIRCLE_WIDTH / 2, PADDING + offset - CIRCLE_WIDTH / 2, (displaySize.x - PADDING - offset + CIRCLE_WIDTH / 2), (displaySize.y - PADDING - offset + CIRCLE_WIDTH / 2)); canvas.drawArc(rectTemp, start + 270, size, true, paint); }
Example 19
Source File: CircleWatchface.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public void addArch(Canvas canvas, float offset, int color, float size) { Paint paint = new Paint(); paint.setColor(color); RectF rectTemp = new RectF(PADDING + offset - CIRCLE_WIDTH / 2, PADDING + offset - CIRCLE_WIDTH / 2, (displaySize.x - PADDING - offset + CIRCLE_WIDTH / 2), (displaySize.y - PADDING - offset + CIRCLE_WIDTH / 2)); canvas.drawArc(rectTemp, 270, size, true, paint); }
Example 20
Source File: SwitchButton.java From FastAndroid with Apache License 2.0 | 3 votes |
/** * @param canvas * @param left * @param top * @param right * @param bottom * @param startAngle * @param sweepAngle * @param paint */ private void drawArc(Canvas canvas, float left, float top, float right, float bottom, float startAngle, float sweepAngle, Paint paint) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { canvas.drawArc(left, top, right, bottom, startAngle, sweepAngle, true, paint); } else { rect.set(left, top, right, bottom); canvas.drawArc(rect, startAngle, sweepAngle, true, paint); } }