下面是一个绘图工具类,我像画笔笔尖一样使用它。对于绘图应用程序。
在我的主要活动中,我有一个这种对象类型的 arrayList,我想按颜色对它们进行排序。
正如你所看到的,我有一个 compareTo 方法,它只返回 int1-int2 (其中 int 是每个工具的颜色值。但这并没有按照我预期的方式对它们进行排序。
我试图像彩虹一样按颜色对它们进行分类。
现在我知道,如果它们的类型是 Color 而不是 Int,这可能会更容易,但是数据源将返回 Int 值,例如黑色的 0xff000000。
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));
}
/*if(flatTip){
mPaint.setStrokeCap(Paint.Cap.SQUARE);
}else{
mPaint.setStrokeCap(Paint.Cap.ROUND);
}*/
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");
return (color-other.color);
}
}