@Override protected void onDraw(Canvas canvas) { // draw the background and color wheel canvas.drawBitmap(mBackground, mBackgroundPosition.x, mBackgroundPosition.y, null); canvas.drawBitmap(mWheel, mWheelPosition.x, mWheelPosition.y, null); // setup paint for the gradient filling Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.FILL); paint.setStrokeWidth(2.0f); // create a shader that will show the range of brightness settings float[] gradientStartColor = new float[3]; float[] gradientEndColor = new float[3]; System.arraycopy(mNewColor, 0, gradientStartColor, 0, mNewColor.length); System.arraycopy(mNewColor, 0, gradientEndColor, 0, mNewColor.length); gradientStartColor[2] = 1.0f; gradientEndColor[2] = 0.0f; Shader gradientShader = new LinearGradient( (float) (mWheelPosition.x + mRadius), mWheelPosition.y, mOuterArcRect.right, mWheelPosition.y + mWheel.getHeight(), Color.HSVToColor(gradientStartColor), Color.HSVToColor(gradientEndColor), Shader.TileMode.MIRROR); paint.setShader(gradientShader); canvas.drawPath(mArcPath, paint); drawHSCrosshairs(canvas); drawBrightnessIndicator(canvas); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (paint == null) { paint = new Paint(); luar = new LinearGradient( 0.f, 0.f, 0.f, this.getMeasuredHeight(), 0xffffffff, 0xff000000, TileMode.CLAMP); } int rgb = Color.HSVToColor(color); Shader dalam = new LinearGradient(0.f, 0.f, this.getMeasuredWidth(), 0.f, 0xffffffff, rgb, TileMode.CLAMP); ComposeShader shader = new ComposeShader(luar, dalam, PorterDuff.Mode.MULTIPLY); paint.setShader(shader); canvas.drawRect(0.f, 0.f, this.getMeasuredWidth(), this.getMeasuredHeight(), paint); }
int random_color() { // return 0xFF000000 | (int) (Math.random() * (float) 0xFFFFFF); // totally random final int COLORS = 12; hsv[0] = irand(0, COLORS) * (360f / COLORS); return Color.HSVToColor(hsv); }
private void updateListener() { if (mListener != null) { mListener.OnColorChanged(Color.HSVToColor(mNewColor)); } }
private int darkenColor(int color) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] *= 0.9f; return Color.HSVToColor(hsv); }