Java Code Examples for android.graphics.Canvas#drawCircle()
The following examples show how to use
android.graphics.Canvas#drawCircle() .
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 BaseDialog with Apache License 2.0 | 9 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: Utils.java From MaterialNavigationDrawer with Apache License 2.0 | 6 votes |
public static Bitmap getCroppedBitmapDrawable(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); // canvas.drawRoundRect(rectF, roundPx, roundPx, paint); canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); //Bitmap _bmp = Bitmap.createScaledBitmap(output, 60, 60, false); //return _bmp; return output; }
Example 3
Source File: MaterialRippleLayout.java From KickAssSlidingMenu with Apache License 2.0 | 6 votes |
@Override public void draw(Canvas canvas) { final boolean positionChanged = adapterPositionChanged(); if (rippleOverlay) { if (!positionChanged) { rippleBackground.draw(canvas); } super.draw(canvas); if (!positionChanged) { if (rippleRoundedCorners != 0) { Path clipPath = new Path(); RectF rect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight()); clipPath.addRoundRect(rect, rippleRoundedCorners, rippleRoundedCorners, Path.Direction.CW); canvas.clipPath(clipPath); } canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint); } } else { if (!positionChanged) { rippleBackground.draw(canvas); canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint); } super.draw(canvas); } }
Example 4
Source File: SHCircleProgressBar.java From SHSwipeRefreshLayout with MIT License | 6 votes |
@Override public void draw(Canvas canvas, Paint paint) { final int viewWidth = SHCircleProgressBar.this.getWidth(); final int viewHeight = SHCircleProgressBar.this.getHeight(); canvas.drawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2 + mShadowRadius), mShadowPaint); canvas.drawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2), paint); }
Example 5
Source File: MultitouchView.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // draw all pointers for (int size = mActivePointers.size(), i = 0; i < size; i++) { PointF point = mActivePointers.valueAt(i); if (point != null) mPaint.setColor(colors[i % 9]); canvas.drawCircle(point.x, point.y, SIZE, mPaint); } canvas.drawText("Total pointers: " + mActivePointers.size(), 10, 40 , textPaint); }
Example 6
Source File: ImageUtil.java From android-graphics-demo with Apache License 2.0 | 5 votes |
public static Bitmap createCircle(int width, int height) { Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.BLUE); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); float radius = Math.min(width, height) * 0.45f; canvas.drawCircle(width / 2, height / 2, radius, paint); return bitmap; }
Example 7
Source File: DotMatrixIdenticon.java From Identiconizer with Apache License 2.0 | 5 votes |
@Override public Bitmap generateIdenticonBitmap(byte[] hash) { if (hash.length < 16) return null; Bitmap bmp = Bitmap.createBitmap(SIZE, SIZE, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); canvas.drawColor(BG_COLOR); int blue = (hash[13] & 0x01f) << 3; int green = (hash[14] & 0x01f) << 3; int red = (hash[15] & 0x01f) << 3; int color = Color.rgb(red, green, blue); if (getColorDistance(color, BG_COLOR) <= 64.0) { color = getComplementaryColor(color); } Paint p = new Paint(); p.setColor(color); p.setStyle(Paint.Style.FILL_AND_STROKE); p.setAntiAlias(true); for (int y = 0; y < 5; y++) { for (int x = 0; x < 5; x++) { final int index = y * 5 + x; float radius; if ((index & 1) == 0) { radius = hash[index/2] & 0x0F; } else { radius = (hash[index/2] >> 4) & 0x0F; } canvas.drawCircle(x * SIZE / 5 + SIZE / 10, y * SIZE / 5 + SIZE / 10, radius, p); } } return bmp; }
Example 8
Source File: CircleImageView.java From NewFastFrame with Apache License 2.0 | 5 votes |
@Override public void draw(Canvas canvas, Paint paint) { final int viewWidth = CircleImageView.this.getWidth(); final int viewHeight = CircleImageView.this.getHeight(); canvas.drawCircle(viewWidth / 2, viewHeight / 2, viewWidth / 2, mShadowPaint); canvas.drawCircle(viewWidth / 2, viewHeight / 2, viewWidth / 2 - mShadowRadius, paint); }
Example 9
Source File: FancyProgress4.java From FancyProgress with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { canvas.save(); canvas.translate(mRadius, mRadius); for (int i = 0; i < mBallCenters.length; i++) { mPaint.setColor(COLORS[i]); PointF mCurrentCenter = getCurrentCenter(i, mPercent); canvas.drawCircle(mCurrentCenter.x, mCurrentCenter.y, mRadius, mPaint); } canvas.restore(); }
Example 10
Source File: RippleLayout.java From AndroidStudyDemo with GNU General Public License v2.0 | 5 votes |
private void play(Canvas canvas, int mTimer) { int alpha = 5; // 透明度从5开始 for (int i=0; i<=mTimer; i++) { alpha += 2; // 每绘制一个外圆,透明度加2 mPaint.setAlpha(alpha); mPaint.setStrokeWidth(2); canvas.drawCircle(mBitmapWidth/2, mBitmapHeight/2, mInnerRadius+i, mPaint); } }
Example 11
Source File: FloatingActionButton.java From FABtransitions with MIT License | 5 votes |
@Override protected void onDraw(Canvas canvas) { setClickable(true); canvas.drawCircle(getWidth() / 2, getHeight() / 2, (float) (getWidth() / 2.6), mButtonPaint); canvas.drawBitmap(mBitmap, (getWidth() - mBitmap.getWidth()) / 2, (getHeight() - mBitmap.getHeight()) / 2, mDrawablePaint); }
Example 12
Source File: RYBDrawStrategyStateOne.java From youqu_master with Apache License 2.0 | 5 votes |
@Override public void drawIcon(Canvas canvas, float fraction, Drawable drawable, int colorOfIcon, WidthAndHeightOfView widthAndHeightOfView) { float newFraction = fraction / 0.65f; int centerX = widthAndHeightOfView.getWidth() / 2; int centerY = widthAndHeightOfView.getHeight() / 2 - 150; Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); canvas.save(); paint.setColor(Color.parseColor("#e53935")); if (newFraction <= 0.33f) { canvas.drawCircle(centerX, centerY - 50, 100 * (newFraction / 0.33f), paint); } else { canvas.drawCircle(centerX, centerY - 50, 100, paint); } if (newFraction > 0.33f) { paint.setColor(Color.parseColor("#fdd835")); if (newFraction <= 0.66f) canvas.drawCircle(centerX -35, centerY + 35,100 * ((newFraction - 0.33f) / 0.33f), paint); else canvas.drawCircle(centerX -35, centerY + 35,100, paint); } if (newFraction > 0.66f) { paint.setColor(Color.parseColor("#1e88e5")); if (newFraction <= 1f) canvas.drawCircle(centerX + 35, centerY + 35, 100 * ((newFraction - 0.66f) / 0.34f), paint); else canvas.drawCircle(centerX + 35, centerY + 35, 100, paint); } canvas.restore(); }
Example 13
Source File: DotView.java From ReadMark with Apache License 2.0 | 5 votes |
/** * 把bitmap变圆 * * @param bitmap * @return */ private Bitmap getCircleBitmap(Bitmap bitmap) { //创建一个Bitmap,准备在上面作画 Bitmap base = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(base); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); //防抖动 paint.setDither(true); //先在base上画一个圆 canvas.drawCircle(getMeasuredWidth() / 2 , getMeasuredHeight() / 2 , getMeasuredWidth() / 2, paint); //设置为SRC_IN paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); //再在base上画上传进来的bitmap,注意坐标对应(这里从原点开始) canvas.drawBitmap(bitmap, 0, 0, paint); //回收 bitmap.recycle(); bitmap = null; return base; }
Example 14
Source File: DirectedLocationOverlay.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public void draw(final Canvas c, final Projection pj) { if (this.mLocation != null) { pj.toPixels(this.mLocation, screenCoords); if (this.mShowAccuracy && this.mAccuracy > 10) { final float accuracyRadius = pj.metersToEquatorPixels(this.mAccuracy); /* Only draw if the DirectionArrow doesn't cover it. */ if (accuracyRadius > 8) { /* Draw the inner shadow. */ this.mAccuracyPaint.setAntiAlias(false); this.mAccuracyPaint.setAlpha(30); this.mAccuracyPaint.setStyle(Style.FILL); c.drawCircle(screenCoords.x, screenCoords.y, accuracyRadius, this.mAccuracyPaint); /* Draw the edge. */ this.mAccuracyPaint.setAntiAlias(true); this.mAccuracyPaint.setAlpha(150); this.mAccuracyPaint.setStyle(Style.STROKE); c.drawCircle(screenCoords.x, screenCoords.y, accuracyRadius, this.mAccuracyPaint); } } /* * Rotate the direction-Arrow according to the bearing we are driving. And draw it to * the canvas. */ this.directionRotater.setRotate(this.mBearing, DIRECTION_ARROW_CENTER_X, DIRECTION_ARROW_CENTER_Y); final Bitmap rotatedDirection = Bitmap.createBitmap(DIRECTION_ARROW, 0, 0, DIRECTION_ARROW_WIDTH, DIRECTION_ARROW_HEIGHT, this.directionRotater, false); c.drawBitmap(rotatedDirection, screenCoords.x - rotatedDirection.getWidth() / 2, screenCoords.y - rotatedDirection.getHeight() / 2, this.mPaint); } }
Example 15
Source File: IndicateTouchLocationActivity.java From coursera-android with MIT License | 4 votes |
@Override protected void onDraw(Canvas canvas) { canvas.drawCircle(mX, mY, MAX_SIZE / mTouches, mPaint); }
Example 16
Source File: QiblaTimeView.java From prayer-times-android with Apache License 2.0 | 4 votes |
@SuppressLint("DrawAllocation") @Override protected void onDraw(@NonNull Canvas canvas) { int width = getWidth(); int center = width / 2; canvas.drawCircle(center, center, (center * 19) / 20f, mBackgroundPaint); int size = center / 10; //sun line if (mShowSun) { canvas.drawLine(center, center, (float) (center - 0.9 * center * Math.cos(Math.toRadians(mCurrentAngle))), (float) (center - 0.9 * center * Math.sin(Math.toRadians(mCurrentAngle))), mYellowPaint); canvas.save(); canvas.clipPath(mClipPath); canvas.drawCircle((float) (center - 0.85 * center * Math.cos(Math.toRadians(mCurrentAngle))), (float) (center - 0.85 * center * Math.sin(Math.toRadians(mCurrentAngle))), size, mSunPaint); canvas.restore(); } float nightAngle = (float) (mSunriseAngle - mSunsetAngle); canvas.drawArc(new RectF(center - center * 0.9f, center - center * 0.9f, center + center * 0.9f, center + center * 0.9f), (float) -mSunriseAngle + 90, nightAngle, true, mNightPaint); float sw = mYellowPaint.getStrokeWidth() / 2; canvas.drawArc(new RectF(center - center * 0.9f + sw, center - center * 0.9f + sw, center + center * 0.9f - sw, center + center * 0.9f - sw), (float) -mSunriseAngle + 90, -(360 - nightAngle), false, mYellowPaint); canvas.drawCircle(center, center, center / 10f, mCenterPaint); int y = center - center / 2; mKaabe.setBounds(center - size, y - size, center + size, y + size); mKaabe.draw(canvas); canvas.drawCircle(center, center, (center * 19) / 20f, mOuterStrokePaint); float textShift = center / 30f; if (mQiblaTime != null) { if (mQiblaTime.getFront() != null) { canvas.drawPath(mTopPath, mTrianglePaint); canvas.drawText(mQiblaTime.getFront(), center, center - center * 0.9f + textShift, mTextPaint); } if (mQiblaTime.getLeft() != null) { canvas.drawPath(mLeftPath, mTrianglePaint); canvas.drawText(mQiblaTime.getLeft(), center - center * 0.84f, center + textShift, mTextPaint); } if (mQiblaTime.getRight() != null) { canvas.drawPath(mRightPath, mTrianglePaint); canvas.drawText(mQiblaTime.getRight(), center + center * 0.84f, center + textShift, mTextPaint); } if (mQiblaTime.getBack() != null) { canvas.drawPath(mBottomPath, mTrianglePaint); canvas.drawText(mQiblaTime.getBack(), center, center + center * 0.9f + textShift, mTextPaint); } } }
Example 17
Source File: CircleBarVisualizer.java From Bop with Apache License 2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { if (radius == -1) { radius = getHeight() < getWidth() ? getHeight() : getWidth(); radius = (int) (radius * 0.65 / 2); double circumference = 2 * Math.PI * radius; paint.setStrokeWidth((float) (circumference / 120)); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeWidth(4); } circlePaint.setColor(color); canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius, circlePaint); if (bytes != null) { if (points == null || points.length < bytes.length * 4) { points = new float[bytes.length * 4]; } double angle = 0; for (int i = 0; i < 120; i++, angle += 3) { int x = (int) Math.ceil(i * 8.5); int t = ((byte) (-Math.abs(bytes[x]) + 128)) * (getHeight() / 4) / 128; points[i * 4] = (float) (getWidth() / 2 + radius * Math.cos(Math.toRadians(angle))); points[i * 4 + 1] = (float) (getHeight() / 2 + radius * Math.sin(Math.toRadians(angle))); points[i * 4 + 2] = (float) (getWidth() / 2 + (radius + t) * Math.cos(Math.toRadians(angle))); points[i * 4 + 3] = (float) (getHeight() / 2 + (radius + t) * Math.sin(Math.toRadians(angle))); } canvas.drawLines(points, paint); } super.onDraw(canvas); }
Example 18
Source File: CropHighlightView.java From CVScanner with GNU General Public License v3.0 | 4 votes |
private void drawEdges(Canvas canvas) { final float[] p = mTrapezoid.getScreenPoints(getMatrix()); Path path = new Path(); path.moveTo((int) p[0], (int) p[1]); path.lineTo((int) p[2], (int) p[3]); path.lineTo((int) p[4], (int) p[5]); path.lineTo((int) p[6], (int) p[7]); path.close(); path.computeBounds(mPathBounds, false); mPathBounds.round(mPathBoundsRounded); canvas.getClipBounds(mCanvasCLipRect); mContext.getDrawingRect(mViewDrawingRect); mTopRect.set(0, 0, mViewDrawingRect.right, getDrawRect().top); mRightRect.set(0, getDrawRect().top, getDrawRect().left, getDrawRect().bottom); mLeftRect.set(getDrawRect().right, getDrawRect().top, mViewDrawingRect.right, getDrawRect().bottom); mBottomRect.set(0, getDrawRect().bottom, mViewDrawingRect.right, mViewDrawingRect.bottom); canvas.drawRect(mTopRect, mFocusPaint); canvas.drawRect(mRightRect, mFocusPaint); canvas.drawRect(mLeftRect, mFocusPaint); canvas.drawRect(mBottomRect, mFocusPaint); if (mCanvasCLipRect.contains(mPathBoundsRounded)) { canvas.save(); canvas.clipRect(getDrawRect()); path.setFillType(Path.FillType.INVERSE_EVEN_ODD); canvas.drawPath(path, mFocusPaint); canvas.restore(); } canvas.drawLine(p[0], p[1], p[2], p[3], mOutlinePaint); canvas.drawLine(p[2], p[3], p[4], p[5], mOutlinePaint); canvas.drawLine(p[4], p[5], p[6], p[7], mOutlinePaint); canvas.drawLine(p[0], p[1], p[6], p[7], mOutlinePaint); canvas.drawCircle(p[0], p[1], mCropCornerHandleRadius, mOutlinePaint); canvas.drawCircle(p[2], p[3], mCropCornerHandleRadius, mOutlinePaint); canvas.drawCircle(p[4], p[5], mCropCornerHandleRadius, mOutlinePaint); canvas.drawCircle(p[6], p[7], mCropCornerHandleRadius, mOutlinePaint); float x = (p[0] + p[2]) / 2; float y = (p[1] + p[3]) / 2; canvas.drawCircle(x, y, mCropEdgeHandleRadius, mOutlinePaint); x = (p[2] + p[4]) / 2; y = (p[3] + p[5]) / 2; canvas.drawCircle(x, y, mCropEdgeHandleRadius, mOutlinePaint); x = (p[4] + p[6]) / 2; y = (p[5] + p[7]) / 2; canvas.drawCircle(x, y, mCropEdgeHandleRadius, mOutlinePaint); x = (p[0] + p[6]) / 2; y = (p[1] + p[7]) / 2; canvas.drawCircle(x, y, mCropEdgeHandleRadius, mOutlinePaint); }
Example 19
Source File: RippleBackground.java From ShowcaseView with Apache License 2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { int radius = (Math.min(getWidth(), getHeight())) / 2; canvas.drawCircle(radius, radius, radius - rippleStrokeWidth, paint); }
Example 20
Source File: CropAreaView.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { if (freeform) { int lineThickness = AndroidUtilities.dp(2); int handleSize = AndroidUtilities.dp(16); int handleThickness = AndroidUtilities.dp(3); int originX = (int) actualRect.left - lineThickness; int originY = (int) actualRect.top - lineThickness; int width = (int) (actualRect.right - actualRect.left) + lineThickness * 2; int height = (int) (actualRect.bottom - actualRect.top) + lineThickness * 2; if (dimVisibile) { canvas.drawRect(0, 0, getWidth(), originY + lineThickness, dimPaint); canvas.drawRect(0, originY + lineThickness, originX + lineThickness, originY + height - lineThickness, dimPaint); canvas.drawRect(originX + width - lineThickness, originY + lineThickness, getWidth(), originY + height - lineThickness, dimPaint); canvas.drawRect(0, originY + height - lineThickness, getWidth(), getHeight(), dimPaint); } if (!frameVisible) { return; } int inset = handleThickness - lineThickness; int gridWidth = width - handleThickness * 2; int gridHeight = height - handleThickness * 2; GridType type = gridType; if (type == GridType.NONE && gridProgress > 0) type = previousGridType; shadowPaint.setAlpha((int) (gridProgress * 26)); linePaint.setAlpha((int) (gridProgress * 178)); for (int i = 0; i < 3; i++) { if (type == GridType.MINOR) { for (int j = 1; j < 4; j++) { if (i == 2 && j == 3) continue; canvas.drawLine(originX + handleThickness + gridWidth / 3 / 3 * j + gridWidth / 3 * i, originY + handleThickness, originX + handleThickness + gridWidth / 3 / 3 * j + gridWidth / 3 * i, originY + handleThickness + gridHeight, shadowPaint); canvas.drawLine(originX + handleThickness + gridWidth / 3 / 3 * j + gridWidth / 3 * i, originY + handleThickness, originX + handleThickness + gridWidth / 3 / 3 * j + gridWidth / 3 * i, originY + handleThickness + gridHeight, linePaint); canvas.drawLine(originX + handleThickness, originY + handleThickness + gridHeight / 3 / 3 * j + gridHeight / 3 * i, originX + handleThickness + gridWidth, originY + handleThickness + gridHeight / 3 / 3 * j + gridHeight / 3 * i, shadowPaint); canvas.drawLine(originX + handleThickness, originY + handleThickness + gridHeight / 3 / 3 * j + gridHeight / 3 * i, originX + handleThickness + gridWidth, originY + handleThickness + gridHeight / 3 / 3 * j + gridHeight / 3 * i, linePaint); } } else if (type == GridType.MAJOR) { if (i > 0) { canvas.drawLine(originX + handleThickness + gridWidth / 3 * i, originY + handleThickness, originX + handleThickness + gridWidth / 3 * i, originY + handleThickness + gridHeight, shadowPaint); canvas.drawLine(originX + handleThickness + gridWidth / 3 * i, originY + handleThickness, originX + handleThickness + gridWidth / 3 * i, originY + handleThickness + gridHeight, linePaint); canvas.drawLine(originX + handleThickness, originY + handleThickness + gridHeight / 3 * i, originX + handleThickness + gridWidth, originY + handleThickness + gridHeight / 3 * i, shadowPaint); canvas.drawLine(originX + handleThickness, originY + handleThickness + gridHeight / 3 * i, originX + handleThickness + gridWidth, originY + handleThickness + gridHeight / 3 * i, linePaint); } } } canvas.drawRect(originX + inset, originY + inset, originX + width - inset, originY + inset + lineThickness, framePaint); canvas.drawRect(originX + inset, originY + inset, originX + inset + lineThickness, originY + height - inset, framePaint); canvas.drawRect(originX + inset, originY + height - inset - lineThickness, originX + width - inset, originY + height - inset, framePaint); canvas.drawRect(originX + width - inset - lineThickness, originY + inset, originX + width - inset, originY + height - inset, framePaint); canvas.drawRect(originX, originY, originX + handleSize, originY + handleThickness, handlePaint); canvas.drawRect(originX, originY, originX + handleThickness, originY + handleSize, handlePaint); canvas.drawRect(originX + width - handleSize, originY, originX + width, originY + handleThickness, handlePaint); canvas.drawRect(originX + width - handleThickness, originY, originX + width, originY + handleSize, handlePaint); canvas.drawRect(originX, originY + height - handleThickness, originX + handleSize, originY + height, handlePaint); canvas.drawRect(originX, originY + height - handleSize, originX + handleThickness, originY + height, handlePaint); canvas.drawRect(originX + width - handleSize, originY + height - handleThickness, originX + width, originY + height, handlePaint); canvas.drawRect(originX + width - handleThickness, originY + height - handleSize, originX + width, originY + height, handlePaint); } else { if (circleBitmap == null || circleBitmap.getWidth() != actualRect.width()) { if (circleBitmap != null) { circleBitmap.recycle(); circleBitmap = null; } try { circleBitmap = Bitmap.createBitmap((int) actualRect.width(), (int) actualRect.height(), Bitmap.Config.ARGB_8888); Canvas circleCanvas = new Canvas(circleBitmap); circleCanvas.drawRect(0, 0, actualRect.width(), actualRect.height(), dimPaint); circleCanvas.drawCircle(actualRect.width() / 2, actualRect.height() / 2, actualRect.width() / 2, eraserPaint); circleCanvas.setBitmap(null); } catch (Throwable ignore) { } } canvas.drawRect(0, 0, getWidth(), (int) actualRect.top, dimPaint); canvas.drawRect(0, (int) actualRect.top, (int) actualRect.left, (int) actualRect.bottom, dimPaint); canvas.drawRect((int) actualRect.right, (int) actualRect.top, getWidth(), (int) actualRect.bottom, dimPaint); canvas.drawRect(0, (int) actualRect.bottom, getWidth(), getHeight(), dimPaint); if (circleBitmap != null) { canvas.drawBitmap(circleBitmap, (int) actualRect.left, (int) actualRect.top, null); } } }