我的活动包含名为ArrayList<KNDrawingTOOL>
allTools
KNDrawingTool在下面..它实现了Comparable,而compare方法基本上是Hue的排序颜色。这很好..但我想采取那个排序的数组,然后按值重新排序,保持Hue排序..有没有办法做到这一点?
KNDrawingTool
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);
答案 0 :(得分: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];