FileDocCategorySizeDatePackage
HsvColorComparator.javaAPI DocAndroid 5.1 API1727Thu Mar 12 22:22:50 GMT 2015com.android.colorpicker

HsvColorComparator

public class HsvColorComparator extends Object implements Comparator
A color comparator which compares based on hue, saturation, and value.

Fields Summary
Constructors Summary
Methods Summary
public intcompare(java.lang.Integer lhs, java.lang.Integer rhs)

        float[] hsv = new float[3];
        Color.colorToHSV(lhs, hsv);
        float hue1 = hsv[0];
        float sat1 = hsv[1];
        float val1 = hsv[2];

        float[] hsv2 = new float[3];
        Color.colorToHSV(rhs, hsv2);
        float hue2 = hsv2[0];
        float sat2 = hsv2[1];
        float val2 = hsv2[2];

        if (hue1 < hue2) {
            return 1;
        } else if (hue1 > hue2) {
            return -1;
        } else {
            if (sat1 < sat2) {
                return 1;
            } else if (sat1 > sat2) {
                return -1;
            } else {
                if (val1 < val2) {
                    return 1;
                } else if (val1 > val2) {
                    return -1;
                }
            }
        }
        return 0;