package com.qiyou.mb.android.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.qiyou.mb.android.QiYouConstant;
import com.qiyou.mb.android.service.TimtickService;
import com.qiyou.mb.android.utils.log.QLog;

public class TimeTickReceiver extends BroadcastReceiver {

	public static String TAG ="com.qiyou.TimeTickReceiver"; 
    public static final String dTAG ="com.qiyou"; 
	 @Override
    public void onReceive(Context context, Intent intent) {
			QLog.getLogger().d(dTAG,TAG+".......TimeTickReceiver....... intent.getAction() " +intent.getAction());
			if (intent.getAction().equals(Intent.ACTION_TIME_TICK)) {
				  Intent serviceIntent = new Intent(context, TimtickService.class); 
				  
				  SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
				  long lastStart = settings.getLong(QiYouConstant.PK_LONG_LAST_TRACK_START,-1);
				  if(lastStart <=0){
					  context.stopService(serviceIntent);
					  return;
				  }
				  
				  String  key = QiYouConstant.EXTRA_KEY_TICK_UPDATE;		 
			     
			       serviceIntent.putExtra(key, true);
			       context.startService(serviceIntent);
//			     if(QiYouConstant.DEVELOPER_MODE)   Utils.logStackTrace(new Exception("it is for debug only...to start TimtickService...for checking gps "),dTAG); 
			} 
    }
}
