LIFX / lifx-sdk-android

LIFX Android SDK
http://lifx.co/
MIT License
90 stars 30 forks source link

Add Ability to initialise a LFXHSBColor instance with RGB Integers and Standard Android Color class. #8

Open PercyBoyes opened 10 years ago

PercyBoyes commented 10 years ago

Explained in the title

janheinrichmerker commented 7 years ago

Could be easily done by adding the following lines to the LFXHSBColor class:

public static LFXHSBColor fromColor(@ColorInt int color, @IntRange(from = 0, to = 10000) int kelvin) {
    float[] hsb = new float[3];
    Color.colorToHSV(color, hsb);
    return getColor(hsb[0], hsb[1], hsb[2], kelvin);
}

public static LFXHSBColor fromRGB(@IntRange(from = 0, to = 255) int red,
        @IntRange(from = 0, to = 255) int green,
        @IntRange(from = 0, to = 255) int blue,
        @IntRange(from = 0, to = 10000) int kelvin) {
    int color = Color.rgb(red, green, blue);
    return fromColor(color, kelvin);
}