package com.qiyou.mb.android.ui;

import java.util.ArrayList;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.iflytek.speech.ErrorCode;
import com.iflytek.speech.ISpeechModule;
import com.iflytek.speech.InitListener;
import com.iflytek.speech.SpeechConstant;
import com.iflytek.speech.SpeechSynthesizer;
import com.iflytek.speech.SpeechUtility;
import com.iflytek.speech.SynthesizerListener;
import com.qiyou.mb.android.Activity_qiyouBase;
import com.qiyou.mb.android.QiYouApplication;
import com.qiyou.mb.android.QiYouConstant;
import com.qiyou.mb.android.R;
import com.qiyou.mb.android.beans.Track;
import com.qiyou.mb.android.ui.charts.AbstractChart;
import com.qiyou.mb.android.ui.charts.DistEleChartNoDown;
import com.qiyou.mb.android.ui.charts.DistKmSpeedChart;
import com.qiyou.mb.android.ui.charts.DistSpeedChart;
import com.qiyou.mb.android.upgrade.UpdateManager;
import com.qiyou.mb.android.utils.Utils;
import com.qiyou.mb.android.utils.log.QLog;

public class ChartSpeedKm extends Activity_qiyouBase {
	public static final String TAG ="com.qiyou.About";
	public static final String dTAG ="com.qiyou";
	@Override
	protected void onCreate(Bundle savedInstanceState) { 
//		updateActionBar(false);
		super.onCreate(savedInstanceState); 
		app = (QiYouApplication) getApplication();
		setContentView(R.layout.chart_speekm);
		
//		initialSpeech();
		
		 Bundle bundle = this.getIntent().getExtras();
	        //接收name值
		 chartType = bundle.getInt("type");
		 trackId =bundle.getInt("id");
		setChartView();
	}
	LinearLayout ll ;
	int chartType=1;
	int trackId;
	private void setChartView(){
		TextView txt =(TextView) this.findViewById(R.id.txt_view_chart);
//    	if(app.getCurrentTrack()==null) return;	 
		 ll = (LinearLayout)this.findViewById(R.id.td_chart_speekm);
		 ArrayList<Track> trs = new ArrayList<Track>();	
		 if(app.getRecordingTrack().getTrackBean().getTrackId()==trackId)
			 trs.add(app.getRecordingTrack());
		 else  if(app.getCurrentTrack().getTrackBean().getTrackId()==trackId || trackId>0 && app.getCurrentTrack().getTrackBean().getSvrNumber()==trackId )
			 trs.add(app.getCurrentTrack());
		 else{
			 ll.setVisibility(View.GONE);
			 txt.setText("图表加载错误");
			 
			 return;
		 }
		 
		
		 if(chartType==1){
			 txt.setText("速度变化曲线图");
			 	geChart(trs,new DistSpeedChart());
			 }
		 else if(chartType ==2){
			 txt.setText("配速变化柱状图");
			 geChart(trs,new DistKmSpeedChart());
		 }
		 else if(chartType ==3){
			 txt.setText("高度变化曲线图");
			 geChart(trs,new DistEleChartNoDown());
		 }
		 
	}
	
	 
	 void geChart(ArrayList<Track> trs,AbstractChart chart){
	    	
	    	chart.setTrs(trs); 
	    	showCharts(chart.getChartView(this));
		 	 
	    }
	 
	   
	    void showCharts(View v)
	    {  
	    	try{
	    		if(ll==null)return;
		    	if(ll.getChildCount()>0)
		    		ll.removeAllViews(); //this is must.
//			 int height=500;
//			 height =QiYouConstant.PV_INT_SCREEN_WIDTH/2;
			int height=LayoutParams.MATCH_PARENT;
			 v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,height)); //set the layout, or will not show out 
		     ll.addView(v);
			}catch (Exception e)
			{
				Utils.logStackTrace(e, TAG);
			}
	    	 
	    }
	    
}
