package com.koeping.lukas.sensordatacollector;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.hardware.SensorManager;


public class SensorService extends IntentService {
    private SensorDataWriter sdw;
    private SensorDataCollector sdc;
    private SensorManager sensorManager;
    private String directory_name;
    private long startTime;

    public SensorService () {
        super("SensorService");

    }

    @Override
    public void onDestroy() {
        sdw.closeWriters();
        this.sensorManager.unregisterListener(sdc);
    }


    @Override
    public int onStartCommand(Intent intent, int flags, int startID) {
        this.directory_name = intent.getStringExtra("directory_name");
        this.startTime = intent.getLongExtra("startTime", 0);
        sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        sdw = new SensorDataWriter(this.directory_name);
        sdc = new SensorDataCollector(sdw, sensorManager, this.startTime);

        return START_STICKY;
    }



    @Override
    protected void onHandleIntent(Intent intent) {
        while(true) {
            //SensorDataCollector is doing the work and is called in onCreate
        }

    }
}
