Android DrawArc SweepGradient over 360 °

I am trying to create a color wheel that allows the user to choose between solid color or gradients. The user can also move these colors around the wheel.

The problem is with the gradient. When the angle exceeds 360 °, the displayed color reverts to the first color instead of continuing the gradient.

I am using a custom view and the code I am inserting is called from the onDraw method.

int start = Color.rgb((int)previous.startRed, (int)previous.startGreen, (int)previous.startBlue);
int end = Color.rgb((int)previous.endRed, (int)previous.endGreen, (int)previous.endBlue);
int[] colors = {start, end, end};
float from = from_angle / 360.0f;
float to = (from_angle + to_angle) / 360.0f;
float[] positions = {from,to, to};
Log.v("Print", "print positions " + positions[0] + " " + positions[1]);
Shader gradient = new SweepGradient (oval.centerX(), oval.centerY(),colors, positions);
paint.setShader(gradient);
canvas.drawArc(oval, from_angle, to_angle + 1, false, paint);

      

Here is an image to show the problem I am facing. enter image description here

Any hint would be appreciated. Thank.

+3


source to share





All Articles