0

我有一个ArrayList<KNDrawingTOOL>被调用的活动allTools

KNDrawingTool 在下面.. 它实现了 Comparable 并且比较方法基本上是按色调对颜色进行排序。效果很好..但我想采用该排序数组,然后按值再次对其进行排序,保持色调排序..有没有办法做到这一点?

KND绘图工具

 public class KNDrawingTool implements Comparable<KNDrawingTool>{

    public int id;
    public String name;
    public int size;
    public int color;
    public int cost;
    public int capacity;
    public int amountLeft;
    public String type;
    public Paint mPaint;


    public KNDrawingTool(String toolType, Boolean flatTip, int paintId, String paintName, int paintSize,int paintColor, int paintCost, int canCapacity, int remainingAmount){
        type = toolType;
        id = paintId;
        name = paintName;
        size = paintSize;
        color =paintColor;
        cost = paintCost;
        capacity = canCapacity;
        amountLeft = remainingAmount;

        mPaint = new Paint();

        if(type == "paint"){
           mPaint.setMaskFilter(new BlurMaskFilter(15, BlurMaskFilter.Blur.NORMAL));
        }

        mPaint.setAntiAlias(true);
        mPaint.setDither(true);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setColor(color);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(size);



    }


    /* (non-Javadoc)
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    @Override
    public int compareTo(KNDrawingTool other) {
        Log.v("TOOL", "SOrting by Hue");
        //return (color-other.color);

        float[] hsv1 = new float[3];
        float[] hsv2 = new float[3];

        Color.colorToHSV(color,hsv1);
        Color.colorToHSV(other.color,hsv2);
        return ((int)hsv1[0]-(int)hsv2[0]);
    }
}

我的主要课程只是打电话Collections.sort(allTools);

就像我说的那样,这是按 HUE 对它们进行排序的。我想做第二次传递,然后按值对它们进行排序,以保持色调顺序。

4

1 回答 1

0

您可以在 1 遍中进行排序

float[] hsv1 = new float[3];
float[] hsv2 = new float[3];

Color.colorToHSV(color, hsv1);
Color.colorToHSV(other.color, hsv2);

if ((int)hsv1[0] == (int)hsv2[0]) {
    return (int)hsv1[2] - (int)hsv2[2];
}

return (int)hsv1[0] - (int)hsv2[0];
于 2013-06-21T03:18:25.743 回答