Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //========================================
  2. public class PieChartView extends View{
  3.  
  4.     private final static String[] RColors = {"#448c9b", "#789a98", "#a4a795", "#ac6226", "#ef3c5e", "#b17170", "#9a9a82", "#bda763"};
  5.    
  6.     private RectF rec;
  7.     private Paint p = new Paint();
  8.     private String[][] data = {
  9.             {"Facebook", "20"},
  10.             {"Twitter", "20"},
  11.             {"Whats app", "20"},
  12.             {"Pinterest", "20"},
  13.             {"Baby App", "20"}
  14.     };
  15.     private int d = 0;
  16.     private float textSize = 20f;
  17.    
  18.     //========================
  19.     public PieChartView(Context context, AttributeSet attrs) {
  20.         super(context, attrs);     
  21.     }
  22.  
  23.     //========================
  24.     public PieChartView(Context ctx){super(ctx);}
  25.    
  26.     //========================
  27.     @Override
  28.     public void onSizeChanged(int nw, int nh, int ow, int oh){
  29.         super.onSizeChanged(nw, nh, ow, oh);
  30.         d = nw>nh?nh:nw;
  31.         rec = new RectF(0, 0, d, d);
  32.         p.setFlags(Paint.ANTI_ALIAS_FLAG);
  33.     }
  34.    
  35.     //========================
  36.     public void setTextSize(float size){textSize=size;}
  37.  
  38.     //========================
  39.     /**Set data to be shown in pie chart view
  40.      * @param dList ArrayList of Object[], 1st element will contain the name, 2nd the percentage (int)
  41.      */
  42.     public void setData(ArrayList<Object[]> dList){
  43.         data = new String[dList.size()][2];
  44.         int i=0;
  45.         for(Object[] op:dList){
  46.             data[i++] = new String[]{op[0]+"",op[1]+""};
  47.         }
  48.     }
  49. }