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

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

 import org.apache.http.Header;
import org.apache.http.entity.StringEntity;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v7.widget.GridLayout;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import com.qiyou.mb.android.upgrade.UpdateManager;
//import android.widget.ImageView;
import com.qiyou.mb.android.utils.image.QimageView;

import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;

import com.loopj.android.http.JsonHttpResponseHandler;
import com.qiyou.mb.android.QiYouApplication;
import com.qiyou.mb.android.QiYouConstant;
import com.qiyou.mb.android.R;
import com.qiyou.mb.android.beans.Track;
import com.qiyou.mb.android.beans.basic.StatTrack;
import com.qiyou.mb.android.beans.basic.Statics_bean;
import com.qiyou.mb.android.beans.basic.TypeStatistics;
import com.qiyou.mb.android.content_providers.TrackProvider;
import com.qiyou.mb.android.service.TrackDbServiceBackground;
import com.qiyou.mb.android.ui.ChartSpeedKm;
import com.qiyou.mb.android.utils.QiyouRestClient;
import com.qiyou.mb.android.utils.Utils;
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.log.QLog;
//import com.qiyou.mb.android.service.TrackDbService;
 

/**
 * @author mwang
 *
 */
//public class TrackDetail_fragment extends TrackTabs_fragment  implements LoaderCallbacks<Cursor> {
public class TrackDetail_fragment extends TrackTabs_fragment {
 
	@Override
	public void setFTag(){
		TAG="com.qiyou.TrackDetail_fragment";
	}
	public static String getFTag(){
		return "com.qiyou.TrackDetail_fragment";
	}
	@Override
	public String getCurrentTag(){
		return "com.qiyou.TrackDetail_fragment";
	}
	
	ProgressDialog progressDialog ;
    private Handler handler ;
//	private View vContainer;
//	private String trackId;
	int lastId =0;
//    protected MainActivity activity;
      QiYouApplication app;
//    private boolean getLastTrack =false;
//    Track lastTrack;
    Track currentTrack;
    Statics_bean currentStat;
    Statics_bean lastStat;
    TypeStatistics TypeStatistics;
    int inflat_source ;
    int inType=-1;
    boolean showSecondes =false;
//    boolean isWebRequest =false;
    
	/**
	 * 
	 */
	public TrackDetail_fragment() {
		// TODO Auto-generated constructor stub
		workingTrackType= WorkingTrackType.DETAIL;
	}

 	public static TrackDetail_fragment newInstance(int inType,int trackId)
	{
		
		TrackDetail_fragment f = new TrackDetail_fragment();
		Bundle args = new Bundle(); 
//	    args.putString(QiYouConstant.EXTRA_KEY_ID, trackId);
//	    args.putString(QiYouConstant.EXTRA_KEY_TYPE, inType);
	    args.putInt(QiYouConstant.EXTRA_KEY_ID, trackId);
	    args.putInt(QiYouConstant.EXTRA_KEY_TYPE, inType);
	    f.setArguments(args);
	    return f;
	}
	 
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);		
		isShowEdit=true;
		app = (QiYouApplication) this.getActivity().getApplication();
		if(activity==null){
			    activity = (com.qiyou.mb.android.ui.MainActivity)getActivity();
			}
//		if(activity.app.currentTrack!=null)app.initialStatTrack(activity.app.currentTrack.getTrackBean().getType().toInt());
		QLog.getLogger().d(dTAG, TAG+" onCreate, app Current trackid is: "+ app.getCurrentTrack().getTrackBean().getTrackId());
		inflat_source =R.layout.track_chart_detailfragment;
	}
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		activity.app.playBack=false;
		isPlayback=false;
//		 mTrack =activity.app.getCurrentTrack(); 
		
//		int source =R.layout.track_chart_detailfragment;
//		source =R.layout.track_chart_detailfragment;
		vContainer = inflater.inflate(inflat_source, container, false);	
		super. onCreateView( inflater,  container, savedInstanceState);
 
		initialDetailViews();
//		initViewMap();
	    if (getArguments() != null) {	      
//	        String  Id = getArguments().getString(QiYouConstant.EXTRA_KEY_ID);
//	        if(Id!=null)trackId =Integer.valueOf(Id);
	        trackId =getArguments().getInt(QiYouConstant.EXTRA_KEY_ID);
//	        String t=getArguments().getString(QiYouConstant.EXTRA_KEY_TYPE);
//	        if(!TextUtils.isEmpty(t))
//	        	inType=Integer.valueOf(t);
	        inType = getArguments().getInt(QiYouConstant.EXTRA_KEY_TYPE);
	         isWebRequest = getArguments().getBoolean(QiYouConstant.EXTRA_KEY_WEB_REQUEST);
	      }
	    
	    if(!activity.app.playBack) 
	    	initialFootmark();
	    chk_showChats.setVisibility(View.GONE);
		
		
//		initialGestureDetector();
		return vContainer;
		}
	
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) { 
		super.onActivityCreated(savedInstanceState);
//		   activity = (MainActivity)getActivity();
//		   activity.app.currentActiveFragment =TAG;  
		 
		   QLog.getLogger().d(dTAG, TAG+ " onActivityCreated, get id from bundle is: "+ trackId  );
		   QLog.getLogger().d(dTAG, TAG+" onActivityCreated, app Current trackid is: "+ app.getCurrentTrack().getTrackBean().getTrackId());
//		   lastId= trackId.intValue() -1;	
		   getStat();
		   		/*if(!isWebRequest)
				if(activity.app.mStatistics!=null 
						&&activity.app.mStatistics.getStatisticsTracks().get(inType)!=null){
					 
					ConcurrentHashMap<Integer,Statics_bean> sbs =activity.app.mStatistics.getStatisticsTracks().get(inType).getSbs();
					  
					currentStat =sbs.get(trackId);	
				   
//					try{
						QLog.getLogger().d(dTAG, TAG+" activity.app.mStatistics.getStatisticsTracks()" +
								".get(inType).getTrackIds()" +
								".get(trackId)"
								+(activity.app.mStatistics.getStatisticsTracks().get(inType).getTrackIds().get(trackId)==null));
					lastId =activity.app.mStatistics.getStatisticsTracks().get(inType).getTrackIds().get(trackId)==null?//  05-14 20:53:59.159   491   636 I am_crash: [24750,com.qiyou.mb.android,572998,java.lang.NullPointerException,NULL,TrackDetail_fragment.java,135]: system_server
								0:activity.app.mStatistics.getStatisticsTracks().get(inType).getTrackIds().get(trackId) ; //int 不能赋值null
					
					lastStat =lastId>0?activity.app.mStatistics.getStatisticsTracks().get(inType).getSbs().get(lastId):null ;	
					
					if(lastStat==null || lastId==0 && trackId>1){
						for(int i=trackId-1;i>0;i--)
							if(activity.app.mStatistics.getStatisticsTracks().get(inType).getSbs().get(i)!=null){
								lastId=i;
								break;
							}
					}
					
					
//					}
//					catch(Exception e){
//						Utils.logStackTrace(e, dTAG);
//					}    bundle.putInt("id", mTrack_bean.getTrackId());
	 
					lastStat =lastId>0?activity.app.mStatistics.getStatisticsTracks().get(inType).getSbs().get(lastId):null ;	
				}*/
		         setTrackDesc();
//				 setTrackDetail1();//set current track information with currentStat. 
				 getLastTrackDetail(); 
				 getStatTrack();
				 setTrackDetailMax();
	 	  
     	  
//		   	progressDialog = ProgressDialog.show(activity, "请稍等...", "获取数据中...", true);
		 
//				 tabhost.setEnabled(false);
				 
//				 for(int i=1;i<tabhost.getTabWidget().getChildCount();i++)
//					 tabhost.getTabWidget().getChildAt(i).setVisibility(View.GONE);
//				 tabhost.getChildAt(i).setVisibility(View.GONE);
		   	handler = new Handler(){

				@Override
				public void handleMessage(Message msg) {
					
					//关闭ProgressDialog
//					progressDialog.dismiss();
					
					if(msg.what==0){
					//更新UI
					
 
//					 getLastTrackDetail(); 
//				     setTrackDetail3(); 
					 setWorkingTrack();
//					 getStatTrack();
//					 setTrackDetailMax();  
					 setStaticMap();
					 setTrackDesc();
				     //populate data tab of footmark,map,charts
					 if(isAdded()){  //java.lang.IllegalStateException: Fragment TrackDetail_fragment{42823558} not attached to Activity
						 drawTrack(); 
					 }
				     showFootmarkData(true);
				     showCharts();
				     validEditButtons();
//				     tabhost.setEnabled(true);
//				     for(int i=1;i<tabhost.getTabWidget().getChildCount();i++)
//				    	 tabhost.getTabWidget().getChildAt(i).setVisibility(View.VISIBLE);
//				     
				     showTabs(true);
					 topWaiting=0;
					}
					else if(msg.what==1){
						setTabhostTitle();
//						mMsgText.setVisibility(View.VISIBLE);
//						mMsgText.setText("查询超时,请重试");
					    topWaiting=0;
					}
//					if(mTrack.getTrackBean().getType()==TrackType.GPX)
						setTrackDetail1();
				}};
		   
				new Thread(){

					@Override
					public void run() {
						//需要花时间计算的方法	 
//						app.currentTrack = app.getTrackCache().get(trackId);
//						currentTrack =app.currentTrack ;
						if(!isWebRequest)
						while( app.getCurrentTrack().getTrackBean().getTrackId() != trackId 
								||app.getCurrentTrack().getTrackBean().getTrkseg().isEmpty()							 
//								|| app.getStatisticsTrack(app.getCurrentTrack().getTrackBean().getType().toInt()).getSbs().size()==0
//			        			||app.mStatisticsTracks!=null && 
//			        				app.mStatisticsTracks.get(app.getCurrentTrack().getTrackBean().getType().toInt()).getStaticsTrackBeans().size()==0
			        		 ){
//			        	 			        		
//							app.currentTrack = app.getTrackCache().get(trackId);
							app.setCurrentTrack(app.getTrackCache().get(trackId), isWebRequest);
							currentTrack =app.currentTrack ;
 			        	 try {
			 				Thread.sleep(100);
			 				topWaiting+=100;
			 				QLog.getLogger().d(dTAG, TAG+" topWaiting:"+topWaiting);
 	 				 
			 				if(topWaiting>QiYouConstant.MAX_TIME_GET_TRACK_FROM_DB   )
			 				{ 
			 					QLog.getLogger().d(dTAG, TAG+" topWaiting:"+topWaiting+",limit is:"+QiYouConstant.MAX_TIME_GET_TRACK_FROM_DB );
			 					if(app.getCurrentTrack().getTrackBean().getTrackId() != trackId)
			 					{
				 					handler.sendEmptyMessage(1);
				 					
			 					} else
			 						handler.sendEmptyMessage(0);
			 					
			 					 return;
			 				}
			 			  } catch (InterruptedException e) {
			 				// TODO Auto-generated catch block
			 				Utils.logStackTrace(e, TAG);
			 				}
				    	}
			    		 
			         
						//向handler发消息
						handler.sendEmptyMessage(0);
					}}.start();
		     	 
					 
	}
	
	
	 @Override
		protected void initialViews(){		
			 super.initialViews();
	 		 initialCateViews();
			 
			 /* td_btnShowChartKm1 = (Button) vContainer.findViewById(R.id.td_btnShowChartKm1);  
				 if(td_btnShowChartKm1!=null)
					 td_btnShowChartKm1.setOnClickListener(ButtonOnClickListener);
				 td_btnShowChartSpeed1 = (Button) vContainer.findViewById(R.id.td_btnShowChartSpeed1);  
				 if(td_btnShowChartSpeed1!=null)
					 td_btnShowChartSpeed1.setOnClickListener(ButtonOnClickListener);
				 td_btnShowChartEle1 = (Button) vContainer.findViewById(R.id.td_btnShowChartEle1);  
				 if(td_btnShowChartEle1!=null)
					 td_btnShowChartEle1.setOnClickListener(ButtonOnClickListener);  */
				 
		 }
		   void initialCateViews(){
			 cateLv = (com.qiyou.mb.android.ui.fragments.InnerGridView) vContainer.findViewById(R.id.cate_list); 
			 cateLv. setOnTouchListener(new OnTouchListener() {
				    @Override
				    public boolean onTouch(View v, MotionEvent event) {
		 		        Utils.hideSoftKeyboard(activity);
				        return false;
				    }
				});
			 
			   editNewCate=(EditText) vContainer.findViewById(R.id.edit_newCate); ;
//			   editNewCate.setFilters(new InputFilter[]{new InputFilter.LengthFilter(10)}); 
//		  	   editNewCate.setSelectAllOnFocus(true); 
		  	 editNewCate.setVisibility(View.GONE);
		   btnNewCate =(Button) vContainer.findViewById(R.id.btnSaveCate); 
		   btnNewCate.setOnClickListener(
				   new android.view.View.OnClickListener() {
					    @Override
						public void onClick(View view) {
					    	 Utils.hideSoftKeyboard(activity); 
					    	 final EditText inputServer = new EditText(activity);
					    	 inputServer.setHint("请输入新标签（10字内）");
					    	 inputServer.setFilters(new InputFilter[]{new InputFilter.LengthFilter(10)}); 
					    	 AlertDialog.Builder builder = new AlertDialog.Builder(activity);
			                 builder.setTitle("输入新标签").setIcon(android.R.drawable.ic_dialog_info).setView(inputServer)
			                         .setNegativeButton("取消", null);
			                 builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { 
			                     public void onClick(DialogInterface dialog, int which) {  
			                    	 editNewCate.setText(inputServer.getText());
			                    	 saveNewCate();
			                     }
			                 });
			                 builder.show();
					    	 
					    	   
					    }

						 }
				   );   
		 
		  }
		    
		 @Override
		 protected void saveNewCate(){
			 
			 String newCate= editNewCate.getText().toString();
			 if(TextUtils.isEmpty(newCate)){
				 editNewCate.setText(R.string.new_category);
				 return;
			 }
		 	 if(editNewCate.getText().toString().equalsIgnoreCase(
					 activity.getResources().getString(R.string.new_category))){
				 newCate =null;			 
			 }  
//			 editNewCate.setText(R.string.new_category);
			 	 
//			 if(TextUtils.isEmpty(newCate))return;
			 String msg="";
			 isCateChangesSaved =activity.app.updateCates(newCate);
			 if(isCateChangesSaved){
				 msg ="更改已提交保存。";
				 Toast.makeText(activity, msg, Toast.LENGTH_SHORT).show();
//				 editNewCate.clearFocus();	
				 showCategoryList(cateLv,textContainer); 
			 }
//			 else  
//			 editNewCate.selectAll();
//			 editNewCate.setText("");
//			 else
//				 msg ="没有更改需要保存。";
//			 Toast.makeText(activity, msg, Toast.LENGTH_SHORT).show();
			 
		 }
		 
		 @Override
		 void initialFootmark(){
			 super.initialFootmark();
//			 textContainer =(ScrollView)vContainer.findViewById(R.id.td_scrollView); 		  
			  if(textContainer!=null)
			     textContainer.setOnTouchListener(new OnTouchListener() {
				    @Override
				    public boolean onTouch(View v, MotionEvent event) {
		 		        Utils.hideSoftKeyboard(activity);
				        return false;
				    }
				});
		 
		 }	 
		 
		 
	
	void getStat(){
		if(!isWebRequest)
			if(activity.app.mStatistics!=null 
					&&activity.app.mStatistics.getStatisticsTracks().get(inType)!=null){
				 
				ConcurrentHashMap<Integer,Statics_bean> sbs =activity.app.mStatistics.getStatisticsTracks().get(inType).getSbs();
				  
				currentStat =sbs.get(trackId);	
			   
//				try{
					QLog.getLogger().d(dTAG, TAG+" activity.app.mStatistics.getStatisticsTracks()" +
							".get(inType).getTrackIds()" +
							".get(trackId)"
							+(activity.app.mStatistics.getStatisticsTracks().get(inType).getTrackIds().get(trackId)==null));
				lastId =activity.app.mStatistics.getStatisticsTracks().get(inType).getTrackIds().get(trackId)==null?//  05-14 20:53:59.159   491   636 I am_crash: [24750,com.qiyou.mb.android,572998,java.lang.NullPointerException,NULL,TrackDetail_fragment.java,135]: system_server
							0:activity.app.mStatistics.getStatisticsTracks().get(inType).getTrackIds().get(trackId) ; //int 不能赋值null
				
				lastStat =lastId>0?activity.app.mStatistics.getStatisticsTracks().get(inType).getSbs().get(lastId):null ;	
				
				if(lastStat==null || lastId==0 && trackId>1){
					for(int i=trackId-1;i>0;i--)
						if(activity.app.mStatistics.getStatisticsTracks().get(inType).getSbs().get(i)!=null){
							lastId=i;
							break;
						}
				}
				
				
//				}
//				catch(Exception e){
//					Utils.logStackTrace(e, dTAG);
//				}    bundle.putInt("id", mTrack_bean.getTrackId());
 
				lastStat =lastId>0?activity.app.mStatistics.getStatisticsTracks().get(inType).getSbs().get(lastId):null ;	
			}
	}
	int topWaiting=0;
	public int topWaitingCount(){
		return ++topWaiting;
	}
	
	@Override
	protected void drawTrack(){
		 
			  canDrawTrack=app.getCurrentTrack().getTrackBean().getTrackId() == trackId;
			  canDrawTrack=canDrawTrack ||this.isWebRequest && app.getCurrentTrack().getTrackBean().getSvrNumber() == trackId;
			  super.drawTrack();
		 
	 }

	@Override
	protected void initialTabhost(){

		  tabhost = (TabHost)vContainer.findViewById(R.id.tabhost);
		 tabhost.setup();  

        TabHost.TabSpec dataSpec = tabhost.newTabSpec(tabData); // This param will
                                                            // be used as tabId.
//        homeSpec.setIndicator(null,     getResources().getDrawable(R.drawable.empty_photo));
        dataSpec.setIndicator(tabData);
        dataSpec.setContent(R.id.tab_statistic);
        tabhost.addTab(dataSpec); 
         super.initialTabhost();  
	}
	
	  @Override  
			protected void showMapViews(){ 
	 
			  super.showMapViews();
//				LinearLayout tm_ll_top_txt =(LinearLayout)vContainer.findViewById(R.id.tm_ll_top_txt); 
//				tm_ll_top_txt.setVisibility( View.VISIBLE );
//				
				LinearLayout trackDetail =(LinearLayout)vContainer.findViewById(R.id.ll_recording_data);
//				tm_ll_top_txt.setVisibility(ll.getVisibility()==View.GONE?View.VISIBLE:View.GONE);
				if(trackDetail!=null) trackDetail.setVisibility( View.GONE );
			    if(btnLocation!=null)
			    	btnLocation.setVisibility(View.GONE);
			 
			    if(this.btnRotation!=null)
					btnRotation.setVisibility(View.GONE);
				
				if(this.btnAutoZoom!=null)
					btnAutoZoom.setVisibility(View.GONE);
				
				if(this.btnSaveScreen!=null)
					btnSaveScreen.setVisibility(View.VISIBLE);  
				GridLayout grid_top_txt =(GridLayout)vContainer.findViewById(R.id.grid_top_txt);
				if(grid_top_txt!=null)grid_top_txt.setVisibility( View.VISIBLE );
				((TextView)this.vContainer.findViewById(R.id.tm_top_speed_title)).setText("均速");
//				takeMapScreenshot();
			
			} 
	
/*	@Override
	public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {	    
				    
	//	if (!getLastTrack  ) return   new CursorLoader(activity, null, null, null, null, null);		 
			  //  to load data from db.
 		String[] projection = new String[] {TrackProvider.KEY_TRACK_DISTANCE,
		   TrackProvider.KEY_TRACK_EDOWN_DIST ,TrackProvider.KEY_TRACK_EUP_DIST,
		   TrackProvider.KEY_TRACK_PAUSE_TIME ,TrackProvider.KEY_TRACK_TOPSPEED,
		   TrackProvider.KEY_TRACK_SPORT_TIME
		   };		
		    String selection = TrackProvider.KEY_ID + "='" + lastId + "'";
		    
		    return new CursorLoader(activity, TrackProvider.TRACKS_URI, projection, selection, null, null);
				 
		}	
	*/
  
	
	private TextView mSpeedText4;
	private TextView mSpeedText3;
	private TextView mSpeedText2;
	private TextView mSpeedText1;

	private TextView mtSpeedText4;
	private TextView mtSpeedText3;
	private TextView mtSpeedText2;
	private TextView mtSpeedText1;
	
	private TextView mBurnText1;
	private TextView mBurnText2;
	private TextView mBurnText3;
	private TextView mBurnText4;
	
	
	private TextView mTotalTimeText1;
	private TextView mTotalTimeText2;
	private TextView mTotalTimeText3;
	private TextView mTotalTimeText4;
	
	private TextView mDistanceText1;
	private TextView mDistanceText2;
	private TextView mDistanceText3;
	private TextView mDistanceText4;
	
	private TextView mRdText1;
	private TextView mRdText2;
	private TextView mRdText3;
	private TextView mRdText4;
	
	 
	
	private TextView mTopSpeedText1;
	private TextView mTopSpeedText2;
	private TextView mTopSpeedText3;
	private TextView mTopSpeedText4;
	
	private TextView mSportTimeText1;
	private TextView mSportTimeText2;
	private TextView mSportTimeText3;
	private TextView mSportTimeText4;
	
//	private TextView mPausedTimeText1;
//	private TextView mPausedTimeText2;
//	private TextView mPausedTimeText3;
//	private TextView mPausedTimeText4;
	
 
 
//	private TextView mOffTimeText1;
//	private TextView mOffTimeText2;
//	private TextView mOffTimeText3; 
//	private TextView mOffTimeText4; 
 
//	private TextView mTotaleDownText1;
//	private TextView mTotaleDownText2;
//	private TextView mTotaleDownText3;
//	private TextView mTotaleDownText4; 
	private TextView mTotaleUpText1;
	private TextView mTotaleUpText2;
	private TextView mTotaleUpText3;
	private TextView mTotaleUpText4;
	
	private TextView mTotalUpText1;
	private TextView mTotalUpText2;
	private TextView mTotalUpText3;
	private TextView mTotalUpText4;

	private TextView mTotalDownText1;
	private TextView mTotalDownText2;
	private TextView mTotalDownText3;
	private TextView mTotalDownText4; 
	
	private TextView mMaxEleText1;
	private TextView mMaxEleText2;
	private TextView mMaxEleText3;
	private TextView mMaxEleText4; 
	
	private TextView mMinEleText1;
	private TextView mMinEleText2;
	private TextView mMinEleText3;
	private TextView mMinEleText4; 
	
	private TextView mKmTimeText1;
	private TextView mKmTimeText2;
	private TextView mKmTimeText3;
	private TextView mKmTimeText4;  
	private TextView mTextAccount;
	private TextView mTrackType;  

//	private TextView mSummaryText;
//	private TextView mRoadBookText;//td_textView_roadbook
//	private Button btnSave;
//	private Button btnViewCompareChart;
//	private Button btnViewCurrentChart;
//	private Button btnRoadbook;
	private TextView mMsgText; 
 	protected Spinner spDetailTrackType; 

   void initialDetailViews()
	{
//		gf1 = (GifView) vContainer.findViewById(R.id.td_gif); 
       spDetailTrackType = (Spinner)vContainer.findViewById(R.id.SpinnerTrackType);
		mTrackId = (TextView) vContainer.findViewById(R.id.td_textView_TrackID);//
		mMsgText = (TextView) vContainer.findViewById(R.id.td_textView_Notice);

		mTrackStarTimeText = (TextView) vContainer.findViewById(R.id.td_textView_Startime);
		mTrackEndTimeText = (TextView) vContainer.findViewById(R.id.td_textView_EndTime);
		 
		mTrackType=(TextView) vContainer.findViewById(R.id.td_textView_trackType) ; 
		
		mSpeedText1 = (TextView) vContainer.findViewById(R.id.td_textView_av_speed1);
		mSpeedText2 = (TextView) vContainer.findViewById(R.id.td_textView_av_speed2);
		mSpeedText3 = (TextView) vContainer.findViewById(R.id.td_textView_av_speed3);
		mSpeedText4 = (TextView) vContainer.findViewById(R.id.td_textView_av_speed4);
		
		mtSpeedText1 = (TextView) vContainer.findViewById(R.id.td_textView_tavs1);
		mtSpeedText2 = (TextView) vContainer.findViewById(R.id.td_textView_tavs2);
		mtSpeedText3 = (TextView) vContainer.findViewById(R.id.td_textView_tavs3);
		mtSpeedText4 = (TextView) vContainer.findViewById(R.id.td_textView_tavs4);
		
		mBurnText1 = (TextView) vContainer.findViewById(R.id.td_textView_burn1);
		mBurnText2 = (TextView) vContainer.findViewById(R.id.td_textView_burn2);
		mBurnText3 = (TextView) vContainer.findViewById(R.id.td_textView_burn3);
		mBurnText4 = (TextView) vContainer.findViewById(R.id.td_textView_burn4);
		
		mTextAccount  = (TextView) vContainer.findViewById(R.id.td_textView_account);
		

		mTotalTimeText1 = (TextView) vContainer.findViewById(R.id.td_textView_totalTime1);
		mTotalTimeText2 = (TextView) vContainer.findViewById(R.id.td_textView_totalTime2);
		mTotalTimeText3 = (TextView) vContainer.findViewById(R.id.td_textView_totalTime3);
		mTotalTimeText4 = (TextView) vContainer.findViewById(R.id.td_textView_totalTime4);
		
		mSportTimeText1 = (TextView) vContainer.findViewById(R.id.td_textView_sport_time1);
		mSportTimeText2 = (TextView) vContainer.findViewById(R.id.td_textView_sport_time2);
		mSportTimeText3 = (TextView) vContainer.findViewById(R.id.td_textView_sport_time3);
		mSportTimeText4 = (TextView) vContainer.findViewById(R.id.td_textView_sport_time4);
		
		
		mDistanceText1 = (TextView) vContainer.findViewById(R.id.td_textView_Distance1 );
		mDistanceText2 = (TextView) vContainer.findViewById(R.id.td_textView_Distance2);
		mDistanceText3 = (TextView) vContainer.findViewById(R.id.td_textView_Distance3); 
		mDistanceText4 = (TextView) vContainer.findViewById(R.id.td_textView_Distance4);
		

		mRdText1 = (TextView) vContainer.findViewById(R.id.td_textView_maxRd1 );
		mRdText2 = (TextView) vContainer.findViewById(R.id.td_textView_maxRd2 );
		mRdText3 = (TextView) vContainer.findViewById(R.id.td_textView_maxRd3 );
		mRdText4 = (TextView) vContainer.findViewById(R.id.td_textView_maxRd4 );
		 
		
		mTopSpeedText1 = (TextView) vContainer.findViewById(R.id.td_textView_top_speed1 );
		mTopSpeedText2 = (TextView) vContainer.findViewById(R.id.td_textView_top_speed2);
		mTopSpeedText3 = (TextView) vContainer.findViewById(R.id.td_textView_top_speed3);
		mTopSpeedText4 = (TextView) vContainer.findViewById(R.id.td_textView_top_speed4);

//		mPausedTimeText1 = (TextView) vContainer.findViewById(R.id.td_textView_paused_time1 );
//		mPausedTimeText2 = (TextView) vContainer.findViewById(R.id.td_textView_paused_time2);
//		mPausedTimeText3 = (TextView) vContainer.findViewById(R.id.td_textView_paused_time3);
//		mPausedTimeText4 = (TextView) vContainer.findViewById(R.id.td_textView_paused_time4);
		
//		mOffTimeText1 = (TextView) vContainer.findViewById(R.id.td_textView_off_time1 );
//		mOffTimeText2 = (TextView) vContainer.findViewById(R.id.td_textView_off_time2);
//		mOffTimeText3 = (TextView) vContainer.findViewById(R.id.td_textView_off_time3);
//		mOffTimeText4 = (TextView) vContainer.findViewById(R.id.td_textView_off_time4);
		
		
		mTotaleUpText1 = (TextView) vContainer.findViewById(R.id.td_textView_eUp1 );
		mTotaleUpText2 = (TextView) vContainer.findViewById(R.id.td_textView_eUp2);
		mTotaleUpText3 = (TextView) vContainer.findViewById(R.id.td_textView_eUp3);
		mTotaleUpText4 = (TextView) vContainer.findViewById(R.id.td_textView_eUp4);
		
		mTotalUpText1 = (TextView) vContainer.findViewById(R.id.td_textView_Up1 );
		mTotalUpText2 = (TextView) vContainer.findViewById(R.id.td_textView_Up2);
		mTotalUpText3 = (TextView) vContainer.findViewById(R.id.td_textView_Up3);
		mTotalUpText4 = (TextView) vContainer.findViewById(R.id.td_textView_Up4);
		
		mTotalDownText1 = (TextView) vContainer.findViewById(R.id.td_textView_Down1);
		mTotalDownText2 = (TextView) vContainer.findViewById(R.id.td_textView_Down2);
		mTotalDownText3 = (TextView) vContainer.findViewById(R.id.td_textView_Down3);
		mTotalDownText4 = (TextView) vContainer.findViewById(R.id.td_textView_Down4);
		
		mMaxEleText1 = (TextView) vContainer.findViewById(R.id.td_textView_Maxe1);
		mMaxEleText2 = (TextView) vContainer.findViewById(R.id.td_textView_Maxe2);
		mMaxEleText3 = (TextView) vContainer.findViewById(R.id.td_textView_Maxe3);
		mMaxEleText4 = (TextView) vContainer.findViewById(R.id.td_textView_Maxe4);
		
		mMinEleText1 = (TextView) vContainer.findViewById(R.id.td_textView_Mine1);
		mMinEleText2 = (TextView) vContainer.findViewById(R.id.td_textView_Mine2);
		mMinEleText3 = (TextView) vContainer.findViewById(R.id.td_textView_Mine3);
		mMinEleText4 = (TextView) vContainer.findViewById(R.id.td_textView_Mine4);
		
		mKmTimeText1 = (TextView) vContainer.findViewById(R.id.td_textView_kmtime);
		mKmTimeText2 = (TextView) vContainer.findViewById(R.id.td_textView_kmtime2);
		mKmTimeText3 = (TextView) vContainer.findViewById(R.id.td_textView_kmtime3);
		mKmTimeText4 = (TextView) vContainer.findViewById(R.id.td_textView_kmtime4);
		
		shareView =(View) vContainer.findViewById(R.id.td_shareview);
		staticMapImg= (QimageView) vContainer.findViewById(R.id.td_staticMap);
//		mTotaleDownText1 = (TextView) vContainer.findViewById(R.id.td_textView_eDown1);
//		mTotaleDownText2 = (TextView) vContainer.findViewById(R.id.td_textView_eDown2);
//		mTotaleDownText3 = (TextView) vContainer.findViewById(R.id.td_textView_eDown3);
//		mTotaleDownText4 = (TextView) vContainer.findViewById(R.id.td_textView_eDown4);
		
	 	btnSave = (Button) vContainer.findViewById(R.id.td_btnSaveTtrack);
	 	btnDel = (Button) vContainer.findViewById(R.id.td_btnDelTtrack);
		btnUpload = (Button) vContainer.findViewById(R.id.td_btnUploadTtrack);
		btnShare = (Button) vContainer.findViewById(R.id.td_btnShareTtrack);
		if(btnShare!=null)
			btnShare.setOnClickListener(ButtonOnClickListener);
//		btnViewCompareChart = (Button) vContainer.findViewById(R.id.td_btnViewCompareChart);
//		btnViewCurrentChart = (Button) vContainer.findViewById(R.id.td_btnViewCurrentChart);
		td_btnPlayback= (Button) vContainer.findViewById(R.id.td_btnPlayback);
		td_btnContinue= (Button) vContainer.findViewById(R.id.td_btnContinue);
		btnNavi= (Button) vContainer.findViewById(R.id.td_btnNavi);  
//		btnRoadbook= (Button) vContainer.findViewById(R.id.td_btn_roadbook);
//		td_btn_export=(Button) vContainer.findViewById(R.id.td_btn_export);
//		td_btn_export.setOnClickListener(ButtonOnClickListener);
		if(btnSave!=null){
		  btnSave.setOnClickListener(ButtonOnClickListener);
		}
		if(btnDel!=null){
		  btnDel.setOnClickListener(ButtonOnClickListener);
		}
		if(btnUpload!=null){
			btnUpload.setOnClickListener(ButtonOnClickListener);
		}
		btnNavi.setOnClickListener(ButtonOnClickListener);
		 btnSNav=(Button) vContainer.findViewById(R.id.td_btnSNav);//
//		 btnSNav.setOnClickListener( ButtonOnClickListener);
		 
		 btnSNav.setOnClickListener( new android.view.View.OnClickListener() { 
			    @Override
				public void onClick(View view) {
			    	startNavi(true); 
			    	}
			    }
			 );
		 
//		btnViewCompareChart.setOnClickListener(ButtonOnClickListener);
//		btnViewCurrentChart.setOnClickListener(ButtonOnClickListener);
		td_btnPlayback.setOnClickListener(ButtonOnClickListener);
//		btnRoadbook.setOnClickListener(ButtonOnClickListener);
		
		if(td_btnContinue!=null)
			td_btnContinue.setOnClickListener(ButtonOnClickListener); 
//		initialTabhost();
//		initTrackTypeSpin();
//		initialChartViews();
		mMsgText.setVisibility(View.GONE);
		/*
		td_btnPlayback= (Button) vContainer.findViewById(R.id.td_btnPlayback);
		td_btnContinue= (Button) vContainer.findViewById(R.id.td_btnContinue);
//		btnRoadbook= (Button) vContainer.findViewById(R.id.td_btn_roadbook);
		td_btn_export=(Button) vContainer.findViewById(R.id.td_btn_export);
		btnSave.setOnClickListener(ButtonOnClickListener);
//		btnViewCompareChart.setOnClickListener(ButtonOnClickListener);
//		btnViewCurrentChart.setOnClickListener(ButtonOnClickListener);
		td_btnPlayback.setOnClickListener(ButtonOnClickListener);
//		btnRoadbook.setOnClickListener(ButtonOnClickListener);
		td_btn_export.setOnClickListener(ButtonOnClickListener); 
		td_btnContinue.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);  
	}
   
  
   @Override
   protected void  updateTrackAvstatus(){
	   if(mTrack_bean==null)return;
	   if(mTrack_bean.getAvStatus()!=TrackAvStatus.DELETED){
		   
//		   mTrack_bean.setAvStatus(TrackAvStatus.INACTIVE);
		   newAvailableDialog(); 
		   
	   }else{
		   mTrack_bean.setAvStatus(TrackAvStatus.ACTIVE);
		   btnDel.setText(R.string.delete); 
		   app.updateTrackAvStatus(mTrack_bean.getTrackId());
	   }	    
   }
 
  /* @Override
   protected void startNavi(){
	   activity.app.naviTrackId=trackId;
	   activity.startNaviService();
 
	   
   }; */
	protected void newAvailableDialog( ) {
		   AlertDialog.Builder builder = new Builder(activity);
		   builder.setMessage("您确认要删除记录吗？");
		   builder.setTitle("删除记录");
		   builder.setCancelable(true);
		   builder.setNeutralButton("取消", new OnClickListener() {
			   @Override
			   public void onClick(DialogInterface dialog, int which) {
			   dialog.dismiss();	 
				}
				});
		   builder.setPositiveButton("确认删除", new OnClickListener() {
		   @Override
		   public void onClick(DialogInterface dialog, int which) {
		   dialog.dismiss();	
			   
			   mTrack_bean.setAvStatus(TrackAvStatus.DELETED);
			   if(mTrack_bean.getType()!=TrackType.GPX){
				   app. mStatistics.trackMinus(app.getCurrentTrack());				
				   app.writeStatiscs();
			   }
			    //notice the UI
			   app.updateTrackAvStatus(mTrack_bean.getTrackId()); 
//			   app.tracks_cached.remove(Integer.valueOf(mTrack_bean.getTrackId()));
			   app.setGpxShowingTracks(String.valueOf(mTrack_bean.getTrackId()),false);
			   dialog.dismiss();	
			   activity.showLocalTrackList();
			   
			}
			});
		/*  builder.setNegativeButton("放入回收站", new OnClickListener() {
		 @Override
		 public void onClick(DialogInterface dialog, int which) {
			 
				 mTrack_bean.setAvStatus(TrackAvStatus.INACTIVE);
				 btnDel.setText(R.string.track_edit_restore); 
				 app.updateTrackAvStatus(mTrack_bean.getTrackId());
				 dialog.dismiss();
			 }
			 });*/
		  	builder.create().show();
		 	}
	
   
	@Override
	 protected void validEditButtons(){
			if(td_btnPlayback!=null){  
				//正在记录的track不可以回放
				boolean canNotPlay =   activity.app.currentTrack==null
										|| activity.app.currentTrack!=null 	  && activity.app.currentTrack.getTrackBean().getDistance()==0
										|| activity.app.recordingTrack!=null  
												&& activity.app.recordingTrack.getTrackBean().getTrackId() == activity.app.currentTrack.getTrackBean().getTrackId() 	
												&&	activity.app.recordingTrack.getTrackBean().getStatus()!=TrackStatus.FINISHED
										;
				td_btnPlayback.setEnabled(!canNotPlay);  
//				td_btnPlayback.setVisibility(canNotPlay?View.GONE:View.VISIBLE);
				
//				td_btnPlayback.setEnabled(activity.app.currentTrack!=null && activity.app.currentTrack.getTrackBean().getDistance()>0);
			}
			if(td_btnContinue!=null){				
				boolean canContinue =  activity.app.getRecordingTrack().getTrackBean().getTrackId() !=mTrack_bean.getTrackId();
				canContinue =canContinue 
						&& mTrack_bean.getAvStatus()!=TrackAvStatus.DELETED 
						&& mTrack_bean.getAvStatus()!=TrackAvStatus.INACTIVE
//						&& mTrack_bean!=null
						&& mTrack_bean.getTrackId()>0;
				td_btnContinue.setEnabled(canContinue );			
			}
			if(td_btn_export!=null)
				td_btn_export.setEnabled(mTrack_bean!=null&&mTrack_bean.getTrackId()>0);
			
			boolean canNavi= (td_btn_export!=null?td_btn_export.isEnabled():true ) 
					&& activity.app.getCurrentTrack().getTrackBean().getDistance()>0
					&& mTrack_bean!=null
//					&& app.naviTrackId!=mTrack_bean.getTrackId()
					&& mTrack_bean.getTrackId()!=activity.app.getRecordingTrack().getTrackBean().getTrackId()
//					&& !app.playBack
					;
 			if(btnNavi!=null){
 				btnNavi.setEnabled(canNavi); 				
 			} 
 		  
 			if(btnShare!=null){
 				btnShare.setEnabled(activity.app.getCurrentTrack().getTrackBean().getDistance()>0); 
 			}
			updateDelButton();
			updateUploadButton();
//			if(spDetailTrackType!=null){
//				spDetailTrackType.setVisibility( td_btnPlayback.getVisibility());	
//			}
			/*if(td_edit_Type!=null){
				if(spDetailTrackType.getVisibility()==View.GONE)
					td_edit_Type.setVisibility(View.VISIBLE);	
			}*/
			
			
//			if(td_btn_export!=null){ 
//				 
////				td_btn_export.setVisibility( td_btnPlayback.getVisibility());
////				 td_btn_export.setEnabled(QiYouConstant.DEVELOPER_MODE);
//			}
			super.validEditButtons(); 
			
		} 
	  @Override 
	  protected  void  continueTrack() {
//	    	td_btnContinue.setText("加载中。。。");
	    	td_btnContinue.setEnabled(false);
	    	activity.continueTrack();
	    }
	 
	  private void updateDelButton(){
		   if(workingTrackType==WorkingTrackType.DETAIL||workingTrackType==WorkingTrackType.GPX){
			   btnDel.setVisibility(View.VISIBLE);
			   btnDel.setEnabled(activity.app.getRecordingTrack().getTrackBean().getTrackId()!=trackId);
			   if(mTrack_bean.getAvStatus()!=TrackAvStatus.DELETED){ 
				   btnDel.setText(R.string.delete); 
			   }else{ 
				   btnDel.setText(R.string.track_edit_restore); 
			   }
			   
		   }
		   else	   
			   btnDel.setVisibility(View.GONE);
	   }
	  
	    void updateUploadButton(){  
		   
	    if(btnUpload==null){
	    	return;
	    }
	    	
//		  btnUpload.setEnabled(mTrack_bean.getStatus()!=TrackStatus.RECORDING && mTrack_bean.getDistance()>0);
		  btnUpload.setEnabled( mTrack_bean.getDistance()>0);
//		  btnUpload.setEnabled(mTrack_bean.getUserid()<=0  
//			 || mTrack_bean.getUserid()==QiYouConstant.PV_USER_ID);
		  
		  btnUpload.setText(mTrack_bean.getSvrNumber()>0?"更新云端":"上传云端");
//		  btnUpload.setVisibility(mTrack_bean.getDistance()>0?View.VISIBLE:View.GONE); 
	  }
	  
	 
//	    private String td_textView_Distance2;
//	    private String td_textView_eDown2;
//	    private String td_textView_eUp2;
////	    private String td_textView_paused_time2;
//	    private String td_textView_top_speed2;
//	    private String td_textView_SportTime2;  
//	    private String td_textView_TotalSportTime2;  
//	    private String td_textView_av_speed2;
//	    private String td_textView_tav_speed2;
////	    private String td_textView_OffTime2 ;  
//	    private String td_textView_Rd2  ;  

        /**
	   * {@inheritDoc}
	   * When the Loader has completed, schedule an update of the Fragment UI on the main application thread.
	   * 
	   */
	 
	 
	 private void getLastTrackDetail()
	 {
			if(lastStat==null) return;
	    	 
	    	 
			    
//				lastTrack = app.getTrackCache().get((Integer.valueOf(lastId)));
//	    		  td_textView_Distance2 =String.format("%.2f", lastStat.getDistance()/1000.0);
//			      td_textView_eDown2 = String.format("%.0f", Math.abs(lastStat.geteDownDist()));
//			      td_textView_eUp2 = String.format("%.0f", lastStat.geteUpDist()+lastStat.geteDownDist()) ;
//			      td_textView_eUp2 = String.format("%.0f", lastStat.geteUpDist()) ;

//			      td_textView_paused_time2 =   Utils.getTimeCnt(lastStat.getPause(),showSecondes);
//			      td_textView_top_speed2 =   String.format("%.2f", lastStat.getTopSpeed());
//			      td_textView_SportTime2 = Utils.getTimeCnt(lastStat.getSportTime() ,showSecondes); 
//			      td_textView_TotalSportTime2 =Utils.getTimeCnt( lastStat.getSportTime() +
//			    		  lastStat.getPause(),showSecondes); 
//			      td_textView_OffTime2 = Utils.getTimeCnt(lastStat.getOffTime(),showSecondes);
//			      td_textView_av_speed2 =String.format("%.2f",lastStat.getAVS());//String.format("%.2f", lastStat.getSportTime()>0?3600*lastStat.getDistance()/lastStat.getSportTime():0 ) ;
//			      td_textView_tav_speed2=String.format("%.2f",lastStat.getTAVS());
//			      td_textView_Rd2 = String.format("%.2f", lastStat.getMaxRdist()/1000.0 );
	    	 
			setLastTrackDetai();
	 }
	 
	 
	 protected void setLastTrackDetai(){ 
//			      handler.post(new Runnable () {
//				        public void run() {
				        	mTopSpeedText2.setText(String.format("%.2f", lastStat.getTopSpeed()));
				        	mDistanceText2.setText(String.format("%.2f", lastStat.getDist()/1000.0));			        	
				        	mTotaleUpText2.setText(String.format("%.0f", lastStat.geteUpDist()) );
				        	if( lastStat.getUpDist()>0){ 
					        	mTotalUpText2.setText(String.format("%.2f", lastStat.getUpDist()/1000)  );
					        	mTotalDownText2.setText(String.format("%.2f", lastStat.getDownDist()/1000)  );
					        	mMaxEleText2.setText(String.format("%.0f", lastStat.getMaxEle())  );
					        	mMinEleText2.setText(String.format("%.0f", lastStat.getMinEle())  );
				        	}
//				        	mTotaleDownText2.setText(td_textView_eDown2);
				        	mSportTimeText2.setText( Utils.getTimeCnt(lastStat.getSportTime() ,showSecondes)); 
//				        	mPausedTimeText2.setText(td_textView_paused_time2);  
				        	mSpeedText2.setText(String.format("%.2f",lastStat.getAvs()));
				        	mtSpeedText2.setText(String.format("%.2f",lastStat.getTavs()));
				        	mBurnText2.setText( String.format("%.0f", lastStat.getBurn() ));
				            mTotalTimeText2.setText(Utils.getTimeCnt( lastStat.getSportTime() +   lastStat.getPause(),showSecondes));
//				            mOffTimeText2.setText(td_textView_OffTime2);
				            mRdText2.setText(String.format("%.2f", lastStat.getMaxR()/1000.0 ));
				            if(lastStat.getKmTime()>0)
				            	mKmTimeText2.setText(Utils.getTimeMS(lastStat.getKmTime()));
//				        }        
//				      });
	    	 
	 }

/*	@Override
	public void onLoaderReset(Loader<Cursor> arg0) {
		// TODO Auto-generated method stub
		
	}   
	*/
//	GifView gf1;
	 
	 
	
	 
	 
	 void setVersion(){
		 
		 TextView versionName =(TextView)vContainer.findViewById(R.id.i7lv_words);
		 versionName.setText(versionName.getText() +" V"+ UpdateManager.getVersionName(app)+(QiYouConstant.DEVELOPER_MODE?":-D":"")); 
	 }
	 
	 
	 
	protected void setTrackDetail1()
	{ 
//		if(app.getCurrentTrack().getTrackBean().getTrackId() != trackId && app.getRecordingTrack().getTrackBean().getTrackId() == trackId)
//			activity.app.setCurrentTrack(activity.app.getRecordingTrack());
 
//					  currentTrack = app.getTrackCache().get(trackId);
//					  lastTrack = app.getTrackCache().get((Integer.valueOf(lastId)));
					  
//					  Iterator<Integer> reader=app.getTrackCache().keySet().iterator();
//					 
//					  while(reader.hasNext())
//					  {
//						  int i =reader.next();
//						  Track tr = app.getTrackCache().get(i);
//						  QLog.getLogger().d(dTAG, TAG+ " app.getTrackCache().get(i)'s track id, key of "+i +" : "+ tr.getTrackBean().getTrackId() );
//					  }
//					  
					setVersion();
					  QLog.getLogger().d(dTAG, TAG+ " ..................end of get ids............. "+  System.currentTimeMillis() );
					  if(currentStat ==null){
						  
						  if(app.getCurrentTrack().getTrackBean().getTrackId() == trackId){
							  currentStat = new Statics_bean(app.getCurrentTrack().getTrackBean()) ;
						  }
						  else							  
							  return;
					  }
					  
					  if(app.getCurrentTrack().getTrackBean().getTrackId() == trackId){ //check and update the statistics
						  try{
							  if(currentStat.getAvs()!=app.getCurrentTrack().getTrackBean().getAvs()){
							     app. mStatistics.trackMinus(app.getCurrentTrack());
								 app. mStatistics.mergeTrack(app.getCurrentTrack());
	//								 if( canSendLocation2UI)
										 app.writeStatiscs();
										 getStat();
							  }
						  }catch(Exception e){
							  
						  }
						  
//						  currentStat = new Statics_bean(app.getCurrentTrack().getTrackBean()) ;
						  
						  
						  
					  }
 
					  if(currentStat ==null){ // some case cause currentStat = null
						  
						  if(app.getCurrentTrack().getTrackBean().getTrackId() == trackId){
							  currentStat = new Statics_bean(app.getCurrentTrack().getTrackBean()) ;
						  }
						  else							  
							  return;
					  }
					  
					  
					  String td_trackEndTime = Utils.getFormatedTime(currentStat.getEndTime()) ;//+currentStat.getStatus() ;
				      if(activity.app.getRecordingTrack().getTrackBean().getTrackId()==trackId)
				    	  td_trackEndTime="运动进行中";
//				      final String td_textView_OffTime1 = Utils.getTimeCnt( currentStat.getOffTime(),showSecondes); 
				      
//				      final String td_textView_Rd1 = String.format("%.2f", currentStat.getMaxRdist()/1000.0 );
//				      final String td_textView_name =currentStat.getName();
				      
				      mDistanceText1.setText(String.format("%.2f", currentStat.getDist()/1000.0 ));	
				      mTotalTimeText1.setText(Utils.getTimeCnt(  currentStat.getTotalTime(),showSecondes));				    	
				      mRdText1.setText(String.format("%.2f", currentStat.getMaxR()/1000.0 ));
				      if(currentStat.getSvrNo()>0)
					    	mTrackId.setText(String.valueOf(currentStat.getSvrNo()));
//				     if(mTrack.getTrackBean().getType()==TrackType.GPX && currentStat.getSvrNo()==0 ||mTrack.isLushu())
				      
//				      mTextAccount.setText(mTrack_bean.getUserName());
				      if(activity.app.user!=null){
				    	  mTextAccount.setText(mTrack_bean.getUserid()==activity.app.user.getUserbean().getId()?activity.app.user.getUserbean().getUserName()/*.getAccount()*/:"");
				      }
				      if(mTrack.isLushu())
				    	  return;
				    	
				    if(mTrackStarTimeText==null)return;
				      
//				    if(currentStat.getSvrNo()>0)
//				    	mTrackId.setText(String.valueOf(currentStat.getSvrNo()));
//				    mTrackId.setText(String.valueOf(trackId));				    
					mTrackStarTimeText.setText(Utils.getFormatedTime(currentStat.getStartTime()) );
					mTrackEndTimeText.setText(td_trackEndTime);
				//	mSummaryText.setText(td_textView_Distance1);		
//					mRoadBookText.setText(td_textview_roadbook);
					
				    if(currentStat.getTopSpeed()>= currentStat.getAvs())
				    	mTopSpeedText1.setText(String.format("%.2f", currentStat.getTopSpeed()));
					if(mSpeedText1!=null)
						mSpeedText1.setText(String.format("%.2f", currentStat.getAvs() ));
					mtSpeedText1.setText( String.format("%.2f", currentStat.getTavs() ));
					if(mBurnText1!=null)
						mBurnText1.setText( String.format("%.0f", currentStat.getBurn() ));
			    		
			    
			    	mTotaleUpText1.setText(String.format("%.0f",currentStat.geteUpDist()));
			    	
//			    	mTotaleDownText1.setText(td_textView_eDown1);
			    	if(mSportTimeText1!=null)
			    		mSportTimeText1.setText(Utils.getTimeCnt( currentStat.getSportTime(),showSecondes));
//			    	mPausedTimeText1.setText(td_textView_paused_time1);  
			    	if(currentStat.getUpDist()>0 ){
				    	mTotalUpText1.setText(String.format("%.2f",currentStat.getUpDist()/1000));	
				    	mTotalDownText1.setText(String.format("%.2f",currentStat.getDownDist()/1000));
				    	mMaxEleText1.setText(String.format("%.0f",currentStat.getMaxEle()));
				    	mMinEleText1.setText(String.format("%.0f",currentStat.getMinEle()));
			    	}
			    	if(currentStat.getKmTime()>0)
			    		mKmTimeText1.setText(Utils.getTimeMS(currentStat.getKmTime()));	
//			        showCharts(2);
//			        td_btnPlayback.setEnabled(currentTrack.getTrackBean().getStatus() != QiYouConstant.TRACK_STATUS_TRACKING);
//			        td_btnPlayback.setEnabled(activity.app.getRecordingTrack().getTrackBean().getTrackId() != trackId 
//			        		 || activity.app.getRecordingTrack().getTrackBean().getTrackId()  == trackId 
//			        		    && activity.app.getRecordingTrack().getTrackBean().getStatus()!=QiYouConstant.TRACK_STATUS_TRACKING);
//	        }        
//	      });
			    	validEditButtons();	
			    	 
		                

	}
	@Override
	protected void setStaticMap(){
		super.setStaticMap();
		 if(staticMapImg==null)return;
		 IL.DisplayImage(mTrack.getStaticMap(),staticMapImg); 
		 /*
		   if(mTrack.isStaticMapExist()){
	    		 IL.DisplayImage(mTrack.getStaticMap(),staticMapImg); 
	    	 }
	    	 else
	    	 
	    		 staticMapImg.setVisibility(View.GONE);*/
            
	   }

	
/*	 private void getTrackDetailUpdated(){
		app.getCurrentTrack().getTrackBean().setName(mNameEdit.getText().toString());
		app.getCurrentTrack().getTrackBean().setComment(mCommentEdit.getText().toString());
		app.getCurrentTrack().getTrackBean().setDescription(mDescEdit.getText().toString());
		 
	}*/
 
	
	protected void setTrackDetailMax()
	{if(TypeStatistics==null)return;
		mTopSpeedText3.setText(String.format("%.2f", TypeStatistics.getStatTrack().getTopSpeed()));
		mSpeedText3.setText(String.format("%.2f",TypeStatistics.getStatTrack().getAvSpeed()));
		mtSpeedText3.setText(String.format("%.2f",TypeStatistics.getStatTrack().getTavSpeed()));
		mBurnText3.setText( String.format("%.0f", TypeStatistics.getStatTrack().getBurn() ));
    	mDistanceText3.setText(String.format("%.2f",TypeStatistics.getStatTrack().getDist()/1000));
    	mTotaleUpText3.setText(String.format("%.0f",TypeStatistics.getStatTrack().getUpDistE()));
    	if(TypeStatistics.getStatTrack().getUpDistE()>0){ 
	    	mTotalUpText3.setText(String.format("%.2f",TypeStatistics.getStatTrack().getUpDistE()/1000));
	    	mTotalDownText3.setText(String.format("%.2f",TypeStatistics.getStatTrack().getDownDist()/1000));
	    	mMaxEleText3.setText(String.format("%.0f",TypeStatistics.getStatTrack().getMaxEle()));
	    	mMinEleText3.setText(String.format("%.0f",TypeStatistics.getStatTrack().getMinEle()));
    	}
//    	mTotaleDownText3.setText(String.format("%.0f", Math.abs(TypeStatistics.getStatTrack().getMaxeDownDist())));
    	mSportTimeText3.setText( Utils.getTimeCnt(TypeStatistics.getStatTrack().getSportTime(),showSecondes));
//    	mPausedTimeText3.setText(Utils.getTimeCnt( TypeStatistics.getStatTrack().getMaxPause(),showSecondes));
    	mTotalTimeText3.setText(Utils.getTimeCnt(TypeStatistics.getStatTrack().getTotalTime(),showSecondes));
//    	mOffTimeText3.setText(Utils.getTimeCnt( TypeStatistics.getStatTrack().getMaxOffTime(),showSecondes));
    	mRdText3.setText(String.format("%.2f",TypeStatistics.getStatTrack().getMaxR()/1000));
    	if(	TypeStatistics.getStatTrack().getMinKmTime()>0)
    	 mKmTimeText3.setText(Utils.getTimeMS(TypeStatistics.getStatTrack().getMinKmTime()));
    	setTrackDetailAv();
        setSelectedTrackType();
	}
	
	/*
	 * av track
	 */
	protected void setTrackDetailAv()
	{
		mTopSpeedText4.setText(String.format("%.2f",TypeStatistics.getStatTrack().getAvtopSpeed()));
		mSpeedText4.setText(String.format("%.2f",TypeStatistics.getStatTrack().getAvavSpeed()));
		mtSpeedText4.setText(String.format("%.2f",TypeStatistics.getStatTrack().getAvTavSpeed()));
		mBurnText4.setText( String.format("%.0f", TypeStatistics.getStatTrack().getAvBurn()));

    	mDistanceText4.setText(String.format("%.2f",TypeStatistics.getStatTrack().getAvdist()/1000));	 
//    	mTotaleUpText4.setText(String.format("%.0f",TypeStatistics.getStatTrack().getAveUpDist()+TypeStatistics.getStatTrack().getAveDownDist()));
    	mTotaleUpText4.setText(String.format("%.0f",TypeStatistics.getStatTrack().getAveUpDist() ));
    	if(TypeStatistics.getStatTrack().getAvUpDist()>0){
	    	mTotalUpText4.setText(String.format("%.2f",TypeStatistics.getStatTrack().getAvUpDist()/1000 )); 
	    	mTotalDownText4.setText(String.format("%.2f",TypeStatistics.getStatTrack().getAvDownDist()/1000 )); 
	    	mMaxEleText4.setText(String.format("%.0f",TypeStatistics.getStatTrack().getAvMaxEle() )); 
	    	mMinEleText4.setText(String.format("%.0f",TypeStatistics.getStatTrack().getAvMinEle() )); 
    	}
//    	mTotaleDownText4.setText(String.format("%.0f", Math.abs(TypeStatistics.getStatTrack().getAveDownDist())));
    	mSportTimeText4.setText( Utils.getTimeCnt(TypeStatistics.getStatTrack().getAvsportTime(),showSecondes));
//    	mPausedTimeText4.setText(Utils.getTimeCnt( TypeStatistics.getStatTrack().getAvpause(),showSecondes));
    	mTotalTimeText4.setText(Utils.getTimeCnt(TypeStatistics.getStatTrack().getAvtotalTime(),showSecondes));
//    	mOffTimeText4.setText(Utils.getTimeCnt( TypeStatistics.getStatTrack().getAvoffTime(),showSecondes));
    	mRdText4.setText(String.format("%.2f",TypeStatistics.getStatTrack().getAvmaxR()/1000));
    	if(TypeStatistics.getStatTrack().getAvKmTime()>0)
    		mKmTimeText4.setText(Utils.getTimeMS(TypeStatistics.getStatTrack().getAvKmTime()));
    	setCurrentColors();
	}
	
	
	
	void setCurrentColors(){
		if(mDistanceText1==null ||currentStat==null)return;
		
		  mDistanceText1.setText(String.format("%.2f", currentStat.getDist()/1000.0 ));
		  int style =0;
		
		  style=currentStat.getDist()==TypeStatistics.getStatTrack().getDist()?R.style.topText_b:
			  currentStat.getDist()<TypeStatistics.getStatTrack().getAvdist()?R.style.lowText:0; 
		  if(style>0)
			  mDistanceText1.setTextAppearance(activity, style);
		  
		  style=currentStat.getMaxR()==TypeStatistics.getStatTrack().getMaxR()?R.style.topText_b:
			  currentStat.getMaxR()<TypeStatistics.getStatTrack().getAvmaxR()?R.style.lowText:0; 
		  if(style>0)
			  mRdText1.setTextAppearance(activity, style);		  
//	      mTotalTimeText1.setText(Utils.getTimeCnt(  currentStat.getTotalTime(),showSecondes));				    	
//	      mRdText1.setText(String.format("%.2f", currentStat.getMaxRdist()/1000.0 ));
 
	      if(mTrack.isLushu())
	    	  return;
	    	
	    if(mTrackStarTimeText==null)return;
	      
 
	   
		  style=currentStat.getTopSpeed()==TypeStatistics.getStatTrack().getTopSpeed()?R.style.topText_b:
			  currentStat.getTopSpeed()<TypeStatistics.getStatTrack().getAvtopSpeed()?R.style.lowText:0; 
		  if(style>0)
			  mTopSpeedText1.setTextAppearance(activity, style);		  
//		mTopSpeedText1.setText(String.format("%.2f", currentStat.getTopSpeed()));
		if(mSpeedText1!=null){
		
			 style=currentStat.getAvs()==TypeStatistics.getStatTrack().getAvSpeed()?R.style.topText_b:
				  currentStat.getAvs()<TypeStatistics.getStatTrack().getAvavSpeed()?R.style.lowText:0; 
			  if(style>0)
				  mSpeedText1.setTextAppearance(activity, style);		  
//			mSpeedText1.setText(String.format("%.2f", currentStat.getAVS() ));
		}
		

		 style=currentStat.getTavs()==TypeStatistics.getStatTrack().getTavSpeed()?R.style.topText_b:
			  currentStat.getTavs()<TypeStatistics.getStatTrack().getAvTavSpeed()?R.style.lowText:0; 
		  if(style>0)
			  mtSpeedText1.setTextAppearance(activity, style);			  
//		mtSpeedText1.setText( String.format("%.2f", currentStat.getTAVS() ));
		  
		if(mBurnText1!=null){
			 style=currentStat.getBurn()==TypeStatistics.getStatTrack().getBurn()?R.style.topText_b:
				  currentStat.getBurn()<TypeStatistics.getStatTrack().getAvBurn()?R.style.lowText:0; 
			  if(style>0)
				  mBurnText1.setTextAppearance(activity, style);	
//			mBurnText1.setText( String.format("%.0f", currentStat.getBurn() ));
		}
   		
   
		 style=currentStat.geteUpDist()==TypeStatistics.getStatTrack().getUpDistE()?R.style.topText_b:
			  currentStat.geteUpDist()<TypeStatistics.getStatTrack().getAveUpDist()?R.style.lowText:0; 
		  if(style>0)
			  mTotaleUpText1.setTextAppearance(activity, style);	
		  
//	   	mTotaleUpText1.setText(String.format("%.0f",currentStat.geteUpDist()));
	   	
	//   	mTotaleDownText1.setText(td_textView_eDown1);
	   	if(mSportTimeText1!=null){
	   	 style=currentStat.getSportTime()==TypeStatistics.getStatTrack().getSportTime()?R.style.topText_b:
			  currentStat.getSportTime()<TypeStatistics.getStatTrack().getAvsportTime()?R.style.lowText:0; 
		  if(style>0)
			  mSportTimeText1.setTextAppearance(activity, style);	
		  
//	   		mSportTimeText1.setText(Utils.getTimeCnt( currentStat.getSportTime(),showSecondes));
	   	}
	//   	mPausedTimeText1.setText(td_textView_paused_time1);  
	   	if(currentStat.getUpDist()>0 ){
	   		 style=currentStat.getUpDist()==TypeStatistics.getStatTrack().getUpDistE()?R.style.topText_b:
				  currentStat.getUpDist()<TypeStatistics.getStatTrack().getAvUpDist()?R.style.lowText:0; 
			  if(style>0)
				  mTotalUpText1.setTextAppearance(activity, style);	
			  
//			  mTotalUpText1.setText(String.format("%.2f",currentStat.getUpDist()/1000));	
				 style=currentStat.getDownDist()==TypeStatistics.getStatTrack().getDownDist()?R.style.topText_b:
					  currentStat.getDownDist()<TypeStatistics.getStatTrack().getAvDownDist()?R.style.lowText:0; 
				  if(style>0)
					  mTotalDownText1.setTextAppearance(activity, style);	
				  
//		    	mTotalDownText1.setText(String.format("%.2f",currentStat.getDownDist()/1000));
				  style=currentStat.getMaxEle()==TypeStatistics.getStatTrack().getMaxEle()?R.style.topText_b:
					  currentStat.getMaxEle()<TypeStatistics.getStatTrack().getAvMaxEle()?R.style.lowText:0; 
				  if(style>0)
					  mMaxEleText1.setTextAppearance(activity, style);	
				  
//		    	mMaxEleText1.setText(String.format("%.0f",currentStat.getMaxEle()));
		    	/* style=currentStat.getMinEle()==TypeStatistics.getStatTrack().getMaxMinEle()?R.style.topText_b:
					  currentStat.getMinEle()>TypeStatistics.getStatTrack().getAvMinEle()?R.style.lowText:0; 
				  if(style>0)
					  mMinEleText1.setTextAppearance(activity, style);	*/
				  
//		    	mMinEleText1.setText(String.format("%.0f",currentStat.getMinEle()));
	   	}
	   	
	    style=currentStat.getKmTime()==TypeStatistics.getStatTrack().getMinKmTime()?R.style.topText_b:
			  currentStat.getKmTime()>TypeStatistics.getStatTrack().getAvKmTime()?R.style.lowText:0; 
		  if(style>0)
			  mKmTimeText1.setTextAppearance(activity, style);	
		  
//	   	mKmTimeText1.setText(Utils.getTimeMS(currentStat.getKmTime()));	 
	}
	
	
	 
/*    private ImageGetter imageGetter = new ImageGetter() {
        @Override
        public Drawable getDrawable(String source) {
//                int id = Integer.parseInt(source);//source为图片id。比如  R.id.tupian
        	   
                Drawable d = null;
                try {
                        d =  Drawable.createFromPath(source);// getResources().getDrawable(id);
                } catch (Exception ex) {
                        ex.printStackTrace();
                }
              if(d!=null)  d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
                return d;
        }
};*/
	
    
    /*void saveTrack() {
    	boolean isSaveAble=false;
    	isSaveAble = mCommentEdit.getText().toString().equalsIgnoreCase(app.getCurrentTrack().getTrackBean().getComment());
    	isSaveAble = isSaveAble || mDescEdit.getText().toString().equalsIgnoreCase(app.getCurrentTrack().getTrackBean().getDescription());
    	isSaveAble = isSaveAble  || mNameEdit.getText().toString().equalsIgnoreCase(app.getCurrentTrack().getTrackBean().getName());
    	isSaveAble = isSaveAble  ||trackType==app.getCurrentTrack().getTrackBean().getType().toInt();
        
    	if(!isSaveAble ){
    		Toast.makeText(activity,"没有变更需要保存。", Toast.LENGTH_SHORT).show();	
    		return;	 
    	}
        
    	getTrackDetailUpdated();
    	Intent serviceIntent = new Intent(activity, TrackDbServiceBackground.class);	   
	    serviceIntent.putExtra(QiYouConstant.UPDATE_TRACK, trackId);
	   // serviceIntent.putExtra(QiYouConstant.EXTRA_KEY_FORCEREFRESH, true);        
	    activity.startService(serviceIntent);
	    Toast.makeText(activity,"变更已成功保存。", Toast.LENGTH_SHORT).show();
    }
     */

    
  
    private ArrayAdapter<?> spAdapter;
    
    @Override
	void initTrackTypeSpin(){
    	
    	int type_array=  Utils.getTrackType();//R.array.trackType;
//    	if(QiYouConstant.DEVELOPER_MODE)
//    		type_array =R.array.trackType_develop_use;
//
     
    	spDetailTrackType = (Spinner)vContainer.findViewById(R.id.SpinnerTrackType);
    	
    	if(spDetailTrackType==null)return;
		spDetailTrackType.setVisibility(View.VISIBLE);	
		 
		//将可选内容与ArrayAdapter连接起来
    	spAdapter = QArrayAdapter.createFromResource( getActivity(), type_array, android.R.layout.simple_spinner_item);

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

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

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

		//设置默认值
//    	spDetailTrackType.setVisibility(View.VISIBLE);

	} 
 //     int trackType;
	class SpinnerXMLSelectedListener implements OnItemSelectedListener{
		@Override
		public void onItemSelected(AdapterView<?> spinner, View textView, int spID,
				long arg3) { 
			  switch (spinner.getId() ){ 
				case R.id.SpinnerTrackType: {
					oTrackType = activity.app.getCurrentTrack().getTrackBean().getType().toInt();
					activity.app.getCurrentTrack().getTrackBean().setType(TrackType.valueOf(spID));
					mTrackType.setText(spDetailTrackType.getSelectedItem().toString());
            		}
				 
				break;		            	
				}
			  }

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub
			
		}
			
	 } 
	   @Override
	void setSelectedTrackType(){ 
//		   spDetailTrackType.setSelection(activity.app.getCurrentTrack().getTrackBean().getType().toInt());
		  /* spDetailTrackType.setSelection(inType);
 	   
		   mTrackType.setText(spDetailTrackType.getSelectedItem().toString());
		   */
		   
		   if(inType< spDetailTrackType.getCount()){
			   spDetailTrackType.setSelection(inType);	 
		   }else
			   spDetailTrackType.setSelection(spDetailTrackType.getCount()-1);
		   
		   mTrackType.setText(spDetailTrackType.getSelectedItem().toString());
//		   spDetailTrackType.setEnabled(inType!=TrackType.GPX.toInt() );//||QiYouConstant.DEVELOPER_MODE);
	   }
	   void getStatTracks(){
 
			TypeStatistics = new TypeStatistics();
			if(activity.app.getStatisticsTrack(inType)==null) return;//no records for selected type or date.
 		
	 
			
			 ConcurrentHashMap<Integer,Statics_bean> sbs =activity.app.getStatisticsTrack(inType).getSbs();
			 Statics_bean sb;
			 
			 for(Integer key :sbs.keySet()){
				 sb=sbs.get(key); 
				 if(sb==null)continue; 
				 		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.setUpDistE( sb.geteUpDist());
				st.setTopSpeed(sb.getTopSpeed() );		       
				st.setPause(sb.getPause() );
				st.setOffTime( sb.getOffTime()); 
				st.setDist(sb.getDist());	 
	    		st.setMaxR( sb.getMaxR());
	    		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();
			 
		
		}
		
	   
	   void getStatTrack(){
//			TypeStatistics =activity.app.getTracksStat(mTrack_bean.getType().toInt(), 0, 0);
		   TypeStatistics =activity.app.getTracksStat(inType, 0, 0);
 
			QLog.getLogger().d(dTAG, TAG+  " -------------------Get StatTrack. -------------"  );
		}
	   
		 
			@Override	 
			void showTabs(boolean isVisible ){ 
				
				if(trackId==0)return;
				if(tabhost==null)return;
				
			 	 String title=isVisible?tabData:trackId>0?"数据加载中。。。":tabData;//"定位成功后将自动开始";
				
				TextView textview = (TextView)tabhost.getTabWidget().getChildAt(0).findViewById(android.R.id.title);			
//	 			textview.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
				textview.setText(title);  
				
				
				int visible = isVisible?View.VISIBLE:View.GONE;
				for(int i=1;i<tabhost.getTabWidget().getChildCount();i++){
					
//					if( tabhost.getTabWidget().getChildAt(i).getId() == R.id.tab_toolbar)continue;
				
			    	 tabhost.getTabWidget().getChildAt(i).setVisibility(visible);
				} 
				
				/*if(isPlayback){ //hide the edit tab for playback
					tabhost.getTabWidget().getChildAt(tabhost.getTabWidget().getChildCount()-1).setVisibility(View.GONE);
				}*/
				
				/*if(trackId==0){ //show map while connecting to GPS.
					 tabhost.getTabWidget().getChildAt(2).setVisibility(View.VISIBLE);
//					 textview = (TextView)tabhost.getTabWidget().getChildAt(2).findViewById(android.R.id.title);			
//					 textview.setText(""); 
				}*/
				
			}
			void setSvrNo(int svrNo){
				 mTrackId.setText(svrNo);
			}
			@Override
			void processJsonObject(String method,JSONObject jsonObject,String msg)throws JSONException{ 
				super.processJsonObject(  method,jsonObject,  msg);
			 /*	handler = new Handler(){

					@Override
					public void handleMessage(Message msg) {
						
						//关闭ProgressDialog
//						progressDialog.dismiss();
						
						if(msg.what==0){
						//更新UI
							mTrackId.setText(mTrack_bean.getSvrNumber());
						}
						else if(msg.what==1){
							 
						}
					}};*/
				 int svrNo= jsonObject.getInt("svrNumber"); 
				 if(svrNo>0){
					 mTrackId.setText(String.valueOf(svrNo));
					 btnUpload.setText("更新云端");
//					 handler.sendEmptyMessage(0);
					 
				 }
				 
			}
			
		/*	@Override
			void showSpeedKmChart(int type){
				Intent intent =  new Intent(activity, ChartSpeedKm.class);
				 Bundle bundle=new Bundle(); 
			    bundle.putInt("type", type);
			    intent.putExtras(bundle);
				activity.startActivity(intent);
				
			};*/
			
	   @Override
		public void onResume() {
//		   setTrackDesc();
			super.onResume();
			if(editNewCate!=null){
				editNewCate.clearFocus();
			}
			
//			if(mTrack_bean.getAvStatus()!=TrackAvStatus.ACTIVE){
			if(!this.isWebRequest && mTrack_bean.getAvStatus()==TrackAvStatus.DELETED){
				activity.showTrackStatics();
			}
//			activity.updateActionBarTitle( getResources().getString(R.string.frg_trackdetail)+ "    编号"+trackId);
			int title=isWebRequest?R.string.frg_trackWeb
					:inflat_source ==R.layout.gpx_lushu_fragment?R.string.frg_trackLushu:R.string.frg_trackdetail;

//			activity.updateActionBarTitle( getResources().getString(R.string.frg_trackdetail)+ "  "+mTrack_bean.getName());
			activity.updateActionBarTitle( getResources().getString(title)+ "｜"+mTrack_bean.getName());
//		   	activity.app.currentActiveFragment =getFTag();    
		   	validEditButtons();
//		    activity.app.canSendLocation2UI =false;
		    activity.app.updateUIstatus(false);
		    setWorkingTrack();
		    Utils.hideSoftKeyboard(activity);
//		    activity.updateTabVisibility(false);
//		 	mRecTrack = activity.app.getCurrentTrack().getTrackBean(); 
//		   	drawTrack=true;
//		   	drawTrack(); 
//		    mMapView.onResume();
//		    setSelectedTrackType();
		    QLog.getLogger().d(dTAG," 当前用户id "+ activity.app.user.getUserbean().getId() );
		    if(isForShare &&mTrack.getTrackBean().getTrackId()>0 && activity.app.user.getUserbean().getId()>0){		    	
//				 isForShare	 =false;
				this.uploadTrack(mTrack); 
			 }
		}
		
		
		
		 @Override
			public void onPause() {
//			 activity.updateTabVisibility(true);
				super.onPause(); 

			}
		 @Override
			public void onDestroy() {  
				super.onDestroy();
			}

		@Override
		public void onSaveInstanceState(Bundle outState) {
			super.onSaveInstanceState(outState); 
		}
		@Override
		public void setTabOnFiling() {
			 MAPVIEW_INDEX=2;
			 maxTabIndex = 2;
			
		} 	
		@Override
		public boolean isShowBottomTabs() {
			// TODO Auto-generated method stub
//			activity.updateActionBar(true );
			return false;
		}
		
		
		
		//to get trackList can be merged
		
	/*	
	    private  String whereClause=" 1=1 ";
		@Override
		public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
			 String[] projection = new String[] {TrackProvider.KEY_ID,TrackProvider.KEY_TRACK_NAME };
		    String orderby =( TrackProvider.KEY_ID +" DESC");
		    whereClause+=" and ( ifnull(" + TrackProvider.KEY_TRACK_AVSTATUS +","+TrackAvStatus.ACTIVE +")="  +TrackAvStatus.ACTIVE   +
					" OR " + TrackProvider.KEY_TRACK_AVSTATUS+" = "+TrackAvStatus.ACTIVE +")";
		    whereClause += " and TrackProvider.KEY_ID >"+ trackId;
		    return new CursorLoader(activity, TrackProvider.TRACKS_URI, 
		    		projection, whereClause, null,   orderby);
	  
		}
		@Override
		public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
			// TODO Auto-generated method stub
			
		}
		@Override
		public void onLoaderReset(Loader<Cursor> arg0) {
			// TODO Auto-generated method stub
			
		}*/
}
