/**
 * 
 */
package com.qiyou.mb.android.receivers;
import java.util.ArrayList;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.qiyou.mb.android.QiYouConstant;
import com.qiyou.mb.android.service.TrackDbServiceBackground;
import com.qiyou.mb.android.utils.log.QLog;
//import com.qiyou.mb.android.service.TrackDbService;

/**
 * @author mwang
 *
 */
public class NewWaypointsReceiver extends BroadcastReceiver {

	public static String TAG ="com.qiyou.NEW_WAYPOINTS_RECEIVER";
	public static final String dTAG ="com.qiyou";
	  
	/**
	 * 
	 */
	public NewWaypointsReceiver() {
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
	 */
	@Override
	public void onReceive(Context context, Intent intent) {	 

		    //location service -->track service     
		    String key = QiYouConstant.NEW_LOCATION; 
		    if (intent.hasExtra(key)) {
//		    	QLog.getLogger().d(dTAG,TAG+" "+"LocationService Receiver got noticed, and sending to TrackService for db update");
		    	@SuppressWarnings("unchecked")
				ArrayList<String> locLst = (ArrayList<String>) intent.getExtras().get(key) ;
		      // This update came from Passive provider, so we can extract the location
		      // directly.
		    //  location = (Location)intent.getExtras().get(key);
//		       String JsonWp = intent.getExtras().get(key).toString();
//		       ArrayList<String> locLst = (ArrayList<String>)(intent.getExtras().getParcelable(QiYouConstant.NEW_LOCATION));
		       Intent serviceIntent = new Intent(context, TrackDbServiceBackground.class);
		       serviceIntent.putExtra(key, locLst);
		       context.startService(serviceIntent); 
//		      return;
		    } 
		    //from locationservice to trackservice
		    key = QiYouConstant.EXTRA_KEY_FORCE_UPDATE; 
		    if (intent.hasExtra(key)) { 
		    	QLog.getLogger().d(dTAG,TAG+" "+ "Force update Receiver got noticed, and sending to TrackService for db update");
		    	QLog.getLogger().d("Force_update", "Force update Receiver got noticed, and sending to TrackService for db update");
				
		    	Intent serviceIntent = new Intent(context, TrackDbServiceBackground.class);
		       serviceIntent.putExtra(key, true);
		       context.startService(serviceIntent); 
		      
		    } 
		    
		   /* key = QiYouConstant.EXTRA_KEY_FORCE_UPDATE_STAT; 
		    if (intent.hasExtra(key)) { 
		    	QLog.getLogger().dLog(dTAG,TAG+"  begin to update track statics");
		    	 
		       Intent serviceIntent = new Intent(context, TrackDbServiceBackground.class);
		       serviceIntent.putExtra(key, true);
		       context.startService(serviceIntent); 
		      
		    } */
		    
		  
		  
	}

}
