package com.tzapps.tzpalette.data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.tzapps.tzpalette.algorithm.ClusterCenter;
import com.tzapps.tzpalette.algorithm.KMeansProcessor;
import com.tzapps.tzpalette.utils.ColorUtils;

import android.graphics.Bitmap;
import android.util.Log;

public class PaletteData
{
    Bitmap mThumb;
    List<Integer> mColors;
    
    public PaletteData()
    {
        mThumb  = null;
        mColors = new ArrayList<Integer>();
    }
    
    public PaletteData(Bitmap thumb)
    {
        mThumb  = thumb;
        mColors = new ArrayList<Integer>();
    }
    
    public void setThumb(Bitmap thumb)
    {
        if (mThumb != null)
            mThumb.recycle();
        
        mThumb = thumb;
    }
    
    public Bitmap getThumb()
    {
        return mThumb;
    }
    
    public void addColor(int color)
    {
        mColors.add(color);
    }
    
    public int[] getColors()
    {
        int numOfColors = mColors.size();
        int[] colors = new int[mColors.size()];
        
        for (int i = 0; i < numOfColors; i++)
        {
            colors[i] = mColors.get(i);
        }
        
        Arrays.sort(colors);
        
        return colors;
    }

    public void analysis()
    {
        KMeansProcessor proc = new KMeansProcessor(8, 10);   
        
        // TODO: async this process to avoid UI thread block
        proc.processKMean(mThumb);
        
        for (ClusterCenter center : proc.getClusterCenters())
            addColor(center.getValue());
    }
}

@@ -106,16 +106,74 @@
 .List;%0A%0A
+import android.graphics.Bitmap;%0Aimport android.util.Log;%0A%0A
 import c
@@ -276,126 +276,75 @@
 or;%0A
-import com.tzapps.tzpalette.utils.ColorUtils;%0A%0Aimport android.graphics.Bitmap;%0Aimport android.util.Log;%0A%0Apublic class 
+%0Apublic class PaletteData%0A%7B%0A    private static final String TAG = %22
 Pale
@@ -346,26 +346,31 @@
 %22PaletteData
-%0A%7B
+%22;%0A    
 %0A    Bitmap 
@@ -1281,32 +1281,88 @@
 nalysis()%0A    %7B%0A
+        Log.d(TAG, %22palette data analysis()%22);%0A        %0A
         KMeansPr

add log output