milosmns / circular-slider-android

Circular Slider UI Control for Android
GNU General Public License v3.0
307 stars 51 forks source link

How this use? #9

Closed webserveis closed 7 years ago

webserveis commented 8 years ago

How to get the value, angle value?

milosmns commented 7 years ago

Currently, you get the angle value from the [0, 1] float range depending on your start_angle value. This angle value represents the percentage of the circle that the slider went around (standard radian, counter-clockwise). For example, if you set the start_angle to 3.14 (Pi), your 'zero' would be on the left side. If you would like to convert these values to the human clock form ('zero' on top, clockwise), you can use the following two functions to convert to clock value and back. Both return a value from the [0, 1] range so you can multiply with your values - clock values would obviously be in the [1, 12] range.

Converter functions for start_angle="3.14" example:

// you get the angle from the slider listener
float convertAngleToClock(float angle) {
    return (3f / 4f - angle) % 1;
}
// use the returned value in the `setPosition(float)` method
float convertClockToPosition(float clock) {
    return 1f - ((1f / 4f + clock) % 1);
}

It's very similar for other start_value angles, you just change the 1/4 and 3/4 values to your rotation phases.