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

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.location.Location;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.text.InputFilter;
import android.text.InputType;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MyLocationData;
import com.loopj.android.http.RequestParams;
import com.qiyou.mb.android.QiYouConstant;
import com.qiyou.mb.android.R;
import com.qiyou.mb.android.beans.Track;
import com.qiyou.mb.android.beans.basic.Media;
import com.qiyou.mb.android.beans.basic.Waypoint;
import com.qiyou.mb.android.beans.basic.Waypoint_bean;
import com.qiyou.mb.android.service.LocationMornitorService;
import com.qiyou.mb.android.service.TrackDbServiceBackground;
import com.qiyou.mb.android.ui.ChartSpeedKm;
import com.qiyou.mb.android.utils.Exportdb;
import com.qiyou.mb.android.utils.TrackInterface;
import com.qiyou.mb.android.utils.Utils;
import com.qiyou.mb.android.utils.base.IlocationFragment;
import com.qiyou.mb.android.utils.enums.TrackAvStatus;
import com.qiyou.mb.android.utils.enums.TrackStatus;
import com.qiyou.mb.android.utils.enums.TrackType;
import com.qiyou.mb.android.utils.enums.WorkingTrackType;
import com.qiyou.mb.android.utils.enums.mediaType;
import com.qiyou.mb.android.utils.enums.wpFlag;
import com.qiyou.mb.android.utils.image.QimageView;
import com.qiyou.mb.android.utils.log.QLog;
import com.umeng.analytics.MobclickAgent;

import java.io.File;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;

//import android.widget.ImageView;
//import com.qiyou.mb.android.utils.TrackInterface.Exporter;

public class TrackingBasic_fragment extends Querybase_fragment implements IlocationFragment  {
//	public static final String TAG ="com.qiyou.TrackingBasic_fragment";
//	public static final String dTAG ="com.qiyou";
	@Override
	public void setFTag(){
		TAG="com.qiyou.TrackingBasic_fragment";
	}
	
	protected int currentLayout;
	/**
	 * MapView 是地图主控件
	 */
	 
//	protected ImageLoader IL;   
	protected MyLocationData locData = null;
	/* MyLocationData locData = new MyLocationData.Builder()
     .accuracy(location.getRadius())
             // 此处设置开发者获取到的方向信息，顺时针0-360
     .direction(100).latitude(location.getLatitude())
     .longitude(location.getLongitude()).build();
mBaiduMap.setMyLocationData(locData);*/
	protected Boolean mIsPaused =false;
//	Boolean isActive= false;
    protected boolean isPlayback =false;	
//	protected MainActivity activity;
//	protected Track mTrack =null;;
//	protected Track_bean mTrack_bean =null; 
	protected Location currentLocation;
	protected Location lastLocation;
	protected final long update_interval = QiYouConstant.MAX_GPS_SPAN/2*5; 
//	protected boolean mapviewInitialized =false; 
//	protected boolean canFinish ;
//	ProgressDialog progressDialog ;
	private Handler handler ;
//	boolean firstLoad;
//	protected /*MyLocationOverlay*/ MyLocationData myLocationOverlay = null;
	protected LinearLayout liveList;
    int alpha=100;
	final String CANCEL="取消";
	final String COMPLETE="结束";
	final String CONFIRM ="请再次点击确认";
	WorkingTrackType workingTrackType; 
	boolean isStartPlay =false; 
	boolean isPlayPause =false; 
	boolean isPlaying=false;
	protected QimageView staticMapImg;
	protected View shareView;
	protected Boolean canLocationMap =true;//true;
	protected Boolean canRotationMap =true;//true;
	public TrackingBasic_fragment() {
		// TODO Auto-generated constructor stub
	}
  
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
//		activity =(MainActivity)getActivity();
	
//		 if(activity.app!=null)activity.app.currentActiveFragment =TAG;
//		 currentLayout =R.layout.trackingbasic_fragment;
		QLog.getLogger().d(dTAG,TAG+" "+ "onCreate");
//		drawTrack=true;
		 
	}
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {   
		 
//		if(vContainer==null)
//			vContainer = inflater.inflate(R.layout.trackingbasic_fragment, container, false);
		 firstLoad=true;
		vContainer = inflater.inflate(currentLayout, container, false);
		initialViews( );
	 	mornitorLocations();
//	 	initialLLViews();
		return vContainer;
		}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState); 
		  
		  // QLog.getLogger().d(dTAG,TAG+" "+ "onCreateView(), isPlayback: " + activity.app.playBack  ); 
		 
			trackOnActivityCreated();
			
 			}

	 void trackOnActivityCreated(){

		  setWorkingTrack();
		  updateUI(null, false);
//		  vContainer = inflater.inflate(R.layout.trackingmap_fragment, container, false);	
		  isPlayback = isPlayback||activity.app.playBack;
		
		  if(QiYouConstant.PV_LAST_LAT>0 ){
//		        locData.latitude = Utils.getbdLat(QiYouConstant.PV_LAST_LAT,QiYouConstant.PV_LAST_LON);
//				locData.longitude =  Utils.getbdLon(QiYouConstant.PV_LAST_LAT,QiYouConstant.PV_LAST_LON); 
				 locData = new MyLocationData.Builder() 
			     .latitude(Utils.getbdLat(QiYouConstant.PV_LAST_LAT,QiYouConstant.PV_LAST_LON))
			     .longitude(Utils.getbdLon(QiYouConstant.PV_LAST_LAT,QiYouConstant.PV_LAST_LON)).build();
	        }
//		  locData = new LocationData();
 
		
//		  if(activity.app.isLastTrackExist()&&btnFinish!=null){
//				btnFinish.setVisibility(View.GONE);
//			}
		  setFinishButtonVisibility(false);
		  
		  if(workingTrackType==WorkingTrackType.RECORDING){
			      trackId = activity.app.settings.getInt(QiYouConstant.PK_INT_LAST_UNFINISHED_TRACKID,-1);
				  long lastStart =activity.app.settings.getLong(QiYouConstant.PK_LONG_LAST_TRACK_START,-1);
					// QLog.getLogger().dLog(dTAG,TAG+" "+String.format( "onActivityCreated(), trackId:%s ,startTime: %s" , trackId,Utils.getFormatedTime(lastStart))   ); 
					
					
					if(lastStart>0 && trackId<=0 ){//&& activity.app.canRecord()){
		//				activity.app.initialNewTrack(QiYouConstant.TRACK_TYPE_BIKE);
						activity.app.initialNewTrack(TrackType.BIKE);
					}else 
						if(!isPlaying && trackId >0 && activity.app.recordingTrack!=null 
										&& activity.app.recordingTrack.getTrackBean().getTrackId() !=trackId){//01-20 18:59:15.886 18491 18491 E AndroidRuntime: Caused by: java.lang.NullPointerException
								 
									setFinishButtonVisibility(false);
										  
		//							progressDialog = ProgressDialog.show(activity, "请稍等...", "获取数据中...", true);
								    activity.app.restoreLastTracking(); 
								   	handler = new Handler(){
					
										@Override
										public void handleMessage(Message msg) {
											
											//关闭ProgressDialog
		//									progressDialog.dismiss(); 
											
											 //更新UI
		//										 switchButtonStatus(); 
											
											  if(msg.what==1){
		//										Toast.makeText(activity, "查询超时...获取记录数据失败",Toast.LENGTH_SHORT).show();
												setTabhostTitle();
		//										setFinishButtonVisibility(true);	
														
		//							 			textview.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
		//										textview.setText(title);
												
												if(btnFinish!=null) {
//													btnFinish.setVisibility(View.VISIBLE);
													setFinishButtonVisibility(true);
												}
											}else
											{
												 
												 setSelectedTrackType();
												
												 // QLog.getLogger().d(dTAG,TAG+" onActivityCreated(), app.restoreLastTracking()-----done.  "   );
												 
//												 setTrackDesc();
												 showTabs(true);
												 mIsPaused =  mTrack_bean.getStatus() == TrackStatus.PAUSED;
											}
											  updateUI(null,false ) ;
											  validEditButtons();
//											  setTrackDesc();
										}};
								   
								   
										new Thread(){
					
											@Override
											public void run() {
												//需要花时间计算的方法		
												int topWaiting=0;
												 // QLog.getLogger().d(dTAG, TAG+ "  mTrack_bean.getTrackId():"+mTrack_bean.getTrackId()+", trackId:"+trackId);
									        	while( mTrack_bean.getTrackId() !=trackId){
						 			        	 try {
						 			        		 // QLog.getLogger().d(dTAG, TAG+ "  mTrack_bean.getTrackId():"+mTrack_bean.getTrackId()+", trackId:"+trackId);
									 				Thread.sleep(50);
									 				topWaiting+=50;
									 				if(topWaiting>QiYouConstant.MAX_TIME_GET_TRACK_FROM_DB )
									 				{ 
									 					handler.sendEmptyMessage(1);
									 					return;
		//							 					break;
									 				}
									 			  } catch (InterruptedException e) {
									 				// TODO Auto-generated catch block
									 				Utils.logStackTrace(e, TAG);
									 				}
										    	}
									    		 
												
												//向handler发消息
												handler.sendEmptyMessage(0);
											}}.start(); 
								  
					//				Bundle args = new Bundle(); 
					//			    args.putInt(QiYouConstant.EXTRA_KEY_ID, trackId);
					//			    setArguments(args);
								  
								  Location loc =activity.app.lastLocation ==null?activity.app.lm.getLastKnownLocation(LocationManager.GPS_PROVIDER ):activity.app.lastLocation;
								  if(loc==null||locData==null)return;
//								  locData.latitude =loc.getLatitude();
//				 				  locData.longitude=loc.getLongitude();
				 				  
				 				  locData = new MyLocationData.Builder() 
				 			     .latitude(loc.getLatitude())
				 			     .longitude(loc.getLongitude()).build();
				 			 
//								  updateUI(loc,false ) ;
								  updateUI(null,false ) ;
								  // QLog.getLogger().d(dTAG,TAG+" "+ "onActivityCreated(), app.restoreLastTracking()  "   ); 
								  
								  return;
							  	}
		  		
		 
		  			}
			 
			     if(QiYouConstant.PV_LAST_LAT>0 ){
//	 			        locData.latitude = Utils.getbdLat(QiYouConstant.PV_LAST_LAT,QiYouConstant.PV_LAST_LON);
//	 					locData.longitude =  Utils.getbdLon(QiYouConstant.PV_LAST_LAT,QiYouConstant.PV_LAST_LON); 
	 					 locData = new MyLocationData.Builder() 
		 			     .latitude(Utils.getbdLat(QiYouConstant.PV_LAST_LAT,QiYouConstant.PV_LAST_LON))
		 			     .longitude(Utils.getbdLon(QiYouConstant.PV_LAST_LAT,QiYouConstant.PV_LAST_LON)).build();
			        }
			       
			     /* if(isPlayback)
				   	{
				   		this.drawTrack(activity.app.currentTrack.getTrackBean());
				   		playbackTrackDrawed =true;
				   	}*/
	 }
	
	  
//	 private Chronometer tm_chronometer_sport;
//	 private Chronometer tm_chronometer_pause;
	private ProgressBar navi_progress;
	protected MapView mMapView = null;
	protected TextView mTrackId;
	protected TextView mTrackStartTime; 
	protected TextView mSpeedText;
	protected TextView mSportTimeText; 
	protected TextView mDistanceText; 
	protected TextView mEleText;
	protected TextView mPauseTimeText; 
//	protected TextView mEleText_up;
//	protected TextView mEleText_down;
	protected TextView tm_textView_bearing;
	protected TextView mTopSpeedText;
	protected TextView mAVSspeedText;
//	protected TextView mOfftimeText;
	protected TextView mCostText;
	protected TextView top_sptime;//tm_textView_top_sptime
	protected TextView top_dist;//tm_textView_top_dist
	protected TextView top_speed;
	protected TextView totalTimeText; 
//	protected TextView maxRText; 
	protected TextView mTAVSText;
	
	protected TextView mTrackType;
	
	protected EditText mNameEdit; 
	protected TextView mTrackStarTimeText;
	protected TextView mTrackEndTimeText;
	protected EditText mDescEdit;
	protected EditText mCommentEdit;
	

	protected Button btnFinish;
	protected Button btnPause;
//	protected Button btnViewMap;
	protected Button btnCamera;
	protected ImageButton btnKmpoints;
	protected ImageButton btnMapLive;
	protected ImageButton btnLiveList; 
	protected ImageButton btnMapLoadRoadbook;
 //	protected Button btnTurnPoints;
	protected ImageButton btnPlay;
	
//	protected ImageButton btnPlay;
	protected ImageButton btnPlayPause;
	protected ImageButton btnPlaySpeech;
	
	protected ImageButton btnNaviStop;
	protected ImageButton btnNaviPause;
//	protected Button btnPlayMap;
//	protected Button btnPlayPauseMap;
//	protected Button btnFullScreen;
	protected ImageButton btnLocation;  
	protected ImageButton btnRotation;	
	protected ImageButton btnAutoZoom;
	protected ImageButton btnSaveScreen;  
	protected ImageButton btnSataliteMap;//tm_btnSatalite
	protected Button 	btnChartSpeed; 
	protected Button 	btnChartDist;  
	protected Button 	btnChartEle;
	protected Button 	td_btnPlayback;
	protected Button    btnNavi;
	protected Button    btnSNav;
	protected Button    btnReverse;
	protected Button 	td_btnContinue;
	protected Button 	td_btnShowChartKm;
	protected Button 	td_btnShowChartSpeed;
	protected Button 	td_btnShowChartEle;
	protected Button 	td_btnShowChartKm1;
	protected Button 	td_btnShowChartSpeed1;
	protected Button 	td_btnShowChartEle1;
	protected Button td_btn_export;
	protected Button btnSave;
	protected Button btnDel;
	protected Button btnUpload;
	protected Button btnShare;
	protected Button btnImport;
	
	protected ImageButton btnMapWayinstruction; 
	protected ImageButton btnMapPicture;

//	private TextView td_edit_Type;
	protected TextView td_track_sumary;
	

	
//	private   LinearLayout ll_note;
	private   LinearLayout ll_speed_title ;
	private   LinearLayout ll_recording_control;
	private   LinearLayout ll_play_control ;
	protected   LinearLayout ll_navi_progress ;
	protected TextView txt_nav_info;
 	private void initialLLViews(){
 		ll_note =(LinearLayout)vContainer.findViewById(R.id.ll_note);  
 		ll_speed_title =(LinearLayout)vContainer.findViewById(R.id.ll_speed_title);
 		ll_recording_control =(LinearLayout)vContainer.findViewById(R.id.ll_recording_control);
 		ll_play_control =(LinearLayout)vContainer.findViewById(R.id.ll_playback_control);
 		ll_navi_progress =(LinearLayout)vContainer.findViewById(R.id.ll_Navi_control);
 		txt_nav_info=(TextView)vContainer.findViewById(R.id.txt_nav_info);
 	}
	
	private void validLLViews(){
//		return; mSpeedText!=null &&  
		 
		if(ll_note==null|| isPlaying ||mTrack_bean==null   )return;
		if(mIsPaused){
			mSpeedText.setText(R.string.tracking_pause);			
		}
//		if(mTrack_bean==null)return;
//		if(ll_note==null)initialLLViews();
	 
//		if(mNoteText==null) return;
		
		boolean showNotes =!Utils.isGpsEnabled(activity)||mTrack_bean.getTrackId()==0;
		showNotes= showNotes &&  !mIsPaused || activity.app.isShowSlidTabs();
		
		ll_note.setVisibility(showNotes?View.VISIBLE:View.GONE);	
		ll_speed_title.setVisibility(showNotes?View.GONE:View.VISIBLE);
		if(!showNotes)return;
 	
//		if(mTrack_bean.getTrackId()>0)return;
		if(!Utils.isGpsPermited(activity)){
			mNoteText.setText(R.string.permitGPS); 
			mSpeedText.setText(R.string.GPSNotPermited);
			return;
		}else
		if(!Utils.isGpsEnabled(activity)) {
//			((TextView)vContainer.findViewById(R.id.text_no_gps)).setText(R.string.GPSOFF);
			mNoteText.setText(R.string.enableGPS); 
			mSpeedText.setText(R.string.GPSOFF);			
		}
		else{
			if(activity.app.isShowSlidTabs()){  
				mNoteText.setText("提示：往右滑动屏幕可以切换到地图界面");
				return;
			}
			
			mSpeedText.setText(R.string.no_sat_singal);
//			((TextView)vContainer.findViewById(R.id.text_no_gps)).setText(R.string.noSatlite);
			mNoteText.setText(R.string.noSatliteDesc); 
		}
		 
	}
	
  protected void initialViews( )
	{ 
	
//	   tm_chronometer_sport =(Chronometer) vContainer.findViewById(R.id.tbs_chronometer_sport);
//	  tm_chronometer_pause =(Chronometer) vContainer.findViewById(R.id.tbs_chronometer_pause);
//	  if(workingTrackType!=WorkingTrackType.DETAIL && workingTrackType!=WorkingTrackType.GPX ){
     if(workingTrackType==WorkingTrackType.RECORDING || workingTrackType==WorkingTrackType.PLAYBACK ){
	 
    	   navi_progress =(ProgressBar)vContainer.findViewById(R.id.navi_progress);
		   mTrackId = (TextView) vContainer.findViewById(R.id.tbs_textView_id);
		   mTrackStartTime = (TextView) vContainer.findViewById(R.id.tbs_textView_starttime);	 
		  tm_textView_bearing = (TextView) vContainer.findViewById(R.id.tbs_textView_bearing);
		  mSpeedText = (TextView) vContainer.findViewById(R.id.tbs_textView_Speed);
		  mSportTimeText = (TextView) vContainer.findViewById(R.id.tbs_textView_Time);
		  mDistanceText = (TextView) vContainer.findViewById(R.id.tbs_textView_Distance); 
		  mEleText = (TextView) vContainer.findViewById(R.id.tbs_textView_ele);
//		  mEleText_up = (TextView) vContainer.findViewById(R.id.tbs_textView_eleUp);
	//	  mEleText_down = (TextView) vContainer.findViewById(R.id.tbs_textView_eleDown);
		  mPauseTimeText = (TextView) vContainer.findViewById(R.id.tbs_textView_pause);
		  mTopSpeedText = (TextView) vContainer.findViewById(R.id.tbs_textView_topspeed);
		  mAVSspeedText = (TextView) vContainer.findViewById(R.id.tbs_textView_avs);
		  mCostText = (TextView) vContainer.findViewById(R.id.tbs_textView_cost);
//		  mTrackType =(TextView) vContainer.findViewById(R.id.tbs_textView_trackType);
	//	   mOfftimeText = (TextView) vContainer.findViewById(R.id.tbs_textView_offtime);
//		   maxRText= (TextView) vContainer.findViewById(R.id.tbs_textView_maxR); 
		   totalTimeText= (TextView) vContainer.findViewById(R.id.tbs_textView_totalTime);
		   mTAVSText = (TextView) vContainer.findViewById(R.id.tbs_textView_tavs); 
			mNoteText = (TextView) vContainer.findViewById(R.id.text_note);
	//	   td_edit_Type= (TextView) vContainer.findViewById(R.id.td_edit_Type);
	//		mNameEdit= (EditText) vContainer.findViewById(R.id.td_edit_Name);
	//		mSummaryText    = (TextView) vContainer.findViewById(R.id.td_textView_TrackSummary);
	//		mRoadBookText = (TextView) vContainer.findViewById(R.id.td_textView_roadbook);//
	//		mCommentEdit = (EditText) vContainer.findViewById(R.id.td_edit_comment);
	//		mDescEdit = (EditText) vContainer.findViewById(R.id.td_edit_desc);		
			mTrackStarTimeText = (TextView) vContainer.findViewById(R.id.td_textView_Startime);
			mTrackEndTimeText = (TextView) vContainer.findViewById(R.id.td_textView_EndTime);
			
		   
		   
		    btnPause = (Button) vContainer.findViewById(R.id.tbs_btnPauseTtrack);
		  
	//		btnViewMap = (Button) vContainer.findViewById(R.id.tbs_btnViewMap);
		    
	//		btnKmpoints=(Button) vContainer.findViewById(R.id.tbs_btnKMpoints); 
	//	    btnTurnPoints=(Button) vContainer.findViewById(R.id.tbs_btnTurnPoints);	 
	//	    btnSaveScreen=(Button) vContainer.findViewById(R.id.tm_btnSaveScreen);	 
		    btnPlayPause = (ImageButton) vContainer.findViewById(R.id.pl_btnPauseTtrack);
		    btnPlay = (ImageButton) vContainer.findViewById(R.id.pl_btnPlayTtrack);
		
		    btnFinish = (Button) vContainer.findViewById(R.id.tbs_btnFinishTtrack);  
		   
			
			
	//	    btnPlay = (ImageButton) vContainer.findViewById(R.id.pl_btnPlayTtrack); 
	//		btnPlayPauseMap = (Button) vContainer.findViewById(R.id.pl_PauseTtrackMap);
	//		btnPlayMap = (Button) vContainer.findViewById(R.id.pl_PlayTtrackMap);
		    if(btnPlay!=null){ 
			    btnPlay.setOnClickListener(ButtonOnClickListener); 
			    btnPlayPause.setOnClickListener(ButtonOnClickListener); 
			    btnPause.setOnClickListener(ButtonOnClickListener); 
			    btnFinish.setOnClickListener(ButtonOnClickListener);   
			 }
		    
	//		btnPlayPauseMap.setOnClickListener(ButtonOnClickListener); 
	//		btnPlayMap.setOnClickListener(ButtonOnClickListener);	    
//		    btnSave = (Button) vContainer.findViewById(R.id.td_btnSaveTtrack);	 
//			btnSave.setOnClickListener(ButtonOnClickListener);
//			
	//		btnViewMap.setOnClickListener(ButtonOnClickListener); 
//			btnCamera =(Button) vContainer.findViewById(R.id.tbs_btnCamera);
//			btnCamera.setOnClickListener(ButtonOnClickListener); 
			
			//开始/停止按钮 
	//		btnPause.setOnClickListener( ButtonOnClickListener);  
			
			
			
	//		btnViewCompareChart = (Button) vContainer.findViewById(R.id.td_btnViewCompareChart);
	//		btnViewCurrentChart = (Button) vContainer.findViewById(R.id.td_btnViewCurrentChart);
		    
		    
		
		}
	     
     
	     td_btn_export=(Button) vContainer.findViewById(R.id.td_btn_export);
		 if(td_btn_export!=null){
			 td_btn_export.setOnClickListener(ButtonOnClickListener);
		 }
		 
		 mTrackType =(TextView) vContainer.findViewById(R.id.tbs_textView_trackType);
		 btnCamera =(Button) vContainer.findViewById(R.id.tbs_btnCamera);
		 if(btnCamera!=null)btnCamera.setOnClickListener(ButtonOnClickListener); 
		 
		 /*td_btnShowChartKm = (Button) vContainer.findViewById(R.id.td_btnShowChartKm);  
		 if(td_btnShowChartKm!=null)
			 td_btnShowChartKm.setOnClickListener(ButtonOnClickListener);
		 td_btnShowChartSpeed = (Button) vContainer.findViewById(R.id.td_btnShowChartSpeed);  
		 if(td_btnShowChartSpeed!=null)
			 td_btnShowChartSpeed.setOnClickListener(ButtonOnClickListener);
		 td_btnShowChartEle = (Button) vContainer.findViewById(R.id.td_btnShowChartEle);  
		 if(td_btnShowChartEle!=null)
			 td_btnShowChartEle.setOnClickListener(ButtonOnClickListener);*/
	 
	  
		initialChartViews();
		initTrackTypeSpin();
		initialLLViews();
		
		 
	}
		
  protected void initialChartViews(){

//		btnChartSpeed=(Button) vContainer.findViewById(R.id.td_btnChartSpeed);
//		btnChartEle=(Button) vContainer.findViewById(R.id.td_btnChartEle);
//		btnChartDist=(Button) vContainer.findViewById(R.id.td_btnChartDist);
//		btnChartSpeed.setOnClickListener(ButtonOnClickListener);
//		btnChartEle.setOnClickListener(ButtonOnClickListener);
//		btnChartDist.setOnClickListener(ButtonOnClickListener);
  }
	
   protected   OnClickListener  ButtonOnClickListener = new OnClickListener() {
	    @Override
		public void onClick(View view) {
	    	switch (view.getId() ){
	    		case R.id.tbs_btnFinishTtrack: {finishRecordingTrack();break;}	    		
//	    		case R.id.tbs_btnPauseTtrack:{pauseRecordingTrack() ;break;}camerPics()
	    		case R.id.tbs_btnPauseTtrack:{camerPics() ;	break;}
	    		case R.id.tbs_btnCamera:{camerPics();break;}
//	    		case R.id.tbs_btnViewMap:{  activity.showTrackDetailMap(null);;break;}  
	    		case R.id.tbs_btnKMpoints:{showPoints(1);break;} 
//	    		case R.id.tbs_btnTurnPoints:{showPoints(0);break;}
//	    		case R.id.tm_btnFullscreen:{showMapViews();break;}
	    		case R.id.tm_btnLocaiton:{locationInMap(null);break;}
	    		case R.id.tm_btnRotaiton:{roationMap();break;} 
	    		case R.id.tm_btnAutozoom:{autoZoomMap();break;}
	    		case R.id.pl_btnPlayTtrack: {startStopPlay();	break;}
	    		case R.id.pl_btnSpeech: {playSpeech();	break;}
	    		case R.id.navi_btnSpeech: {playSpeech();	break;}
	    		
	    		case R.id.pl_btnPauseTtrack:{playbackPause();break;}
	    		case R.id.tm_btnSaveScreen:{saveScreen();break;} 
	    		case R.id.tm_btnSatalite:{showSatelliteMap();break;}  
//	    		case R.id.pl_PauseTtrackMap:{playbackPause();break;}
//	    		case R.id.pl_PlayTtrackMap:{startStopPlay();break;}
//	    		case R.id.td_btnChartSpeed:{ showCharts(2)  ;break;}
//	    		case R.id.td_btnChartEle:{ showCharts(1)  ;break;}
//	    		case R.id.td_btnChartDist:{  showCharts(0)   ;break;}
	    		case R.id.td_btnPlayback:{playBack() ;break;}
	    		case R.id.td_btnNavi:{startNavi(false) ;break;} 
	    		case R.id.rt_btnSNav:{startNavi(true) ;break;} 
// 	    		case R.id.td_btn_roadbook:{buildRoadBook(true) ;break;}
	    		case R.id.td_btn_export:{exportTrack()  ;break;} 
	    		case R.id.td_btnContinue:{  continueTrack()   ;break;} 
	    		case R.id.td_btnShowChartSpeed:{  showSpeedKmChart(1)   ;break;}
	    		case R.id.td_btnShowChartKm:{  showSpeedKmChart(2)   ;break;}
	    		case R.id.td_btnShowChartEle:{  showSpeedKmChart(3)   ;break;}
	    		case R.id.td_btnImport: {importTrack();	break;}
	    		case R.id.td_btnShowChartSpeed1:{  showSpeedKmChart(1)   ;break;}
	    		case R.id.td_btnShowChartKm1:{  showSpeedKmChart(2)   ;break;}
	    		case R.id.td_btnShowChartEle1:{  showSpeedKmChart(3)   ;break;}
	    		
	    		case R.id.td_btnSaveTtrack: {saveTrack(false);break;} 
	    		case R.id.td_btnDelTtrack: {updateTrackAvstatus();break;}
	    		case R.id.td_btnUploadTtrack: {uploadTrack(mTrack);break;}
	    		case R.id.td_btnDeleteTtrack: {deleteWebTrack(mTrack);break;}

	    		
	    		case R.id.td_btnShareTtrack: {shareTrack(mTrack);break;}
	    		case R.id.rt_btnStart:{  setRouteStart()   ;break;} 
	    		case R.id.rt_btnEnd: {setRouteEnd();break;} 
	    		case R.id.rt_btnWps: {setRouteWps();break;}
	    		case R.id.rt_btnTent: {setRouteTent();break;}
	    		case R.id.rt_btnRest: {setRouteRest();break;}
	    		case R.id.rt_btnCheck: {setRouteCheck();break;}
	    		case R.id.rt_btnHand: {setRouteHand();break;}  
	    		case R.id.rt_btnCalculate:{routeSearch()   ;break;} 
	    		case R.id.rt_btnReset: {routeReset();break;} 
	    		case R.id.rt_btnSave: {routeSave();break;}
	    		case R.id.tbs_btnwayinstruction: {showWayinstructions();break;}
	    		case R.id.tbs_btnpicture: {showMapPicture();break;}
	    		case R.id.navi_btnStop: {stopNavi();break;}
	    		case R.id.navi_btnPause: {startPauseNavi();break;}
	    		case R.id.rt_btnReverse: {reverseRoute();break;}
	    		case R.id.act_btn_loadRoadbook:{loadRoadBook();break;}
	    		case R.id.btn_location_confirm:{pickLocation();break;}
	    		case R.id.img_btnEdituser:{showMyinfo();break;}
//	    		case R.id.ll_newact:{showNewAction();break;}
//	    		case R.id.ll_newteam:{showNewTeam();break;}
//	    		case R.id.ll_shuoshuo:{activity.showNoteList();break;} 
//	    		case R.id.ll_trackList:{activity.showLocalTrackList();break;} 
//	    		case R.id.ll_start_place:{pickGeoPlace(view.getId() );break;}
//	    		case R.id.ll_end_place:{pickGeoPlace(view.getId() );break;}
	    		case R.id.act_txt_endGeo_picker:{pickGeoPlace(view.getId() );break;}
	    		case R.id.act_txt_startGeo_picker:{pickGeoPlace(view.getId() );break;}
	    		case R.id.btn_submitAct:{submitSvrObj();break;}
	    		case R.id.btn_SaveAct:{saveSvrObj();break;} 
	    		case R.id.act_btn_delRoadbook:{delActBook();break;}
	    		case R.id.act_btn_join:{joinSvrObj();break;} 
	    		case R.id.act_btn_refresh:{refresh();break;}
	    		case R.id.act_txt_startGeo_share:{shareEndUrl(R.id.act_txt_startGeo_share);break;}
	    		case R.id.act_txt_endGeo_share:{shareEndUrl(R.id.act_txt_endGeo_share);break;}
	    		case R.id.st_btn_query: { 	doQuery() ; break; }
	    		case R.id.btn_CateQuery: { doCatesQuery(); break; }
	    		case R.id.btn_WebQuery: { initialWebQuery(); break; }
//	    		case R.id.btn_webpageup: { webPageup(); break; }
//	    		case R.id.btn_webpagedown: { webPagedown(); break; }
//	    		case R.id.loadMoreButton: {   loadingMore()  ;break;}
	    		case R.id.share_btn_refresh: {  doLiveQuery(); break; }
	    		case R.id.share_btn_list: {  showShareListOnMap(); break; }
	    		case R.id.share_btn_query: {  queryFromShareList(); break; }
	    		case R.id.map_btnLoadRoadbook: {  loadRoadBookInMap(); break; }
	    		case R.id.map_btnLive: {  switchLive(); break; }
	    		case R.id.map_btnSharelist: {  switchLiveList(); break; }
	    		
	    		case R.id.btnHeadDetail: { showObjDetail(); break; }
	    		case R.id.imgTopBanner: { showPicPicker(); break; }
	    		case R.id.user_abulm: { showPicPicker(); break; }
	    		case R.id.act_btn_share: { shareObj(); break; }
	    		case R.id.usr_btn_logout: { logout(); break; }
				case R.id.btn_more_history:{activity.showLocalTrackList();break;  }
				case R.id.btn_more_configure:{activity.	startPrefActivity(); break; }
				case R.id.btn_more_offlinemap:{activity.showOffline();break;}
 	    	}
	    			
	    }
	    };
	    void deleteWebTrack(Track track ){
	    	
	    	if (track.getTrackBean().getSvrNumber() > 0 && track.getTrackBean().getUserid() == activity.app.user.getUserbean().getId()){
	    		final TrackAvStatus status = TrackAvStatus.DELETED; 
	    		mTrack_bean.setAvStatus(status);
	    		
	    		AlertDialog.Builder builder = new Builder(activity);
				   builder.setMessage("确认删除吗？");
				   builder.setTitle("提示");
				   builder.setCancelable(false);
				   builder.setPositiveButton("确认", new android.content.DialogInterface.OnClickListener() {
					   @Override
					   public void onClick(DialogInterface dialog, int which) {
					   dialog.dismiss();	
					 
						  
					   updateTrackStatus(mTrack_bean.getSvrNumber(),status); 
							 
					   
						}
					});
				  builder.setNegativeButton("取消", new android.content.DialogInterface.OnClickListener() {
					 @Override
					 public void onClick(DialogInterface dialog, int which) {
						 dialog.dismiss();
						 
						 }
					 });
				  	builder.create().show();
				
				  	
				
	    	}
	    		  
	    }
	    void shareObj(){};
	    void showObjDetail(){}
	    void importTrack(){}
	 
	    void switchLiveList(){
	    	liveList =(LinearLayout)vContainer.findViewById(R.id.ll_liveList) ;
		    LinearLayout leftBtns=(LinearLayout)vContainer.findViewById(R.id.ll_left_btns) ;
		    boolean toShowLive= liveList.getVisibility()==View.GONE;
		    liveList.setVisibility(toShowLive?View.VISIBLE:View.GONE);
		    vContainer.findViewById(R.id.share_ll_list).setVisibility(liveList.getVisibility());
		    leftBtns.setVisibility(toShowLive?View.GONE:View.VISIBLE);
		    // to switch roate/autolocation
		   
		 /*   if(canLocationMap){
		    	canLocationMap =!toShowLive;
		    }
		    if(canRotationMap){
		    	canRotationMap =!toShowLive;
		    }
		    */
	    	
		    if(toShowLive){// hiding list
		    	canLocationMap =false;
		    	canRotationMap =false;
		    	doLiveQuery();
		    }
	    	 
	    	
	    	 if(!toShowLive){// hiding list 
	    			 roationMap();
	    		    locationInMap(null);
	    		    clearLiveItems();
			    }
	    	 
	    
		    btnLiveList.setImageResource(toShowLive?
						R.drawable.icon_livelist:R.drawable.icon_livelistoff);
	    	
	    }
	    void clearLiveItems(){
	    	
	    }

	    @Override
		RequestParams buildLiveQueryParames(){
			RequestParams params = new RequestParams(); 
//			final int GEO_CITY_TYPE=2;
		 
//		    if(activity.currentAcitiviy==null) return null;
			params.add("userId", String.valueOf(activity.app.user.getUserbean().getId()));
			params.add("from", String.valueOf(lastMaxLiveTime)); 
			params.add("isCycle", String.valueOf(true)); 
			QLog.getLogger().d(dTAG, TAG+" web query params: "+params);
		 
			return params;
		}
		
		
	    void switchLive(){
	    	
	    	 QiYouConstant.PV_BL_SHARE_LOCATION = !QiYouConstant.PV_BL_SHARE_LOCATION;
	    	 
	    	 this.btnMapLive.setImageResource(QiYouConstant.PV_BL_SHARE_LOCATION?
	    			 							R.drawable.icon_radio:R.drawable.icon_radio_in);
	    	 
	    	 vContainer.findViewById(R.id.ll_liveshareMsg).setVisibility( View.GONE);
	    	 
	    	String msg= QiYouConstant.PV_BL_SHARE_LOCATION?
	    			 	"直播开始":"直播关闭";
	    	 this.showNotes(msg, true);
	    	
	    	if(!QiYouConstant.PV_BL_SHARE_LOCATION) {
	    		  activity.app.saveShareLocationOption();
	    		return;
	    	}
	    	
	    
	    	
	    	 final EditText inputServer = new EditText(activity);
	    	 inputServer.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});
        	 inputServer.setText(QiYouConstant.PV_STR_SHARE_MSG );
	    	 AlertDialog.Builder builder = new AlertDialog.Builder(activity);
             builder.setTitle("位置共享，直播说说").setIcon(android.R.drawable.ic_dialog_info).setView(inputServer);
//                     .setNegativeButton("取消", null);
             
           /*  builder.setNegativeButton("取消", new android.content.DialogInterface.OnClickListener() {
				 @Override
				 public void onClick(DialogInterface dialog, int which) {
					 dialog.dismiss();
					 
					 }
				 });*/
             
             
             builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { 
                 public void onClick(DialogInterface dialog, int which) {
                	 
                     
                	 QiYouConstant.PV_STR_SHARE_MSG = inputServer.getText().toString();
                 	 ((TextView)vContainer.findViewById(R.id.txt_livesharemsg)).setText(QiYouConstant.PV_STR_SHARE_MSG);
                     vContainer.findViewById(R.id.ll_liveshareMsg).setVisibility(View.VISIBLE);
                     activity.app.saveShareLocationOption();
                 }
             });
             builder.show();
             
         	if (activity.app.user.getUserbean().getId() == 0){
	    		activity.showLogin();
	    		 
	    	}
	    }
	    void loadRoadBookInMap(){
	    	
	    	
	    	 final EditText inputServer = new EditText(activity);
	    	 inputServer.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20) });
	    	  inputServer.setInputType(InputType.TYPE_CLASS_NUMBER);
 	    	 AlertDialog.Builder builder = new AlertDialog.Builder(activity);
             builder.setTitle("请输入云端路书编号").setIcon(R.drawable.icon_roadbook).setView(inputServer)
                     .setNegativeButton("取消", null);
             builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {

                 public void onClick(DialogInterface dialog, int which) {
                	 
                     
                	 String s= inputServer.getText().toString();
                	 if(!TextUtils.isEmpty(s)){
                		 try{ 
                			 int i =Integer.parseInt(s.trim()); 
                			 requestTrackFromWeb(i); 
                			 Toast.makeText(activity, "正在加载云端路书，路书加载完毕后可以进行路书编辑、导入本地、导航等操作",Toast.LENGTH_LONG).show();
                		 }catch(Exception e){
                			 inputServer.setText("");
                			 showNotes("路书编号输入错误",true);
                		 }
                	 } else{
                		showNotes("路书编号输入错误",true);
                	 }
                	 
                 }
             });
             builder.show();
	    	
	    	
	    	
	    }
	    void shareEndUrl(int viewId){} 
	    void refresh(){}
	    void joinSvrObj(){}
	    void delActBook(){}
	    void submitSvrObj(){}
	    void saveSvrObj(){}
	    void showNewAction(){}
	    void showNewTeam(){}
 	    void showMyinfo(){}
	    void pickLocation(){}
	    void stopNavi(){}
	    void reverseRoute(){}    
	    void startPauseNavi(){}
	    void loadRoadBook(){}
	    
	    void pickGeoPlace(int textViewId){
	    
	    	
	    	
	    	
	    	
	    }    
	    void  showSpeedKmChart(int type){
	    	if(mTrack_bean==null)return;
	    	Intent intent =  new Intent(activity, ChartSpeedKm.class);
			 Bundle bundle=new Bundle(); 
		    bundle.putInt("type", type);
		    bundle.putInt("id", mTrack_bean.getTrackId());
		    bundle.putInt("id", trackId);
		    intent.putExtras(bundle);
			activity.startActivity(intent);
	    	
	    };
		 
		 private void playSpeech(){
			QiYouConstant.PV_INT_NAVI_SPEAK_MODEL=QiYouConstant.PV_INT_NAVI_SPEAK_MODEL!=2?2:1;
			QiYouConstant.CAN_SPEAK=!QiYouConstant.CAN_SPEAK ||QiYouConstant.PV_INT_NAVI_SPEAK_MODEL!=2;
			
			setSpeechIcon();
			if(!QiYouConstant.CAN_SPEAK){
				activity.app.stopSpeech(); 
			}
//			else{
//				activity.app.resumeSpeech();
//			}
				
		 }
		 private void setSpeechIcon(){
			 if(btnPlaySpeech!=null){
				 QiYouConstant.CAN_SPEAK=QiYouConstant.CAN_SPEAK && Utils.checkSpeechServiceInstall(activity);
//				 btnPlaySpeech.setImageResource(QiYouConstant.CAN_SPEAK?R.drawable.icon_voice:R.drawable.icon_novoice);
				 btnPlaySpeech.setImageResource(QiYouConstant.CAN_SPEAK&&QiYouConstant.PV_INT_NAVI_SPEAK_MODEL!=2?R.drawable.icon_voice:R.drawable.icon_novoice);

				 if(!Utils.checkSpeechServiceInstall(activity)){
					 Toast toast=	Toast.makeText(activity,  "语音播报不可用，请安装《讯飞语音+》", Toast.LENGTH_LONG );
	    		 	 toast.show();
	    		 	 if(txt_nav_info!=null)
	    		 		 txt_nav_info.setText("导航语音不可用，请安装《讯飞语音+》");
				 }
//				 btnPlaySpeech.setEnabled( Utils.checkSpeechServiceInstall(activity));
			 }
		 }
		
	    protected void showWayinstructions(){}
	    protected void showMapPicture(){}
	
	    boolean canShowSatellite=false;
	    protected void showSatelliteMap(){	    	
	    	if(mMapView==null)return;	 
	    		canShowSatellite=!canShowSatellite;
//	    		mMapView.setSatellite(canShowSatellite);
	    		mMapView.getMap().setMapType(canShowSatellite?BaiduMap.MAP_TYPE_SATELLITE:BaiduMap.MAP_TYPE_NORMAL); 
//	    		btnSataliteMap.setText(canShowSatellite?"平面":"卫星");
	    		btnSataliteMap.setImageResource(canShowSatellite?R.drawable.flatmap:R.drawable.satellite);
	    		
	    } 
	    
	    protected void  autoZoomMap(){}
	    protected void  setRouteStart(){}
	    protected void  setRouteWps(){}
	    protected void  setRouteTent(){}
	    protected void  setRouteRest(){}
	    protected void  setRouteCheck(){}
	    protected void  setRouteHand(){}
	    protected void  setRouteEnd(){}
	    protected void  routeSearch(){}
	    protected void  routeReset(){}
	    protected void  routeSave(){}
	    protected void roationMap(){}
	    protected void  updateTrackAvstatus(){}
	      
	    protected void showPoints(final int which){}
	    protected void  showMapViews(){}
	    protected void  locationInMap(Location loc){}
	    protected void startStopPlay(){}	    
	    protected void playbackPause(){}
	    protected void  showCharts(int type){}
	    protected void playBack(){}; 
	    
	    protected void startNavi(boolean isSimulation){	  
	    	 activity.startNaviService(trackId,isSimulation);	
	/*	new Thread(){
	    			
	    			@Override
	    			public void run() {
	    				 activity.startNaviService(trackId,false);	
	    		    	 
	    			}}.start(); 
	    	*/		
			
	    } 
	   
	    protected void continueTrack(){};
		void showTabs(boolean isVisible ){}
	    boolean needConfirmToFinish=false;
	    protected void finishRecordingTrack(){
//			if( !(activity.app.recordingTrack!=null &&activity.app.recordingTrack.getTrackBean().getTrackId()>0)) return;
//	    	btnFinish.setText("结束中。。。");
	    	needConfirmToFinish =!needConfirmToFinish;
	    	
//	    	final String confirmExist=CONFIRM+(trackId>0?COMPLETE:CANCEL)+"? ";
	    	final String confirmExist=CONFIRM+(trackId>0?COMPLETE:CANCEL)+" ";
	    	setBtnButtonText(confirmExist);	    	
//			btnPause.setVisibility(View.GONE);
	    	handler = new Handler(){

				@Override
				public void handleMessage(Message msg) {
					
					//关闭ProgressDialog
//					progressDialog.dismiss();
					
					if(msg.what==10){ //not confirmed in 5 sec						 
						  btnFinish.setEnabled(true);
						  needConfirmToFinish=false;
						  updateFinshButonText(); 
						  btnPause.setVisibility(View.VISIBLE);
						 return;
					}
					else if(msg.what==20){ //confirmed
						btnPause.setVisibility(View.GONE);
						needConfirmToFinish=false;
						btnFinish.setText((trackId>0?"正在"+COMPLETE:CANCEL));
						btnFinish.setEnabled(false);
						btnCamera.setVisibility(View.GONE);

						
						new Thread(){
							
							@Override
							public void run() {
								
						    	if(canFinish()){
//						    		saveScreen();
						    		long st=System.currentTimeMillis();
//						    		 activity.app.getCurrentTrack().getTrackBean().getType().toInt() , activity.app.getCurrentTrack().getTrackBean().getTrackId()
						    		 int trackType =mTrack_bean.getType().toInt();
						    		 int trackId= mTrack_bean.getTrackId();
						    		activity.finishRecording();
						    		  // QLog.getLogger().dLog(dTAG,  "activity.finishRecording() cost time:" +(System.currentTimeMillis()-st)); 
						    		if(QiYouConstant.PV_INT_SPORTS_SPEAK_MODEL<2)
						    			activity.app.speech("运动结束",1);
						    		int ttwaiting=0;
						    		/*while(ttwaiting<3000 && (activity.app.recordingTrack!=null || activity.app.isLastTrackExist())){*/
						    		while(ttwaiting<2000 && (  activity.app.isLastTrackExist())){
						    			try {
											Thread.sleep(100);
											ttwaiting+=100;
										} catch (InterruptedException e) {
											// TODO Auto-generated catch block
											e.printStackTrace();
										}
						    		}
						    		 // QLog.getLogger().dLog(dTAG,  " ttwaiting: " +ttwaiting); 
						    		  // QLog.getLogger().dLog(dTAG,  "before show detail cost time:" +(System.currentTimeMillis()-st)); 
						    		activity.showTrackDetail(trackType,trackId );
						    	}else{
						    		if(QiYouConstant.PV_INT_SPORTS_SPEAK_MODEL<2)
						    			activity.app.speech("运动取消",1);
						    		activity.cancelRecording();
						    		handler.sendEmptyMessage(30);
						    	}
						    	
						    		
							}}.start(); 
							
				       
//							activity.updateTabTitle();
					}
					else if(msg.what==30){
						  
					       activity.updateTabVisibility(true);						
							 
					}
					
					else
					{
						setBtnButtonText(confirmExist +msg.what);
						
					}
					
					
				}};
				
	    	
	    	
	    	if(needConfirmToFinish){
//	    		btnFinish.setText("确认结束？");
	    		activity.clearRecordingCache();
	    		new Thread(){
	    			@Override
					public void run() {	
	    				int totalWaiting=0;
 	    				boolean cleaned=false;
	    			
	    				while(needConfirmToFinish ||!cleaned){	    					
//	    					setBtnButtonText("确认结束？");
	    					if(totalWaiting<=5000){
	    						totalWaiting+=1000;
		    					try{
		    						
		    						Thread.sleep(1000);
		    						 cleaned=true; //make sure the clearRecordingCache() processed
//		    						setBtnButtonText("确认结束？ "+totalWaiting/5);
		    						handler.sendEmptyMessage(6- totalWaiting/1000);
		    					  } catch (InterruptedException e) {
		    			 				// TODO Auto-generated catch block
		    			 				Utils.logStackTrace(e, TAG);
		    			 				}
	    					}
	    					else{
	    						handler.sendEmptyMessage(10);
	    						return;
	    					}
	    					
	    					
	    				}
	    				handler.sendEmptyMessage(20);
	    			}}.start(); 
	    		
	    		
	    	return;
	    	} 
	    	 
		}
	 
	    
	    void setBtnButtonText(String text){
	    	btnFinish.setText(text);
	    }
	 
	  /*  protected void pauseRecordingTrack(){
	    	
	    	mIsPaused = this.mTrack_bean.getStatus() ==TrackStatus.PAUSED;
	    	activity.pausingTrack(!mIsPaused); 
	    	if (mIsPaused) {					
	    		activity.app.speech("运动继续",2);
//				mIsPaused = true;
//				activity.pausingTrack(QiYouConstant.TRACK_STATUS_TRACKING); 
				btnPause.setText("暂停");

			} else {					
 
				activity.app.speech("运动暂停",2);
				btnPause.setText("继续");
			}  
	       
	    	mIsPaused=!mIsPaused;
	        updateUI(new Location("pause"),false);
	  
	    }*/
	    
	    protected Spinner spTrackType; 
	    private ArrayAdapter<?> spAdapter;
	    class QArrayAdapter extends ArrayAdapter<String>{

			 
			public QArrayAdapter(Context context, int textViewResourceId,
		            List<String> cateList) {
		        super(context, textViewResourceId, cateList);
		        // TODO Auto-generated constructor stub
		    }
			@Override
			public View getDropDownView(int position, View convertView,
					ViewGroup parent) {
				TextView v = (TextView) super.getView(position, convertView,
						parent);
				// v.setMinimumHeight((int) (200*
				// getResources().getDisplayMetrics().density));

				v.setBackgroundResource(R.drawable.linearlayout_horizontal);

				// v.setTextAppearance(activity, R.style.ll_text_view_1);
				v.setPadding(5, 8, 5, 8);
				int selected = spTrackType.getSelectedItemPosition();
				if (position == selected) {
					v.setTypeface(null, Typeface.BOLD);
					v.setBackgroundResource(R.drawable.head_linearlayout);
				}
				//
				// v.getPaint().setFlags(0);
				// v.setTypeface(null, Typeface.BOLD);
				// LayoutParams lp = new LayoutParams();

				v.setLayoutParams(new android.widget.AbsListView.LayoutParams(
						LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
				return v;
			}

			/*
			@Override
	          public View getDropDownView(int position, View convertView, ViewGroup parent) {
	              TextView v =(TextView) super.getView(position, convertView, parent);
//	              v.setMinimumHeight((int) (200* getResources().getDisplayMetrics().density));
	            
	              v.setBackgroundResource(R.drawable.linearlayout);
	              
//	              v.setTextAppearance(activity, R.style.ll_text_view_1);
	              v.setPadding(5, 8, 5, 8);
	              int selected = spTrackType.getSelectedItemPosition();
			        if(position == selected){
			            v.setBackgroundResource(R.drawable.note_linearlayout);
			        }
//	              
//			      v.getPaint().setFlags(0);
//			      v.setTypeface(null, Typeface.BOLD); 
//			       LayoutParams lp  = new LayoutParams();
	              
		         v.setLayoutParams(new android.widget.AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
	              return v;
	          }
	          */
	       

		}

	    void initTrackTypeSpin(){
	    	spTrackType = (Spinner)vContainer.findViewById(R.id.SpinnerTrackType);
 	    	if(spTrackType==null)return;
			 int spinner=workingTrackType==WorkingTrackType.RECORDING?R.layout.thinspinner:R.layout.myspinner;
			//将可选内容与ArrayAdapter连接起来
//	    	spAdapter = ArrayAdapter.createFromResource( getActivity(), R.array.trackType, android.R.layout.simple_spinner_item);\
	    	spAdapter = QArrayAdapter.createFromResource( getActivity(), Utils.getTrackType()/*R.array.trackType*/, spinner/*R.layout.myspinner*/) ;

			//设置下拉列表的风格	
	    	spAdapter.setDropDownViewResource(R.layout.spinner_item);

			//将adapter2 添加到spinner中
	    	spTrackType.setAdapter(spAdapter);

			//添加事件Spinner事件监听  
	    	spTrackType.setOnItemSelectedListener(new SpinnerXMLSelectedListener());

			//设置默认值
//	    	spTrackType.setVisibility(View.VISIBLE);
			
		}
	    protected int oTrackType; //track's original type
		class SpinnerXMLSelectedListener implements OnItemSelectedListener{
			@Override
			public void onItemSelected(AdapterView<?> spinner, View textView, int spID,
					long arg3) {
				
				if(!firstLoad)
				  switch (spinner.getId() ){ 
					case R.id.SpinnerTrackType: {
						if(activity.app.playBack)return;
//						trackType =spID;
						/*oTrackType =activity.app.getRecordingTrack().getTrackBean().getType().toInt();
						activity.app.getRecordingTrack().getTrackBean().setType(TrackType.valueOf(spID));
						activity.app.setLastTracktype(); 
						mTrackType.setText(spTrackType.getSelectedItem().toString());*/
						oTrackType =mTrack_bean.getType().toInt();
						mTrack_bean.setType(TrackType.valueOf(spID));
						activity.app.setLastTracktype(); 
						if(mTrackType!=null)
							mTrackType.setText(spTrackType.getSelectedItem().toString());
	            		}
					 
					break;	
					
					case R.id.sp_Web_inputType: {
											
						webSpinnerSelected(spID);
						 
						
						break;
					}
					
					} 
				else 
					firstLoad =false;
//					isSwitchWebInputOnly =false;
					}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub
				
			}
				
		 }
		  
			
		   void setSelectedTrackType(){
			   try{
				   if(spTrackType==null)return;
				   int type=0;
				   isPlayback =activity.app.getRecordingTrack().getTrackBean().getType().toInt()==TrackType.COPY.toInt();
				   if(!isPlayback){
					    type = activity.app.getLastTracktype();
					    type =type < activity.app.getRecordingTrack().getTrackBean().getType().toInt()?
						activity.app.getRecordingTrack().getTrackBean().getType().toInt():type; 
				   }else {  
					    type =type<activity.app.getCurrentTrack().getTrackBean().getType().toInt()?
						activity.app.getCurrentTrack().getTrackBean().getType().toInt():type; 
				   }
				   // QLog.getLogger().d(dTAG, " set trackType is:"+ type);
				   spTrackType.setSelection(type); 
				   if(mTrackType!=null)
					   mTrackType.setText(spTrackType.getSelectedItem().toString());
	//			   spTrackType.setSelection(TrackType.FLY.toInt());
			   } catch(IndexOutOfBoundsException e ){
				   Utils.logStackTrace(e, TAG);
			   } catch(Exception e ){
				   Utils.logStackTrace(e, TAG);
		   }
		   }
	    
	    
//		public String getPath(Uri uri) {
//			String[] projection = { MediaStore.Images.Media.DATA };
//			Cursor cursor = managedQuery(uri, projection, null, null, null);
//			int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
//			cursor.moveToFirst();
//			return cursor.getString(column_index);
//		}
	    
	    String camPicName=null;
		protected void camerPics(){
			 MobclickAgent.onEvent(activity,"camera");
			Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
			
			String sdStatus = Environment.getExternalStorageState();
			if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用
//				Log.v(dTAG,	"SD 卡不可用");

        		 Toast toast=	Toast.makeText(activity,  "SD 卡不可用", Toast.LENGTH_LONG );
    		 	 toast.show();
    		 	
//				return;
			}

			String filePath =mTrack.getMediaPah(mediaType.PIC);
			File PHOTO_DIR = new File(filePath);
			
			if(!PHOTO_DIR.exists()) PHOTO_DIR.mkdirs();// 创建文件夹					
//			camPicName =filePath + String.format("%s.jpg",System.currentTimeMillis()); 
			camPicName =filePath + DateFormat.format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA))+".jpg"; 
//			String name= DateFormat.format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA))+".jpg";
			
			 File mCurrentPhotoFile	  = new File(camPicName);
				
				
			intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mCurrentPhotoFile)); // set the image file name
			 
			startActivityForResult(intent, TAKE_PHOTO);
		}
		
		private final int TAKE_PHOTO=1000;
		
		@Override
		public void onActivityResult(int requestCode, int resultCode, Intent data) {
			
			super.onActivityResult(requestCode, resultCode, data);  
//			String fileName = null ;
			
				if (TAKE_PHOTO==requestCode && resultCode == Activity.RESULT_OK) { 
					final Waypoint wp = new Waypoint();
					if(mTrack.getLastWp()!=null){ 
						wp.getWb().setLatitude( mTrack.getLastWp().getWb().getLatitude());
						wp.getWb().setLongitude( mTrack.getLastWp().getWb().getLongitude());
						wp.getWb().setTime( mTrack.getLastWp().getWb().getTime());
						wp.getWb().setSumDist( mTrack.getLastWp().getWb().getSumDist());
						wp.getWb().setSpeed( mTrack.getLastWp().getWb().getSpeed());
						wp.getWb().setElevation( mTrack.getLastWp().getWb().getElevation());
						
					}
					
					
					 final Handler	 commentHandler	= new Handler(){
							
							@Override
							public void handleMessage(Message msg) {   
								
								  QLog.getLogger().d(dTAG, "camPicName is :"+ camPicName);
								 setMD(camPicName,System.currentTimeMillis(),wp,mediaType.PIC); 
							 	currentTab=1;
				    			setSelectedTab();
							}};
							
					
					
					
					
					 
					 AlertDialog.Builder builder = new AlertDialog.Builder(activity);
					  
		     		 
	            	 LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	            	 final View layout = inflater.inflate(R.layout.image_dialog,
	            	                                (ViewGroup) activity.findViewById(R.id.layout_root));
	            	 
	            	 layout. setOnTouchListener(new OnTouchListener() {
	     			    @Override
	     			    public boolean onTouch(View v, MotionEvent event) {
	     			    	InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
	     			    	imm.hideSoftInputFromWindow(layout.getWindowToken(), 0);
	     			        return false;
	     			        
	     			    }
	     			});
	     		 
	            	 final EditText edit = (EditText) layout.findViewById(R.id.pic_edit_desc); 
	            	 QimageView image = (QimageView) layout.findViewById(R.id.camer_pic);
	            	 image. setOnTouchListener(new OnTouchListener() {
		     			    @Override
		     			    public boolean onTouch(View v, MotionEvent event) {
		     			    	InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
		     			    	imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
		     			        return false;
		     			    }
		     			});
	            	  QLog.getLogger().d(dTAG, "camPicName is :"+ camPicName);
	            	 IL.DisplayImage(camPicName,  image); 
	            	 builder.setView(layout);
	                 builder.setTitle("您可以在此输入照片说明").setIcon(android.R.drawable.ic_dialog_info)//.setView(edit)
	                         .setNegativeButton("先不输入", new DialogInterface.OnClickListener() { 
	    	                     public void onClick(DialogInterface dialog, int which) { 
	    	                    	 commentHandler.sendEmptyMessage(0);
	    	                     }
	    	                 });
	                 builder.setPositiveButton("输入完毕", new DialogInterface.OnClickListener() {

	                     public void onClick(DialogInterface dialog, int which) {
	                    	 Media md = new Media();
	 						//TODO: add comments,etc to media object\
	 						md.setTime(System.currentTimeMillis());
	 						md.setType(mediaType.PIC);
//	 						md.setCommont("Hello Camera Lens!");
	 						md.setUri(camPicName);
	 						md.setComment( edit.getText().toString());
	 						wp.getWb().getMedias().add(md);
	                    	 
	                       commentHandler.sendEmptyMessage(1);
	                        
	                     }
	                 });
	               
	                 builder.show();
					
				}
				
				   
//				  createSmallPic(PicName,QiYouConstant.SMALLPIC_SIZE);
			}
		
		
		long playbackSumPausetime=0;
		long playbackSumOfftime=0;
		private boolean canShowTabs=true;
		private long lastsptime=0;
		private long lastpausetime=0;
		private long totalTime=0;
		private float topspd=0;
		private float maxR=0;
//		private boolean isPausing =false;
		@Override
		public void updateUI(Location location, Boolean isOnPause ) { 
			
		
//			if(isPlaying && isGPSloc)  return; 
			
		 	 
		 		activity.updateTabVisibility(isShowBottomTabs());
			 
		    validLLViews();
 
			
			if(mDistanceText==null)return;
//			try{
//				isPlaying =activity.app.playBack;
//				QLog.getLogger().d(dTAG,TAG+" updateui get the location.");
				
//			if(!isPlaying || isPlaying &&location!=null &&location.getExtras()!=null) {
				updateGraphics(location,isOnPause); 
//			}
					 float speed =location==null?0:location.getSpeed();
					 if(speed>0){
						if(isPlaying )
							topspd =topspd<speed?speed*3.6f:topspd;
//						else
//							 mTrack_bean.setTopSpeed(speed*3.6f);
						
					 }   else if(speed==-1){ //playback over 
						  
						 return;
					 } 
					
					 
					 
					 if(mTrack_bean.getTrackId()>0 
//							 ||mTrack_bean!=null   &&
					    	||	 isPlaying
					    		   ){
						 	
					       	 double dist =isPlaying?
					       			 location==null?0:(location.getExtras()!=null?location.getExtras().getFloat("dist"):0 )
					       			 :activity.app.sumDist>=mTrack_bean.getDistance() ?
					       			 activity.app.sumDist:mTrack_bean.getDistance();
					       			 
							mDistanceText.setText( String.format("%.2f", dist/1000f)); 
							//set ele sumup
//							mEleText_up.setText(String.format("%.0f",  mTrack_bean.getEsumUp()));
//							mEleText_down.setText(String.format("%.2f",recordingTrack.geteDownDist()));
			         	 	trackId =isPlaying?activity.app.getCurrentTrack().getTrackBean().getTrackId():mTrack_bean.getTrackId();			         	 	
							mTrackId.setText(String.valueOf(trackId));
						    updateFinshButonText(); 
						    long tracktime =isPlaying?location==null?0:(location.getExtras()!=null?location.getExtras().getLong("wptime"):0 ):mTrack_bean.getStartTime();
							  
						    if(isPlaying){
									  playbackSumPausetime +=location==null?0:location.getExtras().getLong("pausetime");
									  playbackSumOfftime +=location==null?0:location.getExtras().getLong("offtime");
									  lastsptime =  location==null?0:(location.getExtras()!=null?location.getExtras().getLong("sptime"):0);
									  mSportTimeText.setText(Utils.getTimeCnt(lastsptime,true)) ;	
									  mPauseTimeText.setText(Utils.getTimeCnt( playbackSumPausetime+playbackSumOfftime ,true)) ;
									  mTrack_bean.setSportTime(lastsptime); 
									  totalTime =playbackSumOfftime+playbackSumPausetime+lastsptime;
									  maxR =location==null?0:(location.getExtras()!=null?location.getExtras().getFloat("maxR"):0);
						    } else
						    	 updateTimeView( speed);
						    
						    
						    
							if(tracktime>0)
								mTrackStartTime.setText(Utils.getFormatedTime(tracktime)); 
							
							double avs =3600*dist/lastsptime;
							avs=avs>(isPlaying?topspd:mTrack_bean.getTopSpeed())?0:avs;
							mAVSspeedText.setText(avs>0?String.format("%.2f",avs):"--"); 
							
							double tavs=totalTime>0?(float) ( 3600*dist/totalTime):0;
							tavs=tavs>avs?avs:tavs;
							mTAVSText.setText(tavs>0?String.format("%.2f",tavs):"--");
							
//							mOfftimeText.setText(Utils.getTimeCnt(isPlaying?playbackSumOfftime:mTrack_bean.getOffTime(),false));;
							
						
							//set maxR
//							maxRText.setText( String.format("%.2f",isPlaying?maxR: mTrack_bean.getMaxR()/1000f)); 
									        	 
							totalTimeText.setText(Utils.getTimeCnt( totalTime)) ;
//							long pausetime= totalTime -sptime ;//-mTrack_bean.getOffTime();
//							if(location!=null && location.getSpeed()==0 ||TextUtils.isEmpty(mPauseTimeText.getText())){ 
							
//							mTopSpeedText.setText(String.format("%.2f",isPlaying?topspd:mTrack_bean.getTopSpeed())); 
							 mTopSpeedText.setText(String.format("%.2f",isPlaying?topspd:mTrack_bean.getTopSpeed())); 
							if(canShowTabs){
								showTabs(true);
								canShowTabs=false;
							}
							 
							this.mCostText.setText(String.format("%.2f", isPlaying?Utils.getCalories(activity.app.getCurrentTrack().getTrackBean().getType(),avs,lastsptime,0): mTrack.getCalBurn()));
							
				     }else
				    	 setWorkingTrack();
					 
					 mIsPaused =  mTrack_bean.getStatus() == TrackStatus.PAUSED;	
					 
//				    	 mTrack_bean = activity.app.getRecordingTrack().getTrackBean();
					if(location ==null)return; 
					tm_textView_bearing.setVisibility(View.GONE);
					boolean isGPSloc =Utils.isLocOfGPS(location);
//					if(isGPSloc){
//						activity.app.lastGPStime=System.currentTimeMillis() ;//location.getTime();
//						QLog.getLogger().d(dTAG,TAG+" "+ "MORNITOR_LOCATION_SERVICE   activity.app.lastGPStime:" +activity.app.lastGPStime);
//					    QLog.getLogger().d(dTAG,TAG+"MORNITOR_LOCATION_SERVICE  System.currentTimeMillis()  " + System.currentTimeMillis()    );
//					    // QLog.getLogger().dLog(TAG," Location is here 0111 ");
//					}
					
					if(location.getSpeed()>0){ 
						 speed  = location.getSpeed()*3.6f ; 
//						 mTopSpeedText.setText(String.format("%.2f",mTrack_bean.getTopSpeed()));//make sure the showing topspeed is the ever toppest.
//						 mTopSpeedText.setText(String.format("%.2f",isPlaying?topspd:mTrack_bean.getTopSpeed())); 
						 mSpeedText.setText( String.format("%.2f",speed)) ;
//						 mSpeedText.setText(String.valueOf(location.getSpeed()*3.6f)) ;
//			 		     tm_textView_bearing.setText(String.valueOf(location.getBearing()));  
						  tm_textView_bearing.setVisibility(View.VISIBLE);
			 		     tm_textView_bearing.setText(Utils.getBearMsg(location.getBearing(),true));  
			 		      mEleText.setText( String.format("%.0f", location.getAltitude())); 
					}else { 	
							if(isPlaying){
				    			  mSpeedText.setText( "回放就绪") ;
				    		}
				    		else 
							if(isGPSloc &&(isOnPause || location.getSpeed()==0))	{
								if("--".equals(mEleText.getText().toString()) || TextUtils.isEmpty(mEleText.getText().toString()))
										mEleText.setText( String.format("%.0f", location.getAltitude())); 
								 
			//							mSpeedText.setText(isPausing?R.string.tracking_pause:R.string.tracking_auto_pause);  
										mSpeedText.setText(R.string.tracking_auto_pause);  
			//							  tm_textView_bearing.setVisibility(View.GONE);
			//							tm_textView_bearing.setText("");  
//										mEleText.setText( "--"); 
										if(top_speed!=null)	{
//											top_speed.setText(String.format("%.2f",  mTrack_bean.getAvs()));//+"(均速)");
											 top_speed.setText(mSpeedText.getText());
										}
									 
							    }else {
							    		mEleText.setText( "--"); 
								    	if(!mIsPaused && !Utils.isGpsEnabled(activity)){
								    		mSpeedText.setText(R.string.GPSOFF);
								    		if(top_speed!=null)	{
												 top_speed.setText(mSpeedText.getText());
											}
			//					    		tm_textView_bearing.setVisibility(View.GONE);
								    	} else  {
										    		 if(mIsPaused||  !isGPSloc || !location.hasSpeed()	){	 
														mSpeedText.setText(mIsPaused?R.string.tracking_pause:
															Utils.isGpsPermited(activity)? R.string.no_sat_singal:R.string.GPSNotPermited);   
											            if(top_speed!=null) { 
//											            	top_speed.setText(  mAVSspeedText.getText()+"(均速)" );
//											            	top_speed.setText(  mAVSspeedText.getText()  );
											            	 top_speed.setText(mSpeedText.getText());
											           }
										    		}  
								    		}
							    } 
								
						}
					
					/*if(TextUtils.isEmpty(mSpeedText.getText())){
						mSpeedText.setText(mIsPaused?R.string.tracking_pause:R.string.no_sat_singal); 
					}*/
					if(top_dist!=null||top_sptime!=null||top_speed!=null) {   
					
					 top_dist.setText(mDistanceText.getText() );// = (TextView) vContainer.findViewById(R.id.tm_textView_top_dist);
					 
					 top_sptime.setText(mSportTimeText.getText() );
//					 if(location!=null)
					 top_speed.setText(mSpeedText.getText());
//					 else
//						 top_speed.setText("_._");
					 } 
					
//					if(!isPlaying || isPlaying &&location!=null &&location.getExtras()!=null) {
						 updateMapView(location);
//					}
				   
					 
//				    mIsPaused =true; 
				   
		//		   if(isOnPause && mapviewInitialized)	{
				     
				    	
				    	
		   
//			}catch(Exception e)
//			{
//				Log.e(dTAG,TAG+" updateui error.");
//				Utils.logStackTrace(e, dTAG);
//			}
			
//			validLLViews();
//			activity.app.updateStatistics();
		}
	  
		private void  updateTimeView(float speed){
			
//			QLog.getLogger().d(dTAG, TAG+" get totalTime,mIsPaused"+mIsPaused +"--------------------------------->");
		   if(mTrack_bean.getStartTime()==0)return;
		
			long manualPaused =activity.app.getPausedTime(false);
//			totalTime=mIsPaused?mTrack_bean.getTotalTime():System.currentTimeMillis() -mTrack_bean.getStartTime()-manualPaused;
//		    totalTime = System.currentTimeMillis() -mTrack_bean.getStartTime()-manualPaused;
//			totalTime =totalTime<=0?lastsptime+lastpausetime:totalTime;
		    totalTime = System.currentTimeMillis() -mTrack_bean.getStartTime()-manualPaused;
			totalTime =totalTime-lastsptime>0?totalTime:System.currentTimeMillis() -mTrack_bean.getStartTime();
		    
//		    QLog.getLogger().dLog(dTAG, TAG+" get totalTime,mTrack_bean.getStartTime()"+Utils.getFormatedTime(mTrack_bean.getStartTime())  );
//			QLog.getLogger().dLog(dTAG, TAG+" get totalTime:"+totalTime+Utils.getTimeCnt(totalTime) +" ,manualPaused:"+Utils.getTimeCnt(manualPaused));
//			totalTime = mTrack_bean.getStartTime()>0 && totalTime>0?  totalTime  :0;
			if(speed>0){
				lastsptime = totalTime - lastpausetime;
//				lastsptime=lastsptime>=0?lastsptime:0;
			}else if(speed==0 ||TextUtils.isEmpty(mPauseTimeText.getText())){ 
				lastpausetime =totalTime - lastsptime;
				mPauseTimeText.setText(Utils.getTimeCnt(  lastpausetime,true)) ;
			}
			
			mSportTimeText.setText(Utils.getTimeCnt(lastsptime,true)) ;
			// QLog.getLogger().d(dTAG, TAG+" get totalTime:"+Utils.getTimeCnt(totalTime) +" ,manualPaused:"+Utils.getTimeCnt(manualPaused));
			// QLog.getLogger().d(dTAG, TAG+" get totalTime:"+Utils.getTimeCnt(totalTime) +" get lastsptime:"+ lastsptime +" get lastpuasetime:"+ lastsptime+ " mTrack_bean.getStartTime():" +mTrack_bean.getStartTime());

			totalTime=totalTime<lastsptime?lastsptime:totalTime;
		}
		
    protected void updateGraphics(Location location, Boolean isOnPause){ }	
	protected void updateMapView(Location location){ 
	    
	} 
		 
		
		boolean canFinish(){
			return activity.app.recordingTrack!=null && activity.app.recordingTrack.getTrackBean().getTrackId()>0;
		}
		
		protected void switchButtonStatus(){
		 
			  // QLog.getLogger().d(dTAG,TAG+" "+"xxxxxxxxxx xxxxxxxxxxxx switchButtonStatus.xxxxxxxxxxxxxxxxxxxxxx" );

		/* 	if( btnPause!=null && activity.app.recordingTrack!=null){
				if(activity.app.recordingTrack.getTrackBean().getStatus() == TrackStatus.PAUSED)
					btnPause.setText("继续");
				else
					btnPause.setText("暂停");
				int visibility =activity.app.recordingTrack.getTrackBean().getTrackId()>0?View.VISIBLE:View.GONE;
				btnPause.setVisibility(visibility);
			} */
//
//			if( activity.app.recordingTrack!=null &&  activity.app.recordingTrack.getTrackBean().getTrackId()==0)
//				tm_btnCamera.setVisibility(View.GONE);
			if(activity.app.playBack){ 
				 
				showPlaybackButtons();
				return;
			}
			else
				showMapButtons();
//			else{ 
//				if(activity.app.currentActiveFragment.equalsIgnoreCase(TrackingBasic_fragment.TAG) ){
//					showBasicButtons();
//					
//					
//				}else
//				if(activity.app.currentActiveFragment.equalsIgnoreCase(Tracking_fragment.TAG) ){
//					showMapButtons();
//				}
//				
//				if(btnPause!=null)
//					btnPause.setVisibility(View.GONE);
//				
			/*	if(btnPlayPause!=null)
					btnPlayPause.setVisibility(View.GONE);
				
				if(btnPlay!=null)   
					btnPlay.setVisibility(View.GONE);  */

			    if(btnFinish!=null){
						
//						   canFinish =activity.app.recordingTrack!=null &&activity.app.recordingTrack.getTrackBean().getTrackId()>0;				
//							btnFinish.setEnabled(canFinish);
//							String title=(String) btnFinish.getText();
							String title =canFinish()?"结束":"取消";
							btnFinish.setText(title); 
						}	
			    
			    validEditButtons();
//			}
			
//			}
						 
		}
		
		/*protected void showBasicButtons(){
    		if( btnTurnPoints!=null)
				 btnTurnPoints.setVisibility(View.GONE);
//			if( btnFullScreen!=null)
//				btnFullScreen.setVisibility(View.GONE);
			if( btnLocation!=null)
				btnLocation.setVisibility(View.GONE);
			if( btnKmpoints!=null)
				btnKmpoints.setVisibility(View.GONE);
//			if(this.btnViewMap!=null)
//				btnViewMap.setVisibility(View.GONE);  
			if(this.btnSaveScreen!=null)
				btnSaveScreen.setVisibility(View.GONE);  
		}*/
		
		protected void showMapButtons(){
			
//			if( btnTurnPoints!=null)
//				 btnTurnPoints.setVisibility(View.GONE);
//			if(this.btnFullScreen!=null)
//				btnFullScreen.setVisibility(View.VISIBLE);
			if(this.btnLocation!=null){
				btnLocation.setVisibility(View.VISIBLE);
				btnLocation.getBackground().setAlpha(alpha);
				}
			if(this.btnKmpoints!=null){
				btnKmpoints.setVisibility(View.VISIBLE);
				btnKmpoints.getBackground().setAlpha(alpha);
			}
			if(this.btnRotation!=null){
				btnRotation.setVisibility(View.VISIBLE);
				btnRotation.getBackground().setAlpha(alpha);
				}	
			
			if(this.btnAutoZoom!=null){
				btnAutoZoom.setVisibility(View.VISIBLE);
				btnAutoZoom.getBackground().setAlpha(alpha);
				}	
			
			
//			if(this.btnViewMap!=null)
//				btnViewMap.setVisibility(View.GONE); 
			if(this.btnSaveScreen!=null){
				btnSaveScreen.setVisibility(View.VISIBLE);
				btnSaveScreen.getBackground().setAlpha(alpha);
			}
			
			if(this.btnSataliteMap!=null){
				btnSataliteMap.setVisibility(View.VISIBLE);
				btnSataliteMap.getBackground().setAlpha(alpha);
			}
			
			
			setFinishButtonVisibility(true);
//			if( btnFinish!=null)
//				btnFinish.setVisibility(View.VISIBLE);
			/*if(this.btnCamera!=null)
				btnCamera.setVisibility(View.VISIBLE); */
			 if(this.btnCamera!=null){
				boolean visible =trackId==activity.app.getRecordingTrack().getTrackBean().getTrackId();
				visible =visible && activity.app.getRecordingTrack().getTrackBean().getStatus()!=TrackStatus.FINISHED;
				visible=visible&& mTrack_bean.getType()!=TrackType.GPX;
				btnCamera.setVisibility(visible?View.VISIBLE:View.GONE);
			 }
			 
//			if(btnPlayPause!=null)
//				btnPlayPause.setVisibility(View.GONE);
//			
//			if(btnPlay!=null){  
//				btnPlay.setVisibility(View.GONE);
//				}
			 if( ll_recording_control!=null)ll_recording_control.setVisibility(View.VISIBLE);
			 if( ll_play_control!=null)ll_play_control.setVisibility(View.GONE);
			 if( ll_navi_progress!=null){
				 ll_navi_progress.setVisibility(activity.app.isNaving?View.VISIBLE:View.GONE);
			 }
			 if( btnPlaySpeech!=null)
				 btnPlaySpeech.setImageResource(QiYouConstant.CAN_SPEAK&&QiYouConstant.PV_INT_NAVI_SPEAK_MODEL!=2?R.drawable.icon_voice:R.drawable.icon_novoice);

		}
		
		
		protected void showPlaybackButtons(){
			
			if(this.btnLocation!=null)
				btnLocation.setVisibility(View.GONE);
			
			if(this.btnRotation!=null)
				btnRotation.setVisibility(View.VISIBLE);
			
			if(this.btnAutoZoom!=null)
				btnAutoZoom.setVisibility(View.VISIBLE);
			
			if(btnFinish!=null)
				btnFinish.setVisibility(View.GONE);
			
			if(btnPause!=null)
				btnPause.setVisibility(View.GONE);
			
			if(this.btnCamera!=null)
				btnCamera.setVisibility(View.GONE); 
			
//			if(btnPlayPause!=null)
//				btnPlayPause.setVisibility(View.VISIBLE);
//			
//			if(btnPlay!=null ){  
//				btnPlay.setVisibility(View.VISIBLE);
//			}
			if(ll_recording_control!=null)
				ll_recording_control.setVisibility(View.GONE);
			if(ll_play_control!=null)
				ll_play_control.setVisibility(View.VISIBLE);
			 
			
//			if(btnPlayPauseMap!=null){  
//				btnPlayPauseMap.setVisibility(View.VISIBLE);
//				btnPlayPauseMap.getBackground().setAlpha(alpha);
//			}
//			if(btnPlayMap!=null){  
//				btnPlayMap.setVisibility(View.VISIBLE);
//				btnPlayMap.getBackground().setAlpha(alpha);
//			}
 
			if(this.btnKmpoints!=null){
				btnKmpoints.setVisibility(View.VISIBLE);
				btnKmpoints.getBackground().setAlpha(alpha);
			}
				
//			if(this.btnViewMap!=null)
//				btnViewMap.setVisibility(View.GONE); 
			if(this.btnSaveScreen!=null){
				btnSaveScreen.setVisibility(View.GONE);
//				btnSaveScreen.getBackground().setAlpha(alpha);
			}
			
			if(this.btnSataliteMap!=null){
				btnSataliteMap.setVisibility(View.VISIBLE);
				btnSataliteMap.getBackground().setAlpha(alpha);
			}
			
			
		}
		
		
		
		
		
		
	   protected void mornitorLocations(){

			if ( !isPlaying) {
				Intent	broadcastIntent = new Intent(activity,LocationMornitorService.class); // monitor the location 
				activity.startService(broadcastIntent);
			}
		}
		 
	   @Override
	   protected void setMD(String picName,long time,Waypoint wp,mediaType mdType){
		   if(!TextUtils.isEmpty(picName )) { 
			 		
			   mTrack.setMd(picName, wp, mdType);
			   doSave();
			   createSmallPic(picName,QiYouConstant.WEB_PIC_SIZE,
					   buildPicWaterMarkTitle(wp!=null?wp.getWb().getSumDist():mTrack_bean.getLastWp().getWb().getSumDist(),time));
//				QLog.getLogger().d(dTAG,TAG+" "+ "onActivityResult(), medias with wp is  " +wp.toJsonWp()  ); 
//			   activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.parse(picName))); 
			
			   Bitmap bitmap = BitmapFactory.decodeFile(picName);
               MediaStore.Images.Media.insertImage(activity.getContentResolver(), bitmap, "爱骑驴" , "爱骑驴"); 
			   
			   Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);   
			   Uri uri = Uri.fromFile(new File(picName));   
			   intent.setData(uri);   
			   activity.sendBroadcast(intent);  
			  
			 /* activity.msc.connect();
			   try {
				   Thread.sleep(1000);
			   } catch (InterruptedException e) {
			   // TODO Auto-generated catch block
				   e.printStackTrace();
			   }
			   
			   URL url = null;
			   try {
				   url = picName.toURL();
			   } catch (MalformedURLException e) {
				   e.printStackTrace();
			   }

			   activity.msc.scanFile(picName, null);
			   activity.msc.disconnect();*/
		   }	   
		   
	   } 
	   
	    protected void saveScreen(){  } 
	    
	      
	     
	
	   
	   
//		    @Override
//		    protected void onRestoreInstanceState(Bundle savedInstanceState) {
//		    	super.onRestoreInstanceState(savedInstanceState);
//		    	mMapView.onRestoreInstanceState(savedInstanceState);
//		    }
 
	   
	   protected void setFinishButtonVisibility(boolean isVisible){
			
			if(btnFinish==null)return;
			
			
			if(!isVisible || 
					activity.app.playBack|| 
					activity.app.isLastTrackExist()&& trackId>0 && mTrack_bean.getTrackId() !=trackId  
//					||btnPlay!=null &&btnPlay.getVisibility()==View.VISIBLE
					){					
					btnFinish.setVisibility(View.GONE);
 
			}
				else{
					btnFinish.setVisibility(View.VISIBLE);
 
				}
					
			btnPause.setVisibility(btnFinish.getVisibility());
		}
		
	   
	   protected void  updateFinshButonText(){
//		   if(isPlaying ||btnPlay!=null &&btnPlay.getVisibility()==View.VISIBLE)return;
		   if(isPlaying  )return;
//		if( btnFinish!=null && btnFinish.getText().equals("取消") && trackId>0){
		if( btnFinish!=null && !needConfirmToFinish){
			//		    String title =canFinish()?"结束":"取消";
//			btnFinish.setVisibility(View.VISIBLE);
			String text=trackId>0?COMPLETE:CANCEL;
			btnFinish.setVisibility(View.VISIBLE);
			btnFinish.setText(text); 
			
		}
	   }
	   
	   
	   protected void setWorkingTrack(){
//		       mTrack =new Track();
//			   mTrack_bean =mTrack.getTrackBean(); 
	   }
	   
	   void shareTrack(Track track){
		 
//		   if( isWebRequest && track.getTrackBean().getUserid()!= activity.app.user.getUserbean().getId() )return;
		   
		   super.shareTrack(track);
		   if(track.getTrackBean().getSvrNumber()==0)return; 
		    mTrackId.setText(String.valueOf(track.getTrackBean().getSvrNumber()));
			 saveTrack(true);
			 if(track.getTrackBean().getTrackId()>0){
				 String title ="爱骑驴 "+ track.getTrackBean().getType().toCHString()+" 分享："
						 		+track.getTrackBean().getName();
				/* String content = "运动简报：" + track.getSummary()
						 		 +(TextUtils.isEmpty(track.getTrackBean().getDescription())?"":"\n"+ track.getTrackBean().getDescription());	*/
		 
			 String fomat=track.getTrackBean().geteUpDist()>0?"距离 %.1f公里， 用时 %s\n爬高 %.0f米":"距离 %.1f公里， 用时 %s";
			 String content =  String.format(fomat
					 , track.getTrackBean().getDistance()/1000
					 , Utils.getTimeCnt(track.getTrackBean().getSportTime(),false)
					 , track.getTrackBean().geteUpDist()
					 
					 );
			 
				 String targetUrl =	QiYouConstant.BASE_URL;
				 if(track.getTrackBean().getSvrNumber()>0){
					 targetUrl+= "track/"+track.getTrackBean().getSvrNumber();
					 
				 }
				
//				 String imageUrl =track.getStaticMap();
				 String imageUrl =track.getStaticMapUrl();
//				 staticMapImg.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
				 
//				 hide4share(View.VISIBLE);
				     
//				 hide4share(View.GONE);
				activity.doShareTrack(title, content, imageUrl, Utils.getBitmapFromView(shareView),targetUrl); 
				MobclickAgent.onEvent(activity,"shareTrack");
//				staticMapImg.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
//				 hide4share(View.VISIBLE);
//				 hide4share(View.GONE);
			 }else
			 {
				 activity.defaultShare();
			 }
			 isForShare=false;
		 }
	   
	   private void hide4share(int Visibility){
		   
		/*    if(td_btnShowChartSpeed!=null)
		    	td_btnShowChartSpeed.setVisibility(Visibility); 
		    if(td_btnShowChartKm!=null)
		    	td_btnShowChartKm.setVisibility(Visibility);
//		    if(td_btnShowChartKm1!=null)
//		    	td_btnShowChartKm1.setVisibility(Visibility);
//		    if(td_btnShowChartSpeed1!=null)
//		    	td_btnShowChartSpeed1.setVisibility(Visibility);
		    if(td_btnShowChartEle!=null)
		    	td_btnShowChartEle.setVisibility(Visibility);*/
		   if( vContainer.findViewById(R.id.ll_showShareTitle)==null) return;  

			   vContainer.findViewById(R.id.ll_showShareTitle).setVisibility(Visibility);

		   /* vContainer.findViewById(R.id.ll_ShowChartEle).setVisibility(Visibility);
		    vContainer.findViewById(R.id.ll_ShowChartSpeed).setVisibility(Visibility);
		    vContainer.findViewById(R.id.ll_ShowChartKm).setVisibility(Visibility);*/
			   
//			try {
//				Thread.sleep(500);
//			} catch (InterruptedException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}   
	   }
	   
	   boolean isCateChangesSaved=false;
	   private  void saveTrack(boolean isSilence) {
		   isCateChangesSaved=false;
		   saveNewCate();
	    	boolean isChanged;
	    	Utils.hideSoftKeyboard(activity);
	    	isChanged = !mCommentEdit.getText().toString().equalsIgnoreCase(mTrack_bean.getComment());
	    	isChanged = isChanged || !mDescEdit.getText().toString().equalsIgnoreCase(mTrack_bean.getDescription());
	    	isChanged = isChanged  || !mNameEdit.getText().toString().equalsIgnoreCase(mTrack_bean.getName());
	    	isChanged = isChanged  ||oTrackType!=mTrack_bean.getType().toInt();
	        
	    	if(!isChanged ){
	    		if(!isCateChangesSaved)
	    			if(!isSilence)
	    				Toast.makeText(activity,"没有变更需要保存。", Toast.LENGTH_SHORT).show();	
	    		return;	 
	    	}
	        
	    	getTrackDetailUpdated();
	    	
	    	doSave();
	    	
		    if(oTrackType!=mTrack_bean.getType().toInt()){
		    	activity.app.getStaticsTracks();
		    }
		    
		    
		    if(!isSilence)
		    	Toast.makeText(activity,"变更已成功保存。", Toast.LENGTH_SHORT).show();
	    }
	   
	   protected void saveNewCate(){}
	   protected void doSave(){
		   Intent serviceIntent = new Intent(activity, TrackDbServiceBackground.class);	   
		    serviceIntent.putExtra(QiYouConstant.UPDATE_TRACK, mTrack_bean.getTrackId());
		   // serviceIntent.putExtra(QiYouConstant.EXTRA_KEY_FORCEREFRESH, true);        
		    activity.startService(serviceIntent);
	   }
	   
	   
	   private void getTrackDetailUpdated(){
		   mTrack_bean.setName(mNameEdit.getText().toString());
		   mTrack_bean.setComment(mCommentEdit.getText().toString());
		   mTrack_bean.setDescription(mDescEdit.getText().toString());
			 
		}
	   
	   
	   
	   protected void validEditButtons(){
		 
//			setTrackDesc();
			
		}
	   
	  void initialEditViews(){
		   if(mNameEdit!=null)return;
		 	mNameEdit= (EditText) vContainer.findViewById(R.id.td_edit_Name); 
		 	mNameEdit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(10)});
			mCommentEdit = (EditText) vContainer.findViewById(R.id.td_edit_comment);
			mCommentEdit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(50)});
			mDescEdit = (EditText) vContainer.findViewById(R.id.td_edit_desc);	
			mDescEdit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(50)});
			td_track_sumary = (TextView) vContainer.findViewById(R.id.td_track_sumary);
			 btnSave = (Button) vContainer.findViewById(R.id.td_btnSaveTtrack);	 
		     if(btnSave!=null){
		    	 btnSave.setOnClickListener(ButtonOnClickListener);
		     }
		     mNameEdit.setSelectAllOnFocus(true);
//			mNameEdit.setOnFocusChangeListener(onFocusChangeListener);
//			mCommentEdit.setOnFocusChangeListener(onFocusChangeListener);
//			mDescEdit.setOnFocusChangeListener(onFocusChangeListener);
	   }
	   
	   
//	   OnFocusChangeListener onFocusChangeListener =new View.OnFocusChangeListener() {
//	        @Override
//	        public void onFocusChange(View v, boolean hasFocus) { 
//	            	activity.isShowingInput =hasFocus;
//	            
//	        }
//	    } ;
//	   
	   
	   
	   protected void setTrackDesc(){
		   
		   
			QLog.getLogger().d(dTAG,TAG+" begin to set summary....... " ); 

		   
		   
		     initialEditViews();
//			 if(mTrack_bean ==null || mTrack_bean.getTrackId()==0)return;
			 if(mTrack_bean ==null)return;
//			  final String td_textView_name = currentTrack.getTrackBean().getName();
//			  final String td_track_sumary =TextUtils.isEmpty(mTrack_bean.getDescription())? mTrack.getSummary():mTrack_bean.getDescription();
			 
//			  mCommentEdit.setText(mTrack_bean.getComment());
		      mDescEdit.setText(mTrack_bean.getDescription());	
		      if(mNameEdit!=null && !TextUtils.isEmpty(mTrack_bean.getName()))
		    	  mNameEdit.setText(mTrack_bean.getName());
		      
		      String summary="";
		      if(mTrack_bean.getType()==TrackType.GPX){
		    	  
		    	 
		    	  
//		    	  float avspeed=3600f*activity.app.mStatistics.getSumDist()/activity.app.mStatistics.getSumSportTime();
//		    	  avspeed =Float.isNaN(avspeed)||avspeed==0?15:avspeed;
				  float avspeed=  activity.app.getAVS();
		    	 /* float hours=mTrack_bean.getDistance()/1000/avspeed; 
		    	  float totalHours= (float) (hours*1.2f +((int)(hours*1.2/12))*12) ; 
		    	 
		    	   summary =  String.format("来自于%s\n路线总长%s,预计骑行用时%.1f小时，预计全程历时%.1f小时，预计消耗热量%.1f卡路里",
		    			   mTrack_bean.getCreator(),
							Utils.getFormatedDistance(mTrack_bean.getDistance()),
							hours,
							totalHours ,
							mTrack.getCalBurn()
						  );*/
		    	  long hours=(long) (mTrack_bean.getDistance()/avspeed*3600); 
		    	  long totalHours=  (long) (hours*1.2 +((int)(hours/1000/3600/16))*12*3600*1000) ; 
		    	 String geoinfoString=
		    			 mTrack_bean.getStartWp().getWb().getGeo()!=null && mTrack_bean.getLastWp().getWb().getGeo()!=null?
		    					 String.format("从%s出发到%s，",mTrack_bean.getStartWp().getWb().getGeo().toString("，"),
		    							 mTrack_bean.getLastWp().getWb().getGeo().toString(mTrack_bean.getStartWp().getWb().getGeo(),"，") ):"";
		    					 
		    	   summary =  String.format("来自于%s\n%s路线总长%s，预计骑行用时%s，预计全程历时%s，预计消耗热量%.1f卡路里",
		    			   mTrack_bean.getCreator(),
		    			   geoinfoString,
							Utils.getFormatedDistance(mTrack_bean.getDistance()),
 							Utils.getTimeCnt4Read(hours,false),
							Utils.getTimeCnt4Read(totalHours,false) ,
							mTrack.getCalBurn()
						  );
		      }else
		    	  summary= mTrack.getSummary();
		     if(td_track_sumary!=null) 
		      td_track_sumary.setText(summary);
		       
//		 	QLog.getLogger().d(dTAG,TAG+" end set summary....... " ); 
//			QLog.getLogger().d(dTAG,TAG+" set summary. VISIBLE...... " + (td_track_sumary.getVisibility()==View.VISIBLE)); 
//			QLog.getLogger().d(dTAG,TAG+" set summary....... " +td_track_sumary.getText()); 

		 }
	     
		   
		 protected   void exportTrack(){ 
			 
			 if(mTrack_bean ==null||mTrack_bean.getTrackId()==0)return;
			 String mDestXmlFilename =  QiYouConstant.EXP_PATH + "GPX_"+ mTrack_bean.getName()+".gpx";
			 final ProgressDialog progressDialog =ProgressDialog.show(activity, "请稍等...", "正在导出GPX数据至文件\n"+mDestXmlFilename, true); 
			 td_btn_export.setEnabled(false);
		    	
//		    	Toast.makeText(activity,"正在导出数据...请稍候",Toast.LENGTH_LONG ).show();
//		    	try {
//					new TrackInterface().exportGPX(activity,mTrack);
//				} catch (IOException e) {
//					// TODO Auto-generated catch block
//					Utils.logStackTrace(e,dTAG);
//				}
		    	
//		    	final TextView txtNote=(TextView)vContainer.findViewById(R.id.export_notice);
		    	 final   Handler	 handler	= new Handler(){
						
						@Override
						public void handleMessage(Message msg) {
							
							//关闭ProgressDialog
							progressDialog.dismiss(); 
//							if(txtNote!=null)txtNote.setVisibility(View.VISIBLE);
							 //更新UI
//												 switchButtonStatus(); 
							td_btn_export.setEnabled(true); 
							String gpxFile =msg.getData().getString("exportgpx");
							  if(TextUtils.isEmpty(gpxFile)){ 
//								  Toast.makeText(activity,"数据导出出现错误，导出失败。",Toast.LENGTH_SHORT ).show();
//								  if(txtNote!=null)txtNote.setText("数据导出出现错误，导出失败。");
								  showNotes("数据导出出现错误，导出失败。");
							}else
							{
//								  Toast.makeText(activity,"数据已导出至  "+gpxFile,Toast.LENGTH_LONG ).show();
//								  if(txtNote!=null)txtNote.setText("数据已导出至  "+gpxFile);
								showNotes("数据已导出至  "+gpxFile);
							}							  
						}};
						
				new Thread(){ 
					@Override
					public void run() {
						String gpx =new TrackInterface().exportGPX(activity,mTrack);
						Message msg= Message.obtain(handler);// .obtain(handler, 1);
						Bundle bd =new Bundle();
						bd.putString("exportgpx", gpx);
						msg.setData(bd);
						handler.sendMessage(msg);
		    	
				 }}.start();  
				 
				 
				 
				 
				 
		    	
		     	if(!QiYouConstant.DEVELOPER_MODE) return;
		    		
		    	if(mTrack ==null)return;
		    	String[] ids = new String[2];
		    	ids[0] = String.valueOf(-1);
		    	ids[1] = String.valueOf(mTrack_bean.getTrackId());
		    	Exportdb eb = new Exportdb(activity);
				eb.ExportTracks(ids); 
		    	
		    }
        void setTabhostTitle(){
        	if(tabhost!=null)
			     ((TextView)tabhost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)).setText("查询超时,请重试...");	
        }
        
        protected boolean isCustWaypoint(Waypoint_bean wb){
        	// QLog.getLogger().d(TAG, " is it a custWp? -----------------------------------------------" ); 
        	// QLog.getLogger().d(TAG, "is it a custWp?   wb.getTurnFlag():"+ wb.getTurnFlag());
        	// QLog.getLogger().d(TAG, "is it a custWp?  mwb.getName():"+wb.getName()+", road book:"+wb.getRoadBook());
//        	QLog.getLogger().d(TAG, " is it a custWp? (!TextUtils.isEmpty(wb.getName()))"+(!TextUtils.isEmpty(wb.getName())));
//        	int ispass=wb.getRoadBook().indexOf("到达【途经点") ;
//        	QLog.getLogger().d(TAG, " is it a custWp? wb.getRoadBook().indexOf( )>0 ?" +ispass); 
        	
//        	QLog.getLogger().d(TAG, " is it a custWp?"+((!TextUtils.isEmpty(wb.getName()))&&wb.getRoadBook().indexOf("到达【途经点")>0));
        	
//        	return  ((!TextUtils.isEmpty(wb.getName()))&&wb.getRoadBook().indexOf("到达【途经点")==0);
        	
        	/*return  wb.getTurnFlag().toInt()==wpFlag.CUST.toInt()
        			||wb.getTurnFlag().toInt()==wpFlag.TENT.toInt()
        			||wb.getTurnFlag().toInt()==wpFlag.REST.toInt();*/
        	return wb.getTurnFlag().toInt()>=wpFlag.CUST.toInt();
//        	TextUtils.isEmpty(wb.getName())&&wb.getRoadBook().indexOf("到达【途经点")<0
        }
      
	   
	   @Override
		public void onResume() {
			/**
			 * MapView的生命周期与Activity同步，当activity恢复时需调用MapView.onResume()
			 */
		   

		   if(mTrack_bean==null){
			   super.onResume();
			   return;
		   }
		   
//		   if(mTrack_bean!=null)
			   mIsPaused =  mTrack_bean.getStatus() ==TrackStatus.PAUSED;
		   
		    setSelectedTrackType();
		 
		    if(  mTrack_bean.getTrackId()>0 && mPauseTimeText!=null &&!isPlaying){ 
		    	if(mTrack_bean.getSportTime()>lastsptime){
			    	lastsptime=mTrack_bean.getSportTime();			    	
			    }
	 
				if(mIsPaused){
					activity.app.restartPause();
				}
				
				updateTimeView(0);   
		    } 
			activity.app.updateUIstatus(true);
			
 		    updateUI(null, false); //TODO: review if it can be deleted
		   
			mornitorLocations(); 	 
		    // QLog.getLogger().d(dTAG,TAG+" "+"onResume, and trying to draw whole track." );
		    
		    setSpeechIcon();
		   
		   	super.onResume(); 
		}
		
		
		
		/* (non-Javadoc)
		 * @see android.support.v4.app.Fragment#onPause()
		 */
		@Override
		public void onPause() {
			/**
			 * MapView的生命周期与Activity同步，当activity挂起时需调用MapView.onPause()
			 */
 
			activity.app.updateUIstatus(false); 

			lastLocation =null;
			currentLocation = null;
			  
//			mRunning = false;
			QLog.getLogger().d(dTAG,TAG+" "+"onPause" );
			super.onPause();
		}


		@Override
		public void onDestroy() {
//			activity.updateTabVisibility(true);
			super.onDestroy();
		}


		@Override
		public boolean isShowBottomTabs() {
			// TODO Auto-generated method stub
			return false;
		}


		@Override
		public String getCurrentTag() {
			// TODO Auto-generated method stub
			return TAG;
		}


		@Override
		public void setTabOnFiling() {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void doQuery() {
			// TODO Auto-generated method stub
			
		}

//		String lastNavMsg="";
		@Override
		public void navInfo(final Location location ) {
			// TODO Auto-generated method stub
			if(ll_note==null)return;
			if(location==null)return;
			Bundle bd =location.getExtras();
			if(bd==null)return;
			if(navi_progress!=null){
				int progress = bd.getInt( QiYouConstant.NEW_NAVIFO_DIST_PROGRESS);
				navi_progress.setProgress(progress);
			} 
//			String msg =location.getExtras().getString( QiYouConstant.NEW_NAVIFO_MSG);
			if(txt_nav_info!=null)
				txt_nav_info.setText(bd.getString( QiYouConstant.NEW_NAVIFO_MSG));
			 
		    new Handler().post(new Runnable(){
	    		   @Override
				public void run() {
//	    			 
	    			 showNaviPaoPao(  location);
	    		   }
	    	   }); 
			  
			
			
			/*if(!msg.equalsIgnoreCase(lastNavMsg)){ 
//				ll_note.setVisibility(View.VISIBLE);	
				txt_nav_info.setText(location.getExtras().getString( QiYouConstant.NEW_NAVIFO_MSG));
				showNaviPaoPao(  location);
				lastNavMsg=msg;
			}else
				return;*/
		} 
	   
		protected  void showNaviPaoPao(Location location){}
	   
}
/*Handler myHandler = new Handler() {
    public void handleMessage(Message msg) {
        updateUIHere();
    }
}

new Thread() {
    public void run() {
        doStuff();         // 执行耗时操作
        Message msg = myHandler.obtainMessage();
        Bundle b = new Bundle();
        b.putString("key", "value");
        m.setData(b);    // 向消息中添加数据
        myHandler.sendMessage(m);    // 向Handler发送消息，更新UI
    }
}.start();*/




		    