title: sorting integer representations of color - android
body: <p>Below is a drawing tool class that i am using as like a brush tip.  For a drawing application.  </p>
  
  <p>In my main activity i have an arrayList of this object type and I would like to sort them by color.  </p>
  
  <p>As you can see i have a compareTo method that just returns int1-int2 (where ints are the color values of each tool..  but this does not sort them in the way i expected.  </p>
  
  <p>I am trying to sort them by color like a rainbow.</p>
  
  <p>Now i know this would probably be easier if they were of type Color rather than Int, but data source will be returning Int values like 0xff000000 for black.</p>
  
  <pre><code>public class KNDrawingTool implements Comparable&lt;KNDrawingTool&gt;{
  
      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);
      }
  }
  </code></pre>