package com.qiyou.mb.android.ui.fragments;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;
import android.widget.TextView;

import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.model.LatLngBounds;
import com.qiyou.mb.android.QiYouConstant;
import com.qiyou.mb.android.R;
import com.qiyou.mb.android.beans.basic.Activity_bean;
import com.qiyou.mb.android.beans.basic.GPItem;
import com.qiyou.mb.android.beans.basic.Group_bean;
import com.qiyou.mb.android.beans.basic.TypeStatistics;
import com.qiyou.mb.android.ui.charts.AbstractChart;
import com.qiyou.mb.android.ui.charts.TrackPieChart;
import com.qiyou.mb.android.ui.charts.TrackStaticsChart;
import com.qiyou.mb.android.upgrade.UpdateManager;
import com.qiyou.mb.android.utils.Utils;
import com.qiyou.mb.android.utils.base.IlocationFragment;
import com.qiyou.mb.android.utils.enums.TrackStatus;
import com.qiyou.mb.android.utils.log.QLog;

import java.util.HashMap;
 

public class TrackStatics_fragment extends TrackMap_fragment implements IlocationFragment  {
	@Override
	public void setFTag(){
		TAG="com.qiyou.TrackStatics_fragment";
// 		 FirstTabTextColor= getResources().getColorStateList(R.color.red);    
// 		 FirstTabBackGround=R.drawable.icon_statistics;
	}
 
	public static String getFTag(){
		return "com.qiyou.TrackStatics_fragment";
	}
	
	@Override
	public String getCurrentTag(){
		return "com.qiyou.TrackStatics_fragment";
	}
	
	LinearLayout llcharts ;  
//	LinearLayout stat_chart; 
	final String overallChartTab =" 汇总";
	final String  typeTab =" 明细";
	final String aboutTab ="关于";
	
//	final String  =" ";
	final String myfootTab =" 足迹";	
	
	final String moreTab ="更多";	
	final String Chart3 =" ";
//	ProgressDialog progressDialog; 
	Handler  	handler; 
     
   
    private TypeStatistics typeStatistics=null;;
    private TypeStatistics statChart=null;;
   
    private HashMap<String,Double> trackStatMap;
    private TextView mftNoteText;
    private TextView mdetailNoteText;
    private ImageView imgBtnEditUser;
	private Button btnMoreHistory,btnMoreConfigure,btnMoreOffline;
	
//    private  GraphicsOverlay gpFootPointsOverlay = null;
    
	public TrackStatics_fragment() {
		// TODO Auto-generated constructor stub
		TAG="com.qiyou.mb.android.ui.TrackStatics_fragment";
	}
    
    
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if(activity==null){
			    activity = (com.qiyou.mb.android.ui.MainActivity)getActivity();
			}
   	 QLog.getLogger().d(dTAG, TAG+" TrackStatics starting onCreate finished.............");

		
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		 QLog.getLogger().d(dTAG, TAG+" TrackStatics starting onCreateView start.............");
		  vContainer = inflater.inflate(R.layout.track_statics, container, false);	
		  QLog.getLogger().d(dTAG, TAG+" TrackStatics starting initialView start.............");
		  initialView(); 
		  initialMapview();
		  QLog.getLogger().d(dTAG, TAG+" TrackStatics starting initialView end.............");
		  QLog.getLogger().d(dTAG, TAG+" TrackStatics starting  onCreateView finished.............");
		return vContainer;
		}
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		//default to show chart1 
//		llcharts = (LinearLayout)vContainer.findViewById(R.id.st_chart1);
//		stat_chart= (LinearLayout)vContainer.findViewById(R.id.stat_chart);
	
//	      	 if(llcharts.getChildCount()==0)
//	      		 showCharts(0);
//		initQueryTrackTypeSpin();
//		initialStatTracks();
//		mMapView.getOverlays().remove(myLocationOverlay);
		 QLog.getLogger().d(dTAG, TAG+" TrackStatics starting onActivityCreated finished.............");
	}
	@Override
	protected void initialView(){ 
//		  mNoteText = (TextView) vContainer.findViewById(R.id.text_note); 
//		  initialTabhost();
		
		  initialDetails();
		 
		  initStatViews();		
		  
		  initialMoreViews();
		  
		  super.initialView();
		  
		  setVersion();
	}
	@SuppressLint("NewApi")
	@Override
	protected void  initialMapview(){
		super.initialMapview();
 //		gpFootPointsOverlay = new GraphicsOverlay(mMapView);
//		mMapView.getOverlays().add(gpFootPointsOverlay);
		footNumber=0;
		isLookingFootMark=false;
//		
 		
		
//		mMapView.setBuiltInZoomControls(false);
//		myLocationOverlay.setMarker(null);
//		mMapView.setAlpha(0.50f);
		
		
	}
	
	@Override
	protected void initialLiveViews(){
		
	}

	private String notesMsg="";
//	@Override  
	void showLocalNotes(String notes){
		
		if( activity.app.mStatistics==null)return;
		Utils.getlastGeoRequestTime(activity);
		 
		if(QiYouConstant.LAST_GEO_UPDATE>0){
			 Utils.getTimeCnt(System.currentTimeMillis()-QiYouConstant.LAST_GEO_UPDATE);
		}
		boolean notInWifi =!Utils.isNetworkConnected(activity) || Utils.getNetworkType(activity)!= QiYouConstant.NETWORK_TYPE_WIFII;
		Boolean needWifi4GEO =activity.app.mStatistics.getLastTime()>QiYouConstant.LAST_GEO_UPDATE;
		Boolean needWifi4MAP =QiYouConstant.LAST_OFFMAP_UPDATE==0;
		needWifi4GEO=needWifi4GEO&&notInWifi;
		needWifi4MAP=needWifi4MAP&&notInWifi;		
		String split=needWifi4GEO?"\n":"提示：";
//		String split= "\n提示：";
		notesMsg=needWifi4GEO?"提示：请链接WIFI以更新足迹信息":"";
		split=TextUtils.isEmpty(notesMsg)?"提示：":"\n提示：";
		notesMsg+=needWifi4MAP?split+"请链接WIFI检查更新离线地图":"";
		QiYouConstant.CAN_SPEAK=QiYouConstant.CAN_SPEAK && Utils.checkSpeechServiceInstall(activity);
		split=TextUtils.isEmpty(notesMsg)?"提示：":"\n提示：";
		notesMsg+=Utils.checkSpeechServiceInstall(activity)?"":split+"语音导航功能需安装<<讯飞语音+>>"; 
		
//	    ll_ftnote.setVisibility(needWifi4GEO?View.VISIBLE:View.GONE);
//	    mftNoteText.setText("正在为您寻找小脚印");
	    
	    
	    if(TextUtils.isEmpty(notesMsg)){
	    	notesMsg= "您还没有运动记录，马上开始吧！"; 
	    	
	    /*	if(!activity.app.isShowSlidTabs())  
	    		msg= "提示：左右滑动屏幕可以切换标签页面";
	    	else*/
		      if(activity.app.isLastTrackExist()|| activity.app.mStatistics!=null && activity.app.mStatistics.getCnt()>0 &&activity.app.mStatistics.getFirstTime()>0 ){
		    	long time =activity.app.mStatistics.getFirstTime(); 
		    	  
		    	notesMsg =time>0?String.format("驴子从%s开始为您服务",  Utils.getFormatedTime(time)):"";
			 } 
	    
//	    	mNoteText.setText(msg);  
	     
	    }
//	    else{
//	    	mNoteText.setText(notesMsg);   
//	    }
	    
		if(activity.app.isShowSlidTabs()){  
			notesMsg +=TextUtils.isEmpty(notesMsg)?"":"\n";
			notesMsg +="提示：左右滑动屏幕可以切换标签页面"; 
		}
		
		notesMsg =TextUtils.isEmpty(notesMsg)?"提示：运动汇总数据是对您全部运动记录的数据的汇总统计":notesMsg;
		
		mNoteText.setText(notesMsg);   
	}
	
	@Override
	protected void initialTabhost(){
		super.initialTabhost();
		tabhost = (TabHost)vContainer.findViewById(R.id.tabhost);
        tabhost.setup();
        
        
        TabHost.TabSpec statTab = tabhost.newTabSpec(overallChartTab);  
        	statTab.setIndicator(overallChartTab);
        	statTab.setContent(R.id.tab_statchart);
		 tabhost.addTab(statTab);
        
        
        TabHost.TabSpec t1 = tabhost.newTabSpec(typeTab);  
		 t1.setIndicator(typeTab);
		 t1.setContent(R.id.tabType);
		 tabhost.addTab(t1);
		 
//        TabHost.TabSpec readmeTabSpec = tabhost.newTabSpec(aboutTab);  // This param will be used as tabId.
//        readmeTabSpec.setIndicator(aboutTab);
//        readmeTabSpec.setContent(R.id.ll_readme);
//        tabhost.addTab(readmeTabSpec);
        
		 TabHost.TabSpec myfootSpec = tabhost.newTabSpec(myfootTab);  // This param will be used as tabId.
	        myfootSpec.setIndicator(myfootTab);
	        myfootSpec.setContent(R.id.tab_map);
	        tabhost.addTab(myfootSpec);


//		TabHost.TabSpec tabmore = tabhost.newTabSpec("more");  // This param will be used as tabId.
//		myfootSpec.setIndicator("more");
//		myfootSpec.setContent(R.id.tabMore);
//		tabhost.addTab(tabmore);

	        
			 TabHost.TabSpec moreSpec = tabhost.newTabSpec(moreTab);  // This param will be used as tabId.
			 moreSpec.setIndicator(moreTab);
			 moreSpec.setContent(R.id.tabMore);
		     tabhost.addTab(moreSpec);
	        
		 
//        TabHost.TabSpec readmeTabSpec = tabhost.newTabSpec(exchangeTab);  // This param will be used as tabId.
//        readmeTabSpec.setIndicator(exchangeTab);
//        readmeTabSpec.setContent(R.id.ll_exchange);
//        tabhost.addTab(readmeTabSpec);

//        TabHost.TabSpec c1 = tabhost.newTabSpec(AVSchartTab);  
//        c1.setIndicator(AVSchartTab);
//        c1.setContent(R.id.AVSchartTab);
//		tabhost.addTab(c1);
		
//	    int height =getResources().getDimensionPixelSize(R.dimen.tab_top_height);
//		Utils.setTabhostStyle(tabhost,	height,-1);
         
        
	    initialTabhostStyle(tabhost);
		 
//		TabHost.TabSpec chart2 = tabhost.newTabSpec(Chart2);  
//		chart3.setIndicator(Chart3);
//		chart3.setContent(R.id.tab3);
//		tabhost.addTab(chart3);
 

        tabhost.setOnTabChangedListener(new OnTabChangeListener() {
            @Override
            public void onTabChanged(String tabId  ) {
 
            	activity.isMapActive=false;
            	 
//            	   Toast toast = Toast.makeText(getActivity(), tabId, Toast.LENGTH_SHORT);
//                   toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 50);
//                   toast.show();
            	 if(tabId.equalsIgnoreCase(typeTab)){
            		if(activity.app.isStaticsticsDone)
            			initQueryTrackTypeSpin();
            	 }
            	 
            	  if(tabId.equalsIgnoreCase(myfootTab)){
            		  showMyfoot();
            		  activity.isMapActive=true;
//            		  activity.speech("的");
            	 }
             
            	 onMyTabChanged(tabId);
            	 
            	
            	 
//            	 if(tabId.equalsIgnoreCase(overallChartTab)){
//            		
//            		 ll_selection.setVisibility(View.GONE);
//            	 }else{
//            	 
//            		 ll_selection.setVisibility(View.VISIBLE);
//            	 }
//            	else if(tabId.equalsIgnoreCase(Chart1)){ 
//            		
//            	 }
//            	 }else if(tabId.equalsIgnoreCase(Chart3)){
//            		 llcharts = (LinearLayout)vContainer.findViewById(R.id.st_chart3);
//         	      	 if(llcharts.getChildCount()==0)
//         	      		 showCharts(2);
//            	 }
            	 
            	 
            	
            }
        });
        
	}  
	
	 
	
	int chartType;
	@Override	 
	protected void showCharts( int type){
		
    	 chartHeight =getResources().getDimensionPixelSize(R.dimen.chart_height_in_scrollview);
    	 chartHeight=QiYouConstant.PV_INT_SCREEN_HEIGHT/4;
       	this.chartType=type;
        if(typeStatistics ==null)doQuery();
   		if(typeStatistics==null)return;
        if(chartType ==0)getLastAvsDistCharts(statChart);
          
        if(chartType ==1)getTypePieCharts();
        if(chartType ==2)getTypeStatCharts();
        
        
//	    	 String[] tmp =new String[]{};
			  
//	    	llcharts = (LinearLayout)vContainer.findViewById(R.id.st_chart1);
//	    	if(llcharts.getChildCount()>0)
//	    		llcharts.removeAllViews();
//	    	else
	    	{    
	    	
		   	
//	    	 geEleCharts(trs);
//	    	 geEledBarChart(trs);
//	    	 geEleDChart(trs);
//		   	if(chartType ==1)getBasicCharts(trs);
//		   	if(chartType ==2) getBasicCharts(trs);
		   }
	    }
	    
     void getTypeStatCharts(){
//    	  int height =getResources().getDimensionPixelSize(R.dimen.tab_top_height);
    	
    	 getChart(typeStatistics,new TrackStaticsChart());
     }
     
     void getTypePieCharts(){ 
//    	 showCharts((new TrackPieChart(activity.app.mStatisticsTracks)).getChartView(activity));
    	 try{
    		 if(activity.app.mStatistics!=null &&activity.app.mStatistics.getTypeUsedLst().size()>0)
    			 showCharts((new TrackPieChart(activity.app.mStatistics.getTypeUsedLst())).getChartView(activity));
	    	 
	     }catch(Exception e){ 
				 
				Utils.logStackTrace(e, dTAG);
			}
		 }
        
	    void getLastAvsDistCharts(TypeStatistics sttr){
	     
	    	getChart(sttr,new TrackStaticsChart());
	    }
	    
      void getChart(TypeStatistics sttr,AbstractChart chart){ 
	    	chart.setStrack(sttr); 
	    	showCharts(chart.getChartView(activity));
 		 	 
	    }
	    
      int chartHeight=LayoutParams.MATCH_PARENT; 
	    void showCharts(View v)
	    {  
	    	if(v==null)return;
 			try{
 			 
// 			 int height=500;
 			
 			 v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,chartHeight)); //set the layout, or will not show out 
 		     llcharts.addView(v);
 			}catch (Exception e)
 			{
 				Utils.logStackTrace(e,  TAG);
 			}
	    	 
	    }
	    
	    /*
	     * initial statics tracks when it is null
	     */
	    @Override
	    public void doQuery(){
	    	
//	    	getStatTracks();
	    	
	    	int stSize =0;
	    	if(activity.app.mStatistics!=null  )
	    		stSize =activity.app.mStatistics.getStatisticsTracks().size();
//	    	 QLog.getLogger().d(dTAG, TAG+" activity.app.mStatisticsTracks.size()>0?: " +(stSize>0));
//	    	 QLog.getLogger().d(dTAG, TAG+"@@@@@@ activity.app.startTime  : " +activity.app.startTime);
//	    	 QLog.getLogger().d(dTAG, TAG+" activity.app.statTrackLoading?: " +activity.app.statTrackLoading);
//	    	 QLog.getLogger().d(dTAG, TAG+" activity.app.isStaticsticsDone?: " +activity.app.isStaticsticsDone); 
//	    	 QLog.getLogger().d(dTAG, TAG+"  activity.app.isNewLogin?: " + activity.app.isNewLogin); 
	    	
//	       	if(typeStatistics==null || isFilterChanged || stSize==0 ){ //||start,end, type){ 
	      
	       	/*	if(stSize==0){
//	       			activity.app.getStaticsTracks();  
	       			progressDialog = ProgressDialog.show(activity, "请稍等...", "获取数据中...", true);
       		   }*/
		    	 if(activity.app.statTrackLoading ){		    	
		    	/*	progressDialog = ProgressDialog.show(activity, "请稍等...", "获取统计数据中...", true);
		    		progressDialog.setCancelable(true);
		    		progressDialog.setCanceledOnTouchOutside(true);
		    		 ll_note.setVisibility(View.VISIBLE);*/
		    		 mNoteText.setText("正在加载数据，请稍后...");
		    	} 
		    	 if(activity.app.isNewLogin ||!activity.app.isStaticsticsDone){
		    		 mNoteText.setText("正在从云端下载数据。。。请稍等...");
		    	 }
	       		
	       		handler = new Handler(){

    				@Override
    				public void handleMessage(Message msg) {
    					
    					//关闭ProgressDialog
//    					if(progressDialog!=null)progressDialog.dismiss();
//     					 mNoteText.setText("");
    					 
    					
    					if(msg.what==0){
    					//更新UI
//    					 setTrackDetail1();//statusTextView.setText("Completed!");
//    						typeStatistics =activity.app.typeStatistics;
//    						if(spTrackType==null){
////    							buildStatMap();
//    							initQueryTrackTypeSpin();
//    						}
//    						if(firstLoad){
//    							initQueryTrackTypeSpin();
//    						}
    						if (activity.app.mStatistics != null && activity.app.mStatistics.getFirstTime() > 0 && activity.app.mStatistics.getCnt() > 0 ){
    							getStatTracks();
    							setDetails();
    						}
    						showLocalNotes(null);
//    					    showGpxFileList();
//    					    showMyfoot();
//    						mNoteText.setText("");
//    						ll_note.setVisibility(View.GONE);
//    						showCharts(chartType);
    						 
    					}
    					else if(msg.what==1){
      						mNoteText.setText("查询超时,请重试");
//     						ll_note.setVisibility(View.VISIBLE);
    					}
    				}};
    		   
    				new Thread(){

    					@Override
    					public void run() {
    						//需要花时间计算的方法		
    						int topWaiting=0;
    						
    					    activity.app.getStatisticsTrack(trackType);
    			        	while(!activity.app.isStaticsticsDone
    			        			||activity.app.isNewLogin
    			        			||activity.app.statTrackLoading 
    			        			||activity.app.mStatistics ==null
    			        			||activity.app.mStatistics.getCnt() > 0 && activity.app.mStatistics.getStatisticsTracks().get(trackType)==null
    			        			||activity.app.mStatistics.getStatisticsTracks().get(trackType)!=null 
    			        				&& activity.app.mStatistics.getStatisticsTracks().get(trackType)
    			        					.getSbs().size()==0
    			        					
    			        			){ //||start,end, type){ 
     			        	 try {
    			 				Thread.sleep(200);
    			 				topWaiting+=200;
    			 				 QLog.getLogger().d(dTAG, TAG+" get staticts topWaiting: " +topWaiting);
    			 				if(topWaiting>QiYouConstant.MAX_TIME_GET_TRACK_FROM_DB*2 )
    			 				{ 
    			 					handler.sendEmptyMessage(0);
    			 					return;
    			 				}
    			 				if(!(activity.app.statTrackLoading
    			 					|| !activity.app.isStaticsticsDone
    			        			||activity.app.isNewLogin
    			        			||activity.app.statTrackLoading)) {
    			 					break;
    			 				}
    			 			  } catch (InterruptedException e) {
    			 				// TODO Auto-generated catch block
    			 				Utils.logStackTrace(e, TAG);
    			 				handler.sendEmptyMessage(0);
    			 				}
    				    	}
    			    		 
    						
    						//向handler发消息
    						handler.sendEmptyMessage(0);
    					}}.start(); 
    					
//        	} else if(typeStatistics!=null &&typeStatistics.getStart()>0 ){
//        		    getStatTracks();
//				    setDetails();
//					mNoteText.setText("");
//					ll_note.setVisibility(View.GONE);
//        	}
	    	
	    }

	  
		
		void getStatTracks(){
			
			
			
			statChart=	activity.app.mStatistics.getLastStrack();
//			int totalChartSize=11;
			
//			 if(activity.app.typeStatistics==null )
//			initialStatTracks();
			
			//startDate=0;, 	endDate 
			typeStatistics = new TypeStatistics();
			if(activity.app.getStatisticsTrack(trackType)==null) return;//no records for selected type or date.
			QLog.getLogger().d(dTAG, TAG+  " dddddddddddddddddddddd-------------------begin to get StatTrack. ------------of type-"+ trackType  );
			if(custStartDate>0||custEndDate>0){
				startDate =custStartDate;
				endDate =custEndDate;
			}			
			typeStatistics =activity.app.getTracksStat(trackType, startDate, endDate);
			
	/*		
			if(startDate == endDate && startDate==0){
				
				for(Statics_bean sb:activity.app.typeStatistics.getStaticsTrackBeans()){
					if(sb==null)continue;
					if( sb.getType() == trackType)
						typeStatistics.getStaticsTrackBeans().add(sb);
				}
				 
			}else
			
				startDate=startDate>0?startDate:0;
				endDate=endDate>0?endDate:System.currentTimeMillis();  
				
			
			 ConcurrentHashMap<Integer,Statics_bean> sbs =activity.app.getStatisticsTrack(trackType).getSbs();
			 Statics_bean sb;
			 int sbCnt=0;
			 for(Integer key :sbs.keySet()){
				 sb=sbs.get(key); 
				 if(sb==null)continue;
				 
				 if( (
						startDate>0 && endDate >= startDate
						&&	
						(sb.getStartTime()>=startDate && sb.getStartTime()<=endDate
						 ||sb.getEndTime()>=startDate && sb.getEndTime()<=endDate
						)
						||(startDate == endDate && startDate==0)
					)
					&& sb.getType() == trackType )						
						typeStatistics.getSbs().put(sb.getTrackid(), sb);
				} 
			
			StatTrack st = new StatTrack();			
			for(Integer key : typeStatistics.getSbs().keySet()){
			    sb=typeStatistics.getSbs().get(key);
//				st.seteDownDist(sb.geteDownDist() );
				st.seteUpDist( sb.geteUpDist()+sb.geteDownDist());
				st.setTopSpeed(sb.getTopSpeed() );		       
				st.setPause(sb.getPause() );
				st.setOffTime( sb.getOffTime()); 
				st.setDist(sb.getDistance());	 
	    		st.setMaxR( sb.getMaxRdist());
	    		st.setSportTime( sb.getSportTime());
	    		st.setAvSpeed(sb.getAVS());
	    		st.setTAvSpeed(sb.getTAVS());
	    		st.setBurn(sb.getBurn());
//	    		st.setTotalTime(sb.getSportTime()+sb.getPause());
	    		st.setTotalTime(sb.getTotalTime());
//	    		QLog.getLogger().d(dTAG, TAG+  "ddddddddddddddd getStatTracks------------------"  );
//	    		
//	    		QLog.getLogger().d(dTAG, TAG+  "ddddddddddddddd sb.getDistance()"+sb.getDistance()  );
//	    		QLog.getLogger().d(dTAG, TAG+  "ddddddddddddddd sb.getSportTime()"+sb.getSportTime()  );
//	    		QLog.getLogger().d(dTAG, TAG+  "ddddddddddddddd sb.getAVS()"+sb.getAVS()  );
//	    		QLog.getLogger().d(dTAG, TAG+  "ddddddddddddddd sb.getPause()"+sb.getPause()  );
	    		
			}
    	
			typeStatistics.setStatTrack(st); 
			QLog.getLogger().d(dTAG, TAG+  " dddddddddddddddddddddd-------------------Get StatTrack. -------------"  );
			statChart=	activity.app.mStatistics.getLastStrack();
			*/
			 
		
		}
		
		
		
		private TextView mCntText;
		private TextView mSumDistText;		
		private TextView mSumTimeText;
		private TextView mSumSpTimeText;		 
		private TextView mSumSumEupText;
		private TextView mSumSumEdownText;
		private TextView mSumCostText; 
		
		
		
		
		private TextView mSpeedText4;
		private TextView mSpeedText3; 
		
		private TextView mKmTime3;
		private TextView mKmTime4; 
		
		private TextView mTotalTimeText3;
		private TextView mTotalTimeText4;
		
		 
		private TextView mDistanceText3;
		private TextView mDistanceText4;
		
	 
		private TextView mRdText3;
		private TextView mRdText4;
		
		 
		 
		private TextView mTopSpeedText3;
		private TextView mTopSpeedText4;
		
	 
		private TextView mSportTimeText3;
		private TextView mSportTimeText4;
		
		private TextView mTavsText3;
		private TextView mTavsText4;
		
		
		private TextView mBurnText3;
		private TextView mBurnText4;
		
//		private TextView mPausedTimeText3;
//		private TextView mPausedTimeText4;  
//		private TextView mOffTimeText3; 
//		private TextView mOffTimeText4; 
		 
		private TextView mTotaleUpText3;
		private TextView mTotaleUpText4; 
		private TextView mTotaleDownText3;
		private TextView mTotaleDownText4;
		
		private LinearLayout ll_ftnote;
			
		void initialDetails(){
		 	mSpeedText3 = (TextView) vContainer.findViewById(R.id.td_textView_av_speed3);
			mSpeedText4 = (TextView) vContainer.findViewById(R.id.td_textView_av_speed4);
			
			mKmTime3 = (TextView) vContainer.findViewById(R.id.td_textView_kmTime3);
			mKmTime4 = (TextView) vContainer.findViewById(R.id.td_textView_kmTime4);
			

			 mTotalTimeText3 = (TextView) vContainer.findViewById(R.id.td_textView_totalTime3);
			mTotalTimeText4 = (TextView) vContainer.findViewById(R.id.td_textView_totalTime4);
			
		    mSportTimeText3 = (TextView) vContainer.findViewById(R.id.td_textView_sport_time3);
			mSportTimeText4 = (TextView) vContainer.findViewById(R.id.td_textView_sport_time4);
			
			 mTavsText3 = (TextView) vContainer.findViewById(R.id.td_textView_tavs3);
			 mTavsText4 = (TextView) vContainer.findViewById(R.id.td_textView_tavs4);
			
			mBurnText3 = (TextView) vContainer.findViewById(R.id.td_textView_burn3);
			mBurnText4 = (TextView) vContainer.findViewById(R.id.td_textView_burn4); 
			
			 mDistanceText3 = (TextView) vContainer.findViewById(R.id.td_textView_Distance3); 
			mDistanceText4 = (TextView) vContainer.findViewById(R.id.td_textView_Distance4);
			
     		mRdText3 = (TextView) vContainer.findViewById(R.id.td_textView_maxRd3 );
			mRdText4 = (TextView) vContainer.findViewById(R.id.td_textView_maxRd4 );
			 
			 mTopSpeedText3 = (TextView) vContainer.findViewById(R.id.td_textView_top_speed3);
			mTopSpeedText4 = (TextView) vContainer.findViewById(R.id.td_textView_top_speed4);

//		 	mPausedTimeText3 = (TextView) vContainer.findViewById(R.id.td_textView_paused_time3);
//			mPausedTimeText4 = (TextView) vContainer.findViewById(R.id.td_textView_paused_time4);
//			
//			 	mOffTimeText3 = (TextView) vContainer.findViewById(R.id.td_textView_off_time3);
//			mOffTimeText4 = (TextView) vContainer.findViewById(R.id.td_textView_off_time4);
			
			
		 	mTotaleUpText3 = (TextView) vContainer.findViewById(R.id.td_textView_eUp3);
			mTotaleUpText4 = (TextView) vContainer.findViewById(R.id.td_textView_eUp4);
			

			 mTotaleDownText3 = (TextView) vContainer.findViewById(R.id.td_textView_eDown3);
			mTotaleDownText4 = (TextView) vContainer.findViewById(R.id.td_textView_eDown4);
			
			
			
			  mCntText= (TextView) vContainer.findViewById(R.id.ts_txt_cnt);
			  mSumDistText= (TextView) vContainer.findViewById(R.id.ts_sum_dist); 
			  mSumSpTimeText= (TextView) vContainer.findViewById(R.id.ts_sum_sptime); 
			  mSumSumEupText= (TextView) vContainer.findViewById(R.id.ts_sum_eup); 
			  mSumSumEdownText=(TextView) vContainer.findViewById(R.id.ts_sum_edown);
			  mSumCostText= (TextView) vContainer.findViewById(R.id.ts_sum_cost); 
			  mSumTimeText= (TextView) vContainer.findViewById(R.id.ts_sum_alltime); 
			 
			  
			  mNoteText= (TextView) vContainer.findViewById(R.id.note_stat); 
			  ll_note =(LinearLayout)vContainer.findViewById(R.id.ll_note);
			  ll_note.setVisibility(View.VISIBLE);
			 
				
				mRecordingDist= (TextView) vContainer.findViewById(R.id.recording_dist); 
				mRecordingSporttime=(TextView) vContainer.findViewById(R.id.recording_sportTime);
				mRecordingAVS= (TextView) vContainer.findViewById(R.id.recording_avs); 
				mRecordingBurn= (TextView) vContainer.findViewById(R.id.recording_burn);
				mRecordingSpd= (TextView) vContainer.findViewById(R.id.recording_speed); 
				mRecordingNoSpd= (TextView) vContainer.findViewById(R.id.recording_nospeed);
				
				recordingLL = (LinearLayout) vContainer.findViewById(R.id.recording_ll); 
				
				mftNoteText= (TextView)vContainer.findViewById(R.id.ft_notice) ;
				ll_ftnote= (LinearLayout)vContainer.findViewById(R.id.ll_ft_notice);
				
				  
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		private void setDetails(){
//			if(typeStatistics==null){
//				initialDetailValues();	
//			}
			
		 
			
			setAVS_DistChart();
			setType_Chart();
			
// 			if(!firstLoad){
				setTrackAV();
				setTrackMax();
				setBasicData();
				setTypeSt_Chart();
// 			}
			setStatDesc();
//			showGpxFileList();
		 
		}

		private void setTrackMax()
		{
			mTopSpeedText3.setText(String.format("%.2f", typeStatistics.getStatTrack().getTopSpeed()));
			mSpeedText3.setText(String.format("%.2f",typeStatistics.getStatTrack().getAvSpeed()));
	    	mDistanceText3.setText(String.format("%.2f",typeStatistics.getStatTrack().getDist()/1000));	 
	    	mTotaleUpText3.setText(String.format("%.0f",typeStatistics.getStatTrack().getUpDistE()));
//	    	mTotaleDownText3.setText(String.format("%.0f", Math.abs(typeStatistics.getStatTrack().getMaxeDownDist())));
	    	mSportTimeText3.setText( Utils.getTimeCnt(typeStatistics.getStatTrack().getSportTime(),false));
//	    	mPausedTimeText3.setText(Utils.getTimeCnt( typeStatistics.getStatTrack().getMaxPause(),false));
	    	mTotalTimeText3.setText(Utils.getTimeCnt(typeStatistics.getStatTrack().getTotalTime(),false));
//	    	mOffTimeText3.setText(Utils.getTimeCnt( typeStatistics.getStatTrack().getMaxOffTime(),false));
	    	mRdText3.setText(String.format("%.2f",typeStatistics.getStatTrack().getMaxR()/1000));
	    	mBurnText3.setText( String.format("%.2f",typeStatistics.getStatTrack().getBurn()));
	    	mTavsText3.setText( String.format("%.2f",typeStatistics.getStatTrack().getTavSpeed()));
	    	if(typeStatistics.getStatTrack().getUpDistE()>0){
		    	((TextView)vContainer.findViewById(R.id.td_textView_Updist3)).setText(String.format("%.2f",typeStatistics.getStatTrack().getUpDistE()/1000));
		    	((TextView)vContainer.findViewById(R.id.td_textView_downDist3)).setText(String.format("%.2f",typeStatistics.getStatTrack().getDownDist()/1000));
		    	((TextView)vContainer.findViewById(R.id.td_textView_maxEle3)).setText(String.format("%.0f",typeStatistics.getStatTrack().getMaxEle()));
		    	((TextView)vContainer.findViewById(R.id.td_textView_minEle3)).setText(String.format("%.0f",typeStatistics.getStatTrack().getMinEle()));
	    	}
	    	mKmTime3.setText(Utils.getTimeMS(typeStatistics.getStatTrack().getMinKmTime()));
		}
		
		/*
		 * av track
		 */
		private void setTrackAV()
		{
			mTopSpeedText4.setText(String.format("%.2f",typeStatistics.getStatTrack().getAvtopSpeed()));
			mSpeedText4.setText(String.format("%.2f",typeStatistics.getStatTrack().getAvavSpeed()));
	    	mDistanceText4.setText(String.format("%.2f",typeStatistics.getStatTrack().getAvdist()/1000));	 
	    	mTotaleUpText4.setText(String.format("%.0f",typeStatistics.getStatTrack().getAveUpDist() ));
	    	mTotaleDownText4.setText(String.format("%.0f", Math.abs(typeStatistics.getStatTrack().getAveDownDist())));
	    	mSportTimeText4.setText( Utils.getTimeCnt(typeStatistics.getStatTrack().getAvsportTime(),false));
//	    	mPausedTimeText4.setText(Utils.getTimeCnt( typeStatistics.getStatTrack().getAvpause(),false));
	    	mTotalTimeText4.setText(Utils.getTimeCnt(typeStatistics.getStatTrack().getAvtotalTime(),false));
//	    	mOffTimeText4.setText(Utils.getTimeCnt( typeStatistics.getStatTrack().getAvoffTime(),false));
	    	mRdText4.setText(String.format("%.2f",typeStatistics.getStatTrack().getAvmaxR()/1000));
	    	
	    	mBurnText4.setText( String.format("%.2f",typeStatistics.getStatTrack().getAvBurn()));
	    	mTavsText4.setText( String.format("%.2f",typeStatistics.getStatTrack().getAvTavSpeed()));
	    	
	    	if(typeStatistics.getStatTrack().getAvUpDist()>0){
		    	((TextView)vContainer.findViewById(R.id.td_textView_Updist4)).setText(String.format("%.2f",typeStatistics.getStatTrack().getAvUpDist()/1000));
		    	((TextView)vContainer.findViewById(R.id.td_textView_downDist4)).setText(String.format("%.2f",typeStatistics.getStatTrack().getAvDownDist()/1000));
		    	((TextView)vContainer.findViewById(R.id.td_textView_maxEle4)).setText(String.format("%.0f",typeStatistics.getStatTrack().getAvMaxEle()));
		    	((TextView)vContainer.findViewById(R.id.td_textView_minEle4)).setText(String.format("%.0f",typeStatistics.getStatTrack().getAvMinEle()));
	    	}
	    	
	    	mKmTime4.setText(Utils.getTimeMS(typeStatistics.getStatTrack().getAvKmTime()));
		}
		
		private void setAVS_DistChart(){
			 llcharts = (LinearLayout)vContainer.findViewById(R.id.st_distAvsChart);
    		 llcharts.removeAllViews();
 	      	 showCharts(0);
		}
		
		
		private void setType_Chart(){
			 llcharts = (LinearLayout)vContainer.findViewById(R.id.type_chart);
			 llcharts.removeAllViews();
	      	 showCharts(1);
		}
		//type detail chart
		private void setTypeSt_Chart(){
			 llcharts = (LinearLayout)vContainer.findViewById(R.id.st_type_chart);
			 llcharts.removeAllViews();
	      	 showCharts(2);
		}
		
		private void setBasicData(){ 
			
			
			  mCntText.setText(String.format("%s",typeStatistics.getSbs().size()));//typeStatistics.getStatTrack().getCnt()));
			  mSumDistText.setText(String.format("%.2f",typeStatistics.getStatTrack().getSumDist()/1000));
			  mSumSpTimeText.setText(Utils.getTimeCnt(typeStatistics.getStatTrack().getSumSportTime(),false));	 
			  mSumSumEupText.setText(String.format("%.0f",typeStatistics.getStatTrack().getSumEup() ));
			  mSumSumEdownText.setText(String.format("%.0f", Math.abs(typeStatistics.getStatTrack().getSumEdown())));
			  mSumTimeText.setText(Utils.getTimeCnt(typeStatistics.getStatTrack().getSumTotalTime(),false));
 			  mSumCostText.setText(String.format("%.0f", typeStatistics.getStatTrack().getSumBurn()));
 			  
 			  
 			 if(typeStatistics.getStatTrack().getSumUpDist()>0){
 		    	((TextView)vContainer.findViewById(R.id.ts_sum_updist)).setText(String.format("%.2f",typeStatistics.getStatTrack().getSumUpDist()/1000));
 		    	((TextView)vContainer.findViewById(R.id.ts_sum_downdist)).setText(String.format("%.2f",typeStatistics.getStatTrack().getSumDownDist()/1000));
 		    	 
 	    	}
 			  
//			  mSumCostText.setText("--");
//			  QLog.getLogger().d(dTAG, TAG+" dddddddddddddd STATIC UI typeStatistics.getStatTrack().getSumTotalTime(): " +typeStatistics.getStatTrack().getSumTotalTime());   
//			  QLog.getLogger().d(dTAG, TAG+" dddddddddddddd STATIC UI typeStatistics.getStatTrack().getSumOff(): " +typeStatistics.getStatTrack().getSumOff());
			     
		}
		
		
		
		
		private TextView mStat_SumDistText;		
		private TextView mStat_SumTimeText;
		private TextView mStat_SumSpTimeText;		 
		private TextView mStat_SumSumEupText;
		private TextView mStat_SumCostText; 
		private TextView mStat_SumAVSText;
//		private TextView mStat_SumCountText;
//		private TextView mStat_SumMostTypeText; 
//		private LinearLayout ll_statChart;
		private ListView filelv;
		private void initStatViews(){
			mStat_SumDistText = (TextView) vContainer.findViewById(R.id.sum_distance);
			mStat_SumTimeText = (TextView) vContainer.findViewById(R.id.sum_total_time);
			mStat_SumSpTimeText = (TextView) vContainer.findViewById(R.id.sum_sport_time);
			mStat_SumSumEupText = (TextView) vContainer.findViewById(R.id.sum_eup);
			mStat_SumCostText = (TextView) vContainer.findViewById(R.id.sum_Cost);
			mStat_SumAVSText = (TextView) vContainer.findViewById(R.id.sum_avs);
//			mStat_SumCountText = (TextView) vContainer.findViewById(R.id.sum_count);
//			mStat_SumMostTypeText = (TextView) vContainer.findViewById(R.id.sum_mostType);
//			ll_statChart =(LinearLayout)vContainer.findViewById(R.id.stat_chart);
			
			
			
			/*filelv = (ListView) vContainer.findViewById(R.id.gpxfile_list);  
			txt_importNote =(TextView) vContainer.findViewById(R.id.fm_notice);
			mbtn_refresh =(Button)vContainer.findViewById(R.id.btn_refresh);
			mbtn_refresh.setOnClickListener( new OnClickListener()
			{
				@Override
				public void onClick(View v)
				{
					showGpxFileList();
				}
			});
			
			mbtn_import =(Button)vContainer.findViewById(R.id.btn_import);
			mbtn_import.setOnClickListener( new OnClickListener()
			{
				@Override
				public void onClick(View v)
				{
					pareseGPX();
				}
			});*/
		}
		
		
		private void setStatDesc(){
	/*		setNoteMsg();
//			String msg=QiYouConstant.PV_USER_NIK_NAME+" 您还没有运动记录，马上开始吧！";
			String msg= "您还没有运动记录，马上开始吧！";		
//			ll_note.setVisibility(View.VISIBLE);
//			if(activity.app.isLastTrackExist()|| activity.app.mStatistics!=null && activity.app.mStatistics.getFirstTime()>0 ){
		    if(activity.app.isLastTrackExist()|| activity.app.mStatistics!=null && activity.app.mStatistics.getCnt()>0 ){
//				ll_note.setVisibility(View.GONE);
		    	msg =String.format("驴子从%s开始为您服务",  Utils.getFormatedTime(activity.app.mStatistics.getFirstTime()));
			}
		    if(TextUtils.isEmpty(notesMsg))
		    	mNoteText.setText(msg);  */
//			showLocalNotes(null);
//			ll_statChart.setVisibility(View.VISIBLE); 
			mStat_SumDistText.setText(String.format(" %.2f",  activity.app.mStatistics.getSumDist()/1000));
			mStat_SumTimeText.setText(String.format(" %s",  Utils.getTimeCnt(activity.app.mStatistics.getSumTotalTime(),false)));
			mStat_SumSpTimeText.setText(String.format(" %s",  Utils.getTimeCnt(activity.app.mStatistics.getSumSportTime(),false)));
			mStat_SumSumEupText.setText(String.format(" %.1f", activity.app.mStatistics.getSumeUpDist()/1000)); // +activity.app.mStatistics.getSumDownDist()));
			mStat_SumCostText.setText(String.format(" %.2f", activity.app.mStatistics.getSumCost()/1000));
			if(activity.app.mStatistics.getSumSportTime()>0)
				mStat_SumAVSText.setText(String.format(" %.2f",3600*activity.app.mStatistics.getSumDist()/activity.app.mStatistics.getSumSportTime()));
//			    mStat_SumCountText.setText(String.valueOf(activity.app.mStatistics.getCnt()));
//			    mStat_SumMostTypeText.setText(((CItem)activity.app.mStatistics.getTypeUsedLst().get(0)).GetValue()); 
			 
			
			
		
		  
		}
		 

		private TextView mRecordingDist;
		private TextView mRecordingSporttime;
		private TextView mRecordingAVS;
		private TextView mRecordingBurn;
		private TextView mRecordingSpd;
		private LinearLayout recordingLL;
		private TextView mRecordingNoSpd; 
		
		@Override
		public void updateUI(Location location, Boolean isOnPause) {
			// TODO Auto-generated method stub
//			if(location==null) return;
//			setDetails();
			  mRecordingDist.setText(String.format("%.2f", activity.app.getRecordingTrack().getTrackBean().getDistance()/1000f));;
			  mRecordingSporttime.setText( Utils.getTimeCnt(activity.app.getRecordingTrack().getTrackBean().getSportTime(),false));
			  mRecordingAVS.setText(String.format("%.2f", activity.app.getRecordingTrack().getTrackBean().getAvs()));			  
			  mRecordingBurn.setText(String.format("%.2f", activity.app.getRecordingTrack().getTrackBean().getBurn()));
			   
			  String speed="定位中";
//			  mRecordingSpd.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
			  if(Utils.isLocOfGPS(location)){ 
				  if(location.getSpeed()>0){
					 speed =String.format("%.2f", location.getSpeed()*3.6f);
//					 mRecordingSpd.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_END);
					 mRecordingNoSpd.setVisibility(View.GONE);
					 mRecordingSpd.setVisibility(View.VISIBLE);
					 mRecordingSpd.setText(speed); 
					 return;
				 }					 
				 else
					 speed="静止";
				 
			  }else	 if(!Utils.isGpsEnabled(activity)){
				  speed="GPS关闭";
			  }
			  if( activity.app.getRecordingTrack().getTrackBean().getStatus()==TrackStatus.PAUSED){
				  speed="暂停";
			  }
//			  if(location!=null)speed =String.format("%.2f", location.getSpeed()*3.6f);
			  mRecordingSpd.setVisibility(View.GONE);
			  mRecordingNoSpd.setVisibility(View.VISIBLE);
			  mRecordingNoSpd.setText(speed); 
			  if(activity.app.mStatistics!=null && typeStatistics !=null)
				  setDetails();
		}

		private void setVersion(){
			Button updateBtn = (Button) vContainer.findViewById(R.id.readme_btnUpdate);
			if(updateBtn==null)return;
			updateBtn.setOnClickListener( new OnClickListener()
			{
				@Override
				public void onClick(View v)
				{
					UpdateManager manager = new UpdateManager(activity.app);
					// 检查软件更新
					manager.checkUpdate();
				}
			});
			TextView versionName =(TextView)vContainer.findViewById(R.id.readme_version);
			versionName.setText(UpdateManager.getVersionName(activity.app)); 
			
		}
		
		 
		
		
	  private int footNumber=0;
 	  private boolean isLookingFootMark=false;
	  private void showMyfoot(){ 
 		  if(isLookingFootMark) return;
 		  isLookingFootMark=true;
		  
		  if(footNumber>0)return;
		  ll_ftnote.setVisibility( View.VISIBLE );	 
		  final String footmark = "[我曾经到过地方] ";
		  mftNoteText.setText(footmark +"正在为您寻找小脚印");
		  footNumber=0;
		  handler = new Handler(){ 
				@Override
				public void handleMessage(Message msg) {  
 					 isLookingFootMark=false;
					if(msg.what==10){
						 if(footNumber>0){
							 mftNoteText.setText(String.format( "%s共找到%s只小脚印",footmark,footNumber));
							
							 zoomToSpan();
//							 mMapView.refresh();
						 }
						 else 
							 mftNoteText.setText( footmark +"没有找到小脚印" );
					}
				}
	    	};
	    	
//		  gpFootPointsOverlay.removeAll();
		  
			new Thread(){
		        @Override
				public void run() {
		          HashMap<Integer,GPItem> gpsh=    activity.app.mStatistics.getGpList();
				  GPItem gp; 
				  for(Integer i:gpsh.keySet()){
					  gp= gpsh.get(i);
					 
//					  gpFootPointsOverlay.setData(drawFootPoint(gp,gp.getAh()));
					  
//					  QLog.getLogger().d(dTAG, String.format(" drawing bear, gp.getAh()%s,gp.getCnt() %s,gp.getLat() %s,gp.getLng()%s",   gp.getAh(),gp.getCnt(),gp.getLat(),gp.getLng()));
		        		mBaiduMap.addOverlay( drawFootPoint(gp,100)); 
					  
				  } 
				  addFootNumber(gpsh.size());
				  
//				  String bearString="";
			 	    QLog.getLogger().d(dTAG, "QiYouConstant.IS_PROCESSING_GEO_FOOTMARK: "+ QiYouConstant.IS_PROCESSING_GEO_FOOTMARK);
					try {
						while(QiYouConstant.IS_PROCESSING_GEO_FOOTMARK){
							Thread.sleep(1000);
 
						}
					    
 						/*bearString = Utils.readSDFile(QiYouConstant.BEAR_TEXT);	
 						QLog.getLogger().d(dTAG, " bearString: "+ bearString);
					} 
						catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();*/
					} 
					catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
				/*	if(TextUtils.isEmpty(bearString)){
//						mMapView.refresh();
						handler.sendEmptyMessage(10);
						return;
					}*/
			 	   
					/*
			        String[] gps = bearString.split(";");
			        String[] latlon;
			        addFootNumber(gps.length);
			        gp = null;
			        for(String bear:gps){
			        	latlon=bear.split(",");
			        	if(latlon.length==0)continue;
			        	try{
//			        		gp= new GPItem(1,new GeoPoint(Double.valueOf(latlon[0]),Double.valueOf(latlon[1])));
			        		gp= new GPItem(1,Utils.getLatLng(Double.valueOf(latlon[0]),Double.valueOf(latlon[1])),0);
			        		
			        	}catch(NumberFormatException e) {
			        		Utils.logStackTrace(e, TAG);
			        	}
			        	if(gp!=null){
//			        		gpFootPointsOverlay.setData(drawFootPoint(gp,10));
			        		QLog.getLogger().d(dTAG, " drawing   "+ bear);
			        		mBaiduMap.addOverlay( drawFootPoint(gp,10)); 
			        	}
			        } */ 
				  
//				  mMapView.refresh();
				  handler.sendEmptyMessage(10);
				  
		        }}.start(); 
		        
		        
		    	
		        
		       /* new Thread(){
			        @Override
					public void run() {
			         
			        String bearString="";
					try {
						while(QiYouConstant.IS_PROCESSING_GEO_FOOTMARK){
							Thread.sleep(100);
						}
					    
						bearString = Utils.readSDFile(QiYouConstant.BEAR_TEXT);						
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					if(TextUtils.isEmpty(bearString))return;
			        String[] gps = bearString.split(";");
			        String[] latlon;
			        GPItem gp = null;
			        for(String bear:gps){
			        	latlon=bear.split(",");
			        	if(latlon.length==0)continue;
			        	try{
//			        		gp= new GPItem(1,new GeoPoint(Double.valueOf(latlon[0]),Double.valueOf(latlon[1])));
			        		gp= new GPItem(1,Utils.getGeoPoint(Double.valueOf(latlon[0]),Double.valueOf(latlon[1])));
			        		
			        	}catch(NumberFormatException e) {
			        		Utils.logStackTrace(e, TAG);
			        	}
			        	if(gp!=null)
			        		gpFootPointsOverlay.setData(drawFootPoint(gp,5));  
			        } 
					 
					  mMapView.refresh();
			        }}.start(); */
		
		 
	  }
	  
	  
	  @Override
	  protected void zoomToSpan(){ 
			
		    double nwLat = -90 * 1000000;
		    double nwLng = 180 * 1000000;
		    double seLat = 90 * 1000000;
		    double seLng = -180 * 1000000;
		    // find bounding lats and lngs
		    LatLng point;
	  
		    
		    HashMap<Integer,GPItem> gps=  activity.app.mStatistics.getGpList();
		    if(gps.isEmpty())return;
		    GPItem gp;
		    for(Integer i:gps.keySet()){
				  gp= gps.get(i);
				  if(gp==null)continue;
//				  point= gp.getGp();
//				  point =  Utils.getGeoPoint(gp.getLat(),gp.getLng());
				  point =  Utils.getLatLng(gp.getLat(),gp.getLng());
				  if(point==null)continue;
				    nwLat = Math.max(nwLat, point.latitude); 
					nwLng = Math.min(nwLng, point.longitude);
					seLat = Math.min(seLat, point.latitude );
			        seLng = Math.max(seLng, point.longitude);
			  }
		    
		    
			  LatLngBounds.Builder builder = new LatLngBounds.Builder();
			 
//		      builder.include(  new LatLng(nwLat,nwLng) );
//		      builder.include(  new LatLng(seLat,seLng) );
			  builder.include(  new LatLng(nwLat,nwLng) ).include(  new LatLng(seLat,seLng) );
		      
		      mBaiduMap.setMapStatus(MapStatusUpdateFactory
	                    .newLatLngBounds(builder.build()));
		       
		   /*   
		     GeoPoint target = new GeoPoint((nwLat + seLat) / 2, (nwLng + seLng) / 2);
		     
		    int spanLatDelta = (int) (Math.abs(nwLat - seLat)   );
		    int spanLngDelta = (int) (Math.abs(seLng - nwLng)   );
// 		    QLog.getLogger().d(dTAG, String.format(" spanLatDelta: %s ,spanLngDelta: %s " ,  spanLatDelta,spanLngDelta  ));
		    
		    int latDelta= spanLatDelta/100*3;
		    latDelta =latDelta>12810?12810:latDelta;
		    int lngDelta= spanLngDelta/100*3;
//		    QLog.getLogger().d(dTAG, String.format("  latDelta: %s ,lngDelta: %s " ,  latDelta,lngDelta  ));
		    lngDelta =lngDelta>12810?12810:lngDelta;
		    spanLatDelta+=latDelta;
		    spanLngDelta+=lngDelta;*/
//	 	    QLog.getLogger().d(dTAG, String.format(" spanLatDelta latDelta: %s ,lngDelta: %s " ,  latDelta,lngDelta  ));
//		    QLog.getLogger().dLog(dTAG, String.format(" after delta, spanLatDelta: %s ,spanLngDelta: %s " ,  spanLatDelta,spanLngDelta  ));
		    
//		    mMapController.zoomToSpan(spanLatDelta ,    spanLngDelta );   
//		    mMapController.animateTo(target); 
//		    mMapView.refresh();
	}
	  
	  
	  
	  void setUserInfo(){
		  ((LinearLayout)vContainer.findViewById(R.id.ll_user_info)).setVisibility(View.VISIBLE);
		  if(activity.app.user.getUserbean().getId()<=0){
			  setUserLinkSpanTxt(((TextView) vContainer.findViewById(R.id.textview_user_name)),-1,"登录");
			  ((TextView) vContainer.findViewById(R.id.textView_user_score)).setVisibility(View.GONE);
			  return;
		  }

		  setUserLinkSpanTxt(((TextView) vContainer.findViewById(R.id.textview_user_name)),activity.app.user.getUserbean().getId(),activity.app.user.getUserbean().getUserName());
//		  ((TextView) vContainer.findViewById(R.id.textview_user_name)).setText(activity.app.user.getUserbean().getUserName()/*.getAccount()*/);
		  ((TextView) vContainer.findViewById(R.id.textView_user_score)).setText(activity.app.user.getUserbean().getScore()+""); 
//		  ((TextView) vContainer.findViewById(R.id.textView_user_order)).setText(activity.app.user.getUserbean().getPaiming()+"");; 
//		  ((TextView) vContainer.findViewById(R.id.textView_user_title)).setText(activity.app.user.getUserbean().getTitle());; 
		 
	  }
	  
	  
	  
	  
	  
	  
	  
	  
	  //------------------------- more tab---------------------
	  
	  private void initialMoreViews(){ 
		  imgBtnEditUser= (ImageView)vContainer.findViewById(R.id.img_btnEdituser);
		  imgBtnEditUser.setOnClickListener(ButtonOnClickListener);



		  btnMoreHistory =(Button)vContainer.findViewById(R.id.btn_more_history);
		  btnMoreHistory.setOnClickListener(ButtonOnClickListener);

		  btnMoreConfigure =(Button)vContainer.findViewById(R.id.btn_more_configure);
		  btnMoreConfigure.setOnClickListener(ButtonOnClickListener);

		  btnMoreOffline =(Button)vContainer.findViewById(R.id.btn_more_offlinemap);
		  btnMoreOffline.setOnClickListener(ButtonOnClickListener);








//		    ll_myinfo= (LinearLayout)vContainer.findViewById(R.id.ll_myinfo);
//		    ll_myinfo.setOnClickListener(ButtonOnClickListener);
		  /*  ll_newact= (LinearLayout)vContainer.findViewById(R.id.ll_newact);
		    ll_newteam= (LinearLayout)vContainer.findViewById(R.id.ll_newteam); 
		    ll_shuoshuo= (LinearLayout)vContainer.findViewById(R.id.ll_shuoshuo); 
		    ll_trackList= (LinearLayout)vContainer.findViewById(R.id.ll_trackList); 
		    ll_shuoshuo.setOnClickListener(ButtonOnClickListener); 
		    ll_newteam.setOnClickListener(ButtonOnClickListener);
		    ll_newact.setOnClickListener(ButtonOnClickListener);
		    ll_trackList.setOnClickListener(ButtonOnClickListener);*/
	}
	@Override
	void showMyinfo(){
		
		QLog.getLogger().d(dTAG, String.format("to show user detial %s",activity.app.user.getUserbean().getId()));
		
		if(activity.app.user.getUserbean().getId()>0){
// 			activity.showUserDetails(null,activity.app.user.getUserbean().getId());
//			activity.showUserDetails(activity.app.user.getUserbean() );
			 requestUserFromWeb(activity.app.user.getUserbean().getId());
		}
			
		else
			activity.showLogin();
		
//		Toast.makeText(activity, "hello this is myinfo",Toast.LENGTH_SHORT);
		
	}
	
	@Override  
	void showNewAction(){
		
		activity.showActvity(new Activity_bean());
	}  
	@Override  
     void showNewTeam(){
		activity.showGroup(new Group_bean());
	}  
	  
	
	
	
	
	@Override
	@TargetApi(Build.VERSION_CODES.FROYO)
    void initialTabhostStyle(TabHost tabhost){ 
	int height= getResources().getDimensionPixelSize(R.dimen.tab_top_height);
	
	int width=-1;
		TabWidget  tabWidget = tabhost.getTabWidget();
		for (int i =0; i < tabWidget.getChildCount(); i++) {  
//			if( tabWidget.getChildAt(i).getId() == R.id.tab_toolbar)continue;
		    tabWidget.getChildAt(i).getLayoutParams().height = height; 
		    tabWidget.getChildAt(i).getLayoutParams().width = width;
		    TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
		    if(tv==null){
		    	continue;
		    }
			tv.setPadding(2,0,0,5);
		    if(i>0){
//		    	tv.setTextColor( getResources().getColorStateList(R.color.lightslategrey));
		    	tv.setTextColor( getResources().getColorStateList(R.color.darkgray));
// 		        tv.setTextSize(14);
//			    	tabWidget.getChildAt(i).setBackgroundResource(R.color.lightgray);
//				tv.setGravity(Gravity.CENTER_VERTICAL);
//				tv.setBackgroundColor(Color.BLUE);
				ImageView	iv = new ImageView(activity);
				iv.setScaleType(ImageView.ScaleType.CENTER);

		    	if(i==1){

//			 		 iv.setBackgroundResource(R.drawable.icon_chart);
					 iv.setImageResource(R.drawable.icon_chart);
			 		 try{
			 			 ((LinearLayout)tabWidget.getChildAt(i)).setGravity(Gravity.CENTER_VERTICAL);
			 			 ((LinearLayout)tabWidget.getChildAt(i)).addView(iv,0);
			 		 }catch(ClassCastException e){
			 			 
			 		 }
		    	}else if(i==2){
//		    		 ImageView	iv = new ImageView(activity);
//			 		 iv.setBackgroundResource(R.drawable.icon_footmark);
					iv.setImageResource(R.drawable.icon_footmark);
			 		 try{
			 			 ((LinearLayout)tabWidget.getChildAt(i)).setGravity(Gravity.CENTER_VERTICAL);
			 			 ((LinearLayout)tabWidget.getChildAt(i)).addView(iv,0);
			 		 }catch(ClassCastException e){
			 			 
			 		 }
		    	} else if(i==3){
//		    		 ImageView	iv = new ImageView(activity);
//			 		 iv.setBackgroundResource(R.drawable.icon_wall);
					 iv.setPadding(0,0,4,0);
					iv.setImageResource(R.drawable.icon_wall);
			 		 try{
			 			 ((LinearLayout)tabWidget.getChildAt(i)).setGravity(Gravity.CENTER_VERTICAL);
			 			 ((LinearLayout)tabWidget.getChildAt(i)).addView(iv,0);
			 		 }catch(ClassCastException e){
			 			 
			 		 }
		    	}
		    	
		    	
		    }else{
		    	
		    	 
		    		 ImageView	iv = new ImageView(activity); 
			 		 iv.setBackgroundResource(R.drawable.icon_statistics); 
			 		 try{
			 			 ((LinearLayout)tabWidget.getChildAt(i)).setGravity(Gravity.CENTER_VERTICAL);
			 			 ((LinearLayout)tabWidget.getChildAt(i)).addView(iv,0);
			 		 }catch(ClassCastException e){}
			 			 
			 		 
 /*
		        tv.setTextColor( getResources().getColorStateList(R.color.darkgray));
//		     tv.setLayoutParams(new  LayoutParams(    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
////			        tv.setBackgroundColor(color.darkslategrey) ;
//			        tv.setGravity(Gravity.CENTER_VERTICAL); 
			          
		        
		        if(FirstTabTextColor!=null){
		        	tv.setTextColor(FirstTabTextColor);
 
		        	 ImageView	iv = new ImageView(activity); 
			 		 iv.setBackgroundResource(FirstTabBackGround);
			 		 
			 		 try{
			 			 ((LinearLayout)tabWidget.getChildAt(i)).setGravity(Gravity.CENTER_VERTICAL);
			 			 ((LinearLayout)tabWidget.getChildAt(i)).addView(iv,0);
			 		 }catch(ClassCastException e){
			 			 
			 		 }
		        }
		        
//		        tv.setBackgroundResource(color.darkslategrey);
			   */   
		    }
		    
		   }
//			tabhost.getTabWidget().setStripEnabled(true);
	 
		
	}
	
	
	
	
	
	
	
	
	
	
	
	  @Override
		public void onResume() {
			super.onResume();	
//			initialStatTracks();	
			
			/*if( activity.app.isNewLogin){
				 activity.app.isNewLogin=false;
				 this.doQuery();
			}*/		
		 	setFTag();
			if(activity.app.isLastTrackExist()){
				recordingLL.setVisibility( View.VISIBLE );
				updateUI(null,false);
			}else
				recordingLL.setVisibility( View.GONE);
			
			activity.app.updateUIstatus(true);
			updateUI(null,false);
			
			/*if(progressDialog!=null && progressDialog.isShowing() && !activity.app.statTrackLoading)	
 					progressDialog.dismiss();*/
//			showGpxFileList();
			setUserInfo();
			
			
	 }
		@Override
		public void onPause() {
		 
			activity.app.updateUIstatus(false); 
		 
			super.onPause();
		}

	@Override
	public boolean isShowBottomTabs() {
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public void setTabOnFiling() {
		
		 maxTabIndex = 2;
		 MAPVIEW_INDEX=2;
		
	}

	public int getFootNumber() {
		return footNumber;
	}

	public void addFootNumber(int footNumber) {
		this.footNumber += footNumber;
	}
		
 }
	    
	    
	 

 
