package com.example.smarthome;

import org.achartengine.ChartFactory;
import org.achartengine.chart.BarChart.Type;
import org.achartengine.model.CategorySeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.os.Bundle;
import android.util.Log;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;

public class Week extends Activity {

	int w11,w22,w33,w44,w55;
	int []consumption = new int[5];
	String w1,w2,w3,w4,w5,strReceived;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_week);
		
		
		Bundle ext=getIntent().getExtras();
		
		strReceived=ext.getString("str11");
		/*w2=ext.getString("str21");
		w3=ext.getString("str31");
		w4=ext.getString("str41");
		w5=ext.getString("str51");*/
		w1= strReceived.substring(1,4);
		w2= strReceived.substring(4,7);
		w3= strReceived.substring(7,10);
		w4= strReceived.substring(10,13);
		w5= strReceived.substring(13,16);
		Log.i("thread","two socket closed: Finished"+" "+w1+" "+w2+" "+w3+" "+w4+" "+w5);
		getInt(getBaseContext());
	}

	public void getInt(Context context){
		int w11,w22,w33,w44,w55;
		w11= Integer.parseInt(w1);
		w22= Integer.parseInt(w2);
		w33= Integer.parseInt(w3);
		w44= Integer.parseInt(w4);
		w55= Integer.parseInt(w5);
		int y[] = {w11,w22,w33,w44,w55};
		
		CategorySeries series = new CategorySeries("Week");
		for(int i=0; i < y.length; i++){
		series.add("Week"+(i+1),y[i]);
		}
		XYMultipleSeriesDataset dataSet = new XYMultipleSeriesDataset(); // collection of series underone object.,there could any
		dataSet.addSeries(series.toXYSeries()); // number of series//customization of the chart
		XYSeriesRenderer renderer = new XYSeriesRenderer(); // one renderer for one series
		renderer.setColor(Color.RED);
		renderer.setDisplayChartValues(true);
		renderer.setChartValuesSpacing((float) 5.5d);
		renderer.setLineWidth((float) 10.5d);
		XYMultipleSeriesRenderer mRenderer = new
		XYMultipleSeriesRenderer(); // collection multiple valuesfor one renderer or series
		mRenderer.addSeriesRenderer(renderer);
		mRenderer.setChartTitle("Weekly Energy Consumption");
		// mRenderer.setXTitle("xValues");
		mRenderer.setYTitle("Energy");
		mRenderer.setZoomButtonsVisible(true);
		mRenderer.setShowLegend(true);
		mRenderer.setShowGridX(true); // this will showthe grid in graph
		mRenderer.setShowGridY(true);// mRenderer.setAnt
		mRenderer.setBarSpacing(.5);
		mRenderer.setXAxisMin(0);
		mRenderer.setXAxisMax(5);
		mRenderer.setYAxisMax(300);
		mRenderer.setXLabels(0);
		
		mRenderer.addXTextLabel(1, "Week1");
		mRenderer.addXTextLabel(2, "Week2");
		mRenderer.addXTextLabel(3, "Week3");
		mRenderer.addXTextLabel(4, "Week4");
		mRenderer.addXTextLabel(4, "Week5");
		mRenderer.setPanEnabled(true,true);
		Intent inta= ChartFactory.getBarChartIntent(context, dataSet, mRenderer, Type.DEFAULT);
		 startActivity(inta);

		}
}
