com.flask.colorpicker.renderer.ColorWheelRenderer Java Examples

The following examples show how to use com.flask.colorpicker.renderer.ColorWheelRenderer. 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: ColorPickerView.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private void drawColorWheel() {
	colorWheelCanvas.drawColor(0, PorterDuff.Mode.CLEAR);

	if (renderer == null) return;

	float half = colorWheelCanvas.getWidth() / 2f;
	float strokeWidth = STROKE_RATIO * (1f + ColorWheelRenderer.GAP_PERCENTAGE);
	float maxRadius = half - strokeWidth - half / density;
	float cSize = maxRadius / (density - 1) / 2;

	ColorWheelRenderOption colorWheelRenderOption = renderer.getRenderOption();
	colorWheelRenderOption.density = this.density;
	colorWheelRenderOption.maxRadius = maxRadius;
	colorWheelRenderOption.cSize = cSize;
	colorWheelRenderOption.strokeWidth = strokeWidth;
	colorWheelRenderOption.alpha = alpha;
	colorWheelRenderOption.lightness = lightness;
	colorWheelRenderOption.targetCanvas = colorWheelCanvas;

	renderer.initWith(colorWheelRenderOption);
	renderer.draw();
}
 
Example #2
Source File: ColorPickerView.java    From droidddle with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawColor(backgroundColor);
    if (colorWheel != null)
        canvas.drawBitmap(colorWheel, 0, 0, null);
    if (currentColorCircle != null) {
        float maxRadius = canvas.getWidth() / 2f - STROKE_RATIO * (1f + ColorWheelRenderer.GAP_PERCENTAGE);
        float size = maxRadius / density / 2;
        colorWheelFill.setColor(Color.HSVToColor(currentColorCircle.getHsvWithLightness(this.lightness)));
        colorWheelFill.setAlpha((int) (alpha * 0xff));
        canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size * STROKE_RATIO, selectorStroke1);
        canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size * (1 + (STROKE_RATIO - 1) / 2), selectorStroke2);

        canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size, alphaPatternPaint);
        canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size, colorWheelFill);
    }
}
 
Example #3
Source File: ColorPickerView.java    From droidddle with Apache License 2.0 6 votes vote down vote up
private void drawColorWheel() {
    colorWheelCanvas.drawColor(0, PorterDuff.Mode.CLEAR);

    if (renderer == null) return;

    float half = colorWheelCanvas.getWidth() / 2f;
    float strokeWidth = STROKE_RATIO * (1f + ColorWheelRenderer.GAP_PERCENTAGE);
    float maxRadius = half - strokeWidth - half / density;
    float cSize = maxRadius / (density - 1) / 2;

    ColorWheelRenderOption colorWheelRenderOption = renderer.getRenderOption();
    colorWheelRenderOption.density = this.density;
    colorWheelRenderOption.maxRadius = maxRadius;
    colorWheelRenderOption.cSize = cSize;
    colorWheelRenderOption.strokeWidth = strokeWidth;
    colorWheelRenderOption.alpha = alpha;
    colorWheelRenderOption.lightness = lightness;
    colorWheelRenderOption.targetCanvas = colorWheelCanvas;

    renderer.initWith(colorWheelRenderOption);

    renderer.draw();
}
 
Example #4
Source File: ColorPickerView.java    From openlauncher with Apache License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example #5
Source File: ColorPickerView.java    From openlauncher with Apache License 2.0 6 votes vote down vote up
private void drawColorWheel() {
	colorWheelCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
	currentColorCanvas.drawColor(0, PorterDuff.Mode.CLEAR);

	if (renderer == null) return;

	float half = colorWheelCanvas.getWidth() / 2f;
	float strokeWidth = STROKE_RATIO * (1f + ColorWheelRenderer.GAP_PERCENTAGE);
	float maxRadius = half - strokeWidth - half / density;
	float cSize = maxRadius / (density - 1) / 2;

	ColorWheelRenderOption colorWheelRenderOption = renderer.getRenderOption();
	colorWheelRenderOption.density = this.density;
	colorWheelRenderOption.maxRadius = maxRadius;
	colorWheelRenderOption.cSize = cSize;
	colorWheelRenderOption.strokeWidth = strokeWidth;
	colorWheelRenderOption.alpha = alpha;
	colorWheelRenderOption.lightness = lightness;
	colorWheelRenderOption.targetCanvas = colorWheelCanvas;

	renderer.initWith(colorWheelRenderOption);
	renderer.draw();
}
 
Example #6
Source File: ColorPickerView.java    From openlauncher with Apache License 2.0 6 votes vote down vote up
private void initWith(Context context, AttributeSet attrs) {
	final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ColorPickerPreference);

	density = typedArray.getInt(R.styleable.ColorPickerPreference_density, 10);
	initialColor = typedArray.getInt(R.styleable.ColorPickerPreference_initialColor, 0xffffffff);

	pickerColorEditTextColor = typedArray.getInt(R.styleable.ColorPickerPreference_pickerColorEditTextColor, 0xffffffff);

	WHEEL_TYPE wheelType = WHEEL_TYPE.indexOf(typedArray.getInt(R.styleable.ColorPickerPreference_wheelType, 0));
	ColorWheelRenderer renderer = ColorWheelRendererBuilder.getRenderer(wheelType);

	alphaSliderViewId = typedArray.getResourceId(R.styleable.ColorPickerPreference_alphaSliderView, 0);
	lightnessSliderViewId = typedArray.getResourceId(R.styleable.ColorPickerPreference_lightnessSliderView, 0);

	setRenderer(renderer);
	setDensity(density);
	setInitialColor(initialColor, true);

	typedArray.recycle();
}
 
Example #7
Source File: ColorPickerView.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);
	canvas.drawColor(backgroundColor);
	if (colorWheel != null)
		canvas.drawBitmap(colorWheel, 0, 0, null);
	if (currentColorCircle != null) {
		float maxRadius = canvas.getWidth() / 2f - STROKE_RATIO * (1f + ColorWheelRenderer.GAP_PERCENTAGE);
		float size = maxRadius / density / 2;
		colorWheelFill.setColor(Color.HSVToColor(currentColorCircle.getHsvWithLightness(this.lightness)));
		colorWheelFill.setAlpha((int) (alpha * 0xff));
		canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size * STROKE_RATIO, selectorStroke1);
		canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size * (1 + (STROKE_RATIO - 1) / 2), selectorStroke2);

		canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size, alphaPatternPaint);
		canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size, colorWheelFill);
	}
}
 
Example #8
Source File: ColorPickerView.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private void drawColorWheel() {
	colorWheelCanvas.drawColor(0, PorterDuff.Mode.CLEAR);

	if (renderer == null) return;

	float half = colorWheelCanvas.getWidth() / 2f;
	float strokeWidth = STROKE_RATIO * (1f + ColorWheelRenderer.GAP_PERCENTAGE);
	float maxRadius = half - strokeWidth - half / density;
	float cSize = maxRadius / (density - 1) / 2;

	ColorWheelRenderOption colorWheelRenderOption = renderer.getRenderOption();
	colorWheelRenderOption.density = this.density;
	colorWheelRenderOption.maxRadius = maxRadius;
	colorWheelRenderOption.cSize = cSize;
	colorWheelRenderOption.strokeWidth = strokeWidth;
	colorWheelRenderOption.alpha = alpha;
	colorWheelRenderOption.lightness = lightness;
	colorWheelRenderOption.targetCanvas = colorWheelCanvas;

	renderer.initWith(colorWheelRenderOption);
	renderer.draw();
}
 
Example #9
Source File: ColorPickerView.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private void initWith(Context context, AttributeSet attrs) {
	final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ColorPickerPreference);

	density = typedArray.getInt(R.styleable.ColorPickerPreference_density, 10);
	initialColor = typedArray.getInt(R.styleable.ColorPickerPreference_initialColor, 0xffffffff);

	pickerTextColor = typedArray.getInt(R.styleable.ColorPickerPreference_pickerColorEditTextColor, 0xffffffff);

	WHEEL_TYPE wheelType = WHEEL_TYPE.indexOf(typedArray.getInt(R.styleable.ColorPickerPreference_wheelType, 0));
	ColorWheelRenderer renderer = ColorWheelRendererBuilder.getRenderer(wheelType);

	alphaSliderViewId = typedArray.getResourceId(R.styleable.ColorPickerPreference_alphaSliderView, 0);
	lightnessSliderViewId = typedArray.getResourceId(R.styleable.ColorPickerPreference_lightnessSliderView, 0);

	setRenderer(renderer);
	setDensity(density);
	setInitialColor(initialColor, true);

	typedArray.recycle();
}
 
Example #10
Source File: ColorPickerView.java    From timecat with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);
	canvas.drawColor(backgroundColor);
	if (colorWheel != null)
		canvas.drawBitmap(colorWheel, 0, 0, null);
	if (currentColorCircle != null) {
		float maxRadius = canvas.getWidth() / 2f - STROKE_RATIO * (1f + ColorWheelRenderer.GAP_PERCENTAGE);
		float size = maxRadius / density / 2;
		colorWheelFill.setColor(Color.HSVToColor(currentColorCircle.getHsvWithLightness(this.lightness)));
		colorWheelFill.setAlpha((int) (alpha * 0xff));
		canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size * STROKE_RATIO, selectorStroke1);
		canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size * (1 + (STROKE_RATIO - 1) / 2), selectorStroke2);

		canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size, alphaPatternPaint);
		canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size, colorWheelFill);
	}
}
 
Example #11
Source File: ColorPickerView.java    From timecat with Apache License 2.0 6 votes vote down vote up
private void drawColorWheel() {
	colorWheelCanvas.drawColor(0, PorterDuff.Mode.CLEAR);

	if (renderer == null) return;

	float half = colorWheelCanvas.getWidth() / 2f;
	float strokeWidth = STROKE_RATIO * (1f + ColorWheelRenderer.GAP_PERCENTAGE);
	float maxRadius = half - strokeWidth - half / density;
	float cSize = maxRadius / (density - 1) / 2;

	ColorWheelRenderOption colorWheelRenderOption = renderer.getRenderOption();
	colorWheelRenderOption.density = this.density;
	colorWheelRenderOption.maxRadius = maxRadius;
	colorWheelRenderOption.cSize = cSize;
	colorWheelRenderOption.strokeWidth = strokeWidth;
	colorWheelRenderOption.alpha = alpha;
	colorWheelRenderOption.lightness = lightness;
	colorWheelRenderOption.targetCanvas = colorWheelCanvas;

	renderer.initWith(colorWheelRenderOption);
	renderer.draw();
}
 
Example #12
Source File: ColorPickerView.java    From timecat with Apache License 2.0 6 votes vote down vote up
private void initWith(Context context, AttributeSet attrs) {
	final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ColorPickerPreference);

	density = typedArray.getInt(R.styleable.ColorPickerPreference_density, 10);
	initialColor = typedArray.getInt(R.styleable.ColorPickerPreference_initialColor, 0xffffffff);

	pickerTextColor = typedArray.getInt(R.styleable.ColorPickerPreference_pickerColorEditTextColor, 0xffffffff);

	WHEEL_TYPE wheelType = WHEEL_TYPE.indexOf(typedArray.getInt(R.styleable.ColorPickerPreference_wheelType, 0));
	ColorWheelRenderer renderer = ColorWheelRendererBuilder.getRenderer(wheelType);

	alphaSliderViewId = typedArray.getResourceId(R.styleable.ColorPickerPreference_alphaSliderView, 0);
	lightnessSliderViewId = typedArray.getResourceId(R.styleable.ColorPickerPreference_lightnessSliderView, 0);

	setRenderer(renderer);
	setDensity(density);
	setInitialColor(initialColor, true);

	typedArray.recycle();
}
 
Example #13
Source File: ColorPickerView.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);
	canvas.drawColor(backgroundColor);
	if (colorWheel != null)
		canvas.drawBitmap(colorWheel, 0, 0, null);
	if (currentColorCircle != null) {
		float maxRadius = canvas.getWidth() / 2f - STROKE_RATIO * (1f + ColorWheelRenderer.GAP_PERCENTAGE);
		float size = maxRadius / density / 2;
		colorWheelFill.setColor(Color.HSVToColor(currentColorCircle.getHsvWithLightness(this.lightness)));
		colorWheelFill.setAlpha((int) (alpha * 0xff));
		canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size * STROKE_RATIO, selectorStroke1);
		canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size * (1 + (STROKE_RATIO - 1) / 2), selectorStroke2);

		canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size, alphaPatternPaint);
		canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size, colorWheelFill);
	}
}
 
Example #14
Source File: ColorPickerView.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private void initWith(Context context, AttributeSet attrs) {
	final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ColorPickerPreference);

	density = typedArray.getInt(R.styleable.ColorPickerPreference_density, 10);
	initialColor = typedArray.getInt(R.styleable.ColorPickerPreference_initialColor, 0xffffffff);

	pickerTextColor = typedArray.getInt(R.styleable.ColorPickerPreference_pickerColorEditTextColor, 0xffffffff);

	WHEEL_TYPE wheelType = WHEEL_TYPE.indexOf(typedArray.getInt(R.styleable.ColorPickerPreference_wheelType, 0));
	ColorWheelRenderer renderer = ColorWheelRendererBuilder.getRenderer(wheelType);

	alphaSliderViewId = typedArray.getResourceId(R.styleable.ColorPickerPreference_alphaSliderView, 0);
	lightnessSliderViewId = typedArray.getResourceId(R.styleable.ColorPickerPreference_lightnessSliderView, 0);

	setRenderer(renderer);
	setDensity(density);
	setInitialColor(initialColor, true);

	typedArray.recycle();
}
 
Example #15
Source File: ColorWheelRendererBuilder.java    From timecat with Apache License 2.0 5 votes vote down vote up
public static ColorWheelRenderer getRenderer(ColorPickerView.WHEEL_TYPE wheelType) {
	switch (wheelType) {
		case CIRCLE:
			return new SimpleColorWheelRenderer();
		case FLOWER:
			return new FlowerColorWheelRenderer();
	}
	throw new IllegalArgumentException("wrong WHEEL_TYPE");
}
 
Example #16
Source File: ColorWheelRendererBuilder.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public static ColorWheelRenderer getRenderer(ColorPickerView.WHEEL_TYPE wheelType) {
	switch (wheelType) {
		case CIRCLE:
			return new SimpleColorWheelRenderer();
		case FLOWER:
			return new FlowerColorWheelRenderer();
	}
	throw new IllegalArgumentException("wrong WHEEL_TYPE");
}
 
Example #17
Source File: ColorWheelRendererBuilder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public static ColorWheelRenderer getRenderer(ColorPickerView.WHEEL_TYPE wheelType) {
	switch (wheelType) {
		case CIRCLE:
			return new SimpleColorWheelRenderer();
		case FLOWER:
			return new FlowerColorWheelRenderer();
	}
	throw new IllegalArgumentException("wrong WHEEL_TYPE");
}
 
Example #18
Source File: ColorWheelRendererBuilder.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
public static ColorWheelRenderer getRenderer(ColorPickerView.WHEEL_TYPE wheelType) {
	switch (wheelType) {
		case CIRCLE:
			return new SimpleColorWheelRenderer();
		case FLOWER:
			return new FlowerColorWheelRenderer();
	}
	throw new IllegalArgumentException("wrong WHEEL_TYPE");
}
 
Example #19
Source File: ColorPickerView.java    From droidddle with Apache License 2.0 5 votes vote down vote up
private void initWith(Context context, AttributeSet attrs) {
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ColorPickerPreference);

    density = typedArray.getInt(R.styleable.ColorPickerPreference_density, 10);
    initialColor = typedArray.getInt(R.styleable.ColorPickerPreference_initialColor, 0xffffffff);
    WHEEL_TYPE wheelType = WHEEL_TYPE.indexOf(typedArray.getInt(R.styleable.ColorPickerPreference_wheelType, 0));
    ColorWheelRenderer renderer = ColorWheelRendererBuilder.getRenderer(wheelType);

    alphaSliderViewId = typedArray.getResourceId(R.styleable.ColorPickerPreference_alphaSliderView, 0);
    lightnessSliderViewId = typedArray.getResourceId(R.styleable.ColorPickerPreference_lightnessSliderView, 0);

    setRenderer(renderer);
    setDensity(density);
    setInitialColor(initialColor);
}
 
Example #20
Source File: ColorWheelRendererBuilder.java    From droidddle with Apache License 2.0 5 votes vote down vote up
public static ColorWheelRenderer getRenderer(ColorPickerView.WHEEL_TYPE wheelType) {
    switch (wheelType) {
        case CIRCLE:
            return new SimpleColorWheelRenderer();
        case FLOWER:
            return new FlowerColorWheelRenderer();
    }
    throw new IllegalArgumentException("wrong WHEEL_TYPE");
}
 
Example #21
Source File: ColorPickerView.java    From timecat with Apache License 2.0 4 votes vote down vote up
public void setRenderer(ColorWheelRenderer renderer) {
	this.renderer = renderer;
	invalidate();
}
 
Example #22
Source File: ColorPickerView.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public void setRenderer(ColorWheelRenderer renderer) {
	this.renderer = renderer;
	invalidate();
}
 
Example #23
Source File: ColorPickerView.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void setRenderer(ColorWheelRenderer renderer) {
	this.renderer = renderer;
	invalidate();
}
 
Example #24
Source File: ColorPickerView.java    From openlauncher with Apache License 2.0 4 votes vote down vote up
public void setRenderer(ColorWheelRenderer renderer) {
	this.renderer = renderer;
	invalidate();
}
 
Example #25
Source File: ColorPickerView.java    From droidddle with Apache License 2.0 4 votes vote down vote up
public void setRenderer(ColorWheelRenderer renderer) {
    this.renderer = renderer;
    invalidate();
}