@Override protected void drawHandle(Canvas canvas, float x, float y) { solid.setColor(color); solid.setAlpha(Math.round(value * 255)); if (showBorder) canvas.drawCircle(x, y, handleRadius, clearingStroke); if (value < 1) { // this fixes the same artifact issue from ColorPickerView // happens when alpha pattern is drawn underneath a circle with the same size clearBitmapCanvas.drawColor(0, PorterDuff.Mode.CLEAR); clearBitmapCanvas.drawCircle(x, y, handleRadius * 0.75f + 4, alphaPatternPaint); clearBitmapCanvas.drawCircle(x, y, handleRadius * 0.75f + 4, solid); clearStroke = PaintBuilder.newPaint().color(0xffffffff).style(Paint.Style.STROKE).stroke(6).xPerMode(PorterDuff.Mode.CLEAR).build(); clearBitmapCanvas.drawCircle(x, y, handleRadius * 0.75f + (clearStroke.getStrokeWidth() / 2), clearStroke); canvas.drawBitmap(clearBitmap, 0, 0, null); } else { canvas.drawCircle(x, y, handleRadius * 0.75f, solid); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(backgroundColor); float maxRadius = canvas.getWidth() / (1f + ColorWheelRenderer.GAP_PERCENTAGE); float size = maxRadius / density / 2; if (colorWheel != null && currentColorCircle != null) { colorWheelFill.setColor(Color.HSVToColor(currentColorCircle.getHsvWithLightness(this.lightness))); colorWheelFill.setAlpha((int) (alpha * 0xff)); // a separate canvas is used to erase an issue with the alpha pattern around the edges // draw circle slightly larger than it needs to be, then erase edges to proper dimensions currentColorCanvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size + 4, alphaPatternPaint); currentColorCanvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size + 4, colorWheelFill); selectorStroke = PaintBuilder.newPaint().color(0xffffffff).style(Paint.Style.STROKE).stroke(size * (STROKE_RATIO - 1)).xPerMode(PorterDuff.Mode.CLEAR).build(); if (showBorder) colorWheelCanvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size + (selectorStroke.getStrokeWidth() / 2f), selectorStroke); canvas.drawBitmap(colorWheel, 0, 0, null); currentColorCanvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size + (selectorStroke.getStrokeWidth() / 2f), selectorStroke); canvas.drawBitmap(currentColor, 0, 0, null); } }