package edu.berkeley.eecs.emission.cordova.tracker.location.actions;

import java.util.ArrayList;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.google.android.gms.location.ActivityTransition;
import com.google.android.gms.location.ActivityTransitionRequest;
import com.google.android.gms.location.DetectedActivity;
import com.google.android.gms.location.ActivityRecognition;
import com.google.android.gms.tasks.Task;

import edu.berkeley.eecs.emission.cordova.tracker.ConfigManager;
import edu.berkeley.eecs.emission.cordova.tracker.location.TripDiaryStateMachineForegroundService;
import edu.berkeley.eecs.emission.cordova.unifiedlogger.Log;
import edu.berkeley.eecs.emission.cordova.tracker.location.OPGeofenceExitActivityIntentService;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by shankari on 12/31/14.
 */
public class OPGeofenceExitActivityActions {
    private static final int ACTIVITY_IN_NUMBERS = 22848489;
    private int ACTIVITY_DETECTION_INTERVAL;

    private static final String TAG = "OPGeofenceExitActivityActions";

    private Context mCtxt;

    public OPGeofenceExitActivityActions(Context context) {
        this.mCtxt = context;
        ACTIVITY_DETECTION_INTERVAL = ConfigManager.getConfig(context).getFilterTime();
    }

    public Task<Void> start() {
        List<ActivityTransition> activityTransitionList = new ArrayList<ActivityTransition>();
        activityTransitionList.add(new ActivityTransition.Builder()
                .setActivityType(DetectedActivity.WALKING)
                .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
                .build());
        activityTransitionList.add(new ActivityTransition.Builder()
                .setActivityType(DetectedActivity.ON_BICYCLE)
                .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
                .build());
        activityTransitionList.add(new ActivityTransition.Builder()
                .setActivityType(DetectedActivity.RUNNING)
                .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
                .build());
        activityTransitionList.add(new ActivityTransition.Builder()
                .setActivityType(DetectedActivity.IN_VEHICLE)
                .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
                .build());
        activityTransitionList.add(new ActivityTransition.Builder()
                .setActivityType(DetectedActivity.STILL)
                .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
                .build());
        
        Log.d(mCtxt, TAG, "Starting activity transitions for list = "+activityTransitionList);
        ActivityTransitionRequest request = new ActivityTransitionRequest(activityTransitionList);
        return ActivityRecognition.getClient(mCtxt).requestActivityTransitionUpdates(request,
                getActivityTransitionPendingIntent(mCtxt));
    }

    public static PendingIntent getActivityTransitionPendingIntent(Context ctxt) {
        Intent innerIntent = new Intent(ctxt, OPGeofenceExitActivityIntentService.class);
		/*
		 * Setting FLAG_UPDATE_CURRENT so that sending the PendingIntent again updates the original.
		 * We only want to have one geofence active at one point of time.
		 */
        return TripDiaryStateMachineForegroundService.getProperPendingIntent(ctxt, innerIntent);
    }

    public Task<Void> stop() {
        Log.d(mCtxt, TAG, "Stopping activity recognition with interval = "+ACTIVITY_DETECTION_INTERVAL);
        return ActivityRecognition.getClient(mCtxt).removeActivityTransitionUpdates(
                getActivityTransitionPendingIntent(mCtxt));
    }
}

@@ -942,115 +942,8 @@
 s %7B%0A
-    private static final int ACTIVITY_IN_NUMBERS = 22848489;%0A    private int ACTIVITY_DETECTION_INTERVAL;%0A%0A
     
@@ -1132,96 +1132,8 @@
 xt;%0A
-        ACTIVITY_DETECTION_INTERVAL = ConfigManager.getConfig(context).getFilterTime();%0A
     
@@ -3311,113 +3311,8 @@
 ) %7B%0A
-        Log.d(mCtxt, TAG, %22Stopping activity recognition with interval = %22+ACTIVITY_DETECTION_INTERVAL);%0A
     

Remove unused variables copied over from the original activity recognition actions